aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acorn/block/fd1772.c4
-rw-r--r--drivers/acorn/block/mfmhd.c2
-rw-r--r--drivers/acpi/Kconfig54
-rw-r--r--drivers/acpi/ac.c9
-rw-r--r--drivers/acpi/acpi_memhotplug.c8
-rw-r--r--drivers/acpi/asus_acpi.c11
-rw-r--r--drivers/acpi/battery.c9
-rw-r--r--drivers/acpi/button.c12
-rw-r--r--drivers/acpi/container.c10
-rw-r--r--drivers/acpi/ec.c8
-rw-r--r--drivers/acpi/events/evrgnini.c2
-rw-r--r--drivers/acpi/fan.c8
-rw-r--r--drivers/acpi/namespace/nsxfeval.c2
-rw-r--r--drivers/acpi/pci_link.c9
-rw-r--r--drivers/acpi/pci_root.c9
-rw-r--r--drivers/acpi/power.c8
-rw-r--r--drivers/acpi/processor_core.c8
-rw-r--r--drivers/acpi/processor_throttling.c59
-rw-r--r--drivers/acpi/sbs.c10
-rw-r--r--drivers/acpi/scan.c156
-rw-r--r--drivers/acpi/sleep/Makefile2
-rw-r--r--drivers/acpi/sleep/main.c244
-rw-r--r--drivers/acpi/sleep/proc.c24
-rw-r--r--drivers/acpi/sleep/sleep.h2
-rw-r--r--drivers/acpi/sleep/wakeup.c2
-rw-r--r--drivers/acpi/thermal.c8
-rw-r--r--drivers/acpi/utilities/uteval.c4
-rw-r--r--drivers/acpi/video.c8
-rw-r--r--drivers/ata/ata_piix.c113
-rw-r--r--drivers/ata/libata-scsi.c2
-rw-r--r--drivers/ata/pata_ali.c2
-rw-r--r--drivers/ata/pata_hpt37x.c14
-rw-r--r--drivers/base/power/Makefile2
-rw-r--r--drivers/base/power/power.h4
-rw-r--r--drivers/base/power/shutdown.c2
-rw-r--r--drivers/block/amiflop.c2
-rw-r--r--drivers/block/aoe/aoe.h2
-rw-r--r--drivers/block/aoe/aoeblk.c2
-rw-r--r--drivers/block/ataflop.c2
-rw-r--r--drivers/block/cciss.c10
-rw-r--r--drivers/block/cpqarray.c6
-rw-r--r--drivers/block/floppy.c4
-rw-r--r--drivers/block/lguest_blk.c171
-rw-r--r--drivers/block/loop.c4
-rw-r--r--drivers/block/nbd.c4
-rw-r--r--drivers/block/paride/pcd.c4
-rw-r--r--drivers/block/paride/pd.c2
-rw-r--r--drivers/block/paride/pf.c4
-rw-r--r--drivers/block/pktcdvd.c12
-rw-r--r--drivers/block/ps2esdi.c4
-rw-r--r--drivers/block/ps3disk.c8
-rw-r--r--drivers/block/rd.c2
-rw-r--r--drivers/block/sunvdc.c2
-rw-r--r--drivers/block/swim3.c4
-rw-r--r--drivers/block/sx8.c20
-rw-r--r--drivers/block/ub.c6
-rw-r--r--drivers/block/umem.c6
-rw-r--r--drivers/block/viodasd.c2
-rw-r--r--drivers/block/xd.c2
-rw-r--r--drivers/block/xd.h2
-rw-r--r--drivers/block/xen-blkfront.c4
-rw-r--r--drivers/block/xsysace.c4
-rw-r--r--drivers/block/z2ram.c2
-rw-r--r--drivers/cdrom/cdrom.c2
-rw-r--r--drivers/cdrom/viocd.c2
-rw-r--r--drivers/char/Kconfig25
-rw-r--r--drivers/char/Makefile3
-rw-r--r--drivers/char/agp/Kconfig2
-rw-r--r--drivers/char/agp/ati-agp.c9
-rw-r--r--drivers/char/agp/compat_ioctl.c1
-rw-r--r--drivers/char/agp/frontend.c1
-rw-r--r--drivers/char/agp/generic.c2
-rw-r--r--drivers/char/agp/intel-agp.c19
-rw-r--r--drivers/char/agp/sgi-agp.c1
-rw-r--r--drivers/char/hpet.c10
-rw-r--r--drivers/char/hvc_lguest.c80
-rw-r--r--drivers/char/mmtimer.c1
-rw-r--r--drivers/char/mspec.c1
-rw-r--r--drivers/edac/Kconfig4
-rw-r--r--drivers/edac/edac_mc.c64
-rw-r--r--drivers/edac/edac_mc_sysfs.c19
-rw-r--r--drivers/edac/edac_module.h8
-rw-r--r--drivers/edac/edac_pci.c162
-rw-r--r--drivers/edac/edac_pci_sysfs.c297
-rw-r--r--drivers/edac/i3000_edac.c2
-rw-r--r--drivers/i2c/busses/Kconfig4
-rw-r--r--drivers/i2c/chips/ds1682.c3
-rw-r--r--drivers/i2c/chips/tps65010.c2
-rw-r--r--drivers/ide/ide-cd.c4
-rw-r--r--drivers/ide/ide-disk.c4
-rw-r--r--drivers/ide/ide-io.c2
-rw-r--r--drivers/ide/ide-probe.c2
-rw-r--r--drivers/ide/legacy/hd.c2
-rw-r--r--drivers/ide/pci/scc_pata.c4
-rw-r--r--drivers/ieee1394/raw1394.c2
-rw-r--r--drivers/infiniband/hw/ipath/ipath_diag.c1
-rw-r--r--drivers/input/misc/atlas_btns.c9
-rw-r--r--drivers/input/serio/Kconfig2
-rw-r--r--drivers/kvm/kvm_main.c44
-rw-r--r--drivers/kvm/x86_emulate.c2
-rw-r--r--drivers/lguest/Makefile12
-rw-r--r--drivers/lguest/README47
-rw-r--r--drivers/lguest/core.c357
-rw-r--r--drivers/lguest/hypercalls.c144
-rw-r--r--drivers/lguest/interrupts_and_traps.c212
-rw-r--r--drivers/lguest/io.c265
-rw-r--r--drivers/lguest/lg.h47
-rw-r--r--drivers/lguest/lguest.c535
-rw-r--r--drivers/lguest/lguest_asm.S71
-rw-r--r--drivers/lguest/lguest_bus.c75
-rw-r--r--drivers/lguest/lguest_user.c166
-rw-r--r--drivers/lguest/page_tables.c329
-rw-r--r--drivers/lguest/segments.c126
-rw-r--r--drivers/lguest/switcher.S284
-rw-r--r--drivers/md/dm-table.c8
-rw-r--r--drivers/md/dm.c10
-rw-r--r--drivers/md/faulty.c2
-rw-r--r--drivers/md/linear.c14
-rw-r--r--drivers/md/md.c2
-rw-r--r--drivers/md/multipath.c12
-rw-r--r--drivers/md/raid0.c14
-rw-r--r--drivers/md/raid1.c12
-rw-r--r--drivers/md/raid10.c14
-rw-r--r--drivers/md/raid5.c18
-rw-r--r--drivers/media/video/Kconfig4
-rw-r--r--drivers/message/i2o/i2o_block.c4
-rw-r--r--drivers/misc/asus-laptop.c41
-rw-r--r--drivers/misc/sony-laptop.c21
-rw-r--r--drivers/misc/thinkpad_acpi.c20
-rw-r--r--drivers/misc/thinkpad_acpi.h2
-rw-r--r--drivers/mmc/card/queue.c10
-rw-r--r--drivers/mmc/core/bus.c23
-rw-r--r--drivers/mmc/core/core.c144
-rw-r--r--drivers/mmc/core/core.h22
-rw-r--r--drivers/mmc/core/host.c7
-rw-r--r--drivers/mmc/core/mmc.c26
-rw-r--r--drivers/mmc/core/mmc_ops.c2
-rw-r--r--drivers/mmc/core/mmc_ops.h2
-rw-r--r--drivers/mmc/core/sd.c36
-rw-r--r--drivers/mmc/core/sd_ops.c62
-rw-r--r--drivers/mmc/core/sd_ops.h3
-rw-r--r--drivers/mmc/host/at91_mci.c2
-rw-r--r--drivers/mmc/host/au1xmmc.c2
-rw-r--r--drivers/mmc/host/imxmmc.c2
-rw-r--r--drivers/mmc/host/mmci.c2
-rw-r--r--drivers/mmc/host/mmci.h2
-rw-r--r--drivers/mmc/host/omap.c2
-rw-r--r--drivers/mmc/host/pxamci.c2
-rw-r--r--drivers/mmc/host/sdhci.c63
-rw-r--r--drivers/mmc/host/sdhci.h2
-rw-r--r--drivers/mmc/host/wbsd.c15
-rw-r--r--drivers/mmc/host/wbsd.h2
-rw-r--r--drivers/mtd/maps/Kconfig2
-rw-r--r--drivers/net/82596.c1
-rw-r--r--drivers/net/Makefile2
-rw-r--r--drivers/net/acenic.c6
-rw-r--r--drivers/net/atl1/atl1_hw.h9
-rw-r--r--drivers/net/atl1/atl1_main.c28
-rw-r--r--drivers/net/ax88796.c2
-rw-r--r--drivers/net/bfin_mac.c6
-rw-r--r--drivers/net/cxgb3/cxgb3_offload.c2
-rw-r--r--drivers/net/defxx.c17
-rw-r--r--drivers/net/ehea/ehea.h2
-rw-r--r--drivers/net/ehea/ehea_main.c22
-rw-r--r--drivers/net/forcedeth.c16
-rw-r--r--drivers/net/lguest_net.c237
-rw-r--r--drivers/net/lib8390.c9
-rw-r--r--drivers/net/netxen/netxen_nic.h3
-rw-r--r--drivers/net/netxen/netxen_nic_main.c48
-rw-r--r--drivers/net/phy/vitesse.c2
-rw-r--r--drivers/net/pppol2tp.c4
-rw-r--r--drivers/net/ps3_gelic_net.c215
-rw-r--r--drivers/net/ps3_gelic_net.h24
-rw-r--r--drivers/net/ucc_geth.c334
-rw-r--r--drivers/net/ucc_geth.h6
-rw-r--r--drivers/net/ucc_geth_ethtool.c388
-rw-r--r--drivers/net/ucc_geth_mii.c6
-rw-r--r--drivers/pci/pci-acpi.c32
-rw-r--r--drivers/pci/pci.c9
-rw-r--r--drivers/pci/pci.h3
-rw-r--r--drivers/pnp/card.c166
-rw-r--r--drivers/pnp/core.c50
-rw-r--r--drivers/pnp/driver.c75
-rw-r--r--drivers/pnp/interface.c217
-rw-r--r--drivers/pnp/isapnp/compat.c39
-rw-r--r--drivers/pnp/isapnp/core.c332
-rw-r--r--drivers/pnp/isapnp/proc.c21
-rw-r--r--drivers/pnp/manager.c144
-rw-r--r--drivers/pnp/pnpacpi/core.c117
-rw-r--r--drivers/pnp/pnpacpi/rsparser.c441
-rw-r--r--drivers/pnp/pnpbios/bioscalls.c339
-rw-r--r--drivers/pnp/pnpbios/core.c257
-rw-r--r--drivers/pnp/pnpbios/proc.c107
-rw-r--r--drivers/pnp/pnpbios/rsparser.c349
-rw-r--r--drivers/pnp/quirks.c80
-rw-r--r--drivers/pnp/resource.c102
-rw-r--r--drivers/pnp/support.c17
-rw-r--r--drivers/pnp/system.c40
-rw-r--r--drivers/rtc/Makefile42
-rw-r--r--drivers/rtc/class.c5
-rw-r--r--drivers/rtc/rtc-bfin.c2
-rw-r--r--drivers/rtc/rtc-ds1307.c2
-rw-r--r--drivers/rtc/rtc-stk17ta8.c6
-rw-r--r--drivers/s390/block/dasd.c4
-rw-r--r--drivers/s390/block/dasd_int.h2
-rw-r--r--drivers/s390/block/dcssblk.c2
-rw-r--r--drivers/s390/block/xpram.c2
-rw-r--r--drivers/s390/char/Kconfig12
-rw-r--r--drivers/s390/char/raw3270.c6
-rw-r--r--drivers/s390/char/sclp_vt220.c62
-rw-r--r--drivers/s390/char/tape.h2
-rw-r--r--drivers/s390/char/tape_block.c4
-rw-r--r--drivers/s390/char/vmur.c2
-rw-r--r--drivers/s390/cio/blacklist.c19
-rw-r--r--drivers/s390/cio/ccwgroup.c3
-rw-r--r--drivers/s390/cio/chp.c19
-rw-r--r--drivers/s390/cio/chsc.c26
-rw-r--r--drivers/s390/cio/chsc.h2
-rw-r--r--drivers/s390/cio/cio.c13
-rw-r--r--drivers/s390/cio/cio_debug.h2
-rw-r--r--drivers/s390/cio/cmf.c16
-rw-r--r--drivers/s390/cio/css.c32
-rw-r--r--drivers/s390/cio/css.h1
-rw-r--r--drivers/s390/cio/device.c60
-rw-r--r--drivers/s390/cio/device_fsm.c20
-rw-r--r--drivers/s390/cio/device_ops.c257
-rw-r--r--drivers/s390/net/ctcmain.c6
-rw-r--r--drivers/s390/net/netiucv.c4
-rw-r--r--drivers/sbus/char/Kconfig1
-rw-r--r--drivers/sbus/char/jsflash.c2
-rw-r--r--drivers/scsi/scsi_lib.c12
-rw-r--r--drivers/scsi/sd.c4
-rw-r--r--drivers/scsi/sr.c2
-rw-r--r--drivers/serial/68328serial.c71
-rw-r--r--drivers/serial/8250.c5
-rw-r--r--drivers/serial/8250_early.c10
-rw-r--r--drivers/serial/serial_core.c9
-rw-r--r--drivers/spi/spi_s3c24xx.c2
-rw-r--r--drivers/video/Kconfig9
-rw-r--r--drivers/video/chipsfb.c3
-rw-r--r--drivers/video/tgafb.c2
-rw-r--r--drivers/w1/masters/ds1wm.c2
-rw-r--r--drivers/xen/xenbus/xenbus_xs.c2
243 files changed, 7040 insertions, 3290 deletions
diff --git a/drivers/acorn/block/fd1772.c b/drivers/acorn/block/fd1772.c
index 423ed08fb6f7..d7e18ce8dad9 100644
--- a/drivers/acorn/block/fd1772.c
+++ b/drivers/acorn/block/fd1772.c
@@ -372,7 +372,7 @@ static int fd_test_drive_present(int drive);
372static void config_types(void); 372static void config_types(void);
373static int floppy_open(struct inode *inode, struct file *filp); 373static int floppy_open(struct inode *inode, struct file *filp);
374static int floppy_release(struct inode *inode, struct file *filp); 374static int floppy_release(struct inode *inode, struct file *filp);
375static void do_fd_request(request_queue_t *); 375static void do_fd_request(struct request_queue *);
376 376
377/************************* End of Prototypes **************************/ 377/************************* End of Prototypes **************************/
378 378
@@ -1271,7 +1271,7 @@ static void fd1772_checkint(void)
1271 } 1271 }
1272} 1272}
1273 1273
1274static void do_fd_request(request_queue_t* q) 1274static void do_fd_request(struct request_queue* q)
1275{ 1275{
1276 unsigned long flags; 1276 unsigned long flags;
1277 1277
diff --git a/drivers/acorn/block/mfmhd.c b/drivers/acorn/block/mfmhd.c
index d85520f78e68..74058db674db 100644
--- a/drivers/acorn/block/mfmhd.c
+++ b/drivers/acorn/block/mfmhd.c
@@ -924,7 +924,7 @@ static void mfm_request(void)
924 DBG("mfm_request: Dropping out bottom\n"); 924 DBG("mfm_request: Dropping out bottom\n");
925} 925}
926 926
927static void do_mfm_request(request_queue_t *q) 927static void do_mfm_request(struct request_queue *q)
928{ 928{
929 DBG("do_mfm_request: about to mfm_request\n"); 929 DBG("do_mfm_request: about to mfm_request\n");
930 mfm_request(); 930 mfm_request();
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 408b45168aba..934d639b3684 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -43,51 +43,39 @@ menuconfig ACPI
43if ACPI 43if ACPI
44 44
45config ACPI_SLEEP 45config ACPI_SLEEP
46 bool "Sleep States" 46 bool
47 depends on X86 && (!SMP || SUSPEND_SMP) 47 depends on PM_SLEEP
48 default y 48 default y
49 ---help---
50 This option adds support for ACPI suspend states.
51 49
52 With this option, you will be able to put the system "to sleep". 50config ACPI_PROCFS
53 Sleep states are low power states for the system and devices. All 51 bool "Deprecated /proc/acpi files"
54 of the system operating state is saved to either memory or disk 52 depends on PROC_FS
55 (depending on the state), to allow the system to resume operation 53 ---help---
56 quickly at your request. 54 For backwards compatibility, this option allows
55 depricated /proc/acpi/ files to exist, even when
56 they have been replaced by functions in /sys.
57 The deprecated files (and their replacements) include:
57 58
58 Although this option sounds really nifty, barely any of the device 59 /proc/acpi/sleep (/sys/power/state)
59 drivers have been converted to the new driver model and hence few 60 /proc/acpi/info (/sys/modules/acpi/parameters/acpica_version)
60 have proper power management support. 61 /proc/acpi/dsdt (/sys/firmware/acpi/tables/DSDT)
62 /proc/acpi/fadt (/sys/firmware/acpi/tables/FACP)
63 /proc/acpi/debug_layer (/sys/module/acpi/parameters/debug_layer)
64 /proc/acpi/debug_level (/sys/module/acpi/parameters/debug_level)
61 65
62 This option is not recommended for anyone except those doing driver 66 This option has no effect on /proc/acpi/ files
63 power management development. 67 and functions which do not yet exist in /sys.
64 68
65config ACPI_SLEEP_PROC_FS 69 Say N to delete /proc/acpi/ files that have moved to /sys/
66 bool
67 depends on ACPI_SLEEP && PROC_FS
68 default y
69 70
70config ACPI_SLEEP_PROC_SLEEP 71config ACPI_PROCFS_SLEEP
71 bool "/proc/acpi/sleep (deprecated)" 72 bool "/proc/acpi/sleep (deprecated)"
72 depends on ACPI_SLEEP_PROC_FS 73 depends on PM_SLEEP && ACPI_PROCFS
73 default n 74 default n
74 ---help--- 75 ---help---
75 Create /proc/acpi/sleep 76 Create /proc/acpi/sleep
76 Deprecated by /sys/power/state 77 Deprecated by /sys/power/state
77 78
78config ACPI_PROCFS
79 bool "Procfs interface (deprecated)"
80 default y
81 ---help---
82 The Procfs interface for ACPI is made optional for backward compatibility.
83 As the same functions are duplicated in the sysfs interface
84 and this proc interface will be removed some time later,
85 it's marked as deprecated.
86 ( /proc/acpi/debug_layer && debug_level are deprecated by
87 /sys/module/acpi/parameters/debug_layer && debug_level.
88 /proc/acpi/info is deprecated by
89 /sys/module/acpi/parameters/acpica_version )
90
91config ACPI_AC 79config ACPI_AC
92 tristate "AC Adapter" 80 tristate "AC Adapter"
93 depends on X86 81 depends on X86
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index 37c7dc4f9fe5..d8b35093527a 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -34,7 +34,6 @@
34 34
35#define ACPI_AC_COMPONENT 0x00020000 35#define ACPI_AC_COMPONENT 0x00020000
36#define ACPI_AC_CLASS "ac_adapter" 36#define ACPI_AC_CLASS "ac_adapter"
37#define ACPI_AC_HID "ACPI0003"
38#define ACPI_AC_DEVICE_NAME "AC Adapter" 37#define ACPI_AC_DEVICE_NAME "AC Adapter"
39#define ACPI_AC_FILE_STATE "state" 38#define ACPI_AC_FILE_STATE "state"
40#define ACPI_AC_NOTIFY_STATUS 0x80 39#define ACPI_AC_NOTIFY_STATUS 0x80
@@ -56,10 +55,16 @@ static int acpi_ac_add(struct acpi_device *device);
56static int acpi_ac_remove(struct acpi_device *device, int type); 55static int acpi_ac_remove(struct acpi_device *device, int type);
57static int acpi_ac_open_fs(struct inode *inode, struct file *file); 56static int acpi_ac_open_fs(struct inode *inode, struct file *file);
58 57
58const static struct acpi_device_id ac_device_ids[] = {
59 {"ACPI0003", 0},
60 {"", 0},
61};
62MODULE_DEVICE_TABLE(acpi, ac_device_ids);
63
59static struct acpi_driver acpi_ac_driver = { 64static struct acpi_driver acpi_ac_driver = {
60 .name = "ac", 65 .name = "ac",
61 .class = ACPI_AC_CLASS, 66 .class = ACPI_AC_CLASS,
62 .ids = ACPI_AC_HID, 67 .ids = ac_device_ids,
63 .ops = { 68 .ops = {
64 .add = acpi_ac_add, 69 .add = acpi_ac_add,
65 .remove = acpi_ac_remove, 70 .remove = acpi_ac_remove,
diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c
index e65628a03085..5f1127ad5a95 100644
--- a/drivers/acpi/acpi_memhotplug.c
+++ b/drivers/acpi/acpi_memhotplug.c
@@ -53,10 +53,16 @@ static int acpi_memory_device_add(struct acpi_device *device);
53static int acpi_memory_device_remove(struct acpi_device *device, int type); 53static int acpi_memory_device_remove(struct acpi_device *device, int type);
54static int acpi_memory_device_start(struct acpi_device *device); 54static int acpi_memory_device_start(struct acpi_device *device);
55 55
56static const struct acpi_device_id memory_device_ids[] = {
57 {ACPI_MEMORY_DEVICE_HID, 0},
58 {"", 0},
59};
60MODULE_DEVICE_TABLE(acpi, memory_device_ids);
61
56static struct acpi_driver acpi_memory_device_driver = { 62static struct acpi_driver acpi_memory_device_driver = {
57 .name = "acpi_memhotplug", 63 .name = "acpi_memhotplug",
58 .class = ACPI_MEMORY_DEVICE_CLASS, 64 .class = ACPI_MEMORY_DEVICE_CLASS,
59 .ids = ACPI_MEMORY_DEVICE_HID, 65 .ids = memory_device_ids,
60 .ops = { 66 .ops = {
61 .add = acpi_memory_device_add, 67 .add = acpi_memory_device_add,
62 .remove = acpi_memory_device_remove, 68 .remove = acpi_memory_device_remove,
diff --git a/drivers/acpi/asus_acpi.c b/drivers/acpi/asus_acpi.c
index 3cd79caad70c..9c4bd220c44f 100644
--- a/drivers/acpi/asus_acpi.c
+++ b/drivers/acpi/asus_acpi.c
@@ -56,7 +56,6 @@
56#define ACPI_HOTK_NAME "Asus Laptop ACPI Extras Driver" 56#define ACPI_HOTK_NAME "Asus Laptop ACPI Extras Driver"
57#define ACPI_HOTK_CLASS "hotkey" 57#define ACPI_HOTK_CLASS "hotkey"
58#define ACPI_HOTK_DEVICE_NAME "Hotkey" 58#define ACPI_HOTK_DEVICE_NAME "Hotkey"
59#define ACPI_HOTK_HID "ATK0100"
60 59
61/* 60/*
62 * Some events we use, same for all Asus 61 * Some events we use, same for all Asus
@@ -426,14 +425,20 @@ static struct acpi_table_header *asus_info;
426static struct asus_hotk *hotk; 425static struct asus_hotk *hotk;
427 426
428/* 427/*
429 * The hotkey driver declaration 428 * The hotkey driver and autoloading declaration
430 */ 429 */
431static int asus_hotk_add(struct acpi_device *device); 430static int asus_hotk_add(struct acpi_device *device);
432static int asus_hotk_remove(struct acpi_device *device, int type); 431static int asus_hotk_remove(struct acpi_device *device, int type);
432static const struct acpi_device_id asus_device_ids[] = {
433 {"ATK0100", 0},
434 {"", 0},
435};
436MODULE_DEVICE_TABLE(acpi, asus_device_ids);
437
433static struct acpi_driver asus_hotk_driver = { 438static struct acpi_driver asus_hotk_driver = {
434 .name = "asus_acpi", 439 .name = "asus_acpi",
435 .class = ACPI_HOTK_CLASS, 440 .class = ACPI_HOTK_CLASS,
436 .ids = ACPI_HOTK_HID, 441 .ids = asus_device_ids,
437 .ops = { 442 .ops = {
438 .add = asus_hotk_add, 443 .add = asus_hotk_add,
439 .remove = asus_hotk_remove, 444 .remove = asus_hotk_remove,
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index cad932de383d..81651032791b 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -41,7 +41,6 @@
41 41
42#define ACPI_BATTERY_COMPONENT 0x00040000 42#define ACPI_BATTERY_COMPONENT 0x00040000
43#define ACPI_BATTERY_CLASS "battery" 43#define ACPI_BATTERY_CLASS "battery"
44#define ACPI_BATTERY_HID "PNP0C0A"
45#define ACPI_BATTERY_DEVICE_NAME "Battery" 44#define ACPI_BATTERY_DEVICE_NAME "Battery"
46#define ACPI_BATTERY_NOTIFY_STATUS 0x80 45#define ACPI_BATTERY_NOTIFY_STATUS 0x80
47#define ACPI_BATTERY_NOTIFY_INFO 0x81 46#define ACPI_BATTERY_NOTIFY_INFO 0x81
@@ -74,10 +73,16 @@ static int acpi_battery_add(struct acpi_device *device);
74static int acpi_battery_remove(struct acpi_device *device, int type); 73static int acpi_battery_remove(struct acpi_device *device, int type);
75static int acpi_battery_resume(struct acpi_device *device); 74static int acpi_battery_resume(struct acpi_device *device);
76 75
76static const struct acpi_device_id battery_device_ids[] = {
77 {"PNP0C0A", 0},
78 {"", 0},
79};
80MODULE_DEVICE_TABLE(acpi, battery_device_ids);
81
77static struct acpi_driver acpi_battery_driver = { 82static struct acpi_driver acpi_battery_driver = {
78 .name = "battery", 83 .name = "battery",
79 .class = ACPI_BATTERY_CLASS, 84 .class = ACPI_BATTERY_CLASS,
80 .ids = ACPI_BATTERY_HID, 85 .ids = battery_device_ids,
81 .ops = { 86 .ops = {
82 .add = acpi_battery_add, 87 .add = acpi_battery_add,
83 .resume = acpi_battery_resume, 88 .resume = acpi_battery_resume,
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index cb4110b50cd0..540581338ef5 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -66,6 +66,16 @@ MODULE_AUTHOR("Paul Diefenbaugh");
66MODULE_DESCRIPTION("ACPI Button Driver"); 66MODULE_DESCRIPTION("ACPI Button Driver");
67MODULE_LICENSE("GPL"); 67MODULE_LICENSE("GPL");
68 68
69static const struct acpi_device_id button_device_ids[] = {
70 {ACPI_BUTTON_HID_LID, 0},
71 {ACPI_BUTTON_HID_SLEEP, 0},
72 {ACPI_BUTTON_HID_SLEEPF, 0},
73 {ACPI_BUTTON_HID_POWER, 0},
74 {ACPI_BUTTON_HID_POWERF, 0},
75 {"", 0},
76};
77MODULE_DEVICE_TABLE(acpi, button_device_ids);
78
69static int acpi_button_add(struct acpi_device *device); 79static int acpi_button_add(struct acpi_device *device);
70static int acpi_button_remove(struct acpi_device *device, int type); 80static int acpi_button_remove(struct acpi_device *device, int type);
71static int acpi_button_info_open_fs(struct inode *inode, struct file *file); 81static int acpi_button_info_open_fs(struct inode *inode, struct file *file);
@@ -74,7 +84,7 @@ static int acpi_button_state_open_fs(struct inode *inode, struct file *file);
74static struct acpi_driver acpi_button_driver = { 84static struct acpi_driver acpi_button_driver = {
75 .name = "button", 85 .name = "button",
76 .class = ACPI_BUTTON_CLASS, 86 .class = ACPI_BUTTON_CLASS,
77 .ids = "button_power,button_sleep,PNP0C0D,PNP0C0C,PNP0C0E", 87 .ids = button_device_ids,
78 .ops = { 88 .ops = {
79 .add = acpi_button_add, 89 .add = acpi_button_add,
80 .remove = acpi_button_remove, 90 .remove = acpi_button_remove,
diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c
index 0dd3bf7c0ed1..3c25ec7a1871 100644
--- a/drivers/acpi/container.c
+++ b/drivers/acpi/container.c
@@ -52,10 +52,18 @@ MODULE_LICENSE("GPL");
52static int acpi_container_add(struct acpi_device *device); 52static int acpi_container_add(struct acpi_device *device);
53static int acpi_container_remove(struct acpi_device *device, int type); 53static int acpi_container_remove(struct acpi_device *device, int type);
54 54
55static const struct acpi_device_id container_device_ids[] = {
56 {"ACPI0004", 0},
57 {"PNP0A05", 0},
58 {"PNP0A06", 0},
59 {"", 0},
60};
61MODULE_DEVICE_TABLE(acpi, container_device_ids);
62
55static struct acpi_driver acpi_container_driver = { 63static struct acpi_driver acpi_container_driver = {
56 .name = "container", 64 .name = "container",
57 .class = ACPI_CONTAINER_CLASS, 65 .class = ACPI_CONTAINER_CLASS,
58 .ids = "ACPI0004,PNP0A05,PNP0A06", 66 .ids = container_device_ids,
59 .ops = { 67 .ops = {
60 .add = acpi_container_add, 68 .add = acpi_container_add,
61 .remove = acpi_container_remove, 69 .remove = acpi_container_remove,
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index 10e851021eca..469f3f57f881 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -41,7 +41,6 @@
41#include <acpi/actypes.h> 41#include <acpi/actypes.h>
42 42
43#define ACPI_EC_CLASS "embedded_controller" 43#define ACPI_EC_CLASS "embedded_controller"
44#define ACPI_EC_HID "PNP0C09"
45#define ACPI_EC_DEVICE_NAME "Embedded Controller" 44#define ACPI_EC_DEVICE_NAME "Embedded Controller"
46#define ACPI_EC_FILE_INFO "info" 45#define ACPI_EC_FILE_INFO "info"
47 46
@@ -82,10 +81,15 @@ static int acpi_ec_start(struct acpi_device *device);
82static int acpi_ec_stop(struct acpi_device *device, int type); 81static int acpi_ec_stop(struct acpi_device *device, int type);
83static int acpi_ec_add(struct acpi_device *device); 82static int acpi_ec_add(struct acpi_device *device);
84 83
84static const struct acpi_device_id ec_device_ids[] = {
85 {"PNP0C09", 0},
86 {"", 0},
87};
88
85static struct acpi_driver acpi_ec_driver = { 89static struct acpi_driver acpi_ec_driver = {
86 .name = "ec", 90 .name = "ec",
87 .class = ACPI_EC_CLASS, 91 .class = ACPI_EC_CLASS,
88 .ids = ACPI_EC_HID, 92 .ids = ec_device_ids,
89 .ops = { 93 .ops = {
90 .add = acpi_ec_add, 94 .add = acpi_ec_add,
91 .remove = acpi_ec_remove, 95 .remove = acpi_ec_remove,
diff --git a/drivers/acpi/events/evrgnini.c b/drivers/acpi/events/evrgnini.c
index 23ee7bc4a705..b1aaa0e84588 100644
--- a/drivers/acpi/events/evrgnini.c
+++ b/drivers/acpi/events/evrgnini.c
@@ -378,7 +378,7 @@ static u8 acpi_ev_match_pci_root_bridge(char *id)
378static u8 acpi_ev_is_pci_root_bridge(struct acpi_namespace_node *node) 378static u8 acpi_ev_is_pci_root_bridge(struct acpi_namespace_node *node)
379{ 379{
380 acpi_status status; 380 acpi_status status;
381 struct acpi_device_id hid; 381 struct acpica_device_id hid;
382 struct acpi_compatible_id_list *cid; 382 struct acpi_compatible_id_list *cid;
383 acpi_native_uint i; 383 acpi_native_uint i;
384 384
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
index ec655c539492..c81f6bdb68b8 100644
--- a/drivers/acpi/fan.c
+++ b/drivers/acpi/fan.c
@@ -50,10 +50,16 @@ static int acpi_fan_remove(struct acpi_device *device, int type);
50static int acpi_fan_suspend(struct acpi_device *device, pm_message_t state); 50static int acpi_fan_suspend(struct acpi_device *device, pm_message_t state);
51static int acpi_fan_resume(struct acpi_device *device); 51static int acpi_fan_resume(struct acpi_device *device);
52 52
53static const struct acpi_device_id fan_device_ids[] = {
54 {"PNP0C0B", 0},
55 {"", 0},
56};
57MODULE_DEVICE_TABLE(acpi, fan_device_ids);
58
53static struct acpi_driver acpi_fan_driver = { 59static struct acpi_driver acpi_fan_driver = {
54 .name = "fan", 60 .name = "fan",
55 .class = ACPI_FAN_CLASS, 61 .class = ACPI_FAN_CLASS,
56 .ids = "PNP0C0B", 62 .ids = fan_device_ids,
57 .ops = { 63 .ops = {
58 .add = acpi_fan_add, 64 .add = acpi_fan_add,
59 .remove = acpi_fan_remove, 65 .remove = acpi_fan_remove,
diff --git a/drivers/acpi/namespace/nsxfeval.c b/drivers/acpi/namespace/nsxfeval.c
index be4f2899de74..ab65b2c2560e 100644
--- a/drivers/acpi/namespace/nsxfeval.c
+++ b/drivers/acpi/namespace/nsxfeval.c
@@ -440,7 +440,7 @@ acpi_ns_get_device_callback(acpi_handle obj_handle,
440 acpi_status status; 440 acpi_status status;
441 struct acpi_namespace_node *node; 441 struct acpi_namespace_node *node;
442 u32 flags; 442 u32 flags;
443 struct acpi_device_id hid; 443 struct acpica_device_id hid;
444 struct acpi_compatible_id_list *cid; 444 struct acpi_compatible_id_list *cid;
445 acpi_native_uint i; 445 acpi_native_uint i;
446 446
diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
index 3448edd61dc4..c9f526e55392 100644
--- a/drivers/acpi/pci_link.c
+++ b/drivers/acpi/pci_link.c
@@ -46,7 +46,6 @@
46#define _COMPONENT ACPI_PCI_COMPONENT 46#define _COMPONENT ACPI_PCI_COMPONENT
47ACPI_MODULE_NAME("pci_link"); 47ACPI_MODULE_NAME("pci_link");
48#define ACPI_PCI_LINK_CLASS "pci_irq_routing" 48#define ACPI_PCI_LINK_CLASS "pci_irq_routing"
49#define ACPI_PCI_LINK_HID "PNP0C0F"
50#define ACPI_PCI_LINK_DEVICE_NAME "PCI Interrupt Link" 49#define ACPI_PCI_LINK_DEVICE_NAME "PCI Interrupt Link"
51#define ACPI_PCI_LINK_FILE_INFO "info" 50#define ACPI_PCI_LINK_FILE_INFO "info"
52#define ACPI_PCI_LINK_FILE_STATUS "state" 51#define ACPI_PCI_LINK_FILE_STATUS "state"
@@ -54,10 +53,16 @@ ACPI_MODULE_NAME("pci_link");
54static int acpi_pci_link_add(struct acpi_device *device); 53static int acpi_pci_link_add(struct acpi_device *device);
55static int acpi_pci_link_remove(struct acpi_device *device, int type); 54static int acpi_pci_link_remove(struct acpi_device *device, int type);
56 55
56static struct acpi_device_id link_device_ids[] = {
57 {"PNP0C0F", 0},
58 {"", 0},
59};
60MODULE_DEVICE_TABLE(acpi, link_device_ids);
61
57static struct acpi_driver acpi_pci_link_driver = { 62static struct acpi_driver acpi_pci_link_driver = {
58 .name = "pci_link", 63 .name = "pci_link",
59 .class = ACPI_PCI_LINK_CLASS, 64 .class = ACPI_PCI_LINK_CLASS,
60 .ids = ACPI_PCI_LINK_HID, 65 .ids = link_device_ids,
61 .ops = { 66 .ops = {
62 .add = acpi_pci_link_add, 67 .add = acpi_pci_link_add,
63 .remove = acpi_pci_link_remove, 68 .remove = acpi_pci_link_remove,
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index ad4145a37786..f14ff1ffab29 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -38,16 +38,21 @@
38#define _COMPONENT ACPI_PCI_COMPONENT 38#define _COMPONENT ACPI_PCI_COMPONENT
39ACPI_MODULE_NAME("pci_root"); 39ACPI_MODULE_NAME("pci_root");
40#define ACPI_PCI_ROOT_CLASS "pci_bridge" 40#define ACPI_PCI_ROOT_CLASS "pci_bridge"
41#define ACPI_PCI_ROOT_HID "PNP0A03"
42#define ACPI_PCI_ROOT_DEVICE_NAME "PCI Root Bridge" 41#define ACPI_PCI_ROOT_DEVICE_NAME "PCI Root Bridge"
43static int acpi_pci_root_add(struct acpi_device *device); 42static int acpi_pci_root_add(struct acpi_device *device);
44static int acpi_pci_root_remove(struct acpi_device *device, int type); 43static int acpi_pci_root_remove(struct acpi_device *device, int type);
45static int acpi_pci_root_start(struct acpi_device *device); 44static int acpi_pci_root_start(struct acpi_device *device);
46 45
46static struct acpi_device_id root_device_ids[] = {
47 {"PNP0A03", 0},
48 {"", 0},
49};
50MODULE_DEVICE_TABLE(acpi, root_device_ids);
51
47static struct acpi_driver acpi_pci_root_driver = { 52static struct acpi_driver acpi_pci_root_driver = {
48 .name = "pci_root", 53 .name = "pci_root",
49 .class = ACPI_PCI_ROOT_CLASS, 54 .class = ACPI_PCI_ROOT_CLASS,
50 .ids = ACPI_PCI_ROOT_HID, 55 .ids = root_device_ids,
51 .ops = { 56 .ops = {
52 .add = acpi_pci_root_add, 57 .add = acpi_pci_root_add,
53 .remove = acpi_pci_root_remove, 58 .remove = acpi_pci_root_remove,
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index 4ffecd179702..57b9a2998fd0 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -59,10 +59,16 @@ static int acpi_power_remove(struct acpi_device *device, int type);
59static int acpi_power_resume(struct acpi_device *device); 59static int acpi_power_resume(struct acpi_device *device);
60static int acpi_power_open_fs(struct inode *inode, struct file *file); 60static int acpi_power_open_fs(struct inode *inode, struct file *file);
61 61
62static struct acpi_device_id power_device_ids[] = {
63 {ACPI_POWER_HID, 0},
64 {"", 0},
65};
66MODULE_DEVICE_TABLE(acpi, power_device_ids);
67
62static struct acpi_driver acpi_power_driver = { 68static struct acpi_driver acpi_power_driver = {
63 .name = "power", 69 .name = "power",
64 .class = ACPI_POWER_CLASS, 70 .class = ACPI_POWER_CLASS,
65 .ids = ACPI_POWER_HID, 71 .ids = power_device_ids,
66 .ops = { 72 .ops = {
67 .add = acpi_power_add, 73 .add = acpi_power_add,
68 .remove = acpi_power_remove, 74 .remove = acpi_power_remove,
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index 81aceb5da7c7..498422343f38 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -88,10 +88,16 @@ static int acpi_processor_handle_eject(struct acpi_processor *pr);
88extern int acpi_processor_tstate_has_changed(struct acpi_processor *pr); 88extern int acpi_processor_tstate_has_changed(struct acpi_processor *pr);
89 89
90 90
91static const struct acpi_device_id processor_device_ids[] = {
92 {ACPI_PROCESSOR_HID, 0},
93 {"", 0},
94};
95MODULE_DEVICE_TABLE(acpi, processor_device_ids);
96
91static struct acpi_driver acpi_processor_driver = { 97static struct acpi_driver acpi_processor_driver = {
92 .name = "processor", 98 .name = "processor",
93 .class = ACPI_PROCESSOR_CLASS, 99 .class = ACPI_PROCESSOR_CLASS,
94 .ids = ACPI_PROCESSOR_HID, 100 .ids = processor_device_ids,
95 .ops = { 101 .ops = {
96 .add = acpi_processor_add, 102 .add = acpi_processor_add,
97 .remove = acpi_processor_remove, 103 .remove = acpi_processor_remove,
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
index 3f55d1f90c11..0b8204e7082a 100644
--- a/drivers/acpi/processor_throttling.c
+++ b/drivers/acpi/processor_throttling.c
@@ -47,6 +47,9 @@ ACPI_MODULE_NAME("processor_throttling");
47static int acpi_processor_get_throttling(struct acpi_processor *pr); 47static int acpi_processor_get_throttling(struct acpi_processor *pr);
48int acpi_processor_set_throttling(struct acpi_processor *pr, int state); 48int acpi_processor_set_throttling(struct acpi_processor *pr, int state);
49 49
50/*
51 * _TPC - Throttling Present Capabilities
52 */
50static int acpi_processor_get_platform_limit(struct acpi_processor *pr) 53static int acpi_processor_get_platform_limit(struct acpi_processor *pr)
51{ 54{
52 acpi_status status = 0; 55 acpi_status status = 0;
@@ -55,8 +58,10 @@ static int acpi_processor_get_platform_limit(struct acpi_processor *pr)
55 if (!pr) 58 if (!pr)
56 return -EINVAL; 59 return -EINVAL;
57 status = acpi_evaluate_integer(pr->handle, "_TPC", NULL, &tpc); 60 status = acpi_evaluate_integer(pr->handle, "_TPC", NULL, &tpc);
58 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { 61 if (ACPI_FAILURE(status)) {
59 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TPC")); 62 if (status != AE_NOT_FOUND) {
63 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TPC"));
64 }
60 return -ENODEV; 65 return -ENODEV;
61 } 66 }
62 pr->throttling_platform_limit = (int)tpc; 67 pr->throttling_platform_limit = (int)tpc;
@@ -68,9 +73,9 @@ int acpi_processor_tstate_has_changed(struct acpi_processor *pr)
68 return acpi_processor_get_platform_limit(pr); 73 return acpi_processor_get_platform_limit(pr);
69} 74}
70 75
71/* -------------------------------------------------------------------------- 76/*
72 _PTC, _TSS, _TSD support 77 * _PTC - Processor Throttling Control (and status) register location
73 -------------------------------------------------------------------------- */ 78 */
74static int acpi_processor_get_throttling_control(struct acpi_processor *pr) 79static int acpi_processor_get_throttling_control(struct acpi_processor *pr)
75{ 80{
76 int result = 0; 81 int result = 0;
@@ -81,7 +86,9 @@ static int acpi_processor_get_throttling_control(struct acpi_processor *pr)
81 86
82 status = acpi_evaluate_object(pr->handle, "_PTC", NULL, &buffer); 87 status = acpi_evaluate_object(pr->handle, "_PTC", NULL, &buffer);
83 if (ACPI_FAILURE(status)) { 88 if (ACPI_FAILURE(status)) {
84 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PTC")); 89 if (status != AE_NOT_FOUND) {
90 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PTC"));
91 }
85 return -ENODEV; 92 return -ENODEV;
86 } 93 }
87 94
@@ -132,6 +139,10 @@ static int acpi_processor_get_throttling_control(struct acpi_processor *pr)
132 139
133 return result; 140 return result;
134} 141}
142
143/*
144 * _TSS - Throttling Supported States
145 */
135static int acpi_processor_get_throttling_states(struct acpi_processor *pr) 146static int acpi_processor_get_throttling_states(struct acpi_processor *pr)
136{ 147{
137 int result = 0; 148 int result = 0;
@@ -144,7 +155,9 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr)
144 155
145 status = acpi_evaluate_object(pr->handle, "_TSS", NULL, &buffer); 156 status = acpi_evaluate_object(pr->handle, "_TSS", NULL, &buffer);
146 if (ACPI_FAILURE(status)) { 157 if (ACPI_FAILURE(status)) {
147 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TSS")); 158 if (status != AE_NOT_FOUND) {
159 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TSS"));
160 }
148 return -ENODEV; 161 return -ENODEV;
149 } 162 }
150 163
@@ -201,6 +214,10 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr)
201 214
202 return result; 215 return result;
203} 216}
217
218/*
219 * _TSD - T-State Dependencies
220 */
204static int acpi_processor_get_tsd(struct acpi_processor *pr) 221static int acpi_processor_get_tsd(struct acpi_processor *pr)
205{ 222{
206 int result = 0; 223 int result = 0;
@@ -213,6 +230,9 @@ static int acpi_processor_get_tsd(struct acpi_processor *pr)
213 230
214 status = acpi_evaluate_object(pr->handle, "_TSD", NULL, &buffer); 231 status = acpi_evaluate_object(pr->handle, "_TSD", NULL, &buffer);
215 if (ACPI_FAILURE(status)) { 232 if (ACPI_FAILURE(status)) {
233 if (status != AE_NOT_FOUND) {
234 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TSD"));
235 }
216 return -ENODEV; 236 return -ENODEV;
217 } 237 }
218 238
@@ -525,9 +545,6 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr)
525 int result = 0; 545 int result = 0;
526 int step = 0; 546 int step = 0;
527 int i = 0; 547 int i = 0;
528 int no_ptc = 0;
529 int no_tss = 0;
530 int no_tsd = 0;
531 548
532 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 549 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
533 "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n", 550 "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n",
@@ -538,12 +555,14 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr)
538 if (!pr) 555 if (!pr)
539 return -EINVAL; 556 return -EINVAL;
540 557
541 /* TBD: Support ACPI 2.0 objects */ 558 /*
542 no_ptc = acpi_processor_get_throttling_control(pr); 559 * Evaluate _PTC, _TSS and _TPC
543 no_tss = acpi_processor_get_throttling_states(pr); 560 * They must all be present or none of them can be used.
544 no_tsd = acpi_processor_get_tsd(pr); 561 */
545 562 if (acpi_processor_get_throttling_control(pr) ||
546 if (no_ptc || no_tss) { 563 acpi_processor_get_throttling_states(pr) ||
564 acpi_processor_get_platform_limit(pr))
565 {
547 pr->throttling.acpi_processor_get_throttling = 566 pr->throttling.acpi_processor_get_throttling =
548 &acpi_processor_get_throttling_fadt; 567 &acpi_processor_get_throttling_fadt;
549 pr->throttling.acpi_processor_set_throttling = 568 pr->throttling.acpi_processor_set_throttling =
@@ -555,6 +574,8 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr)
555 &acpi_processor_set_throttling_ptc; 574 &acpi_processor_set_throttling_ptc;
556 } 575 }
557 576
577 acpi_processor_get_tsd(pr);
578
558 if (!pr->throttling.address) { 579 if (!pr->throttling.address) {
559 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling register\n")); 580 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling register\n"));
560 return 0; 581 return 0;
@@ -658,18 +679,20 @@ static int acpi_processor_throttling_seq_show(struct seq_file *seq,
658 pr->throttling.state_count - 1); 679 pr->throttling.state_count - 1);
659 680
660 seq_puts(seq, "states:\n"); 681 seq_puts(seq, "states:\n");
661 if (acpi_processor_get_throttling == acpi_processor_get_throttling_fadt) 682 if (pr->throttling.acpi_processor_get_throttling ==
683 acpi_processor_get_throttling_fadt) {
662 for (i = 0; i < pr->throttling.state_count; i++) 684 for (i = 0; i < pr->throttling.state_count; i++)
663 seq_printf(seq, " %cT%d: %02d%%\n", 685 seq_printf(seq, " %cT%d: %02d%%\n",
664 (i == pr->throttling.state ? '*' : ' '), i, 686 (i == pr->throttling.state ? '*' : ' '), i,
665 (pr->throttling.states[i].performance ? pr-> 687 (pr->throttling.states[i].performance ? pr->
666 throttling.states[i].performance / 10 : 0)); 688 throttling.states[i].performance / 10 : 0));
667 else 689 } else {
668 for (i = 0; i < pr->throttling.state_count; i++) 690 for (i = 0; i < pr->throttling.state_count; i++)
669 seq_printf(seq, " %cT%d: %02d%%\n", 691 seq_printf(seq, " %cT%d: %02d%%\n",
670 (i == pr->throttling.state ? '*' : ' '), i, 692 (i == pr->throttling.state ? '*' : ' '), i,
671 (int)pr->throttling.states_tss[i]. 693 (int)pr->throttling.states_tss[i].
672 freqpercentage); 694 freqpercentage);
695 }
673 696
674 end: 697 end:
675 return 0; 698 return 0;
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 974d00ccfe84..7d8e78ea13a5 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -38,7 +38,6 @@
38#define ACPI_SBS_CLASS "sbs" 38#define ACPI_SBS_CLASS "sbs"
39#define ACPI_AC_CLASS "ac_adapter" 39#define ACPI_AC_CLASS "ac_adapter"
40#define ACPI_BATTERY_CLASS "battery" 40#define ACPI_BATTERY_CLASS "battery"
41#define ACPI_SBS_HID "ACPI0002"
42#define ACPI_SBS_DEVICE_NAME "Smart Battery System" 41#define ACPI_SBS_DEVICE_NAME "Smart Battery System"
43#define ACPI_SBS_FILE_INFO "info" 42#define ACPI_SBS_FILE_INFO "info"
44#define ACPI_SBS_FILE_STATE "state" 43#define ACPI_SBS_FILE_STATE "state"
@@ -124,10 +123,17 @@ static int acpi_sbs_add(struct acpi_device *device);
124static int acpi_sbs_remove(struct acpi_device *device, int type); 123static int acpi_sbs_remove(struct acpi_device *device, int type);
125static int acpi_sbs_resume(struct acpi_device *device); 124static int acpi_sbs_resume(struct acpi_device *device);
126 125
126static const struct acpi_device_id sbs_device_ids[] = {
127 {"ACPI0001", 0},
128 {"ACPI0005", 0},
129 {"", 0},
130};
131MODULE_DEVICE_TABLE(acpi, sbs_device_ids);
132
127static struct acpi_driver acpi_sbs_driver = { 133static struct acpi_driver acpi_sbs_driver = {
128 .name = "sbs", 134 .name = "sbs",
129 .class = ACPI_SBS_CLASS, 135 .class = ACPI_SBS_CLASS,
130 .ids = "ACPI0001,ACPI0005", 136 .ids = sbs_device_ids,
131 .ops = { 137 .ops = {
132 .add = acpi_sbs_add, 138 .add = acpi_sbs_add,
133 .remove = acpi_sbs_remove, 139 .remove = acpi_sbs_remove,
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 6b3b8a522476..be74347d1354 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -16,7 +16,7 @@ ACPI_MODULE_NAME("scan");
16extern struct acpi_device *acpi_root; 16extern struct acpi_device *acpi_root;
17 17
18#define ACPI_BUS_CLASS "system_bus" 18#define ACPI_BUS_CLASS "system_bus"
19#define ACPI_BUS_HID "ACPI_BUS" 19#define ACPI_BUS_HID "LNXSYBUS"
20#define ACPI_BUS_DEVICE_NAME "System Bus" 20#define ACPI_BUS_DEVICE_NAME "System Bus"
21 21
22static LIST_HEAD(acpi_device_list); 22static LIST_HEAD(acpi_device_list);
@@ -29,6 +29,62 @@ struct acpi_device_bus_id{
29 unsigned int instance_no; 29 unsigned int instance_no;
30 struct list_head node; 30 struct list_head node;
31}; 31};
32
33/*
34 * Creates hid/cid(s) string needed for modalias and uevent
35 * e.g. on a device with hid:IBM0001 and cid:ACPI0001 you get:
36 * char *modalias: "acpi:IBM0001:ACPI0001"
37*/
38int create_modalias(struct acpi_device *acpi_dev, char *modalias, int size){
39
40 int len;
41
42 if (!acpi_dev->flags.hardware_id)
43 return -ENODEV;
44
45 len = snprintf(modalias, size, "acpi:%s:",
46 acpi_dev->pnp.hardware_id);
47 if (len < 0 || len >= size)
48 return -EINVAL;
49 size -= len;
50
51 if (acpi_dev->flags.compatible_ids) {
52 struct acpi_compatible_id_list *cid_list;
53 int i;
54 int count;
55
56 cid_list = acpi_dev->pnp.cid_list;
57 for (i = 0; i < cid_list->count; i++) {
58 count = snprintf(&modalias[len], size, "%s:",
59 cid_list->id[i].value);
60 if (count < 0 || count >= size) {
61 printk(KERN_ERR "acpi: %s cid[%i] exceeds event buffer size",
62 acpi_dev->pnp.device_name, i);
63 break;
64 }
65 len += count;
66 size -= count;
67 }
68 }
69
70 modalias[len] = '\0';
71 return len;
72}
73
74static ssize_t
75acpi_device_modalias_show(struct device *dev, struct device_attribute *attr, char *buf) {
76 struct acpi_device *acpi_dev = to_acpi_device(dev);
77 int len;
78
79 /* Device has no HID and no CID or string is >1024 */
80 len = create_modalias(acpi_dev, buf, 1024);
81 if (len <= 0)
82 return 0;
83 buf[len++] = '\n';
84 return len;
85}
86static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL);
87
32static int acpi_eject_operation(acpi_handle handle, int lockable) 88static int acpi_eject_operation(acpi_handle handle, int lockable)
33{ 89{
34 struct acpi_object_list arg_list; 90 struct acpi_object_list arg_list;
@@ -154,6 +210,12 @@ static int acpi_device_setup_files(struct acpi_device *dev)
154 goto end; 210 goto end;
155 } 211 }
156 212
213 if (dev->flags.hardware_id || dev->flags.compatible_ids){
214 result = device_create_file(&dev->dev, &dev_attr_modalias);
215 if(result)
216 goto end;
217 }
218
157 /* 219 /*
158 * If device has _EJ0, 'eject' file is created that is used to trigger 220 * If device has _EJ0, 'eject' file is created that is used to trigger
159 * hot-removal function from userland. 221 * hot-removal function from userland.
@@ -178,6 +240,9 @@ static void acpi_device_remove_files(struct acpi_device *dev)
178 if (ACPI_SUCCESS(status)) 240 if (ACPI_SUCCESS(status))
179 device_remove_file(&dev->dev, &dev_attr_eject); 241 device_remove_file(&dev->dev, &dev_attr_eject);
180 242
243 if (dev->flags.hardware_id || dev->flags.compatible_ids)
244 device_remove_file(&dev->dev, &dev_attr_modalias);
245
181 if(dev->flags.hardware_id) 246 if(dev->flags.hardware_id)
182 device_remove_file(&dev->dev, &dev_attr_hid); 247 device_remove_file(&dev->dev, &dev_attr_hid);
183 if(dev->handle) 248 if(dev->handle)
@@ -186,6 +251,37 @@ static void acpi_device_remove_files(struct acpi_device *dev)
186/* -------------------------------------------------------------------------- 251/* --------------------------------------------------------------------------
187 ACPI Bus operations 252 ACPI Bus operations
188 -------------------------------------------------------------------------- */ 253 -------------------------------------------------------------------------- */
254
255int acpi_match_device_ids(struct acpi_device *device,
256 const struct acpi_device_id *ids)
257{
258 const struct acpi_device_id *id;
259
260 if (device->flags.hardware_id) {
261 for (id = ids; id->id[0]; id++) {
262 if (!strcmp((char*)id->id, device->pnp.hardware_id))
263 return 0;
264 }
265 }
266
267 if (device->flags.compatible_ids) {
268 struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
269 int i;
270
271 for (id = ids; id->id[0]; id++) {
272 /* compare multiple _CID entries against driver ids */
273 for (i = 0; i < cid_list->count; i++) {
274 if (!strcmp((char*)id->id,
275 cid_list->id[i].value))
276 return 0;
277 }
278 }
279 }
280
281 return -ENOENT;
282}
283EXPORT_SYMBOL(acpi_match_device_ids);
284
189static void acpi_device_release(struct device *dev) 285static void acpi_device_release(struct device *dev)
190{ 286{
191 struct acpi_device *acpi_dev = to_acpi_device(dev); 287 struct acpi_device *acpi_dev = to_acpi_device(dev);
@@ -219,37 +315,19 @@ static int acpi_bus_match(struct device *dev, struct device_driver *drv)
219 struct acpi_device *acpi_dev = to_acpi_device(dev); 315 struct acpi_device *acpi_dev = to_acpi_device(dev);
220 struct acpi_driver *acpi_drv = to_acpi_driver(drv); 316 struct acpi_driver *acpi_drv = to_acpi_driver(drv);
221 317
222 return !acpi_match_ids(acpi_dev, acpi_drv->ids); 318 return !acpi_match_device_ids(acpi_dev, acpi_drv->ids);
223} 319}
224 320
225static int acpi_device_uevent(struct device *dev, char **envp, int num_envp, 321static int acpi_device_uevent(struct device *dev, char **envp, int num_envp,
226 char *buffer, int buffer_size) 322 char *buffer, int buffer_size)
227{ 323{
228 struct acpi_device *acpi_dev = to_acpi_device(dev); 324 struct acpi_device *acpi_dev = to_acpi_device(dev);
229 int i = 0, length = 0, ret = 0;
230
231 if (acpi_dev->flags.hardware_id)
232 ret = add_uevent_var(envp, num_envp, &i,
233 buffer, buffer_size, &length,
234 "HWID=%s", acpi_dev->pnp.hardware_id);
235 if (ret)
236 return -ENOMEM;
237 if (acpi_dev->flags.compatible_ids) {
238 int j;
239 struct acpi_compatible_id_list *cid_list;
240 325
241 cid_list = acpi_dev->pnp.cid_list; 326 strcpy(buffer, "MODALIAS=");
242 327 if (create_modalias(acpi_dev, buffer + 9, buffer_size - 9) > 0) {
243 for (j = 0; j < cid_list->count; j++) { 328 envp[0] = buffer;
244 ret = add_uevent_var(envp, num_envp, &i, buffer, 329 envp[1] = NULL;
245 buffer_size, &length, "COMPTID=%s",
246 cid_list->id[j].value);
247 if (ret)
248 return -ENOMEM;
249 }
250 } 330 }
251
252 envp[i] = NULL;
253 return 0; 331 return 0;
254} 332}
255 333
@@ -543,25 +621,6 @@ void acpi_bus_data_handler(acpi_handle handle, u32 function, void *context)
543 return; 621 return;
544} 622}
545 623
546int acpi_match_ids(struct acpi_device *device, char *ids)
547{
548 if (device->flags.hardware_id)
549 if (strstr(ids, device->pnp.hardware_id))
550 return 0;
551
552 if (device->flags.compatible_ids) {
553 struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
554 int i;
555
556 /* compare multiple _CID entries against driver ids */
557 for (i = 0; i < cid_list->count; i++) {
558 if (strstr(ids, cid_list->id[i].value))
559 return 0;
560 }
561 }
562 return -ENOENT;
563}
564
565static int acpi_bus_get_perf_flags(struct acpi_device *device) 624static int acpi_bus_get_perf_flags(struct acpi_device *device)
566{ 625{
567 device->performance.state = ACPI_STATE_UNKNOWN; 626 device->performance.state = ACPI_STATE_UNKNOWN;
@@ -624,6 +683,13 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
624 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 683 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
625 union acpi_object *package = NULL; 684 union acpi_object *package = NULL;
626 685
686 struct acpi_device_id button_device_ids[] = {
687 {"PNP0C0D", 0},
688 {"PNP0C0C", 0},
689 {"PNP0C0E", 0},
690 {"", 0},
691 };
692
627 693
628 /* _PRW */ 694 /* _PRW */
629 status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer); 695 status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer);
@@ -643,7 +709,7 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
643 709
644 device->wakeup.flags.valid = 1; 710 device->wakeup.flags.valid = 1;
645 /* Power button, Lid switch always enable wakeup */ 711 /* Power button, Lid switch always enable wakeup */
646 if (!acpi_match_ids(device, "PNP0C0D,PNP0C0C,PNP0C0E")) 712 if (!acpi_match_device_ids(device, button_device_ids))
647 device->wakeup.flags.run_wake = 1; 713 device->wakeup.flags.run_wake = 1;
648 714
649 end: 715 end:
diff --git a/drivers/acpi/sleep/Makefile b/drivers/acpi/sleep/Makefile
index d6c017709c85..195a4f69c0f7 100644
--- a/drivers/acpi/sleep/Makefile
+++ b/drivers/acpi/sleep/Makefile
@@ -1,5 +1,5 @@
1obj-y := poweroff.o wakeup.o 1obj-y := poweroff.o wakeup.o
2obj-$(CONFIG_ACPI_SLEEP) += main.o 2obj-$(CONFIG_ACPI_SLEEP) += main.o
3obj-$(CONFIG_ACPI_SLEEP_PROC_FS) += proc.o 3obj-$(CONFIG_ACPI_SLEEP) += proc.o
4 4
5EXTRA_CFLAGS += $(ACPI_CFLAGS) 5EXTRA_CFLAGS += $(ACPI_CFLAGS)
diff --git a/drivers/acpi/sleep/main.c b/drivers/acpi/sleep/main.c
index 3279e72a94f8..e8cff5dd4cbc 100644
--- a/drivers/acpi/sleep/main.c
+++ b/drivers/acpi/sleep/main.c
@@ -21,6 +21,9 @@
21 21
22u8 sleep_states[ACPI_S_STATE_COUNT]; 22u8 sleep_states[ACPI_S_STATE_COUNT];
23 23
24static u32 acpi_target_sleep_state = ACPI_STATE_S0;
25
26#ifdef CONFIG_SUSPEND
24static struct pm_ops acpi_pm_ops; 27static struct pm_ops acpi_pm_ops;
25 28
26extern void do_suspend_lowlevel(void); 29extern void do_suspend_lowlevel(void);
@@ -35,34 +38,49 @@ static u32 acpi_suspend_states[] = {
35static int init_8259A_after_S1; 38static int init_8259A_after_S1;
36 39
37/** 40/**
41 * acpi_pm_set_target - Set the target system sleep state to the state
42 * associated with given @pm_state, if supported.
43 */
44
45static int acpi_pm_set_target(suspend_state_t pm_state)
46{
47 u32 acpi_state = acpi_suspend_states[pm_state];
48 int error = 0;
49
50 if (sleep_states[acpi_state]) {
51 acpi_target_sleep_state = acpi_state;
52 } else {
53 printk(KERN_ERR "ACPI does not support this state: %d\n",
54 pm_state);
55 error = -ENOSYS;
56 }
57 return error;
58}
59
60/**
38 * acpi_pm_prepare - Do preliminary suspend work. 61 * acpi_pm_prepare - Do preliminary suspend work.
39 * @pm_state: suspend state we're entering. 62 * @pm_state: ignored
40 * 63 *
41 * Make sure we support the state. If we do, and we need it, set the 64 * If necessary, set the firmware waking vector and do arch-specific
42 * firmware waking vector and do arch-specific nastiness to get the 65 * nastiness to get the wakeup code to the waking vector.
43 * wakeup code to the waking vector.
44 */ 66 */
45 67
46extern int acpi_sleep_prepare(u32 acpi_state);
47extern void acpi_power_off(void);
48
49static int acpi_pm_prepare(suspend_state_t pm_state) 68static int acpi_pm_prepare(suspend_state_t pm_state)
50{ 69{
51 u32 acpi_state = acpi_suspend_states[pm_state]; 70 int error = acpi_sleep_prepare(acpi_target_sleep_state);
52 71
53 if (!sleep_states[acpi_state]) { 72 if (error)
54 printk("acpi_pm_prepare does not support %d \n", pm_state); 73 acpi_target_sleep_state = ACPI_STATE_S0;
55 return -EPERM; 74
56 } 75 return error;
57 return acpi_sleep_prepare(acpi_state);
58} 76}
59 77
60/** 78/**
61 * acpi_pm_enter - Actually enter a sleep state. 79 * acpi_pm_enter - Actually enter a sleep state.
62 * @pm_state: State we're entering. 80 * @pm_state: ignored
63 * 81 *
64 * Flush caches and go to sleep. For STR or STD, we have to call 82 * Flush caches and go to sleep. For STR we have to call arch-specific
65 * arch-specific assembly, which in turn call acpi_enter_sleep_state(). 83 * assembly, which in turn call acpi_enter_sleep_state().
66 * It's unfortunate, but it works. Please fix if you're feeling frisky. 84 * It's unfortunate, but it works. Please fix if you're feeling frisky.
67 */ 85 */
68 86
@@ -70,31 +88,31 @@ static int acpi_pm_enter(suspend_state_t pm_state)
70{ 88{
71 acpi_status status = AE_OK; 89 acpi_status status = AE_OK;
72 unsigned long flags = 0; 90 unsigned long flags = 0;
73 u32 acpi_state = acpi_suspend_states[pm_state]; 91 u32 acpi_state = acpi_target_sleep_state;
74 92
75 ACPI_FLUSH_CPU_CACHE(); 93 ACPI_FLUSH_CPU_CACHE();
76 94
77 /* Do arch specific saving of state. */ 95 /* Do arch specific saving of state. */
78 if (pm_state > PM_SUSPEND_STANDBY) { 96 if (acpi_state == ACPI_STATE_S3) {
79 int error = acpi_save_state_mem(); 97 int error = acpi_save_state_mem();
80 if (error) 98
99 if (error) {
100 acpi_target_sleep_state = ACPI_STATE_S0;
81 return error; 101 return error;
102 }
82 } 103 }
83 104
84 local_irq_save(flags); 105 local_irq_save(flags);
85 acpi_enable_wakeup_device(acpi_state); 106 acpi_enable_wakeup_device(acpi_state);
86 switch (pm_state) { 107 switch (acpi_state) {
87 case PM_SUSPEND_STANDBY: 108 case ACPI_STATE_S1:
88 barrier(); 109 barrier();
89 status = acpi_enter_sleep_state(acpi_state); 110 status = acpi_enter_sleep_state(acpi_state);
90 break; 111 break;
91 112
92 case PM_SUSPEND_MEM: 113 case ACPI_STATE_S3:
93 do_suspend_lowlevel(); 114 do_suspend_lowlevel();
94 break; 115 break;
95
96 default:
97 return -EINVAL;
98 } 116 }
99 117
100 /* ACPI 3.0 specs (P62) says that it's the responsabilty 118 /* ACPI 3.0 specs (P62) says that it's the responsabilty
@@ -107,12 +125,8 @@ static int acpi_pm_enter(suspend_state_t pm_state)
107 local_irq_restore(flags); 125 local_irq_restore(flags);
108 printk(KERN_DEBUG "Back to C!\n"); 126 printk(KERN_DEBUG "Back to C!\n");
109 127
110 /* restore processor state 128 /* restore processor state */
111 * We should only be here if we're coming back from STR or STD. 129 if (acpi_state == ACPI_STATE_S3)
112 * And, in the case of the latter, the memory image should have already
113 * been loaded from disk.
114 */
115 if (pm_state > PM_SUSPEND_STANDBY)
116 acpi_restore_state_mem(); 130 acpi_restore_state_mem();
117 131
118 return ACPI_SUCCESS(status) ? 0 : -EFAULT; 132 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
@@ -120,7 +134,7 @@ static int acpi_pm_enter(suspend_state_t pm_state)
120 134
121/** 135/**
122 * acpi_pm_finish - Finish up suspend sequence. 136 * acpi_pm_finish - Finish up suspend sequence.
123 * @pm_state: State we're coming out of. 137 * @pm_state: ignored
124 * 138 *
125 * This is called after we wake back up (or if entering the sleep state 139 * This is called after we wake back up (or if entering the sleep state
126 * failed). 140 * failed).
@@ -128,7 +142,7 @@ static int acpi_pm_enter(suspend_state_t pm_state)
128 142
129static int acpi_pm_finish(suspend_state_t pm_state) 143static int acpi_pm_finish(suspend_state_t pm_state)
130{ 144{
131 u32 acpi_state = acpi_suspend_states[pm_state]; 145 u32 acpi_state = acpi_target_sleep_state;
132 146
133 acpi_leave_sleep_state(acpi_state); 147 acpi_leave_sleep_state(acpi_state);
134 acpi_disable_wakeup_device(acpi_state); 148 acpi_disable_wakeup_device(acpi_state);
@@ -136,28 +150,17 @@ static int acpi_pm_finish(suspend_state_t pm_state)
136 /* reset firmware waking vector */ 150 /* reset firmware waking vector */
137 acpi_set_firmware_waking_vector((acpi_physical_address) 0); 151 acpi_set_firmware_waking_vector((acpi_physical_address) 0);
138 152
153 acpi_target_sleep_state = ACPI_STATE_S0;
154
155#ifdef CONFIG_X86
139 if (init_8259A_after_S1) { 156 if (init_8259A_after_S1) {
140 printk("Broken toshiba laptop -> kicking interrupts\n"); 157 printk("Broken toshiba laptop -> kicking interrupts\n");
141 init_8259A(0); 158 init_8259A(0);
142 } 159 }
160#endif
143 return 0; 161 return 0;
144} 162}
145 163
146int acpi_suspend(u32 acpi_state)
147{
148 suspend_state_t states[] = {
149 [1] = PM_SUSPEND_STANDBY,
150 [3] = PM_SUSPEND_MEM,
151 [5] = PM_SUSPEND_MAX
152 };
153
154 if (acpi_state < 6 && states[acpi_state])
155 return pm_suspend(states[acpi_state]);
156 if (acpi_state == 4)
157 return hibernate();
158 return -EINVAL;
159}
160
161static int acpi_pm_state_valid(suspend_state_t pm_state) 164static int acpi_pm_state_valid(suspend_state_t pm_state)
162{ 165{
163 u32 acpi_state; 166 u32 acpi_state;
@@ -176,12 +179,34 @@ static int acpi_pm_state_valid(suspend_state_t pm_state)
176 179
177static struct pm_ops acpi_pm_ops = { 180static struct pm_ops acpi_pm_ops = {
178 .valid = acpi_pm_state_valid, 181 .valid = acpi_pm_state_valid,
182 .set_target = acpi_pm_set_target,
179 .prepare = acpi_pm_prepare, 183 .prepare = acpi_pm_prepare,
180 .enter = acpi_pm_enter, 184 .enter = acpi_pm_enter,
181 .finish = acpi_pm_finish, 185 .finish = acpi_pm_finish,
182}; 186};
183 187
184#ifdef CONFIG_SOFTWARE_SUSPEND 188/*
189 * Toshiba fails to preserve interrupts over S1, reinitialization
190 * of 8259 is needed after S1 resume.
191 */
192static int __init init_ints_after_s1(struct dmi_system_id *d)
193{
194 printk(KERN_WARNING "%s with broken S1 detected.\n", d->ident);
195 init_8259A_after_S1 = 1;
196 return 0;
197}
198
199static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
200 {
201 .callback = init_ints_after_s1,
202 .ident = "Toshiba Satellite 4030cdt",
203 .matches = {DMI_MATCH(DMI_PRODUCT_NAME, "S4030CDT/4.3"),},
204 },
205 {},
206};
207#endif /* CONFIG_SUSPEND */
208
209#ifdef CONFIG_HIBERNATION
185static int acpi_hibernation_prepare(void) 210static int acpi_hibernation_prepare(void)
186{ 211{
187 return acpi_sleep_prepare(ACPI_STATE_S4); 212 return acpi_sleep_prepare(ACPI_STATE_S4);
@@ -233,41 +258,114 @@ static struct hibernation_ops acpi_hibernation_ops = {
233 .pre_restore = acpi_hibernation_pre_restore, 258 .pre_restore = acpi_hibernation_pre_restore,
234 .restore_cleanup = acpi_hibernation_restore_cleanup, 259 .restore_cleanup = acpi_hibernation_restore_cleanup,
235}; 260};
236#endif /* CONFIG_SOFTWARE_SUSPEND */ 261#endif /* CONFIG_HIBERNATION */
237 262
238/* 263int acpi_suspend(u32 acpi_state)
239 * Toshiba fails to preserve interrupts over S1, reinitialization
240 * of 8259 is needed after S1 resume.
241 */
242static int __init init_ints_after_s1(struct dmi_system_id *d)
243{ 264{
244 printk(KERN_WARNING "%s with broken S1 detected.\n", d->ident); 265 suspend_state_t states[] = {
245 init_8259A_after_S1 = 1; 266 [1] = PM_SUSPEND_STANDBY,
246 return 0; 267 [3] = PM_SUSPEND_MEM,
268 [5] = PM_SUSPEND_MAX
269 };
270
271 if (acpi_state < 6 && states[acpi_state])
272 return pm_suspend(states[acpi_state]);
273 if (acpi_state == 4)
274 return hibernate();
275 return -EINVAL;
247} 276}
248 277
249static struct dmi_system_id __initdata acpisleep_dmi_table[] = { 278/**
250 { 279 * acpi_pm_device_sleep_state - return preferred power state of ACPI device
251 .callback = init_ints_after_s1, 280 * in the system sleep state given by %acpi_target_sleep_state
252 .ident = "Toshiba Satellite 4030cdt", 281 * @dev: device to examine
253 .matches = {DMI_MATCH(DMI_PRODUCT_NAME, "S4030CDT/4.3"),}, 282 * @wake: if set, the device should be able to wake up the system
254 }, 283 * @d_min_p: used to store the upper limit of allowed states range
255 {}, 284 * Return value: preferred power state of the device on success, -ENODEV on
256}; 285 * failure (ie. if there's no 'struct acpi_device' for @dev)
286 *
287 * Find the lowest power (highest number) ACPI device power state that
288 * device @dev can be in while the system is in the sleep state represented
289 * by %acpi_target_sleep_state. If @wake is nonzero, the device should be
290 * able to wake up the system from this sleep state. If @d_min_p is set,
291 * the highest power (lowest number) device power state of @dev allowed
292 * in this system sleep state is stored at the location pointed to by it.
293 *
294 * The caller must ensure that @dev is valid before using this function.
295 * The caller is also responsible for figuring out if the device is
296 * supposed to be able to wake up the system and passing this information
297 * via @wake.
298 */
299
300int acpi_pm_device_sleep_state(struct device *dev, int wake, int *d_min_p)
301{
302 acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
303 struct acpi_device *adev;
304 char acpi_method[] = "_SxD";
305 unsigned long d_min, d_max;
306
307 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
308 printk(KERN_ERR "ACPI handle has no context!\n");
309 return -ENODEV;
310 }
311
312 acpi_method[2] = '0' + acpi_target_sleep_state;
313 /*
314 * If the sleep state is S0, we will return D3, but if the device has
315 * _S0W, we will use the value from _S0W
316 */
317 d_min = ACPI_STATE_D0;
318 d_max = ACPI_STATE_D3;
319
320 /*
321 * If present, _SxD methods return the minimum D-state (highest power
322 * state) we can use for the corresponding S-states. Otherwise, the
323 * minimum D-state is D0 (ACPI 3.x).
324 *
325 * NOTE: We rely on acpi_evaluate_integer() not clobbering the integer
326 * provided -- that's our fault recovery, we ignore retval.
327 */
328 if (acpi_target_sleep_state > ACPI_STATE_S0)
329 acpi_evaluate_integer(handle, acpi_method, NULL, &d_min);
330
331 /*
332 * If _PRW says we can wake up the system from the target sleep state,
333 * the D-state returned by _SxD is sufficient for that (we assume a
334 * wakeup-aware driver if wake is set). Still, if _SxW exists
335 * (ACPI 3.x), it should return the maximum (lowest power) D-state that
336 * can wake the system. _S0W may be valid, too.
337 */
338 if (acpi_target_sleep_state == ACPI_STATE_S0 ||
339 (wake && adev->wakeup.state.enabled &&
340 adev->wakeup.sleep_state <= acpi_target_sleep_state)) {
341 acpi_method[3] = 'W';
342 acpi_evaluate_integer(handle, acpi_method, NULL, &d_max);
343 /* Sanity check */
344 if (d_max < d_min)
345 d_min = d_max;
346 }
347
348 if (d_min_p)
349 *d_min_p = d_min;
350 return d_max;
351}
257 352
258int __init acpi_sleep_init(void) 353int __init acpi_sleep_init(void)
259{ 354{
355 acpi_status status;
356 u8 type_a, type_b;
357#ifdef CONFIG_SUSPEND
260 int i = 0; 358 int i = 0;
261 359
262 dmi_check_system(acpisleep_dmi_table); 360 dmi_check_system(acpisleep_dmi_table);
361#endif
263 362
264 if (acpi_disabled) 363 if (acpi_disabled)
265 return 0; 364 return 0;
266 365
366#ifdef CONFIG_SUSPEND
267 printk(KERN_INFO PREFIX "(supports"); 367 printk(KERN_INFO PREFIX "(supports");
268 for (i = 0; i < ACPI_S_STATE_COUNT; i++) { 368 for (i = ACPI_STATE_S0; i < ACPI_STATE_S4; i++) {
269 acpi_status status;
270 u8 type_a, type_b;
271 status = acpi_get_sleep_type_data(i, &type_a, &type_b); 369 status = acpi_get_sleep_type_data(i, &type_a, &type_b);
272 if (ACPI_SUCCESS(status)) { 370 if (ACPI_SUCCESS(status)) {
273 sleep_states[i] = 1; 371 sleep_states[i] = 1;
@@ -277,10 +375,14 @@ int __init acpi_sleep_init(void)
277 printk(")\n"); 375 printk(")\n");
278 376
279 pm_set_ops(&acpi_pm_ops); 377 pm_set_ops(&acpi_pm_ops);
378#endif
280 379
281#ifdef CONFIG_SOFTWARE_SUSPEND 380#ifdef CONFIG_HIBERNATION
282 if (sleep_states[ACPI_STATE_S4]) 381 status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b);
382 if (ACPI_SUCCESS(status)) {
283 hibernation_set_ops(&acpi_hibernation_ops); 383 hibernation_set_ops(&acpi_hibernation_ops);
384 sleep_states[ACPI_STATE_S4] = 1;
385 }
284#else 386#else
285 sleep_states[ACPI_STATE_S4] = 0; 387 sleep_states[ACPI_STATE_S4] = 0;
286#endif 388#endif
diff --git a/drivers/acpi/sleep/proc.c b/drivers/acpi/sleep/proc.c
index 61f1822cc350..66b62b0d3609 100644
--- a/drivers/acpi/sleep/proc.c
+++ b/drivers/acpi/sleep/proc.c
@@ -14,8 +14,16 @@
14#include "sleep.h" 14#include "sleep.h"
15 15
16#define _COMPONENT ACPI_SYSTEM_COMPONENT 16#define _COMPONENT ACPI_SYSTEM_COMPONENT
17
18/*
19 * this file provides support for:
20 * /proc/acpi/sleep
21 * /proc/acpi/alarm
22 * /proc/acpi/wakeup
23 */
24
17ACPI_MODULE_NAME("sleep") 25ACPI_MODULE_NAME("sleep")
18#ifdef CONFIG_ACPI_SLEEP_PROC_SLEEP 26#ifdef CONFIG_ACPI_PROCFS_SLEEP
19static int acpi_system_sleep_seq_show(struct seq_file *seq, void *offset) 27static int acpi_system_sleep_seq_show(struct seq_file *seq, void *offset)
20{ 28{
21 int i; 29 int i;
@@ -58,7 +66,7 @@ acpi_system_write_sleep(struct file *file,
58 goto Done; 66 goto Done;
59 } 67 }
60 state = simple_strtoul(str, NULL, 0); 68 state = simple_strtoul(str, NULL, 0);
61#ifdef CONFIG_SOFTWARE_SUSPEND 69#ifdef CONFIG_HIBERNATION
62 if (state == 4) { 70 if (state == 4) {
63 error = hibernate(); 71 error = hibernate();
64 goto Done; 72 goto Done;
@@ -68,9 +76,9 @@ acpi_system_write_sleep(struct file *file,
68 Done: 76 Done:
69 return error ? error : count; 77 return error ? error : count;
70} 78}
71#endif /* CONFIG_ACPI_SLEEP_PROC_SLEEP */ 79#endif /* CONFIG_ACPI_PROCFS_SLEEP */
72 80
73#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE) 81#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE) || !defined(CONFIG_X86)
74/* use /sys/class/rtc/rtcX/wakealarm instead; it's not ACPI-specific */ 82/* use /sys/class/rtc/rtcX/wakealarm instead; it's not ACPI-specific */
75#else 83#else
76#define HAVE_ACPI_LEGACY_ALARM 84#define HAVE_ACPI_LEGACY_ALARM
@@ -463,7 +471,7 @@ static const struct file_operations acpi_system_wakeup_device_fops = {
463 .release = single_release, 471 .release = single_release,
464}; 472};
465 473
466#ifdef CONFIG_ACPI_SLEEP_PROC_SLEEP 474#ifdef CONFIG_ACPI_PROCFS_SLEEP
467static const struct file_operations acpi_system_sleep_fops = { 475static const struct file_operations acpi_system_sleep_fops = {
468 .open = acpi_system_sleep_open_fs, 476 .open = acpi_system_sleep_open_fs,
469 .read = seq_read, 477 .read = seq_read,
@@ -471,7 +479,7 @@ static const struct file_operations acpi_system_sleep_fops = {
471 .llseek = seq_lseek, 479 .llseek = seq_lseek,
472 .release = single_release, 480 .release = single_release,
473}; 481};
474#endif /* CONFIG_ACPI_SLEEP_PROC_SLEEP */ 482#endif /* CONFIG_ACPI_PROCFS_SLEEP */
475 483
476#ifdef HAVE_ACPI_LEGACY_ALARM 484#ifdef HAVE_ACPI_LEGACY_ALARM
477static const struct file_operations acpi_system_alarm_fops = { 485static const struct file_operations acpi_system_alarm_fops = {
@@ -498,14 +506,14 @@ static int __init acpi_sleep_proc_init(void)
498 if (acpi_disabled) 506 if (acpi_disabled)
499 return 0; 507 return 0;
500 508
501#ifdef CONFIG_ACPI_SLEEP_PROC_SLEEP 509#ifdef CONFIG_ACPI_PROCFS_SLEEP
502 /* 'sleep' [R/W] */ 510 /* 'sleep' [R/W] */
503 entry = 511 entry =
504 create_proc_entry("sleep", S_IFREG | S_IRUGO | S_IWUSR, 512 create_proc_entry("sleep", S_IFREG | S_IRUGO | S_IWUSR,
505 acpi_root_dir); 513 acpi_root_dir);
506 if (entry) 514 if (entry)
507 entry->proc_fops = &acpi_system_sleep_fops; 515 entry->proc_fops = &acpi_system_sleep_fops;
508#endif 516#endif /* CONFIG_ACPI_PROCFS */
509 517
510#ifdef HAVE_ACPI_LEGACY_ALARM 518#ifdef HAVE_ACPI_LEGACY_ALARM
511 /* 'alarm' [R/W] */ 519 /* 'alarm' [R/W] */
diff --git a/drivers/acpi/sleep/sleep.h b/drivers/acpi/sleep/sleep.h
index f3e70397a7d6..ff1f8504f497 100644
--- a/drivers/acpi/sleep/sleep.h
+++ b/drivers/acpi/sleep/sleep.h
@@ -6,3 +6,5 @@ extern void acpi_enable_wakeup_device_prep(u8 sleep_state);
6extern void acpi_enable_wakeup_device(u8 sleep_state); 6extern void acpi_enable_wakeup_device(u8 sleep_state);
7extern void acpi_disable_wakeup_device(u8 sleep_state); 7extern void acpi_disable_wakeup_device(u8 sleep_state);
8extern void acpi_gpe_sleep_prepare(u32 sleep_state); 8extern void acpi_gpe_sleep_prepare(u32 sleep_state);
9
10extern int acpi_sleep_prepare(u32 acpi_state);
diff --git a/drivers/acpi/sleep/wakeup.c b/drivers/acpi/sleep/wakeup.c
index fab8f2694f03..97c27ddb144d 100644
--- a/drivers/acpi/sleep/wakeup.c
+++ b/drivers/acpi/sleep/wakeup.c
@@ -17,7 +17,6 @@ ACPI_MODULE_NAME("wakeup_devices")
17extern struct list_head acpi_wakeup_device_list; 17extern struct list_head acpi_wakeup_device_list;
18extern spinlock_t acpi_device_lock; 18extern spinlock_t acpi_device_lock;
19 19
20#ifdef CONFIG_ACPI_SLEEP
21/** 20/**
22 * acpi_enable_wakeup_device_prep - prepare wakeup devices 21 * acpi_enable_wakeup_device_prep - prepare wakeup devices
23 * @sleep_state: ACPI state 22 * @sleep_state: ACPI state
@@ -180,7 +179,6 @@ static int __init acpi_wakeup_device_init(void)
180} 179}
181 180
182late_initcall(acpi_wakeup_device_init); 181late_initcall(acpi_wakeup_device_init);
183#endif
184 182
185/* 183/*
186 * Disable all wakeup GPEs before entering requested sleep state. 184 * Disable all wakeup GPEs before entering requested sleep state.
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 58f1338981bc..5a62de1b7f2a 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -92,10 +92,16 @@ static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file);
92static ssize_t acpi_thermal_write_polling(struct file *, const char __user *, 92static ssize_t acpi_thermal_write_polling(struct file *, const char __user *,
93 size_t, loff_t *); 93 size_t, loff_t *);
94 94
95static const struct acpi_device_id thermal_device_ids[] = {
96 {ACPI_THERMAL_HID, 0},
97 {"", 0},
98};
99MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
100
95static struct acpi_driver acpi_thermal_driver = { 101static struct acpi_driver acpi_thermal_driver = {
96 .name = "thermal", 102 .name = "thermal",
97 .class = ACPI_THERMAL_CLASS, 103 .class = ACPI_THERMAL_CLASS,
98 .ids = ACPI_THERMAL_HID, 104 .ids = thermal_device_ids,
99 .ops = { 105 .ops = {
100 .add = acpi_thermal_add, 106 .add = acpi_thermal_add,
101 .remove = acpi_thermal_remove, 107 .remove = acpi_thermal_remove,
diff --git a/drivers/acpi/utilities/uteval.c b/drivers/acpi/utilities/uteval.c
index f112af433e36..0042b7e78b26 100644
--- a/drivers/acpi/utilities/uteval.c
+++ b/drivers/acpi/utilities/uteval.c
@@ -407,7 +407,7 @@ acpi_ut_copy_id_string(char *destination, char *source, acpi_size max_length)
407 407
408acpi_status 408acpi_status
409acpi_ut_execute_HID(struct acpi_namespace_node *device_node, 409acpi_ut_execute_HID(struct acpi_namespace_node *device_node,
410 struct acpi_device_id *hid) 410 struct acpica_device_id *hid)
411{ 411{
412 union acpi_operand_object *obj_desc; 412 union acpi_operand_object *obj_desc;
413 acpi_status status; 413 acpi_status status;
@@ -609,7 +609,7 @@ acpi_ut_execute_CID(struct acpi_namespace_node * device_node,
609 609
610acpi_status 610acpi_status
611acpi_ut_execute_UID(struct acpi_namespace_node *device_node, 611acpi_ut_execute_UID(struct acpi_namespace_node *device_node,
612 struct acpi_device_id *uid) 612 struct acpica_device_id *uid)
613{ 613{
614 union acpi_operand_object *obj_desc; 614 union acpi_operand_object *obj_desc;
615 acpi_status status; 615 acpi_status status;
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index 04ea697f72bf..d98701941981 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -74,10 +74,16 @@ MODULE_LICENSE("GPL");
74static int acpi_video_bus_add(struct acpi_device *device); 74static int acpi_video_bus_add(struct acpi_device *device);
75static int acpi_video_bus_remove(struct acpi_device *device, int type); 75static int acpi_video_bus_remove(struct acpi_device *device, int type);
76 76
77static const struct acpi_device_id video_device_ids[] = {
78 {ACPI_VIDEO_HID, 0},
79 {"", 0},
80};
81MODULE_DEVICE_TABLE(acpi, video_device_ids);
82
77static struct acpi_driver acpi_video_bus = { 83static struct acpi_driver acpi_video_bus = {
78 .name = "video", 84 .name = "video",
79 .class = ACPI_VIDEO_CLASS, 85 .class = ACPI_VIDEO_CLASS,
80 .ids = ACPI_VIDEO_HID, 86 .ids = video_device_ids,
81 .ops = { 87 .ops = {
82 .add = acpi_video_bus_add, 88 .add = acpi_video_bus_add,
83 .remove = acpi_video_bus_remove, 89 .remove = acpi_video_bus_remove,
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index d9fa329fd157..ad070861bb53 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -91,6 +91,7 @@
91#include <linux/device.h> 91#include <linux/device.h>
92#include <scsi/scsi_host.h> 92#include <scsi/scsi_host.h>
93#include <linux/libata.h> 93#include <linux/libata.h>
94#include <linux/dmi.h>
94 95
95#define DRV_NAME "ata_piix" 96#define DRV_NAME "ata_piix"
96#define DRV_VERSION "2.11" 97#define DRV_VERSION "2.11"
@@ -140,6 +141,9 @@ enum {
140 RV = -3, /* reserved */ 141 RV = -3, /* reserved */
141 142
142 PIIX_AHCI_DEVICE = 6, 143 PIIX_AHCI_DEVICE = 6,
144
145 /* host->flags bits */
146 PIIX_HOST_BROKEN_SUSPEND = (1 << 24),
143}; 147};
144 148
145struct piix_map_db { 149struct piix_map_db {
@@ -159,6 +163,10 @@ static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev);
159static void piix_set_dmamode (struct ata_port *ap, struct ata_device *adev); 163static void piix_set_dmamode (struct ata_port *ap, struct ata_device *adev);
160static void ich_set_dmamode (struct ata_port *ap, struct ata_device *adev); 164static void ich_set_dmamode (struct ata_port *ap, struct ata_device *adev);
161static int ich_pata_cable_detect(struct ata_port *ap); 165static int ich_pata_cable_detect(struct ata_port *ap);
166#ifdef CONFIG_PM
167static int piix_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
168static int piix_pci_device_resume(struct pci_dev *pdev);
169#endif
162 170
163static unsigned int in_module_init = 1; 171static unsigned int in_module_init = 1;
164 172
@@ -255,8 +263,8 @@ static struct pci_driver piix_pci_driver = {
255 .probe = piix_init_one, 263 .probe = piix_init_one,
256 .remove = ata_pci_remove_one, 264 .remove = ata_pci_remove_one,
257#ifdef CONFIG_PM 265#ifdef CONFIG_PM
258 .suspend = ata_pci_device_suspend, 266 .suspend = piix_pci_device_suspend,
259 .resume = ata_pci_device_resume, 267 .resume = piix_pci_device_resume,
260#endif 268#endif
261}; 269};
262 270
@@ -881,6 +889,107 @@ static void ich_set_dmamode (struct ata_port *ap, struct ata_device *adev)
881 do_pata_set_dmamode(ap, adev, 1); 889 do_pata_set_dmamode(ap, adev, 1);
882} 890}
883 891
892#ifdef CONFIG_PM
893static struct dmi_system_id piix_broken_suspend_dmi_table[] = {
894 {
895 .ident = "TECRA M5",
896 .matches = {
897 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
898 DMI_MATCH(DMI_PRODUCT_NAME, "TECRA M5"),
899 },
900 },
901 {
902 .ident = "Satellite U200",
903 .matches = {
904 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
905 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite U200"),
906 },
907 },
908 {
909 .ident = "Satellite U205",
910 .matches = {
911 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
912 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite U205"),
913 },
914 },
915 {
916 .ident = "Portege M500",
917 .matches = {
918 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
919 DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M500"),
920 },
921 },
922 { }
923};
924
925static int piix_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
926{
927 struct ata_host *host = dev_get_drvdata(&pdev->dev);
928 unsigned long flags;
929 int rc = 0;
930
931 rc = ata_host_suspend(host, mesg);
932 if (rc)
933 return rc;
934
935 /* Some braindamaged ACPI suspend implementations expect the
936 * controller to be awake on entry; otherwise, it burns cpu
937 * cycles and power trying to do something to the sleeping
938 * beauty.
939 */
940 if (dmi_check_system(piix_broken_suspend_dmi_table) &&
941 mesg.event == PM_EVENT_SUSPEND) {
942 pci_save_state(pdev);
943
944 /* mark its power state as "unknown", since we don't
945 * know if e.g. the BIOS will change its device state
946 * when we suspend.
947 */
948 if (pdev->current_state == PCI_D0)
949 pdev->current_state = PCI_UNKNOWN;
950
951 /* tell resume that it's waking up from broken suspend */
952 spin_lock_irqsave(&host->lock, flags);
953 host->flags |= PIIX_HOST_BROKEN_SUSPEND;
954 spin_unlock_irqrestore(&host->lock, flags);
955 } else
956 ata_pci_device_do_suspend(pdev, mesg);
957
958 return 0;
959}
960
961static int piix_pci_device_resume(struct pci_dev *pdev)
962{
963 struct ata_host *host = dev_get_drvdata(&pdev->dev);
964 unsigned long flags;
965 int rc;
966
967 if (host->flags & PIIX_HOST_BROKEN_SUSPEND) {
968 spin_lock_irqsave(&host->lock, flags);
969 host->flags &= ~PIIX_HOST_BROKEN_SUSPEND;
970 spin_unlock_irqrestore(&host->lock, flags);
971
972 pci_set_power_state(pdev, PCI_D0);
973 pci_restore_state(pdev);
974
975 /* PCI device wasn't disabled during suspend. Use
976 * __pci_reenable_device() to avoid affecting the
977 * enable count.
978 */
979 rc = __pci_reenable_device(pdev);
980 if (rc)
981 dev_printk(KERN_ERR, &pdev->dev, "failed to enable "
982 "device after resume (%d)\n", rc);
983 } else
984 rc = ata_pci_device_do_resume(pdev);
985
986 if (rc == 0)
987 ata_host_resume(host);
988
989 return rc;
990}
991#endif
992
884#define AHCI_PCI_BAR 5 993#define AHCI_PCI_BAR 5
885#define AHCI_GLOBAL_CTL 0x04 994#define AHCI_GLOBAL_CTL 0x04
886#define AHCI_ENABLE (1 << 31) 995#define AHCI_ENABLE (1 << 31)
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 12ac0b511f79..e83647651b31 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -768,7 +768,7 @@ static void ata_scsi_dev_config(struct scsi_device *sdev,
768 * Decrement max hw segments accordingly. 768 * Decrement max hw segments accordingly.
769 */ 769 */
770 if (dev->class == ATA_DEV_ATAPI) { 770 if (dev->class == ATA_DEV_ATAPI) {
771 request_queue_t *q = sdev->request_queue; 771 struct request_queue *q = sdev->request_queue;
772 blk_queue_max_hw_segments(q, q->max_hw_segments - 1); 772 blk_queue_max_hw_segments(q, q->max_hw_segments - 1);
773 } 773 }
774 774
diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c
index 010436795d20..e8a28e94fe47 100644
--- a/drivers/ata/pata_ali.c
+++ b/drivers/ata/pata_ali.c
@@ -45,7 +45,7 @@ static struct dmi_system_id cable_dmi_table[] = {
45 .ident = "HP Pavilion N5430", 45 .ident = "HP Pavilion N5430",
46 .matches = { 46 .matches = {
47 DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"), 47 DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
48 DMI_MATCH(DMI_BOARD_NAME, "OmniBook N32N-736"), 48 DMI_MATCH(DMI_BOARD_VERSION, "OmniBook N32N-736"),
49 }, 49 },
50 }, 50 },
51 { } 51 { }
diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
index b0af65aadde3..84d9c5568567 100644
--- a/drivers/ata/pata_hpt37x.c
+++ b/drivers/ata/pata_hpt37x.c
@@ -26,7 +26,7 @@
26#include <linux/libata.h> 26#include <linux/libata.h>
27 27
28#define DRV_NAME "pata_hpt37x" 28#define DRV_NAME "pata_hpt37x"
29#define DRV_VERSION "0.6.6" 29#define DRV_VERSION "0.6.7"
30 30
31struct hpt_clock { 31struct hpt_clock {
32 u8 xfer_speed; 32 u8 xfer_speed;
@@ -1103,17 +1103,17 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
1103 1103
1104 /* Select the DPLL clock. */ 1104 /* Select the DPLL clock. */
1105 pci_write_config_byte(dev, 0x5b, 0x21); 1105 pci_write_config_byte(dev, 0x5b, 0x21);
1106 pci_write_config_dword(dev, 0x5C, (f_high << 16) | f_low); 1106 pci_write_config_dword(dev, 0x5C, (f_high << 16) | f_low | 0x100);
1107 1107
1108 for(adjust = 0; adjust < 8; adjust++) { 1108 for(adjust = 0; adjust < 8; adjust++) {
1109 if (hpt37x_calibrate_dpll(dev)) 1109 if (hpt37x_calibrate_dpll(dev))
1110 break; 1110 break;
1111 /* See if it'll settle at a fractionally different clock */ 1111 /* See if it'll settle at a fractionally different clock */
1112 if ((adjust & 3) == 3) { 1112 if (adjust & 1)
1113 f_low --; 1113 f_low -= adjust >> 1;
1114 f_high ++; 1114 else
1115 } 1115 f_high += adjust >> 1;
1116 pci_write_config_dword(dev, 0x5C, (f_high << 16) | f_low); 1116 pci_write_config_dword(dev, 0x5C, (f_high << 16) | f_low | 0x100);
1117 } 1117 }
1118 if (adjust == 8) { 1118 if (adjust == 8) {
1119 printk(KERN_WARNING "hpt37x: DPLL did not stabilize.\n"); 1119 printk(KERN_WARNING "hpt37x: DPLL did not stabilize.\n");
diff --git a/drivers/base/power/Makefile b/drivers/base/power/Makefile
index 966a5e287415..9caeaea753a3 100644
--- a/drivers/base/power/Makefile
+++ b/drivers/base/power/Makefile
@@ -1,5 +1,5 @@
1obj-y := shutdown.o 1obj-y := shutdown.o
2obj-$(CONFIG_PM) += main.o suspend.o resume.o sysfs.o 2obj-$(CONFIG_PM_SLEEP) += main.o suspend.o resume.o sysfs.o
3obj-$(CONFIG_PM_TRACE) += trace.o 3obj-$(CONFIG_PM_TRACE) += trace.o
4 4
5ifeq ($(CONFIG_DEBUG_DRIVER),y) 5ifeq ($(CONFIG_DEBUG_DRIVER),y)
diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
index 591a0dd5deee..8ba0830cbc03 100644
--- a/drivers/base/power/power.h
+++ b/drivers/base/power/power.h
@@ -5,7 +5,7 @@
5extern void device_shutdown(void); 5extern void device_shutdown(void);
6 6
7 7
8#ifdef CONFIG_PM 8#ifdef CONFIG_PM_SLEEP
9 9
10/* 10/*
11 * main.c 11 * main.c
@@ -62,7 +62,7 @@ extern int resume_device(struct device *);
62 */ 62 */
63extern int suspend_device(struct device *, pm_message_t); 63extern int suspend_device(struct device *, pm_message_t);
64 64
65#else /* CONFIG_PM */ 65#else /* CONFIG_PM_SLEEP */
66 66
67 67
68static inline int device_pm_add(struct device * dev) 68static inline int device_pm_add(struct device * dev)
diff --git a/drivers/base/power/shutdown.c b/drivers/base/power/shutdown.c
index a47ee1b70d20..56e8eaaac012 100644
--- a/drivers/base/power/shutdown.c
+++ b/drivers/base/power/shutdown.c
@@ -44,7 +44,5 @@ void device_shutdown(void)
44 dev->driver->shutdown(dev); 44 dev->driver->shutdown(dev);
45 } 45 }
46 } 46 }
47
48 sysdev_shutdown();
49} 47}
50 48
diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c
index 6ce8b897e262..c9751b2b57e6 100644
--- a/drivers/block/amiflop.c
+++ b/drivers/block/amiflop.c
@@ -1422,7 +1422,7 @@ static void redo_fd_request(void)
1422 goto repeat; 1422 goto repeat;
1423} 1423}
1424 1424
1425static void do_fd_request(request_queue_t * q) 1425static void do_fd_request(struct request_queue * q)
1426{ 1426{
1427 redo_fd_request(); 1427 redo_fd_request();
1428} 1428}
diff --git a/drivers/block/aoe/aoe.h b/drivers/block/aoe/aoe.h
index 1d8466817943..ba07f762c4cb 100644
--- a/drivers/block/aoe/aoe.h
+++ b/drivers/block/aoe/aoe.h
@@ -138,7 +138,7 @@ struct aoedev {
138 u16 maxbcnt; 138 u16 maxbcnt;
139 struct work_struct work;/* disk create work struct */ 139 struct work_struct work;/* disk create work struct */
140 struct gendisk *gd; 140 struct gendisk *gd;
141 request_queue_t blkq; 141 struct request_queue blkq;
142 struct hd_geometry geo; 142 struct hd_geometry geo;
143 sector_t ssize; 143 sector_t ssize;
144 struct timer_list timer; 144 struct timer_list timer;
diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c
index 4f598270fa31..007faaf008e7 100644
--- a/drivers/block/aoe/aoeblk.c
+++ b/drivers/block/aoe/aoeblk.c
@@ -125,7 +125,7 @@ aoeblk_release(struct inode *inode, struct file *filp)
125} 125}
126 126
127static int 127static int
128aoeblk_make_request(request_queue_t *q, struct bio *bio) 128aoeblk_make_request(struct request_queue *q, struct bio *bio)
129{ 129{
130 struct aoedev *d; 130 struct aoedev *d;
131 struct buf *buf; 131 struct buf *buf;
diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index 14d6b9492750..94268c75d04f 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -1466,7 +1466,7 @@ repeat:
1466} 1466}
1467 1467
1468 1468
1469void do_fd_request(request_queue_t * q) 1469void do_fd_request(struct request_queue * q)
1470{ 1470{
1471 unsigned long flags; 1471 unsigned long flags;
1472 1472
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index a2d6612b80d2..1be82d544dc3 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -139,7 +139,7 @@ static struct board_type products[] = {
139 139
140static ctlr_info_t *hba[MAX_CTLR]; 140static ctlr_info_t *hba[MAX_CTLR];
141 141
142static void do_cciss_request(request_queue_t *q); 142static void do_cciss_request(struct request_queue *q);
143static irqreturn_t do_cciss_intr(int irq, void *dev_id); 143static irqreturn_t do_cciss_intr(int irq, void *dev_id);
144static int cciss_open(struct inode *inode, struct file *filep); 144static int cciss_open(struct inode *inode, struct file *filep);
145static int cciss_release(struct inode *inode, struct file *filep); 145static int cciss_release(struct inode *inode, struct file *filep);
@@ -1584,7 +1584,7 @@ static int deregister_disk(struct gendisk *disk, drive_info_struct *drv,
1584 */ 1584 */
1585 if (h->gendisk[0] != disk) { 1585 if (h->gendisk[0] != disk) {
1586 if (disk) { 1586 if (disk) {
1587 request_queue_t *q = disk->queue; 1587 struct request_queue *q = disk->queue;
1588 if (disk->flags & GENHD_FL_UP) 1588 if (disk->flags & GENHD_FL_UP)
1589 del_gendisk(disk); 1589 del_gendisk(disk);
1590 if (q) { 1590 if (q) {
@@ -2511,7 +2511,7 @@ after_error_processing:
2511/* 2511/*
2512 * Get a request and submit it to the controller. 2512 * Get a request and submit it to the controller.
2513 */ 2513 */
2514static void do_cciss_request(request_queue_t *q) 2514static void do_cciss_request(struct request_queue *q)
2515{ 2515{
2516 ctlr_info_t *h = q->queuedata; 2516 ctlr_info_t *h = q->queuedata;
2517 CommandList_struct *c; 2517 CommandList_struct *c;
@@ -3380,7 +3380,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
3380 do { 3380 do {
3381 drive_info_struct *drv = &(hba[i]->drv[j]); 3381 drive_info_struct *drv = &(hba[i]->drv[j]);
3382 struct gendisk *disk = hba[i]->gendisk[j]; 3382 struct gendisk *disk = hba[i]->gendisk[j];
3383 request_queue_t *q; 3383 struct request_queue *q;
3384 3384
3385 /* Check if the disk was allocated already */ 3385 /* Check if the disk was allocated already */
3386 if (!disk){ 3386 if (!disk){
@@ -3523,7 +3523,7 @@ static void __devexit cciss_remove_one(struct pci_dev *pdev)
3523 for (j = 0; j < CISS_MAX_LUN; j++) { 3523 for (j = 0; j < CISS_MAX_LUN; j++) {
3524 struct gendisk *disk = hba[i]->gendisk[j]; 3524 struct gendisk *disk = hba[i]->gendisk[j];
3525 if (disk) { 3525 if (disk) {
3526 request_queue_t *q = disk->queue; 3526 struct request_queue *q = disk->queue;
3527 3527
3528 if (disk->flags & GENHD_FL_UP) 3528 if (disk->flags & GENHD_FL_UP)
3529 del_gendisk(disk); 3529 del_gendisk(disk);
diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
index b94cd1c32131..be4e3477d83b 100644
--- a/drivers/block/cpqarray.c
+++ b/drivers/block/cpqarray.c
@@ -161,7 +161,7 @@ static int ida_ioctl(struct inode *inode, struct file *filep, unsigned int cmd,
161static int ida_getgeo(struct block_device *bdev, struct hd_geometry *geo); 161static int ida_getgeo(struct block_device *bdev, struct hd_geometry *geo);
162static int ida_ctlr_ioctl(ctlr_info_t *h, int dsk, ida_ioctl_t *io); 162static int ida_ctlr_ioctl(ctlr_info_t *h, int dsk, ida_ioctl_t *io);
163 163
164static void do_ida_request(request_queue_t *q); 164static void do_ida_request(struct request_queue *q);
165static void start_io(ctlr_info_t *h); 165static void start_io(ctlr_info_t *h);
166 166
167static inline void addQ(cmdlist_t **Qptr, cmdlist_t *c); 167static inline void addQ(cmdlist_t **Qptr, cmdlist_t *c);
@@ -391,7 +391,7 @@ static void __devexit cpqarray_remove_one_eisa (int i)
391/* pdev is NULL for eisa */ 391/* pdev is NULL for eisa */
392static int __init cpqarray_register_ctlr( int i, struct pci_dev *pdev) 392static int __init cpqarray_register_ctlr( int i, struct pci_dev *pdev)
393{ 393{
394 request_queue_t *q; 394 struct request_queue *q;
395 int j; 395 int j;
396 396
397 /* 397 /*
@@ -886,7 +886,7 @@ static inline cmdlist_t *removeQ(cmdlist_t **Qptr, cmdlist_t *c)
886 * are in here (either via the dummy do_ida_request functions or by being 886 * are in here (either via the dummy do_ida_request functions or by being
887 * called from the interrupt handler 887 * called from the interrupt handler
888 */ 888 */
889static void do_ida_request(request_queue_t *q) 889static void do_ida_request(struct request_queue *q)
890{ 890{
891 ctlr_info_t *h = q->queuedata; 891 ctlr_info_t *h = q->queuedata;
892 cmdlist_t *c; 892 cmdlist_t *c;
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index fe088045dd08..085b7794fb3e 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -251,7 +251,7 @@ static int irqdma_allocated;
251 251
252static struct request *current_req; 252static struct request *current_req;
253static struct request_queue *floppy_queue; 253static struct request_queue *floppy_queue;
254static void do_fd_request(request_queue_t * q); 254static void do_fd_request(struct request_queue * q);
255 255
256#ifndef fd_get_dma_residue 256#ifndef fd_get_dma_residue
257#define fd_get_dma_residue() get_dma_residue(FLOPPY_DMA) 257#define fd_get_dma_residue() get_dma_residue(FLOPPY_DMA)
@@ -2981,7 +2981,7 @@ static void process_fd_request(void)
2981 schedule_bh(redo_fd_request); 2981 schedule_bh(redo_fd_request);
2982} 2982}
2983 2983
2984static void do_fd_request(request_queue_t * q) 2984static void do_fd_request(struct request_queue * q)
2985{ 2985{
2986 if (max_buffer_sectors == 0) { 2986 if (max_buffer_sectors == 0) {
2987 printk("VFS: do_fd_request called on non-open device\n"); 2987 printk("VFS: do_fd_request called on non-open device\n");
diff --git a/drivers/block/lguest_blk.c b/drivers/block/lguest_blk.c
index 1634c2dd25ec..93e3c4001bf5 100644
--- a/drivers/block/lguest_blk.c
+++ b/drivers/block/lguest_blk.c
@@ -1,6 +1,12 @@
1/* A simple block driver for lguest. 1/*D:400
2 * The Guest block driver
2 * 3 *
3 * Copyright 2006 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation 4 * This is a simple block driver, which appears as /dev/lgba, lgbb, lgbc etc.
5 * The mechanism is simple: we place the information about the request in the
6 * device page, then use SEND_DMA (containing the data for a write, or an empty
7 * "ping" DMA for a read).
8 :*/
9/* Copyright 2006 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation
4 * 10 *
5 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
@@ -25,27 +31,50 @@
25 31
26static char next_block_index = 'a'; 32static char next_block_index = 'a';
27 33
34/*D:420 Here is the structure which holds all the information we need about
35 * each Guest block device.
36 *
37 * I'm sure at this stage, you're wondering "hey, where was the adventure I was
38 * promised?" and thinking "Rusty sucks, I shall say nasty things about him on
39 * my blog". I think Real adventures have boring bits, too, and you're in the
40 * middle of one. But it gets better. Just not quite yet. */
28struct blockdev 41struct blockdev
29{ 42{
43 /* The block queue infrastructure wants a spinlock: it is held while it
44 * calls our block request function. We grab it in our interrupt
45 * handler so the responses don't mess with new requests. */
30 spinlock_t lock; 46 spinlock_t lock;
31 47
32 /* The disk structure for the kernel. */ 48 /* The disk structure registered with kernel. */
33 struct gendisk *disk; 49 struct gendisk *disk;
34 50
35 /* The major number for this disk. */ 51 /* The major device number for this disk, and the interrupt. We only
52 * really keep them here for completeness; we'd need them if we
53 * supported device unplugging. */
36 int major; 54 int major;
37 int irq; 55 int irq;
38 56
57 /* The physical address of this device's memory page */
39 unsigned long phys_addr; 58 unsigned long phys_addr;
40 /* The mapped block page. */ 59 /* The mapped memory page for convenient acces. */
41 struct lguest_block_page *lb_page; 60 struct lguest_block_page *lb_page;
42 61
43 /* We only have a single request outstanding at a time. */ 62 /* We only have a single request outstanding at a time: this is it. */
44 struct lguest_dma dma; 63 struct lguest_dma dma;
45 struct request *req; 64 struct request *req;
46}; 65};
47 66
48/* Jens gave me this nice helper to end all chunks of a request. */ 67/*D:495 We originally used end_request() throughout the driver, but it turns
68 * out that end_request() is deprecated, and doesn't actually end the request
69 * (which seems like a good reason to deprecate it!). It simply ends the first
70 * bio. So if we had 3 bios in a "struct request" we would do all 3,
71 * end_request(), do 2, end_request(), do 1 and end_request(): twice as much
72 * work as we needed to do.
73 *
74 * This reinforced to me that I do not understand the block layer.
75 *
76 * Nonetheless, Jens Axboe gave me this nice helper to end all chunks of a
77 * request. This improved disk speed by 130%. */
49static void end_entire_request(struct request *req, int uptodate) 78static void end_entire_request(struct request *req, int uptodate)
50{ 79{
51 if (end_that_request_first(req, uptodate, req->hard_nr_sectors)) 80 if (end_that_request_first(req, uptodate, req->hard_nr_sectors))
@@ -55,30 +84,62 @@ static void end_entire_request(struct request *req, int uptodate)
55 end_that_request_last(req, uptodate); 84 end_that_request_last(req, uptodate);
56} 85}
57 86
87/* I'm told there are only two stories in the world worth telling: love and
88 * hate. So there used to be a love scene here like this:
89 *
90 * Launcher: We could make beautiful I/O together, you and I.
91 * Guest: My, that's a big disk!
92 *
93 * Unfortunately, it was just too raunchy for our otherwise-gentle tale. */
94
95/*D:490 This is the interrupt handler, called when a block read or write has
96 * been completed for us. */
58static irqreturn_t lgb_irq(int irq, void *_bd) 97static irqreturn_t lgb_irq(int irq, void *_bd)
59{ 98{
99 /* We handed our "struct blockdev" as the argument to request_irq(), so
100 * it is passed through to us here. This tells us which device we're
101 * dealing with in case we have more than one. */
60 struct blockdev *bd = _bd; 102 struct blockdev *bd = _bd;
61 unsigned long flags; 103 unsigned long flags;
62 104
105 /* We weren't doing anything? Strange, but could happen if we shared
106 * interrupts (we don't!). */
63 if (!bd->req) { 107 if (!bd->req) {
64 pr_debug("No work!\n"); 108 pr_debug("No work!\n");
65 return IRQ_NONE; 109 return IRQ_NONE;
66 } 110 }
67 111
112 /* Not done yet? That's equally strange. */
68 if (!bd->lb_page->result) { 113 if (!bd->lb_page->result) {
69 pr_debug("No result!\n"); 114 pr_debug("No result!\n");
70 return IRQ_NONE; 115 return IRQ_NONE;
71 } 116 }
72 117
118 /* We have to grab the lock before ending the request. */
73 spin_lock_irqsave(&bd->lock, flags); 119 spin_lock_irqsave(&bd->lock, flags);
120 /* "result" is 1 for success, 2 for failure: end_entire_request() wants
121 * to know whether this succeeded or not. */
74 end_entire_request(bd->req, bd->lb_page->result == 1); 122 end_entire_request(bd->req, bd->lb_page->result == 1);
123 /* Clear out request, it's done. */
75 bd->req = NULL; 124 bd->req = NULL;
125 /* Reset incoming DMA for next time. */
76 bd->dma.used_len = 0; 126 bd->dma.used_len = 0;
127 /* Ready for more reads or writes */
77 blk_start_queue(bd->disk->queue); 128 blk_start_queue(bd->disk->queue);
78 spin_unlock_irqrestore(&bd->lock, flags); 129 spin_unlock_irqrestore(&bd->lock, flags);
130
131 /* The interrupt was for us, we dealt with it. */
79 return IRQ_HANDLED; 132 return IRQ_HANDLED;
80} 133}
81 134
135/*D:480 The block layer's "struct request" contains a number of "struct bio"s,
136 * each of which contains "struct bio_vec"s, each of which contains a page, an
137 * offset and a length.
138 *
139 * Fortunately there are iterators to help us walk through the "struct
140 * request". Even more fortunately, there were plenty of places to steal the
141 * code from. We pack the "struct request" into our "struct lguest_dma" and
142 * return the total length. */
82static unsigned int req_to_dma(struct request *req, struct lguest_dma *dma) 143static unsigned int req_to_dma(struct request *req, struct lguest_dma *dma)
83{ 144{
84 unsigned int i = 0, idx, len = 0; 145 unsigned int i = 0, idx, len = 0;
@@ -87,8 +148,13 @@ static unsigned int req_to_dma(struct request *req, struct lguest_dma *dma)
87 rq_for_each_bio(bio, req) { 148 rq_for_each_bio(bio, req) {
88 struct bio_vec *bvec; 149 struct bio_vec *bvec;
89 bio_for_each_segment(bvec, bio, idx) { 150 bio_for_each_segment(bvec, bio, idx) {
151 /* We told the block layer not to give us too many. */
90 BUG_ON(i == LGUEST_MAX_DMA_SECTIONS); 152 BUG_ON(i == LGUEST_MAX_DMA_SECTIONS);
153 /* If we had a zero-length segment, it would look like
154 * the end of the data referred to by the "struct
155 * lguest_dma", so make sure that doesn't happen. */
91 BUG_ON(!bvec->bv_len); 156 BUG_ON(!bvec->bv_len);
157 /* Convert page & offset to a physical address */
92 dma->addr[i] = page_to_phys(bvec->bv_page) 158 dma->addr[i] = page_to_phys(bvec->bv_page)
93 + bvec->bv_offset; 159 + bvec->bv_offset;
94 dma->len[i] = bvec->bv_len; 160 dma->len[i] = bvec->bv_len;
@@ -96,26 +162,39 @@ static unsigned int req_to_dma(struct request *req, struct lguest_dma *dma)
96 i++; 162 i++;
97 } 163 }
98 } 164 }
165 /* If the array isn't full, we mark the end with a 0 length */
99 if (i < LGUEST_MAX_DMA_SECTIONS) 166 if (i < LGUEST_MAX_DMA_SECTIONS)
100 dma->len[i] = 0; 167 dma->len[i] = 0;
101 return len; 168 return len;
102} 169}
103 170
171/* This creates an empty DMA, useful for prodding the Host without sending data
172 * (ie. when we want to do a read) */
104static void empty_dma(struct lguest_dma *dma) 173static void empty_dma(struct lguest_dma *dma)
105{ 174{
106 dma->len[0] = 0; 175 dma->len[0] = 0;
107} 176}
108 177
178/*D:470 Setting up a request is fairly easy: */
109static void setup_req(struct blockdev *bd, 179static void setup_req(struct blockdev *bd,
110 int type, struct request *req, struct lguest_dma *dma) 180 int type, struct request *req, struct lguest_dma *dma)
111{ 181{
182 /* The type is 1 (write) or 0 (read). */
112 bd->lb_page->type = type; 183 bd->lb_page->type = type;
184 /* The sector on disk where the read or write starts. */
113 bd->lb_page->sector = req->sector; 185 bd->lb_page->sector = req->sector;
186 /* The result is initialized to 0 (unfinished). */
114 bd->lb_page->result = 0; 187 bd->lb_page->result = 0;
188 /* The current request (so we can end it in the interrupt handler). */
115 bd->req = req; 189 bd->req = req;
190 /* The number of bytes: returned as a side-effect of req_to_dma(),
191 * which packs the block layer's "struct request" into our "struct
192 * lguest_dma" */
116 bd->lb_page->bytes = req_to_dma(req, dma); 193 bd->lb_page->bytes = req_to_dma(req, dma);
117} 194}
118 195
196/*D:450 Write is pretty straightforward: we pack the request into a "struct
197 * lguest_dma", then use SEND_DMA to send the request. */
119static void do_write(struct blockdev *bd, struct request *req) 198static void do_write(struct blockdev *bd, struct request *req)
120{ 199{
121 struct lguest_dma send; 200 struct lguest_dma send;
@@ -126,6 +205,9 @@ static void do_write(struct blockdev *bd, struct request *req)
126 lguest_send_dma(bd->phys_addr, &send); 205 lguest_send_dma(bd->phys_addr, &send);
127} 206}
128 207
208/* Read is similar to write, except we pack the request into our receive
209 * "struct lguest_dma" and send through an empty DMA just to tell the Host that
210 * there's a request pending. */
129static void do_read(struct blockdev *bd, struct request *req) 211static void do_read(struct blockdev *bd, struct request *req)
130{ 212{
131 struct lguest_dma ping; 213 struct lguest_dma ping;
@@ -137,21 +219,30 @@ static void do_read(struct blockdev *bd, struct request *req)
137 lguest_send_dma(bd->phys_addr, &ping); 219 lguest_send_dma(bd->phys_addr, &ping);
138} 220}
139 221
140static void do_lgb_request(request_queue_t *q) 222/*D:440 This where requests come in: we get handed the request queue and are
223 * expected to pull a "struct request" off it until we've finished them or
224 * we're waiting for a reply: */
225static void do_lgb_request(struct request_queue *q)
141{ 226{
142 struct blockdev *bd; 227 struct blockdev *bd;
143 struct request *req; 228 struct request *req;
144 229
145again: 230again:
231 /* This sometimes returns NULL even on the very first time around. I
232 * wonder if it's something to do with letting elves handle the request
233 * queue... */
146 req = elv_next_request(q); 234 req = elv_next_request(q);
147 if (!req) 235 if (!req)
148 return; 236 return;
149 237
238 /* We attached the struct blockdev to the disk: get it back */
150 bd = req->rq_disk->private_data; 239 bd = req->rq_disk->private_data;
151 /* Sometimes we get repeated requests after blk_stop_queue. */ 240 /* Sometimes we get repeated requests after blk_stop_queue(), but we
241 * can only handle one at a time. */
152 if (bd->req) 242 if (bd->req)
153 return; 243 return;
154 244
245 /* We only do reads and writes: no tricky business! */
155 if (!blk_fs_request(req)) { 246 if (!blk_fs_request(req)) {
156 pr_debug("Got non-command 0x%08x\n", req->cmd_type); 247 pr_debug("Got non-command 0x%08x\n", req->cmd_type);
157 req->errors++; 248 req->errors++;
@@ -164,20 +255,31 @@ again:
164 else 255 else
165 do_read(bd, req); 256 do_read(bd, req);
166 257
167 /* Wait for interrupt to tell us it's done. */ 258 /* We've put out the request, so stop any more coming in until we get
259 * an interrupt, which takes us to lgb_irq() to re-enable the queue. */
168 blk_stop_queue(q); 260 blk_stop_queue(q);
169} 261}
170 262
263/*D:430 This is the "struct block_device_operations" we attach to the disk at
264 * the end of lguestblk_probe(). It doesn't seem to want much. */
171static struct block_device_operations lguestblk_fops = { 265static struct block_device_operations lguestblk_fops = {
172 .owner = THIS_MODULE, 266 .owner = THIS_MODULE,
173}; 267};
174 268
269/*D:425 Setting up a disk device seems to involve a lot of code. I'm not sure
270 * quite why. I do know that the IDE code sent two or three of the maintainers
271 * insane, perhaps this is the fringe of the same disease?
272 *
273 * As in the console code, the probe function gets handed the generic
274 * lguest_device from lguest_bus.c: */
175static int lguestblk_probe(struct lguest_device *lgdev) 275static int lguestblk_probe(struct lguest_device *lgdev)
176{ 276{
177 struct blockdev *bd; 277 struct blockdev *bd;
178 int err; 278 int err;
179 int irqflags = IRQF_SHARED; 279 int irqflags = IRQF_SHARED;
180 280
281 /* First we allocate our own "struct blockdev" and initialize the easy
282 * fields. */
181 bd = kmalloc(sizeof(*bd), GFP_KERNEL); 283 bd = kmalloc(sizeof(*bd), GFP_KERNEL);
182 if (!bd) 284 if (!bd)
183 return -ENOMEM; 285 return -ENOMEM;
@@ -187,59 +289,100 @@ static int lguestblk_probe(struct lguest_device *lgdev)
187 bd->req = NULL; 289 bd->req = NULL;
188 bd->dma.used_len = 0; 290 bd->dma.used_len = 0;
189 bd->dma.len[0] = 0; 291 bd->dma.len[0] = 0;
292 /* The descriptor in the lguest_devices array provided by the Host
293 * gives the Guest the physical page number of the device's page. */
190 bd->phys_addr = (lguest_devices[lgdev->index].pfn << PAGE_SHIFT); 294 bd->phys_addr = (lguest_devices[lgdev->index].pfn << PAGE_SHIFT);
191 295
296 /* We use lguest_map() to get a pointer to the device page */
192 bd->lb_page = lguest_map(bd->phys_addr, 1); 297 bd->lb_page = lguest_map(bd->phys_addr, 1);
193 if (!bd->lb_page) { 298 if (!bd->lb_page) {
194 err = -ENOMEM; 299 err = -ENOMEM;
195 goto out_free_bd; 300 goto out_free_bd;
196 } 301 }
197 302
303 /* We need a major device number: 0 means "assign one dynamically". */
198 bd->major = register_blkdev(0, "lguestblk"); 304 bd->major = register_blkdev(0, "lguestblk");
199 if (bd->major < 0) { 305 if (bd->major < 0) {
200 err = bd->major; 306 err = bd->major;
201 goto out_unmap; 307 goto out_unmap;
202 } 308 }
203 309
310 /* This allocates a "struct gendisk" where we pack all the information
311 * about the disk which the rest of Linux sees. We ask for one minor
312 * number; I do wonder if we should be asking for more. */
204 bd->disk = alloc_disk(1); 313 bd->disk = alloc_disk(1);
205 if (!bd->disk) { 314 if (!bd->disk) {
206 err = -ENOMEM; 315 err = -ENOMEM;
207 goto out_unregister_blkdev; 316 goto out_unregister_blkdev;
208 } 317 }
209 318
319 /* Every disk needs a queue for requests to come in: we set up the
320 * queue with a callback function (the core of our driver) and the lock
321 * to use. */
210 bd->disk->queue = blk_init_queue(do_lgb_request, &bd->lock); 322 bd->disk->queue = blk_init_queue(do_lgb_request, &bd->lock);
211 if (!bd->disk->queue) { 323 if (!bd->disk->queue) {
212 err = -ENOMEM; 324 err = -ENOMEM;
213 goto out_put_disk; 325 goto out_put_disk;
214 } 326 }
215 327
216 /* We can only handle a certain number of sg entries */ 328 /* We can only handle a certain number of pointers in our SEND_DMA
329 * call, so we set that with blk_queue_max_hw_segments(). This is not
330 * to be confused with blk_queue_max_phys_segments() of course! I
331 * know, who could possibly confuse the two?
332 *
333 * Well, it's simple to tell them apart: this one seems to work and the
334 * other one didn't. */
217 blk_queue_max_hw_segments(bd->disk->queue, LGUEST_MAX_DMA_SECTIONS); 335 blk_queue_max_hw_segments(bd->disk->queue, LGUEST_MAX_DMA_SECTIONS);
218 /* Buffers must not cross page boundaries */ 336
337 /* Due to technical limitations of our Host (and simple coding) we
338 * can't have a single buffer which crosses a page boundary. Tell it
339 * here. This means that our maximum request size is 16
340 * (LGUEST_MAX_DMA_SECTIONS) pages. */
219 blk_queue_segment_boundary(bd->disk->queue, PAGE_SIZE-1); 341 blk_queue_segment_boundary(bd->disk->queue, PAGE_SIZE-1);
220 342
343 /* We name our disk: this becomes the device name when udev does its
344 * magic thing and creates the device node, such as /dev/lgba.
345 * next_block_index is a global which starts at 'a'. Unfortunately
346 * this simple increment logic means that the 27th disk will be called
347 * "/dev/lgb{". In that case, I recommend having at least 29 disks, so
348 * your /dev directory will be balanced. */
221 sprintf(bd->disk->disk_name, "lgb%c", next_block_index++); 349 sprintf(bd->disk->disk_name, "lgb%c", next_block_index++);
350
351 /* We look to the device descriptor again to see if this device's
352 * interrupts are expected to be random. If they are, we tell the irq
353 * subsystem. At the moment this bit is always set. */
222 if (lguest_devices[lgdev->index].features & LGUEST_DEVICE_F_RANDOMNESS) 354 if (lguest_devices[lgdev->index].features & LGUEST_DEVICE_F_RANDOMNESS)
223 irqflags |= IRQF_SAMPLE_RANDOM; 355 irqflags |= IRQF_SAMPLE_RANDOM;
356
357 /* Now we have the name and irqflags, we can request the interrupt; we
358 * give it the "struct blockdev" we have set up to pass to lgb_irq()
359 * when there is an interrupt. */
224 err = request_irq(bd->irq, lgb_irq, irqflags, bd->disk->disk_name, bd); 360 err = request_irq(bd->irq, lgb_irq, irqflags, bd->disk->disk_name, bd);
225 if (err) 361 if (err)
226 goto out_cleanup_queue; 362 goto out_cleanup_queue;
227 363
364 /* We bind our one-entry DMA pool to the key for this block device so
365 * the Host can reply to our requests. The key is equal to the
366 * physical address of the device's page, which is conveniently
367 * unique. */
228 err = lguest_bind_dma(bd->phys_addr, &bd->dma, 1, bd->irq); 368 err = lguest_bind_dma(bd->phys_addr, &bd->dma, 1, bd->irq);
229 if (err) 369 if (err)
230 goto out_free_irq; 370 goto out_free_irq;
231 371
372 /* We finish our disk initialization and add the disk to the system. */
232 bd->disk->major = bd->major; 373 bd->disk->major = bd->major;
233 bd->disk->first_minor = 0; 374 bd->disk->first_minor = 0;
234 bd->disk->private_data = bd; 375 bd->disk->private_data = bd;
235 bd->disk->fops = &lguestblk_fops; 376 bd->disk->fops = &lguestblk_fops;
236 /* This is initialized to the disk size by the other end. */ 377 /* This is initialized to the disk size by the Launcher. */
237 set_capacity(bd->disk, bd->lb_page->num_sectors); 378 set_capacity(bd->disk, bd->lb_page->num_sectors);
238 add_disk(bd->disk); 379 add_disk(bd->disk);
239 380
240 printk(KERN_INFO "%s: device %i at major %d\n", 381 printk(KERN_INFO "%s: device %i at major %d\n",
241 bd->disk->disk_name, lgdev->index, bd->major); 382 bd->disk->disk_name, lgdev->index, bd->major);
242 383
384 /* We don't need to keep the "struct blockdev" around, but if we ever
385 * implemented device removal, we'd need this. */
243 lgdev->private = bd; 386 lgdev->private = bd;
244 return 0; 387 return 0;
245 388
@@ -258,6 +401,8 @@ out_free_bd:
258 return err; 401 return err;
259} 402}
260 403
404/*D:410 The boilerplate code for registering the lguest block driver is just
405 * like the console: */
261static struct lguest_driver lguestblk_drv = { 406static struct lguest_driver lguestblk_drv = {
262 .name = "lguestblk", 407 .name = "lguestblk",
263 .owner = THIS_MODULE, 408 .owner = THIS_MODULE,
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index e425daa1eac3..9f015fce4135 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -529,7 +529,7 @@ static struct bio *loop_get_bio(struct loop_device *lo)
529 return bio; 529 return bio;
530} 530}
531 531
532static int loop_make_request(request_queue_t *q, struct bio *old_bio) 532static int loop_make_request(struct request_queue *q, struct bio *old_bio)
533{ 533{
534 struct loop_device *lo = q->queuedata; 534 struct loop_device *lo = q->queuedata;
535 int rw = bio_rw(old_bio); 535 int rw = bio_rw(old_bio);
@@ -558,7 +558,7 @@ out:
558/* 558/*
559 * kick off io on the underlying address space 559 * kick off io on the underlying address space
560 */ 560 */
561static void loop_unplug(request_queue_t *q) 561static void loop_unplug(struct request_queue *q)
562{ 562{
563 struct loop_device *lo = q->queuedata; 563 struct loop_device *lo = q->queuedata;
564 564
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index c12951024090..be92c658f06e 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -100,7 +100,7 @@ static const char *nbdcmd_to_ascii(int cmd)
100static void nbd_end_request(struct request *req) 100static void nbd_end_request(struct request *req)
101{ 101{
102 int uptodate = (req->errors == 0) ? 1 : 0; 102 int uptodate = (req->errors == 0) ? 1 : 0;
103 request_queue_t *q = req->q; 103 struct request_queue *q = req->q;
104 unsigned long flags; 104 unsigned long flags;
105 105
106 dprintk(DBG_BLKDEV, "%s: request %p: %s\n", req->rq_disk->disk_name, 106 dprintk(DBG_BLKDEV, "%s: request %p: %s\n", req->rq_disk->disk_name,
@@ -410,7 +410,7 @@ static void nbd_clear_que(struct nbd_device *lo)
410 * { printk( "Warning: Ignoring result!\n"); nbd_end_request( req ); } 410 * { printk( "Warning: Ignoring result!\n"); nbd_end_request( req ); }
411 */ 411 */
412 412
413static void do_nbd_request(request_queue_t * q) 413static void do_nbd_request(struct request_queue * q)
414{ 414{
415 struct request *req; 415 struct request *req;
416 416
diff --git a/drivers/block/paride/pcd.c b/drivers/block/paride/pcd.c
index 1eeb8f2cde71..b8a994a2b013 100644
--- a/drivers/block/paride/pcd.c
+++ b/drivers/block/paride/pcd.c
@@ -183,7 +183,7 @@ static int pcd_packet(struct cdrom_device_info *cdi,
183static int pcd_detect(void); 183static int pcd_detect(void);
184static void pcd_probe_capabilities(void); 184static void pcd_probe_capabilities(void);
185static void do_pcd_read_drq(void); 185static void do_pcd_read_drq(void);
186static void do_pcd_request(request_queue_t * q); 186static void do_pcd_request(struct request_queue * q);
187static void do_pcd_read(void); 187static void do_pcd_read(void);
188 188
189struct pcd_unit { 189struct pcd_unit {
@@ -713,7 +713,7 @@ static int pcd_detect(void)
713/* I/O request processing */ 713/* I/O request processing */
714static struct request_queue *pcd_queue; 714static struct request_queue *pcd_queue;
715 715
716static void do_pcd_request(request_queue_t * q) 716static void do_pcd_request(struct request_queue * q)
717{ 717{
718 if (pcd_busy) 718 if (pcd_busy)
719 return; 719 return;
diff --git a/drivers/block/paride/pd.c b/drivers/block/paride/pd.c
index 31e01488eb51..df819f8a95a6 100644
--- a/drivers/block/paride/pd.c
+++ b/drivers/block/paride/pd.c
@@ -698,7 +698,7 @@ static enum action pd_identify(struct pd_unit *disk)
698 698
699/* end of io request engine */ 699/* end of io request engine */
700 700
701static void do_pd_request(request_queue_t * q) 701static void do_pd_request(struct request_queue * q)
702{ 702{
703 if (pd_req) 703 if (pd_req)
704 return; 704 return;
diff --git a/drivers/block/paride/pf.c b/drivers/block/paride/pf.c
index 5826508f6731..ceffa6034e20 100644
--- a/drivers/block/paride/pf.c
+++ b/drivers/block/paride/pf.c
@@ -202,7 +202,7 @@ module_param_array(drive3, int, NULL, 0);
202#define ATAPI_WRITE_10 0x2a 202#define ATAPI_WRITE_10 0x2a
203 203
204static int pf_open(struct inode *inode, struct file *file); 204static int pf_open(struct inode *inode, struct file *file);
205static void do_pf_request(request_queue_t * q); 205static void do_pf_request(struct request_queue * q);
206static int pf_ioctl(struct inode *inode, struct file *file, 206static int pf_ioctl(struct inode *inode, struct file *file,
207 unsigned int cmd, unsigned long arg); 207 unsigned int cmd, unsigned long arg);
208static int pf_getgeo(struct block_device *bdev, struct hd_geometry *geo); 208static int pf_getgeo(struct block_device *bdev, struct hd_geometry *geo);
@@ -760,7 +760,7 @@ static void pf_end_request(int uptodate)
760 } 760 }
761} 761}
762 762
763static void do_pf_request(request_queue_t * q) 763static void do_pf_request(struct request_queue * q)
764{ 764{
765 if (pf_busy) 765 if (pf_busy)
766 return; 766 return;
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 31be33e4f119..fadbfd880bab 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -752,7 +752,7 @@ static inline struct bio *pkt_get_list_first(struct bio **list_head, struct bio
752 */ 752 */
753static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *cgc) 753static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *cgc)
754{ 754{
755 request_queue_t *q = bdev_get_queue(pd->bdev); 755 struct request_queue *q = bdev_get_queue(pd->bdev);
756 struct request *rq; 756 struct request *rq;
757 int ret = 0; 757 int ret = 0;
758 758
@@ -979,7 +979,7 @@ static void pkt_iosched_process_queue(struct pktcdvd_device *pd)
979 * Special care is needed if the underlying block device has a small 979 * Special care is needed if the underlying block device has a small
980 * max_phys_segments value. 980 * max_phys_segments value.
981 */ 981 */
982static int pkt_set_segment_merging(struct pktcdvd_device *pd, request_queue_t *q) 982static int pkt_set_segment_merging(struct pktcdvd_device *pd, struct request_queue *q)
983{ 983{
984 if ((pd->settings.size << 9) / CD_FRAMESIZE <= q->max_phys_segments) { 984 if ((pd->settings.size << 9) / CD_FRAMESIZE <= q->max_phys_segments) {
985 /* 985 /*
@@ -2314,7 +2314,7 @@ static int pkt_open_dev(struct pktcdvd_device *pd, int write)
2314{ 2314{
2315 int ret; 2315 int ret;
2316 long lba; 2316 long lba;
2317 request_queue_t *q; 2317 struct request_queue *q;
2318 2318
2319 /* 2319 /*
2320 * We need to re-open the cdrom device without O_NONBLOCK to be able 2320 * We need to re-open the cdrom device without O_NONBLOCK to be able
@@ -2477,7 +2477,7 @@ static int pkt_end_io_read_cloned(struct bio *bio, unsigned int bytes_done, int
2477 return 0; 2477 return 0;
2478} 2478}
2479 2479
2480static int pkt_make_request(request_queue_t *q, struct bio *bio) 2480static int pkt_make_request(struct request_queue *q, struct bio *bio)
2481{ 2481{
2482 struct pktcdvd_device *pd; 2482 struct pktcdvd_device *pd;
2483 char b[BDEVNAME_SIZE]; 2483 char b[BDEVNAME_SIZE];
@@ -2626,7 +2626,7 @@ end_io:
2626 2626
2627 2627
2628 2628
2629static int pkt_merge_bvec(request_queue_t *q, struct bio *bio, struct bio_vec *bvec) 2629static int pkt_merge_bvec(struct request_queue *q, struct bio *bio, struct bio_vec *bvec)
2630{ 2630{
2631 struct pktcdvd_device *pd = q->queuedata; 2631 struct pktcdvd_device *pd = q->queuedata;
2632 sector_t zone = ZONE(bio->bi_sector, pd); 2632 sector_t zone = ZONE(bio->bi_sector, pd);
@@ -2647,7 +2647,7 @@ static int pkt_merge_bvec(request_queue_t *q, struct bio *bio, struct bio_vec *b
2647 2647
2648static void pkt_init_queue(struct pktcdvd_device *pd) 2648static void pkt_init_queue(struct pktcdvd_device *pd)
2649{ 2649{
2650 request_queue_t *q = pd->disk->queue; 2650 struct request_queue *q = pd->disk->queue;
2651 2651
2652 blk_queue_make_request(q, pkt_make_request); 2652 blk_queue_make_request(q, pkt_make_request);
2653 blk_queue_hardsect_size(q, CD_FRAMESIZE); 2653 blk_queue_hardsect_size(q, CD_FRAMESIZE);
diff --git a/drivers/block/ps2esdi.c b/drivers/block/ps2esdi.c
index 688a4fb0dc99..3c796e236253 100644
--- a/drivers/block/ps2esdi.c
+++ b/drivers/block/ps2esdi.c
@@ -64,7 +64,7 @@ static void reset_ctrl(void);
64 64
65static int ps2esdi_geninit(void); 65static int ps2esdi_geninit(void);
66 66
67static void do_ps2esdi_request(request_queue_t * q); 67static void do_ps2esdi_request(struct request_queue * q);
68 68
69static void ps2esdi_readwrite(int cmd, struct request *req); 69static void ps2esdi_readwrite(int cmd, struct request *req);
70 70
@@ -473,7 +473,7 @@ static void __init ps2esdi_get_device_cfg(void)
473} 473}
474 474
475/* strategy routine that handles most of the IO requests */ 475/* strategy routine that handles most of the IO requests */
476static void do_ps2esdi_request(request_queue_t * q) 476static void do_ps2esdi_request(struct request_queue * q)
477{ 477{
478 struct request *req; 478 struct request *req;
479 /* since, this routine is called with interrupts cleared - they 479 /* since, this routine is called with interrupts cleared - they
diff --git a/drivers/block/ps3disk.c b/drivers/block/ps3disk.c
index 170fb33dba97..aa8b890c80d7 100644
--- a/drivers/block/ps3disk.c
+++ b/drivers/block/ps3disk.c
@@ -190,7 +190,7 @@ static int ps3disk_submit_flush_request(struct ps3_storage_device *dev,
190} 190}
191 191
192static void ps3disk_do_request(struct ps3_storage_device *dev, 192static void ps3disk_do_request(struct ps3_storage_device *dev,
193 request_queue_t *q) 193 struct request_queue *q)
194{ 194{
195 struct request *req; 195 struct request *req;
196 196
@@ -211,7 +211,7 @@ static void ps3disk_do_request(struct ps3_storage_device *dev,
211 } 211 }
212} 212}
213 213
214static void ps3disk_request(request_queue_t *q) 214static void ps3disk_request(struct request_queue *q)
215{ 215{
216 struct ps3_storage_device *dev = q->queuedata; 216 struct ps3_storage_device *dev = q->queuedata;
217 struct ps3disk_private *priv = dev->sbd.core.driver_data; 217 struct ps3disk_private *priv = dev->sbd.core.driver_data;
@@ -404,7 +404,7 @@ static int ps3disk_identify(struct ps3_storage_device *dev)
404 return 0; 404 return 0;
405} 405}
406 406
407static void ps3disk_prepare_flush(request_queue_t *q, struct request *req) 407static void ps3disk_prepare_flush(struct request_queue *q, struct request *req)
408{ 408{
409 struct ps3_storage_device *dev = q->queuedata; 409 struct ps3_storage_device *dev = q->queuedata;
410 410
@@ -414,7 +414,7 @@ static void ps3disk_prepare_flush(request_queue_t *q, struct request *req)
414 req->cmd_type = REQ_TYPE_FLUSH; 414 req->cmd_type = REQ_TYPE_FLUSH;
415} 415}
416 416
417static int ps3disk_issue_flush(request_queue_t *q, struct gendisk *gendisk, 417static int ps3disk_issue_flush(struct request_queue *q, struct gendisk *gendisk,
418 sector_t *sector) 418 sector_t *sector)
419{ 419{
420 struct ps3_storage_device *dev = q->queuedata; 420 struct ps3_storage_device *dev = q->queuedata;
diff --git a/drivers/block/rd.c b/drivers/block/rd.c
index a1512da32410..65150b548f3a 100644
--- a/drivers/block/rd.c
+++ b/drivers/block/rd.c
@@ -264,7 +264,7 @@ static int rd_blkdev_pagecache_IO(int rw, struct bio_vec *vec, sector_t sector,
264 * 19-JAN-1998 Richard Gooch <rgooch@atnf.csiro.au> Added devfs support 264 * 19-JAN-1998 Richard Gooch <rgooch@atnf.csiro.au> Added devfs support
265 * 265 *
266 */ 266 */
267static int rd_make_request(request_queue_t *q, struct bio *bio) 267static int rd_make_request(struct request_queue *q, struct bio *bio)
268{ 268{
269 struct block_device *bdev = bio->bi_bdev; 269 struct block_device *bdev = bio->bi_bdev;
270 struct address_space * mapping = bdev->bd_inode->i_mapping; 270 struct address_space * mapping = bdev->bd_inode->i_mapping;
diff --git a/drivers/block/sunvdc.c b/drivers/block/sunvdc.c
index d50b82381155..4dff49256ac2 100644
--- a/drivers/block/sunvdc.c
+++ b/drivers/block/sunvdc.c
@@ -444,7 +444,7 @@ out:
444 return err; 444 return err;
445} 445}
446 446
447static void do_vdc_request(request_queue_t *q) 447static void do_vdc_request(struct request_queue *q)
448{ 448{
449 while (1) { 449 while (1) {
450 struct request *req = elv_next_request(q); 450 struct request *req = elv_next_request(q);
diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
index 1a65979f1f0f..b4e462f154ea 100644
--- a/drivers/block/swim3.c
+++ b/drivers/block/swim3.c
@@ -225,7 +225,7 @@ static unsigned short write_postamble[] = {
225static void swim3_select(struct floppy_state *fs, int sel); 225static void swim3_select(struct floppy_state *fs, int sel);
226static void swim3_action(struct floppy_state *fs, int action); 226static void swim3_action(struct floppy_state *fs, int action);
227static int swim3_readbit(struct floppy_state *fs, int bit); 227static int swim3_readbit(struct floppy_state *fs, int bit);
228static void do_fd_request(request_queue_t * q); 228static void do_fd_request(struct request_queue * q);
229static void start_request(struct floppy_state *fs); 229static void start_request(struct floppy_state *fs);
230static void set_timeout(struct floppy_state *fs, int nticks, 230static void set_timeout(struct floppy_state *fs, int nticks,
231 void (*proc)(unsigned long)); 231 void (*proc)(unsigned long));
@@ -290,7 +290,7 @@ static int swim3_readbit(struct floppy_state *fs, int bit)
290 return (stat & DATA) == 0; 290 return (stat & DATA) == 0;
291} 291}
292 292
293static void do_fd_request(request_queue_t * q) 293static void do_fd_request(struct request_queue * q)
294{ 294{
295 int i; 295 int i;
296 for(i=0;i<floppy_count;i++) 296 for(i=0;i<floppy_count;i++)
diff --git a/drivers/block/sx8.c b/drivers/block/sx8.c
index 949ae93499e5..402209fec59a 100644
--- a/drivers/block/sx8.c
+++ b/drivers/block/sx8.c
@@ -278,7 +278,7 @@ struct carm_host {
278 unsigned int state; 278 unsigned int state;
279 u32 fw_ver; 279 u32 fw_ver;
280 280
281 request_queue_t *oob_q; 281 struct request_queue *oob_q;
282 unsigned int n_oob; 282 unsigned int n_oob;
283 283
284 unsigned int hw_sg_used; 284 unsigned int hw_sg_used;
@@ -287,7 +287,7 @@ struct carm_host {
287 287
288 unsigned int wait_q_prod; 288 unsigned int wait_q_prod;
289 unsigned int wait_q_cons; 289 unsigned int wait_q_cons;
290 request_queue_t *wait_q[CARM_MAX_WAIT_Q]; 290 struct request_queue *wait_q[CARM_MAX_WAIT_Q];
291 291
292 unsigned int n_msgs; 292 unsigned int n_msgs;
293 u64 msg_alloc; 293 u64 msg_alloc;
@@ -756,7 +756,7 @@ static inline void carm_end_request_queued(struct carm_host *host,
756 assert(rc == 0); 756 assert(rc == 0);
757} 757}
758 758
759static inline void carm_push_q (struct carm_host *host, request_queue_t *q) 759static inline void carm_push_q (struct carm_host *host, struct request_queue *q)
760{ 760{
761 unsigned int idx = host->wait_q_prod % CARM_MAX_WAIT_Q; 761 unsigned int idx = host->wait_q_prod % CARM_MAX_WAIT_Q;
762 762
@@ -768,7 +768,7 @@ static inline void carm_push_q (struct carm_host *host, request_queue_t *q)
768 BUG_ON(host->wait_q_prod == host->wait_q_cons); /* overrun */ 768 BUG_ON(host->wait_q_prod == host->wait_q_cons); /* overrun */
769} 769}
770 770
771static inline request_queue_t *carm_pop_q(struct carm_host *host) 771static inline struct request_queue *carm_pop_q(struct carm_host *host)
772{ 772{
773 unsigned int idx; 773 unsigned int idx;
774 774
@@ -783,7 +783,7 @@ static inline request_queue_t *carm_pop_q(struct carm_host *host)
783 783
784static inline void carm_round_robin(struct carm_host *host) 784static inline void carm_round_robin(struct carm_host *host)
785{ 785{
786 request_queue_t *q = carm_pop_q(host); 786 struct request_queue *q = carm_pop_q(host);
787 if (q) { 787 if (q) {
788 blk_start_queue(q); 788 blk_start_queue(q);
789 VPRINTK("STARTED QUEUE %p\n", q); 789 VPRINTK("STARTED QUEUE %p\n", q);
@@ -802,7 +802,7 @@ static inline void carm_end_rq(struct carm_host *host, struct carm_request *crq,
802 } 802 }
803} 803}
804 804
805static void carm_oob_rq_fn(request_queue_t *q) 805static void carm_oob_rq_fn(struct request_queue *q)
806{ 806{
807 struct carm_host *host = q->queuedata; 807 struct carm_host *host = q->queuedata;
808 struct carm_request *crq; 808 struct carm_request *crq;
@@ -833,7 +833,7 @@ static void carm_oob_rq_fn(request_queue_t *q)
833 } 833 }
834} 834}
835 835
836static void carm_rq_fn(request_queue_t *q) 836static void carm_rq_fn(struct request_queue *q)
837{ 837{
838 struct carm_port *port = q->queuedata; 838 struct carm_port *port = q->queuedata;
839 struct carm_host *host = port->host; 839 struct carm_host *host = port->host;
@@ -1494,7 +1494,7 @@ static int carm_init_disks(struct carm_host *host)
1494 1494
1495 for (i = 0; i < CARM_MAX_PORTS; i++) { 1495 for (i = 0; i < CARM_MAX_PORTS; i++) {
1496 struct gendisk *disk; 1496 struct gendisk *disk;
1497 request_queue_t *q; 1497 struct request_queue *q;
1498 struct carm_port *port; 1498 struct carm_port *port;
1499 1499
1500 port = &host->port[i]; 1500 port = &host->port[i];
@@ -1538,7 +1538,7 @@ static void carm_free_disks(struct carm_host *host)
1538 for (i = 0; i < CARM_MAX_PORTS; i++) { 1538 for (i = 0; i < CARM_MAX_PORTS; i++) {
1539 struct gendisk *disk = host->port[i].disk; 1539 struct gendisk *disk = host->port[i].disk;
1540 if (disk) { 1540 if (disk) {
1541 request_queue_t *q = disk->queue; 1541 struct request_queue *q = disk->queue;
1542 1542
1543 if (disk->flags & GENHD_FL_UP) 1543 if (disk->flags & GENHD_FL_UP)
1544 del_gendisk(disk); 1544 del_gendisk(disk);
@@ -1571,7 +1571,7 @@ static int carm_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1571 struct carm_host *host; 1571 struct carm_host *host;
1572 unsigned int pci_dac; 1572 unsigned int pci_dac;
1573 int rc; 1573 int rc;
1574 request_queue_t *q; 1574 struct request_queue *q;
1575 unsigned int i; 1575 unsigned int i;
1576 1576
1577 if (!printed_version++) 1577 if (!printed_version++)
diff --git a/drivers/block/ub.c b/drivers/block/ub.c
index 8b13d7d2cb63..c57dd2b3a0c8 100644
--- a/drivers/block/ub.c
+++ b/drivers/block/ub.c
@@ -503,7 +503,7 @@ static void ub_cleanup(struct ub_dev *sc)
503{ 503{
504 struct list_head *p; 504 struct list_head *p;
505 struct ub_lun *lun; 505 struct ub_lun *lun;
506 request_queue_t *q; 506 struct request_queue *q;
507 507
508 while (!list_empty(&sc->luns)) { 508 while (!list_empty(&sc->luns)) {
509 p = sc->luns.next; 509 p = sc->luns.next;
@@ -619,7 +619,7 @@ static struct ub_scsi_cmd *ub_cmdq_pop(struct ub_dev *sc)
619 * The request function is our main entry point 619 * The request function is our main entry point
620 */ 620 */
621 621
622static void ub_request_fn(request_queue_t *q) 622static void ub_request_fn(struct request_queue *q)
623{ 623{
624 struct ub_lun *lun = q->queuedata; 624 struct ub_lun *lun = q->queuedata;
625 struct request *rq; 625 struct request *rq;
@@ -2273,7 +2273,7 @@ err_core:
2273static int ub_probe_lun(struct ub_dev *sc, int lnum) 2273static int ub_probe_lun(struct ub_dev *sc, int lnum)
2274{ 2274{
2275 struct ub_lun *lun; 2275 struct ub_lun *lun;
2276 request_queue_t *q; 2276 struct request_queue *q;
2277 struct gendisk *disk; 2277 struct gendisk *disk;
2278 int rc; 2278 int rc;
2279 2279
diff --git a/drivers/block/umem.c b/drivers/block/umem.c
index dec74bd23496..6b7c02d6360d 100644
--- a/drivers/block/umem.c
+++ b/drivers/block/umem.c
@@ -114,7 +114,7 @@ struct cardinfo {
114 */ 114 */
115 struct bio *bio, *currentbio, **biotail; 115 struct bio *bio, *currentbio, **biotail;
116 116
117 request_queue_t *queue; 117 struct request_queue *queue;
118 118
119 struct mm_page { 119 struct mm_page {
120 dma_addr_t page_dma; 120 dma_addr_t page_dma;
@@ -357,7 +357,7 @@ static inline void reset_page(struct mm_page *page)
357 page->biotail = & page->bio; 357 page->biotail = & page->bio;
358} 358}
359 359
360static void mm_unplug_device(request_queue_t *q) 360static void mm_unplug_device(struct request_queue *q)
361{ 361{
362 struct cardinfo *card = q->queuedata; 362 struct cardinfo *card = q->queuedata;
363 unsigned long flags; 363 unsigned long flags;
@@ -541,7 +541,7 @@ static void process_page(unsigned long data)
541-- mm_make_request 541-- mm_make_request
542----------------------------------------------------------------------------------- 542-----------------------------------------------------------------------------------
543*/ 543*/
544static int mm_make_request(request_queue_t *q, struct bio *bio) 544static int mm_make_request(struct request_queue *q, struct bio *bio)
545{ 545{
546 struct cardinfo *card = q->queuedata; 546 struct cardinfo *card = q->queuedata;
547 pr_debug("mm_make_request %llu %u\n", 547 pr_debug("mm_make_request %llu %u\n",
diff --git a/drivers/block/viodasd.c b/drivers/block/viodasd.c
index dae39911a11d..85916e2665d4 100644
--- a/drivers/block/viodasd.c
+++ b/drivers/block/viodasd.c
@@ -400,7 +400,7 @@ error_ret:
400/* 400/*
401 * This is the external request processing routine 401 * This is the external request processing routine
402 */ 402 */
403static void do_viodasd_request(request_queue_t *q) 403static void do_viodasd_request(struct request_queue *q)
404{ 404{
405 struct request *req; 405 struct request *req;
406 406
diff --git a/drivers/block/xd.c b/drivers/block/xd.c
index 0d97b7eb818a..624d30f7da3f 100644
--- a/drivers/block/xd.c
+++ b/drivers/block/xd.c
@@ -298,7 +298,7 @@ static u_char __init xd_detect (u_char *controller, unsigned int *address)
298} 298}
299 299
300/* do_xd_request: handle an incoming request */ 300/* do_xd_request: handle an incoming request */
301static void do_xd_request (request_queue_t * q) 301static void do_xd_request (struct request_queue * q)
302{ 302{
303 struct request *req; 303 struct request *req;
304 304
diff --git a/drivers/block/xd.h b/drivers/block/xd.h
index 82e090fea957..cffd44a20383 100644
--- a/drivers/block/xd.h
+++ b/drivers/block/xd.h
@@ -104,7 +104,7 @@ static int xd_manual_geo_init (char *command);
104static u_char xd_detect (u_char *controller, unsigned int *address); 104static u_char xd_detect (u_char *controller, unsigned int *address);
105static u_char xd_initdrives (void (*init_drive)(u_char drive)); 105static u_char xd_initdrives (void (*init_drive)(u_char drive));
106 106
107static void do_xd_request (request_queue_t * q); 107static void do_xd_request (struct request_queue * q);
108static int xd_ioctl (struct inode *inode,struct file *file,unsigned int cmd,unsigned long arg); 108static int xd_ioctl (struct inode *inode,struct file *file,unsigned int cmd,unsigned long arg);
109static int xd_readwrite (u_char operation,XD_INFO *disk,char *buffer,u_int block,u_int count); 109static int xd_readwrite (u_char operation,XD_INFO *disk,char *buffer,u_int block,u_int count);
110static void xd_recalibrate (u_char drive); 110static void xd_recalibrate (u_char drive);
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 6746c29181f8..964e51634f2d 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -241,7 +241,7 @@ static inline void flush_requests(struct blkfront_info *info)
241 * do_blkif_request 241 * do_blkif_request
242 * read a block; request is in a request queue 242 * read a block; request is in a request queue
243 */ 243 */
244static void do_blkif_request(request_queue_t *rq) 244static void do_blkif_request(struct request_queue *rq)
245{ 245{
246 struct blkfront_info *info = NULL; 246 struct blkfront_info *info = NULL;
247 struct request *req; 247 struct request *req;
@@ -287,7 +287,7 @@ wait:
287 287
288static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size) 288static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size)
289{ 289{
290 request_queue_t *rq; 290 struct request_queue *rq;
291 291
292 rq = blk_init_queue(do_blkif_request, &blkif_io_lock); 292 rq = blk_init_queue(do_blkif_request, &blkif_io_lock);
293 if (rq == NULL) 293 if (rq == NULL)
diff --git a/drivers/block/xsysace.c b/drivers/block/xsysace.c
index 732ec63b6e9c..cb27e8863d7c 100644
--- a/drivers/block/xsysace.c
+++ b/drivers/block/xsysace.c
@@ -458,7 +458,7 @@ static inline void ace_fsm_yieldirq(struct ace_device *ace)
458} 458}
459 459
460/* Get the next read/write request; ending requests that we don't handle */ 460/* Get the next read/write request; ending requests that we don't handle */
461struct request *ace_get_next_request(request_queue_t * q) 461struct request *ace_get_next_request(struct request_queue * q)
462{ 462{
463 struct request *req; 463 struct request *req;
464 464
@@ -825,7 +825,7 @@ static irqreturn_t ace_interrupt(int irq, void *dev_id)
825/* --------------------------------------------------------------------- 825/* ---------------------------------------------------------------------
826 * Block ops 826 * Block ops
827 */ 827 */
828static void ace_request(request_queue_t * q) 828static void ace_request(struct request_queue * q)
829{ 829{
830 struct request *req; 830 struct request *req;
831 struct ace_device *ace; 831 struct ace_device *ace;
diff --git a/drivers/block/z2ram.c b/drivers/block/z2ram.c
index e40fa98842e5..2d5853cbd4b0 100644
--- a/drivers/block/z2ram.c
+++ b/drivers/block/z2ram.c
@@ -67,7 +67,7 @@ static DEFINE_SPINLOCK(z2ram_lock);
67static struct block_device_operations z2_fops; 67static struct block_device_operations z2_fops;
68static struct gendisk *z2ram_gendisk; 68static struct gendisk *z2ram_gendisk;
69 69
70static void do_z2_request(request_queue_t *q) 70static void do_z2_request(struct request_queue *q)
71{ 71{
72 struct request *req; 72 struct request *req;
73 while ((req = elv_next_request(q)) != NULL) { 73 while ((req = elv_next_request(q)) != NULL) {
diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index 499019bf8f40..67ee3d4b2878 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -2094,7 +2094,7 @@ out:
2094static int cdrom_read_cdda_bpc(struct cdrom_device_info *cdi, __u8 __user *ubuf, 2094static int cdrom_read_cdda_bpc(struct cdrom_device_info *cdi, __u8 __user *ubuf,
2095 int lba, int nframes) 2095 int lba, int nframes)
2096{ 2096{
2097 request_queue_t *q = cdi->disk->queue; 2097 struct request_queue *q = cdi->disk->queue;
2098 struct request *rq; 2098 struct request *rq;
2099 struct bio *bio; 2099 struct bio *bio;
2100 unsigned int len; 2100 unsigned int len;
diff --git a/drivers/cdrom/viocd.c b/drivers/cdrom/viocd.c
index 44cd7b2ddf09..e51550db1575 100644
--- a/drivers/cdrom/viocd.c
+++ b/drivers/cdrom/viocd.c
@@ -398,7 +398,7 @@ static void viocd_end_request(struct request *req, int uptodate)
398 398
399static int rwreq; 399static int rwreq;
400 400
401static void do_viocd_request(request_queue_t *q) 401static void do_viocd_request(struct request_queue *q)
402{ 402{
403 struct request *req; 403 struct request *req;
404 404
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index c8dfd18bea44..b391776e5bf3 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -130,6 +130,7 @@ config ROCKETPORT
130config CYCLADES 130config CYCLADES
131 tristate "Cyclades async mux support" 131 tristate "Cyclades async mux support"
132 depends on SERIAL_NONSTANDARD && (PCI || ISA) 132 depends on SERIAL_NONSTANDARD && (PCI || ISA)
133 select FW_LOADER
133 ---help--- 134 ---help---
134 This driver supports Cyclades Z and Y multiserial boards. 135 This driver supports Cyclades Z and Y multiserial boards.
135 You would need something like this to connect more than two modems to 136 You would need something like this to connect more than two modems to
@@ -726,7 +727,7 @@ config NVRAM
726 727
727config RTC 728config RTC
728 tristate "Enhanced Real Time Clock Support" 729 tristate "Enhanced Real Time Clock Support"
729 depends on !PPC && !PARISC && !IA64 && !M68K && !SPARC64 && (!SPARC32 || PCI) && !FRV && !ARM && !SUPERH && !S390 730 depends on !PPC && !PARISC && !IA64 && !M68K && !SPARC && !FRV && !ARM && !SUPERH && !S390
730 ---help--- 731 ---help---
731 If you say Y here and create a character special file /dev/rtc with 732 If you say Y here and create a character special file /dev/rtc with
732 major number 10 and minor number 135 using mknod ("man mknod"), you 733 major number 10 and minor number 135 using mknod ("man mknod"), you
@@ -750,6 +751,28 @@ config RTC
750 To compile this driver as a module, choose M here: the 751 To compile this driver as a module, choose M here: the
751 module will be called rtc. 752 module will be called rtc.
752 753
754config JS_RTC
755 tristate "Enhanced Real Time Clock Support"
756 depends on SPARC32 && PCI
757 ---help---
758 If you say Y here and create a character special file /dev/rtc with
759 major number 10 and minor number 135 using mknod ("man mknod"), you
760 will get access to the real time clock (or hardware clock) built
761 into your computer.
762
763 Every PC has such a clock built in. It can be used to generate
764 signals from as low as 1Hz up to 8192Hz, and can also be used
765 as a 24 hour alarm. It reports status information via the file
766 /proc/driver/rtc and its behaviour is set by various ioctls on
767 /dev/rtc.
768
769 If you think you have a use for such a device (such as periodic data
770 sampling), then say Y here, and read <file:Documentation/rtc.txt>
771 for details.
772
773 To compile this driver as a module, choose M here: the
774 module will be called js-rtc.
775
753config SGI_DS1286 776config SGI_DS1286
754 tristate "SGI DS1286 RTC support" 777 tristate "SGI DS1286 RTC support"
755 depends on SGI_IP22 778 depends on SGI_IP22
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 8fecaf4010b1..23b26b87cc32 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -109,6 +109,9 @@ obj-$(CONFIG_TCG_TPM) += tpm/
109 109
110obj-$(CONFIG_PS3_FLASH) += ps3flash.o 110obj-$(CONFIG_PS3_FLASH) += ps3flash.o
111 111
112obj-$(CONFIG_JS_RTC) += js-rtc.o
113js-rtc-y = rtc.o
114
112# Files generated that shall be removed upon make clean 115# Files generated that shall be removed upon make clean
113clean-files := consolemap_deftbl.c defkeymap.c 116clean-files := consolemap_deftbl.c defkeymap.c
114 117
diff --git a/drivers/char/agp/Kconfig b/drivers/char/agp/Kconfig
index a9f9c48c2424..713533d8a86e 100644
--- a/drivers/char/agp/Kconfig
+++ b/drivers/char/agp/Kconfig
@@ -50,7 +50,7 @@ config AGP_ATI
50 50
51config AGP_AMD 51config AGP_AMD
52 tristate "AMD Irongate, 761, and 762 chipset support" 52 tristate "AMD Irongate, 761, and 762 chipset support"
53 depends on AGP && X86_32 53 depends on AGP && (X86_32 || ALPHA)
54 help 54 help
55 This option gives you AGP support for the GLX component of 55 This option gives you AGP support for the GLX component of
56 X on AMD Irongate, 761, and 762 chipsets. 56 X on AMD Irongate, 761, and 762 chipsets.
diff --git a/drivers/char/agp/ati-agp.c b/drivers/char/agp/ati-agp.c
index 780e59e588ad..da7513d7b4e7 100644
--- a/drivers/char/agp/ati-agp.c
+++ b/drivers/char/agp/ati-agp.c
@@ -123,21 +123,16 @@ static int ati_create_gatt_pages(int nr_tables)
123 123
124 for (i = 0; i < nr_tables; i++) { 124 for (i = 0; i < nr_tables; i++) {
125 entry = kzalloc(sizeof(struct ati_page_map), GFP_KERNEL); 125 entry = kzalloc(sizeof(struct ati_page_map), GFP_KERNEL);
126 tables[i] = entry;
126 if (entry == NULL) { 127 if (entry == NULL) {
127 while (i > 0) {
128 kfree(tables[i-1]);
129 i--;
130 }
131 kfree(tables);
132 retval = -ENOMEM; 128 retval = -ENOMEM;
133 break; 129 break;
134 } 130 }
135 tables[i] = entry;
136 retval = ati_create_page_map(entry); 131 retval = ati_create_page_map(entry);
137 if (retval != 0) 132 if (retval != 0)
138 break; 133 break;
139 } 134 }
140 ati_generic_private.num_tables = nr_tables; 135 ati_generic_private.num_tables = i;
141 ati_generic_private.gatt_pages = tables; 136 ati_generic_private.gatt_pages = tables;
142 137
143 if (retval != 0) 138 if (retval != 0)
diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
index fcb4b1bf0d4e..ecd4248861b9 100644
--- a/drivers/char/agp/compat_ioctl.c
+++ b/drivers/char/agp/compat_ioctl.c
@@ -28,6 +28,7 @@
28 28
29#include <linux/kernel.h> 29#include <linux/kernel.h>
30#include <linux/pci.h> 30#include <linux/pci.h>
31#include <linux/fs.h>
31#include <linux/agpgart.h> 32#include <linux/agpgart.h>
32#include <asm/uaccess.h> 33#include <asm/uaccess.h>
33#include "agp.h" 34#include "agp.h"
diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
index c7ed617aa7ff..7791e98de51c 100644
--- a/drivers/char/agp/frontend.c
+++ b/drivers/char/agp/frontend.c
@@ -37,6 +37,7 @@
37#include <linux/agpgart.h> 37#include <linux/agpgart.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/mm.h> 39#include <linux/mm.h>
40#include <linux/fs.h>
40#include <linux/sched.h> 41#include <linux/sched.h>
41#include <asm/uaccess.h> 42#include <asm/uaccess.h>
42#include <asm/pgtable.h> 43#include <asm/pgtable.h>
diff --git a/drivers/char/agp/generic.c b/drivers/char/agp/generic.c
index d535c406b319..3db4f4076ed4 100644
--- a/drivers/char/agp/generic.c
+++ b/drivers/char/agp/generic.c
@@ -1170,7 +1170,6 @@ void *agp_generic_alloc_page(struct agp_bridge_data *bridge)
1170 map_page_into_agp(page); 1170 map_page_into_agp(page);
1171 1171
1172 get_page(page); 1172 get_page(page);
1173 SetPageLocked(page);
1174 atomic_inc(&agp_bridge->current_memory_agp); 1173 atomic_inc(&agp_bridge->current_memory_agp);
1175 return page_address(page); 1174 return page_address(page);
1176} 1175}
@@ -1187,7 +1186,6 @@ void agp_generic_destroy_page(void *addr)
1187 page = virt_to_page(addr); 1186 page = virt_to_page(addr);
1188 unmap_page_from_agp(page); 1187 unmap_page_from_agp(page);
1189 put_page(page); 1188 put_page(page);
1190 unlock_page(page);
1191 free_page((unsigned long)addr); 1189 free_page((unsigned long)addr);
1192 atomic_dec(&agp_bridge->current_memory_agp); 1190 atomic_dec(&agp_bridge->current_memory_agp);
1193} 1191}
diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
index a1240603912c..294cdbf4d44d 100644
--- a/drivers/char/agp/intel-agp.c
+++ b/drivers/char/agp/intel-agp.c
@@ -20,7 +20,9 @@
20#define PCI_DEVICE_ID_INTEL_82965G_IG 0x29A2 20#define PCI_DEVICE_ID_INTEL_82965G_IG 0x29A2
21#define PCI_DEVICE_ID_INTEL_82965GM_HB 0x2A00 21#define PCI_DEVICE_ID_INTEL_82965GM_HB 0x2A00
22#define PCI_DEVICE_ID_INTEL_82965GM_IG 0x2A02 22#define PCI_DEVICE_ID_INTEL_82965GM_IG 0x2A02
23#define PCI_DEVICE_ID_INTEL_82965GME_HB 0x2A10
23#define PCI_DEVICE_ID_INTEL_82965GME_IG 0x2A12 24#define PCI_DEVICE_ID_INTEL_82965GME_IG 0x2A12
25#define PCI_DEVICE_ID_INTEL_82945GME_HB 0x27AC
24#define PCI_DEVICE_ID_INTEL_82945GME_IG 0x27AE 26#define PCI_DEVICE_ID_INTEL_82945GME_IG 0x27AE
25#define PCI_DEVICE_ID_INTEL_G33_HB 0x29C0 27#define PCI_DEVICE_ID_INTEL_G33_HB 0x29C0
26#define PCI_DEVICE_ID_INTEL_G33_IG 0x29C2 28#define PCI_DEVICE_ID_INTEL_G33_IG 0x29C2
@@ -33,7 +35,8 @@
33 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965G_1_HB || \ 35 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965G_1_HB || \
34 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965Q_HB || \ 36 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965Q_HB || \
35 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965G_HB || \ 37 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965G_HB || \
36 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GM_HB) 38 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GM_HB || \
39 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GME_HB)
37 40
38#define IS_G33 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G33_HB || \ 41#define IS_G33 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G33_HB || \
39 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q35_HB || \ 42 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q35_HB || \
@@ -213,7 +216,6 @@ static void *i8xx_alloc_pages(void)
213 } 216 }
214 global_flush_tlb(); 217 global_flush_tlb();
215 get_page(page); 218 get_page(page);
216 SetPageLocked(page);
217 atomic_inc(&agp_bridge->current_memory_agp); 219 atomic_inc(&agp_bridge->current_memory_agp);
218 return page_address(page); 220 return page_address(page);
219} 221}
@@ -229,7 +231,6 @@ static void i8xx_destroy_pages(void *addr)
229 change_page_attr(page, 4, PAGE_KERNEL); 231 change_page_attr(page, 4, PAGE_KERNEL);
230 global_flush_tlb(); 232 global_flush_tlb();
231 put_page(page); 233 put_page(page);
232 unlock_page(page);
233 __free_pages(page, 2); 234 __free_pages(page, 2);
234 atomic_dec(&agp_bridge->current_memory_agp); 235 atomic_dec(&agp_bridge->current_memory_agp);
235} 236}
@@ -527,6 +528,7 @@ static void intel_i830_init_gtt_entries(void)
527 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB || 528 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB ||
528 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945G_HB || 529 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945G_HB ||
529 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GM_HB || 530 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GM_HB ||
531 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GME_HB ||
530 IS_I965 || IS_G33) 532 IS_I965 || IS_G33)
531 gtt_entries = MB(48) - KB(size); 533 gtt_entries = MB(48) - KB(size);
532 else 534 else
@@ -538,6 +540,7 @@ static void intel_i830_init_gtt_entries(void)
538 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB || 540 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB ||
539 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945G_HB || 541 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945G_HB ||
540 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GM_HB || 542 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GM_HB ||
543 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GME_HB ||
541 IS_I965 || IS_G33) 544 IS_I965 || IS_G33)
542 gtt_entries = MB(64) - KB(size); 545 gtt_entries = MB(64) - KB(size);
543 else 546 else
@@ -1848,9 +1851,9 @@ static const struct intel_driver_description {
1848 NULL, &intel_915_driver }, 1851 NULL, &intel_915_driver },
1849 { PCI_DEVICE_ID_INTEL_82945G_HB, PCI_DEVICE_ID_INTEL_82945G_IG, 0, "945G", 1852 { PCI_DEVICE_ID_INTEL_82945G_HB, PCI_DEVICE_ID_INTEL_82945G_IG, 0, "945G",
1850 NULL, &intel_915_driver }, 1853 NULL, &intel_915_driver },
1851 { PCI_DEVICE_ID_INTEL_82945GM_HB, PCI_DEVICE_ID_INTEL_82945GM_IG, 1, "945GM", 1854 { PCI_DEVICE_ID_INTEL_82945GM_HB, PCI_DEVICE_ID_INTEL_82945GM_IG, 0, "945GM",
1852 NULL, &intel_915_driver }, 1855 NULL, &intel_915_driver },
1853 { PCI_DEVICE_ID_INTEL_82945GM_HB, PCI_DEVICE_ID_INTEL_82945GME_IG, 0, "945GME", 1856 { PCI_DEVICE_ID_INTEL_82945GME_HB, PCI_DEVICE_ID_INTEL_82945GME_IG, 0, "945GME",
1854 NULL, &intel_915_driver }, 1857 NULL, &intel_915_driver },
1855 { PCI_DEVICE_ID_INTEL_82946GZ_HB, PCI_DEVICE_ID_INTEL_82946GZ_IG, 0, "946GZ", 1858 { PCI_DEVICE_ID_INTEL_82946GZ_HB, PCI_DEVICE_ID_INTEL_82946GZ_IG, 0, "946GZ",
1856 NULL, &intel_i965_driver }, 1859 NULL, &intel_i965_driver },
@@ -1860,9 +1863,9 @@ static const struct intel_driver_description {
1860 NULL, &intel_i965_driver }, 1863 NULL, &intel_i965_driver },
1861 { PCI_DEVICE_ID_INTEL_82965G_HB, PCI_DEVICE_ID_INTEL_82965G_IG, 0, "965G", 1864 { PCI_DEVICE_ID_INTEL_82965G_HB, PCI_DEVICE_ID_INTEL_82965G_IG, 0, "965G",
1862 NULL, &intel_i965_driver }, 1865 NULL, &intel_i965_driver },
1863 { PCI_DEVICE_ID_INTEL_82965GM_HB, PCI_DEVICE_ID_INTEL_82965GM_IG, 1, "965GM", 1866 { PCI_DEVICE_ID_INTEL_82965GM_HB, PCI_DEVICE_ID_INTEL_82965GM_IG, 0, "965GM",
1864 NULL, &intel_i965_driver }, 1867 NULL, &intel_i965_driver },
1865 { PCI_DEVICE_ID_INTEL_82965GM_HB, PCI_DEVICE_ID_INTEL_82965GME_IG, 0, "965GME/GLE", 1868 { PCI_DEVICE_ID_INTEL_82965GME_HB, PCI_DEVICE_ID_INTEL_82965GME_IG, 0, "965GME/GLE",
1866 NULL, &intel_i965_driver }, 1869 NULL, &intel_i965_driver },
1867 { PCI_DEVICE_ID_INTEL_7505_0, 0, 0, "E7505", &intel_7505_driver, NULL }, 1870 { PCI_DEVICE_ID_INTEL_7505_0, 0, 0, "E7505", &intel_7505_driver, NULL },
1868 { PCI_DEVICE_ID_INTEL_7205_0, 0, 0, "E7205", &intel_7505_driver, NULL }, 1871 { PCI_DEVICE_ID_INTEL_7205_0, 0, 0, "E7205", &intel_7505_driver, NULL },
@@ -2051,11 +2054,13 @@ static struct pci_device_id agp_intel_pci_table[] = {
2051 ID(PCI_DEVICE_ID_INTEL_82915GM_HB), 2054 ID(PCI_DEVICE_ID_INTEL_82915GM_HB),
2052 ID(PCI_DEVICE_ID_INTEL_82945G_HB), 2055 ID(PCI_DEVICE_ID_INTEL_82945G_HB),
2053 ID(PCI_DEVICE_ID_INTEL_82945GM_HB), 2056 ID(PCI_DEVICE_ID_INTEL_82945GM_HB),
2057 ID(PCI_DEVICE_ID_INTEL_82945GME_HB),
2054 ID(PCI_DEVICE_ID_INTEL_82946GZ_HB), 2058 ID(PCI_DEVICE_ID_INTEL_82946GZ_HB),
2055 ID(PCI_DEVICE_ID_INTEL_82965G_1_HB), 2059 ID(PCI_DEVICE_ID_INTEL_82965G_1_HB),
2056 ID(PCI_DEVICE_ID_INTEL_82965Q_HB), 2060 ID(PCI_DEVICE_ID_INTEL_82965Q_HB),
2057 ID(PCI_DEVICE_ID_INTEL_82965G_HB), 2061 ID(PCI_DEVICE_ID_INTEL_82965G_HB),
2058 ID(PCI_DEVICE_ID_INTEL_82965GM_HB), 2062 ID(PCI_DEVICE_ID_INTEL_82965GM_HB),
2063 ID(PCI_DEVICE_ID_INTEL_82965GME_HB),
2059 ID(PCI_DEVICE_ID_INTEL_G33_HB), 2064 ID(PCI_DEVICE_ID_INTEL_G33_HB),
2060 ID(PCI_DEVICE_ID_INTEL_Q35_HB), 2065 ID(PCI_DEVICE_ID_INTEL_Q35_HB),
2061 ID(PCI_DEVICE_ID_INTEL_Q33_HB), 2066 ID(PCI_DEVICE_ID_INTEL_Q33_HB),
diff --git a/drivers/char/agp/sgi-agp.c b/drivers/char/agp/sgi-agp.c
index cda608c42bea..98cf8abb3e57 100644
--- a/drivers/char/agp/sgi-agp.c
+++ b/drivers/char/agp/sgi-agp.c
@@ -51,7 +51,6 @@ static void *sgi_tioca_alloc_page(struct agp_bridge_data *bridge)
51 return NULL; 51 return NULL;
52 52
53 get_page(page); 53 get_page(page);
54 SetPageLocked(page);
55 atomic_inc(&agp_bridge->current_memory_agp); 54 atomic_inc(&agp_bridge->current_memory_agp);
56 return page_address(page); 55 return page_address(page);
57} 56}
diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index ba0e74ad74bb..77bf4aa217a8 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -73,7 +73,7 @@ static struct clocksource clocksource_hpet = {
73 .name = "hpet", 73 .name = "hpet",
74 .rating = 250, 74 .rating = 250,
75 .read = read_hpet, 75 .read = read_hpet,
76 .mask = 0xffffffffffffffff, 76 .mask = CLOCKSOURCE_MASK(64),
77 .mult = 0, /*to be caluclated*/ 77 .mult = 0, /*to be caluclated*/
78 .shift = 10, 78 .shift = 10,
79 .flags = CLOCK_SOURCE_IS_CONTINUOUS, 79 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
@@ -1007,9 +1007,15 @@ static int hpet_acpi_remove(struct acpi_device *device, int type)
1007 return -EINVAL; 1007 return -EINVAL;
1008} 1008}
1009 1009
1010static const struct acpi_device_id hpet_device_ids[] = {
1011 {"PNP0103", 0},
1012 {"", 0},
1013};
1014MODULE_DEVICE_TABLE(acpi, hpet_device_ids);
1015
1010static struct acpi_driver hpet_acpi_driver = { 1016static struct acpi_driver hpet_acpi_driver = {
1011 .name = "hpet", 1017 .name = "hpet",
1012 .ids = "PNP0103", 1018 .ids = hpet_device_ids,
1013 .ops = { 1019 .ops = {
1014 .add = hpet_acpi_add, 1020 .add = hpet_acpi_add,
1015 .remove = hpet_acpi_remove, 1021 .remove = hpet_acpi_remove,
diff --git a/drivers/char/hvc_lguest.c b/drivers/char/hvc_lguest.c
index e7b889e404a7..feeccbaec438 100644
--- a/drivers/char/hvc_lguest.c
+++ b/drivers/char/hvc_lguest.c
@@ -1,6 +1,22 @@
1/* Simple console for lguest. 1/*D:300
2 * The Guest console driver
2 * 3 *
3 * Copyright (C) 2006 Rusty Russell, IBM Corporation 4 * This is a trivial console driver: we use lguest's DMA mechanism to send
5 * bytes out, and register a DMA buffer to receive bytes in. It is assumed to
6 * be present and available from the very beginning of boot.
7 *
8 * Writing console drivers is one of the few remaining Dark Arts in Linux.
9 * Fortunately for us, the path of virtual consoles has been well-trodden by
10 * the PowerPC folks, who wrote "hvc_console.c" to generically support any
11 * virtual console. We use that infrastructure which only requires us to write
12 * the basic put_chars and get_chars functions and call the right register
13 * functions.
14 :*/
15
16/*M:002 The console can be flooded: while the Guest is processing input the
17 * Host can send more. Buffering in the Host could alleviate this, but it is a
18 * difficult problem in general. :*/
19/* Copyright (C) 2006 Rusty Russell, IBM Corporation
4 * 20 *
5 * This program is free software; you can redistribute it and/or modify 21 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 22 * it under the terms of the GNU General Public License as published by
@@ -21,49 +37,81 @@
21#include <linux/lguest_bus.h> 37#include <linux/lguest_bus.h>
22#include "hvc_console.h" 38#include "hvc_console.h"
23 39
40/*D:340 This is our single console input buffer, with associated "struct
41 * lguest_dma" referring to it. Note the 0-terminated length array, and the
42 * use of physical address for the buffer itself. */
24static char inbuf[256]; 43static char inbuf[256];
25static struct lguest_dma cons_input = { .used_len = 0, 44static struct lguest_dma cons_input = { .used_len = 0,
26 .addr[0] = __pa(inbuf), 45 .addr[0] = __pa(inbuf),
27 .len[0] = sizeof(inbuf), 46 .len[0] = sizeof(inbuf),
28 .len[1] = 0 }; 47 .len[1] = 0 };
29 48
49/*D:310 The put_chars() callback is pretty straightforward.
50 *
51 * First we put the pointer and length in a "struct lguest_dma": we only have
52 * one pointer, so we set the second length to 0. Then we use SEND_DMA to send
53 * the data to (Host) buffers attached to the console key. Usually a device's
54 * key is a physical address within the device's memory, but because the
55 * console device doesn't have any associated physical memory, we use the
56 * LGUEST_CONSOLE_DMA_KEY constant (aka 0). */
30static int put_chars(u32 vtermno, const char *buf, int count) 57static int put_chars(u32 vtermno, const char *buf, int count)
31{ 58{
32 struct lguest_dma dma; 59 struct lguest_dma dma;
33 60
34 /* FIXME: what if it's over a page boundary? */ 61 /* FIXME: DMA buffers in a "struct lguest_dma" are not allowed
62 * to go over page boundaries. This never seems to happen,
63 * but if it did we'd need to fix this code. */
35 dma.len[0] = count; 64 dma.len[0] = count;
36 dma.len[1] = 0; 65 dma.len[1] = 0;
37 dma.addr[0] = __pa(buf); 66 dma.addr[0] = __pa(buf);
38 67
39 lguest_send_dma(LGUEST_CONSOLE_DMA_KEY, &dma); 68 lguest_send_dma(LGUEST_CONSOLE_DMA_KEY, &dma);
69 /* We're expected to return the amount of data we wrote: all of it. */
40 return count; 70 return count;
41} 71}
42 72
73/*D:350 get_chars() is the callback from the hvc_console infrastructure when
74 * an interrupt is received.
75 *
76 * Firstly we see if our buffer has been filled: if not, we return. The rest
77 * of the code deals with the fact that the hvc_console() infrastructure only
78 * asks us for 16 bytes at a time. We keep a "cons_offset" variable for
79 * partially-read buffers. */
43static int get_chars(u32 vtermno, char *buf, int count) 80static int get_chars(u32 vtermno, char *buf, int count)
44{ 81{
45 static int cons_offset; 82 static int cons_offset;
46 83
84 /* Nothing left to see here... */
47 if (!cons_input.used_len) 85 if (!cons_input.used_len)
48 return 0; 86 return 0;
49 87
88 /* You want more than we have to give? Well, try wanting less! */
50 if (cons_input.used_len - cons_offset < count) 89 if (cons_input.used_len - cons_offset < count)
51 count = cons_input.used_len - cons_offset; 90 count = cons_input.used_len - cons_offset;
52 91
92 /* Copy across to their buffer and increment offset. */
53 memcpy(buf, inbuf + cons_offset, count); 93 memcpy(buf, inbuf + cons_offset, count);
54 cons_offset += count; 94 cons_offset += count;
95
96 /* Finished? Zero offset, and reset cons_input so Host will use it
97 * again. */
55 if (cons_offset == cons_input.used_len) { 98 if (cons_offset == cons_input.used_len) {
56 cons_offset = 0; 99 cons_offset = 0;
57 cons_input.used_len = 0; 100 cons_input.used_len = 0;
58 } 101 }
59 return count; 102 return count;
60} 103}
104/*:*/
61 105
62static struct hv_ops lguest_cons = { 106static struct hv_ops lguest_cons = {
63 .get_chars = get_chars, 107 .get_chars = get_chars,
64 .put_chars = put_chars, 108 .put_chars = put_chars,
65}; 109};
66 110
111/*D:320 Console drivers are initialized very early so boot messages can go
112 * out. At this stage, the console is output-only. Our driver checks we're a
113 * Guest, and if so hands hvc_instantiate() the console number (0), priority
114 * (0), and the struct hv_ops containing the put_chars() function. */
67static int __init cons_init(void) 115static int __init cons_init(void)
68{ 116{
69 if (strcmp(paravirt_ops.name, "lguest") != 0) 117 if (strcmp(paravirt_ops.name, "lguest") != 0)
@@ -73,21 +121,46 @@ static int __init cons_init(void)
73} 121}
74console_initcall(cons_init); 122console_initcall(cons_init);
75 123
124/*D:370 To set up and manage our virtual console, we call hvc_alloc() and
125 * stash the result in the private pointer of the "struct lguest_device".
126 * Since we never remove the console device we never need this pointer again,
127 * but using ->private is considered good form, and you never know who's going
128 * to copy your driver.
129 *
130 * Once the console is set up, we bind our input buffer ready for input. */
76static int lguestcons_probe(struct lguest_device *lgdev) 131static int lguestcons_probe(struct lguest_device *lgdev)
77{ 132{
78 int err; 133 int err;
79 134
135 /* The first argument of hvc_alloc() is the virtual console number, so
136 * we use zero. The second argument is the interrupt number.
137 *
138 * The third argument is a "struct hv_ops" containing the put_chars()
139 * and get_chars() pointers. The final argument is the output buffer
140 * size: we use 256 and expect the Host to have room for us to send
141 * that much. */
80 lgdev->private = hvc_alloc(0, lgdev_irq(lgdev), &lguest_cons, 256); 142 lgdev->private = hvc_alloc(0, lgdev_irq(lgdev), &lguest_cons, 256);
81 if (IS_ERR(lgdev->private)) 143 if (IS_ERR(lgdev->private))
82 return PTR_ERR(lgdev->private); 144 return PTR_ERR(lgdev->private);
83 145
146 /* We bind a single DMA buffer at key LGUEST_CONSOLE_DMA_KEY.
147 * "cons_input" is that statically-initialized global DMA buffer we saw
148 * above, and we also give the interrupt we want. */
84 err = lguest_bind_dma(LGUEST_CONSOLE_DMA_KEY, &cons_input, 1, 149 err = lguest_bind_dma(LGUEST_CONSOLE_DMA_KEY, &cons_input, 1,
85 lgdev_irq(lgdev)); 150 lgdev_irq(lgdev));
86 if (err) 151 if (err)
87 printk("lguest console: failed to bind buffer.\n"); 152 printk("lguest console: failed to bind buffer.\n");
88 return err; 153 return err;
89} 154}
155/* Note the use of lgdev_irq() for the interrupt number. We tell hvc_alloc()
156 * to expect input when this interrupt is triggered, and then tell
157 * lguest_bind_dma() that is the interrupt to send us when input comes in. */
90 158
159/*D:360 From now on the console driver follows standard Guest driver form:
160 * register_lguest_driver() registers the device type and probe function, and
161 * the probe function sets up the device.
162 *
163 * The standard "struct lguest_driver": */
91static struct lguest_driver lguestcons_drv = { 164static struct lguest_driver lguestcons_drv = {
92 .name = "lguestcons", 165 .name = "lguestcons",
93 .owner = THIS_MODULE, 166 .owner = THIS_MODULE,
@@ -95,6 +168,7 @@ static struct lguest_driver lguestcons_drv = {
95 .probe = lguestcons_probe, 168 .probe = lguestcons_probe,
96}; 169};
97 170
171/* The standard init function */
98static int __init hvc_lguest_init(void) 172static int __init hvc_lguest_init(void)
99{ 173{
100 return register_lguest_driver(&lguestcons_drv); 174 return register_lguest_driver(&lguestcons_drv);
diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index 6e55cfb9c65a..e60a74c66e3d 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -25,6 +25,7 @@
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/errno.h> 26#include <linux/errno.h>
27#include <linux/mm.h> 27#include <linux/mm.h>
28#include <linux/fs.h>
28#include <linux/mmtimer.h> 29#include <linux/mmtimer.h>
29#include <linux/miscdevice.h> 30#include <linux/miscdevice.h>
30#include <linux/posix-timers.h> 31#include <linux/posix-timers.h>
diff --git a/drivers/char/mspec.c b/drivers/char/mspec.c
index c716ef0dd370..c08a4152ee8f 100644
--- a/drivers/char/mspec.c
+++ b/drivers/char/mspec.c
@@ -38,6 +38,7 @@
38#include <linux/miscdevice.h> 38#include <linux/miscdevice.h>
39#include <linux/spinlock.h> 39#include <linux/spinlock.h>
40#include <linux/mm.h> 40#include <linux/mm.h>
41#include <linux/fs.h>
41#include <linux/vmalloc.h> 42#include <linux/vmalloc.h>
42#include <linux/string.h> 43#include <linux/string.h>
43#include <linux/slab.h> 44#include <linux/slab.h>
diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig
index 1724c41d2414..98b6b4fb4257 100644
--- a/drivers/edac/Kconfig
+++ b/drivers/edac/Kconfig
@@ -8,7 +8,7 @@ menuconfig EDAC
8 bool "EDAC - error detection and reporting (EXPERIMENTAL)" 8 bool "EDAC - error detection and reporting (EXPERIMENTAL)"
9 depends on HAS_IOMEM 9 depends on HAS_IOMEM
10 depends on EXPERIMENTAL 10 depends on EXPERIMENTAL
11 depends on X86 || MIPS || PPC 11 depends on X86 || PPC
12 help 12 help
13 EDAC is designed to report errors in the core system. 13 EDAC is designed to report errors in the core system.
14 These are low-level errors that are reported in the CPU or 14 These are low-level errors that are reported in the CPU or
@@ -126,7 +126,7 @@ config EDAC_I5000
126config EDAC_PASEMI 126config EDAC_PASEMI
127 tristate "PA Semi PWRficient" 127 tristate "PA Semi PWRficient"
128 depends on EDAC_MM_EDAC && PCI 128 depends on EDAC_MM_EDAC && PCI
129 depends on PPC 129 depends on PPC_PASEMI
130 help 130 help
131 Support for error detection and correction on PA Semi 131 Support for error detection and correction on PA Semi
132 PWRficient. 132 PWRficient.
diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c
index 4471be362599..063a1bffe38b 100644
--- a/drivers/edac/edac_mc.c
+++ b/drivers/edac/edac_mc.c
@@ -214,6 +214,13 @@ void edac_mc_free(struct mem_ctl_info *mci)
214} 214}
215EXPORT_SYMBOL_GPL(edac_mc_free); 215EXPORT_SYMBOL_GPL(edac_mc_free);
216 216
217
218/*
219 * find_mci_by_dev
220 *
221 * scan list of controllers looking for the one that manages
222 * the 'dev' device
223 */
217static struct mem_ctl_info *find_mci_by_dev(struct device *dev) 224static struct mem_ctl_info *find_mci_by_dev(struct device *dev)
218{ 225{
219 struct mem_ctl_info *mci; 226 struct mem_ctl_info *mci;
@@ -268,12 +275,6 @@ static void edac_mc_workq_function(struct work_struct *work_req)
268 if (edac_mc_assert_error_check_and_clear() && (mci->edac_check != NULL)) 275 if (edac_mc_assert_error_check_and_clear() && (mci->edac_check != NULL))
269 mci->edac_check(mci); 276 mci->edac_check(mci);
270 277
271 /*
272 * FIXME: temp place holder for PCI checks,
273 * goes away when we break out PCI
274 */
275 edac_pci_do_parity_check();
276
277 mutex_unlock(&mem_ctls_mutex); 278 mutex_unlock(&mem_ctls_mutex);
278 279
279 /* Reschedule */ 280 /* Reschedule */
@@ -314,36 +315,55 @@ static void edac_mc_workq_teardown(struct mem_ctl_info *mci)
314{ 315{
315 int status; 316 int status;
316 317
317 /* if not running POLL, leave now */ 318 status = cancel_delayed_work(&mci->work);
318 if (mci->op_state == OP_RUNNING_POLL) { 319 if (status == 0) {
319 status = cancel_delayed_work(&mci->work); 320 debugf0("%s() not canceled, flush the queue\n",
320 if (status == 0) { 321 __func__);
321 debugf0("%s() not canceled, flush the queue\n",
322 __func__);
323 322
324 /* workq instance might be running, wait for it */ 323 /* workq instance might be running, wait for it */
325 flush_workqueue(edac_workqueue); 324 flush_workqueue(edac_workqueue);
326 }
327 } 325 }
328} 326}
329 327
330/* 328/*
331 * edac_reset_delay_period 329 * edac_mc_reset_delay_period(unsigned long value)
330 *
331 * user space has updated our poll period value, need to
332 * reset our workq delays
332 */ 333 */
333static void edac_reset_delay_period(struct mem_ctl_info *mci, unsigned long value) 334void edac_mc_reset_delay_period(int value)
334{ 335{
335 /* cancel the current workq request */ 336 struct mem_ctl_info *mci;
336 edac_mc_workq_teardown(mci); 337 struct list_head *item;
337 338
338 /* lock the list of devices for the new setup */
339 mutex_lock(&mem_ctls_mutex); 339 mutex_lock(&mem_ctls_mutex);
340 340
341 /* restart the workq request, with new delay value */ 341 /* scan the list and turn off all workq timers, doing so under lock
342 edac_mc_workq_setup(mci, value); 342 */
343 list_for_each(item, &mc_devices) {
344 mci = list_entry(item, struct mem_ctl_info, link);
345
346 if (mci->op_state == OP_RUNNING_POLL)
347 cancel_delayed_work(&mci->work);
348 }
349
350 mutex_unlock(&mem_ctls_mutex);
351
352
353 /* re-walk the list, and reset the poll delay */
354 mutex_lock(&mem_ctls_mutex);
355
356 list_for_each(item, &mc_devices) {
357 mci = list_entry(item, struct mem_ctl_info, link);
358
359 edac_mc_workq_setup(mci, (unsigned long) value);
360 }
343 361
344 mutex_unlock(&mem_ctls_mutex); 362 mutex_unlock(&mem_ctls_mutex);
345} 363}
346 364
365
366
347/* Return 0 on success, 1 on failure. 367/* Return 0 on success, 1 on failure.
348 * Before calling this function, caller must 368 * Before calling this function, caller must
349 * assign a unique value to mci->mc_idx. 369 * assign a unique value to mci->mc_idx.
diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
index cd090b0677a7..4a0576bd06fc 100644
--- a/drivers/edac/edac_mc_sysfs.c
+++ b/drivers/edac/edac_mc_sysfs.c
@@ -122,6 +122,23 @@ static ssize_t memctrl_int_store(void *ptr, const char *buffer, size_t count)
122 return count; 122 return count;
123} 123}
124 124
125/*
126 * mc poll_msec time value
127 */
128static ssize_t poll_msec_int_store(void *ptr, const char *buffer, size_t count)
129{
130 int *value = (int *)ptr;
131
132 if (isdigit(*buffer)) {
133 *value = simple_strtoul(buffer, NULL, 0);
134
135 /* notify edac_mc engine to reset the poll period */
136 edac_mc_reset_delay_period(*value);
137 }
138
139 return count;
140}
141
125 142
126/* EDAC sysfs CSROW data structures and methods 143/* EDAC sysfs CSROW data structures and methods
127 */ 144 */
@@ -704,7 +721,7 @@ MEMCTRL_ATTR(edac_mc_log_ce,
704 S_IRUGO | S_IWUSR, memctrl_int_show, memctrl_int_store); 721 S_IRUGO | S_IWUSR, memctrl_int_show, memctrl_int_store);
705 722
706MEMCTRL_ATTR(edac_mc_poll_msec, 723MEMCTRL_ATTR(edac_mc_poll_msec,
707 S_IRUGO | S_IWUSR, memctrl_int_show, memctrl_int_store); 724 S_IRUGO | S_IWUSR, memctrl_int_show, poll_msec_int_store);
708 725
709/* Base Attributes of the memory ECC object */ 726/* Base Attributes of the memory ECC object */
710static struct memctrl_dev_attribute *memctrl_attr[] = { 727static struct memctrl_dev_attribute *memctrl_attr[] = {
diff --git a/drivers/edac/edac_module.h b/drivers/edac/edac_module.h
index a2134dfc3cc6..cbc419c8ebc1 100644
--- a/drivers/edac/edac_module.h
+++ b/drivers/edac/edac_module.h
@@ -52,6 +52,8 @@ extern void edac_device_workq_setup(struct edac_device_ctl_info *edac_dev,
52extern void edac_device_workq_teardown(struct edac_device_ctl_info *edac_dev); 52extern void edac_device_workq_teardown(struct edac_device_ctl_info *edac_dev);
53extern void edac_device_reset_delay_period(struct edac_device_ctl_info 53extern void edac_device_reset_delay_period(struct edac_device_ctl_info
54 *edac_dev, unsigned long value); 54 *edac_dev, unsigned long value);
55extern void edac_mc_reset_delay_period(int value);
56
55extern void *edac_align_ptr(void *ptr, unsigned size); 57extern void *edac_align_ptr(void *ptr, unsigned size);
56 58
57/* 59/*
@@ -64,6 +66,10 @@ extern int edac_sysfs_pci_setup(void);
64extern void edac_sysfs_pci_teardown(void); 66extern void edac_sysfs_pci_teardown(void);
65extern int edac_pci_get_check_errors(void); 67extern int edac_pci_get_check_errors(void);
66extern int edac_pci_get_poll_msec(void); 68extern int edac_pci_get_poll_msec(void);
69extern void edac_pci_remove_sysfs(struct edac_pci_ctl_info *pci);
70extern void edac_pci_handle_pe(struct edac_pci_ctl_info *pci, const char *msg);
71extern void edac_pci_handle_npe(struct edac_pci_ctl_info *pci,
72 const char *msg);
67#else /* CONFIG_PCI */ 73#else /* CONFIG_PCI */
68/* pre-process these away */ 74/* pre-process these away */
69#define edac_pci_do_parity_check() 75#define edac_pci_do_parity_check()
@@ -72,6 +78,8 @@ extern int edac_pci_get_poll_msec(void);
72#define edac_sysfs_pci_teardown() 78#define edac_sysfs_pci_teardown()
73#define edac_pci_get_check_errors() 79#define edac_pci_get_check_errors()
74#define edac_pci_get_poll_msec() 80#define edac_pci_get_poll_msec()
81#define edac_pci_handle_pe()
82#define edac_pci_handle_npe()
75#endif /* CONFIG_PCI */ 83#endif /* CONFIG_PCI */
76 84
77#endif /* __EDAC_MODULE_H__ */ 85#endif /* __EDAC_MODULE_H__ */
diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
index d9cd5e048cee..5dee9f50414b 100644
--- a/drivers/edac/edac_pci.c
+++ b/drivers/edac/edac_pci.c
@@ -31,20 +31,12 @@
31static DEFINE_MUTEX(edac_pci_ctls_mutex); 31static DEFINE_MUTEX(edac_pci_ctls_mutex);
32static struct list_head edac_pci_list = LIST_HEAD_INIT(edac_pci_list); 32static struct list_head edac_pci_list = LIST_HEAD_INIT(edac_pci_list);
33 33
34static inline void edac_lock_pci_list(void)
35{
36 mutex_lock(&edac_pci_ctls_mutex);
37}
38
39static inline void edac_unlock_pci_list(void)
40{
41 mutex_unlock(&edac_pci_ctls_mutex);
42}
43
44/* 34/*
45 * The alloc() and free() functions for the 'edac_pci' control info 35 * edac_pci_alloc_ctl_info
46 * structure. The chip driver will allocate one of these for each 36 *
47 * edac_pci it is going to control/register with the EDAC CORE. 37 * The alloc() function for the 'edac_pci' control info
38 * structure. The chip driver will allocate one of these for each
39 * edac_pci it is going to control/register with the EDAC CORE.
48 */ 40 */
49struct edac_pci_ctl_info *edac_pci_alloc_ctl_info(unsigned int sz_pvt, 41struct edac_pci_ctl_info *edac_pci_alloc_ctl_info(unsigned int sz_pvt,
50 const char *edac_pci_name) 42 const char *edac_pci_name)
@@ -53,47 +45,59 @@ struct edac_pci_ctl_info *edac_pci_alloc_ctl_info(unsigned int sz_pvt,
53 void *pvt; 45 void *pvt;
54 unsigned int size; 46 unsigned int size;
55 47
48 debugf1("%s()\n", __func__);
49
56 pci = (struct edac_pci_ctl_info *)0; 50 pci = (struct edac_pci_ctl_info *)0;
57 pvt = edac_align_ptr(&pci[1], sz_pvt); 51 pvt = edac_align_ptr(&pci[1], sz_pvt);
58 size = ((unsigned long)pvt) + sz_pvt; 52 size = ((unsigned long)pvt) + sz_pvt;
59 53
60 if ((pci = kzalloc(size, GFP_KERNEL)) == NULL) 54 /* Alloc the needed control struct memory */
55 pci = kzalloc(size, GFP_KERNEL);
56 if (pci == NULL)
61 return NULL; 57 return NULL;
62 58
59 /* Now much private space */
63 pvt = sz_pvt ? ((char *)pci) + ((unsigned long)pvt) : NULL; 60 pvt = sz_pvt ? ((char *)pci) + ((unsigned long)pvt) : NULL;
64 61
65 pci->pvt_info = pvt; 62 pci->pvt_info = pvt;
66
67 pci->op_state = OP_ALLOC; 63 pci->op_state = OP_ALLOC;
68 64
69 snprintf(pci->name, strlen(edac_pci_name) + 1, "%s", edac_pci_name); 65 snprintf(pci->name, strlen(edac_pci_name) + 1, "%s", edac_pci_name);
70 66
71 return pci; 67 return pci;
72} 68}
73
74EXPORT_SYMBOL_GPL(edac_pci_alloc_ctl_info); 69EXPORT_SYMBOL_GPL(edac_pci_alloc_ctl_info);
75 70
76/* 71/*
77 * edac_pci_free_ctl_info() 72 * edac_pci_free_ctl_info()
78 * frees the memory allocated by edac_pci_alloc_ctl_info() function 73 *
74 * Last action on the pci control structure.
75 *
76 * call the remove sysfs informaton, which will unregister
77 * this control struct's kobj. When that kobj's ref count
78 * goes to zero, its release function will be call and then
79 * kfree() the memory.
79 */ 80 */
80void edac_pci_free_ctl_info(struct edac_pci_ctl_info *pci) 81void edac_pci_free_ctl_info(struct edac_pci_ctl_info *pci)
81{ 82{
82 kfree(pci); 83 debugf1("%s()\n", __func__);
83}
84 84
85 edac_pci_remove_sysfs(pci);
86}
85EXPORT_SYMBOL_GPL(edac_pci_free_ctl_info); 87EXPORT_SYMBOL_GPL(edac_pci_free_ctl_info);
86 88
87/* 89/*
88 * find_edac_pci_by_dev() 90 * find_edac_pci_by_dev()
89 * scans the edac_pci list for a specific 'struct device *' 91 * scans the edac_pci list for a specific 'struct device *'
92 *
93 * return NULL if not found, or return control struct pointer
90 */ 94 */
91static struct edac_pci_ctl_info *find_edac_pci_by_dev(struct device *dev) 95static struct edac_pci_ctl_info *find_edac_pci_by_dev(struct device *dev)
92{ 96{
93 struct edac_pci_ctl_info *pci; 97 struct edac_pci_ctl_info *pci;
94 struct list_head *item; 98 struct list_head *item;
95 99
96 debugf3("%s()\n", __func__); 100 debugf1("%s()\n", __func__);
97 101
98 list_for_each(item, &edac_pci_list) { 102 list_for_each(item, &edac_pci_list) {
99 pci = list_entry(item, struct edac_pci_ctl_info, link); 103 pci = list_entry(item, struct edac_pci_ctl_info, link);
@@ -118,10 +122,13 @@ static int add_edac_pci_to_global_list(struct edac_pci_ctl_info *pci)
118 struct list_head *item, *insert_before; 122 struct list_head *item, *insert_before;
119 struct edac_pci_ctl_info *rover; 123 struct edac_pci_ctl_info *rover;
120 124
125 debugf1("%s()\n", __func__);
126
121 insert_before = &edac_pci_list; 127 insert_before = &edac_pci_list;
122 128
123 /* Determine if already on the list */ 129 /* Determine if already on the list */
124 if (unlikely((rover = find_edac_pci_by_dev(pci->dev)) != NULL)) 130 rover = find_edac_pci_by_dev(pci->dev);
131 if (unlikely(rover != NULL))
125 goto fail0; 132 goto fail0;
126 133
127 /* Insert in ascending order by 'pci_idx', so find position */ 134 /* Insert in ascending order by 'pci_idx', so find position */
@@ -157,6 +164,8 @@ fail1:
157 164
158/* 165/*
159 * complete_edac_pci_list_del 166 * complete_edac_pci_list_del
167 *
168 * RCU completion callback to indicate item is deleted
160 */ 169 */
161static void complete_edac_pci_list_del(struct rcu_head *head) 170static void complete_edac_pci_list_del(struct rcu_head *head)
162{ 171{
@@ -169,6 +178,8 @@ static void complete_edac_pci_list_del(struct rcu_head *head)
169 178
170/* 179/*
171 * del_edac_pci_from_global_list 180 * del_edac_pci_from_global_list
181 *
182 * remove the PCI control struct from the global list
172 */ 183 */
173static void del_edac_pci_from_global_list(struct edac_pci_ctl_info *pci) 184static void del_edac_pci_from_global_list(struct edac_pci_ctl_info *pci)
174{ 185{
@@ -207,35 +218,52 @@ struct edac_pci_ctl_info *edac_pci_find(int idx)
207 218
208 return NULL; 219 return NULL;
209} 220}
210
211EXPORT_SYMBOL_GPL(edac_pci_find); 221EXPORT_SYMBOL_GPL(edac_pci_find);
212 222
213/* 223/*
214 * edac_pci_workq_function() 224 * edac_pci_workq_function()
215 * performs the operation scheduled by a workq request 225 *
226 * periodic function that performs the operation
227 * scheduled by a workq request, for a given PCI control struct
216 */ 228 */
217static void edac_pci_workq_function(struct work_struct *work_req) 229static void edac_pci_workq_function(struct work_struct *work_req)
218{ 230{
219 struct delayed_work *d_work = (struct delayed_work *)work_req; 231 struct delayed_work *d_work = (struct delayed_work *)work_req;
220 struct edac_pci_ctl_info *pci = to_edac_pci_ctl_work(d_work); 232 struct edac_pci_ctl_info *pci = to_edac_pci_ctl_work(d_work);
233 int msec;
234 unsigned long delay;
221 235
222 edac_lock_pci_list(); 236 debugf3("%s() checking\n", __func__);
223 237
224 if ((pci->op_state == OP_RUNNING_POLL) && 238 mutex_lock(&edac_pci_ctls_mutex);
225 (pci->edac_check != NULL) && (edac_pci_get_check_errors()))
226 pci->edac_check(pci);
227 239
228 edac_unlock_pci_list(); 240 if (pci->op_state == OP_RUNNING_POLL) {
241 /* we might be in POLL mode, but there may NOT be a poll func
242 */
243 if ((pci->edac_check != NULL) && edac_pci_get_check_errors())
244 pci->edac_check(pci);
245
246 /* if we are on a one second period, then use round */
247 msec = edac_pci_get_poll_msec();
248 if (msec == 1000)
249 delay = round_jiffies(msecs_to_jiffies(msec));
250 else
251 delay = msecs_to_jiffies(msec);
252
253 /* Reschedule only if we are in POLL mode */
254 queue_delayed_work(edac_workqueue, &pci->work, delay);
255 }
229 256
230 /* Reschedule */ 257 mutex_unlock(&edac_pci_ctls_mutex);
231 queue_delayed_work(edac_workqueue, &pci->work,
232 msecs_to_jiffies(edac_pci_get_poll_msec()));
233} 258}
234 259
235/* 260/*
236 * edac_pci_workq_setup() 261 * edac_pci_workq_setup()
237 * initialize a workq item for this edac_pci instance 262 * initialize a workq item for this edac_pci instance
238 * passing in the new delay period in msec 263 * passing in the new delay period in msec
264 *
265 * locking model:
266 * called when 'edac_pci_ctls_mutex' is locked
239 */ 267 */
240static void edac_pci_workq_setup(struct edac_pci_ctl_info *pci, 268static void edac_pci_workq_setup(struct edac_pci_ctl_info *pci,
241 unsigned int msec) 269 unsigned int msec)
@@ -255,6 +283,8 @@ static void edac_pci_workq_teardown(struct edac_pci_ctl_info *pci)
255{ 283{
256 int status; 284 int status;
257 285
286 debugf0("%s()\n", __func__);
287
258 status = cancel_delayed_work(&pci->work); 288 status = cancel_delayed_work(&pci->work);
259 if (status == 0) 289 if (status == 0)
260 flush_workqueue(edac_workqueue); 290 flush_workqueue(edac_workqueue);
@@ -262,19 +292,25 @@ static void edac_pci_workq_teardown(struct edac_pci_ctl_info *pci)
262 292
263/* 293/*
264 * edac_pci_reset_delay_period 294 * edac_pci_reset_delay_period
295 *
296 * called with a new period value for the workq period
297 * a) stop current workq timer
298 * b) restart workq timer with new value
265 */ 299 */
266void edac_pci_reset_delay_period(struct edac_pci_ctl_info *pci, 300void edac_pci_reset_delay_period(struct edac_pci_ctl_info *pci,
267 unsigned long value) 301 unsigned long value)
268{ 302{
269 edac_lock_pci_list(); 303 debugf0("%s()\n", __func__);
270 304
271 edac_pci_workq_teardown(pci); 305 edac_pci_workq_teardown(pci);
272 306
307 /* need to lock for the setup */
308 mutex_lock(&edac_pci_ctls_mutex);
309
273 edac_pci_workq_setup(pci, value); 310 edac_pci_workq_setup(pci, value);
274 311
275 edac_unlock_pci_list(); 312 mutex_unlock(&edac_pci_ctls_mutex);
276} 313}
277
278EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period); 314EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
279 315
280/* 316/*
@@ -294,14 +330,13 @@ int edac_pci_add_device(struct edac_pci_ctl_info *pci, int edac_idx)
294 debugf0("%s()\n", __func__); 330 debugf0("%s()\n", __func__);
295 331
296 pci->pci_idx = edac_idx; 332 pci->pci_idx = edac_idx;
333 pci->start_time = jiffies;
297 334
298 edac_lock_pci_list(); 335 mutex_lock(&edac_pci_ctls_mutex);
299 336
300 if (add_edac_pci_to_global_list(pci)) 337 if (add_edac_pci_to_global_list(pci))
301 goto fail0; 338 goto fail0;
302 339
303 pci->start_time = jiffies;
304
305 if (edac_pci_create_sysfs(pci)) { 340 if (edac_pci_create_sysfs(pci)) {
306 edac_pci_printk(pci, KERN_WARNING, 341 edac_pci_printk(pci, KERN_WARNING,
307 "failed to create sysfs pci\n"); 342 "failed to create sysfs pci\n");
@@ -323,16 +358,16 @@ int edac_pci_add_device(struct edac_pci_ctl_info *pci, int edac_idx)
323 pci->ctl_name, 358 pci->ctl_name,
324 dev_name(pci), edac_op_state_to_string(pci->op_state)); 359 dev_name(pci), edac_op_state_to_string(pci->op_state));
325 360
326 edac_unlock_pci_list(); 361 mutex_unlock(&edac_pci_ctls_mutex);
327 return 0; 362 return 0;
328 363
364 /* error unwind stack */
329fail1: 365fail1:
330 del_edac_pci_from_global_list(pci); 366 del_edac_pci_from_global_list(pci);
331fail0: 367fail0:
332 edac_unlock_pci_list(); 368 mutex_unlock(&edac_pci_ctls_mutex);
333 return 1; 369 return 1;
334} 370}
335
336EXPORT_SYMBOL_GPL(edac_pci_add_device); 371EXPORT_SYMBOL_GPL(edac_pci_add_device);
337 372
338/* 373/*
@@ -354,22 +389,25 @@ struct edac_pci_ctl_info *edac_pci_del_device(struct device *dev)
354 389
355 debugf0("%s()\n", __func__); 390 debugf0("%s()\n", __func__);
356 391
357 edac_lock_pci_list(); 392 mutex_lock(&edac_pci_ctls_mutex);
358 393
359 if ((pci = find_edac_pci_by_dev(dev)) == NULL) { 394 /* ensure the control struct is on the global list
360 edac_unlock_pci_list(); 395 * if not, then leave
396 */
397 pci = find_edac_pci_by_dev(dev);
398 if (pci == NULL) {
399 mutex_unlock(&edac_pci_ctls_mutex);
361 return NULL; 400 return NULL;
362 } 401 }
363 402
364 pci->op_state = OP_OFFLINE; 403 pci->op_state = OP_OFFLINE;
365 404
366 edac_pci_workq_teardown(pci);
367
368 edac_pci_remove_sysfs(pci);
369
370 del_edac_pci_from_global_list(pci); 405 del_edac_pci_from_global_list(pci);
371 406
372 edac_unlock_pci_list(); 407 mutex_unlock(&edac_pci_ctls_mutex);
408
409 /* stop the workq timer */
410 edac_pci_workq_teardown(pci);
373 411
374 edac_printk(KERN_INFO, EDAC_PCI, 412 edac_printk(KERN_INFO, EDAC_PCI,
375 "Removed device %d for %s %s: DEV %s\n", 413 "Removed device %d for %s %s: DEV %s\n",
@@ -377,14 +415,20 @@ struct edac_pci_ctl_info *edac_pci_del_device(struct device *dev)
377 415
378 return pci; 416 return pci;
379} 417}
380
381EXPORT_SYMBOL_GPL(edac_pci_del_device); 418EXPORT_SYMBOL_GPL(edac_pci_del_device);
382 419
420/*
421 * edac_pci_generic_check
422 *
423 * a Generic parity check API
424 */
383void edac_pci_generic_check(struct edac_pci_ctl_info *pci) 425void edac_pci_generic_check(struct edac_pci_ctl_info *pci)
384{ 426{
427 debugf4("%s()\n", __func__);
385 edac_pci_do_parity_check(); 428 edac_pci_do_parity_check();
386} 429}
387 430
431/* free running instance index counter */
388static int edac_pci_idx; 432static int edac_pci_idx;
389#define EDAC_PCI_GENCTL_NAME "EDAC PCI controller" 433#define EDAC_PCI_GENCTL_NAME "EDAC PCI controller"
390 434
@@ -392,6 +436,17 @@ struct edac_pci_gen_data {
392 int edac_idx; 436 int edac_idx;
393}; 437};
394 438
439/*
440 * edac_pci_create_generic_ctl
441 *
442 * A generic constructor for a PCI parity polling device
443 * Some systems have more than one domain of PCI busses.
444 * For systems with one domain, then this API will
445 * provide for a generic poller.
446 *
447 * This routine calls the edac_pci_alloc_ctl_info() for
448 * the generic device, with default values
449 */
395struct edac_pci_ctl_info *edac_pci_create_generic_ctl(struct device *dev, 450struct edac_pci_ctl_info *edac_pci_create_generic_ctl(struct device *dev,
396 const char *mod_name) 451 const char *mod_name)
397{ 452{
@@ -421,13 +476,18 @@ struct edac_pci_ctl_info *edac_pci_create_generic_ctl(struct device *dev,
421 476
422 return pci; 477 return pci;
423} 478}
424
425EXPORT_SYMBOL_GPL(edac_pci_create_generic_ctl); 479EXPORT_SYMBOL_GPL(edac_pci_create_generic_ctl);
426 480
481/*
482 * edac_pci_release_generic_ctl
483 *
484 * The release function of a generic EDAC PCI polling device
485 */
427void edac_pci_release_generic_ctl(struct edac_pci_ctl_info *pci) 486void edac_pci_release_generic_ctl(struct edac_pci_ctl_info *pci)
428{ 487{
488 debugf0("%s() pci mod=%s\n", __func__, pci->mod_name);
489
429 edac_pci_del_device(pci->dev); 490 edac_pci_del_device(pci->dev);
430 edac_pci_free_ctl_info(pci); 491 edac_pci_free_ctl_info(pci);
431} 492}
432
433EXPORT_SYMBOL_GPL(edac_pci_release_generic_ctl); 493EXPORT_SYMBOL_GPL(edac_pci_release_generic_ctl);
diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
index fac94cae2c3d..69f5dddabddf 100644
--- a/drivers/edac/edac_pci_sysfs.c
+++ b/drivers/edac/edac_pci_sysfs.c
@@ -13,22 +13,25 @@
13#include "edac_core.h" 13#include "edac_core.h"
14#include "edac_module.h" 14#include "edac_module.h"
15 15
16/* Turn off this whole feature if PCI is not configured */
16#ifdef CONFIG_PCI 17#ifdef CONFIG_PCI
17 18
18#define EDAC_PCI_SYMLINK "device" 19#define EDAC_PCI_SYMLINK "device"
19 20
20static int check_pci_errors; /* default YES check PCI parity */ 21/* data variables exported via sysfs */
21static int edac_pci_panic_on_pe; /* default no panic on PCI Parity */ 22static int check_pci_errors; /* default NO check PCI parity */
22static int edac_pci_log_pe = 1; /* log PCI parity errors */ 23static int edac_pci_panic_on_pe; /* default NO panic on PCI Parity */
24static int edac_pci_log_pe = 1; /* log PCI parity errors */
23static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */ 25static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
26static int edac_pci_poll_msec = 1000; /* one second workq period */
27
24static atomic_t pci_parity_count = ATOMIC_INIT(0); 28static atomic_t pci_parity_count = ATOMIC_INIT(0);
25static atomic_t pci_nonparity_count = ATOMIC_INIT(0); 29static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
26static int edac_pci_poll_msec = 1000;
27 30
28static struct kobject edac_pci_kobj; /* /sys/devices/system/edac/pci */ 31static struct kobject edac_pci_top_main_kobj;
29static struct completion edac_pci_kobj_complete;
30static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0); 32static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
31 33
34/* getter functions for the data variables */
32int edac_pci_get_check_errors(void) 35int edac_pci_get_check_errors(void)
33{ 36{
34 return check_pci_errors; 37 return check_pci_errors;
@@ -74,17 +77,22 @@ static void edac_pci_instance_release(struct kobject *kobj)
74{ 77{
75 struct edac_pci_ctl_info *pci; 78 struct edac_pci_ctl_info *pci;
76 79
77 debugf1("%s()\n", __func__); 80 debugf0("%s()\n", __func__);
78 81
82 /* Form pointer to containing struct, the pci control struct */
79 pci = to_instance(kobj); 83 pci = to_instance(kobj);
80 complete(&pci->kobj_complete); 84
85 /* decrement reference count on top main kobj */
86 kobject_put(&edac_pci_top_main_kobj);
87
88 kfree(pci); /* Free the control struct */
81} 89}
82 90
83/* instance specific attribute structure */ 91/* instance specific attribute structure */
84struct instance_attribute { 92struct instance_attribute {
85 struct attribute attr; 93 struct attribute attr;
86 ssize_t(*show) (struct edac_pci_ctl_info *, char *); 94 ssize_t(*show) (struct edac_pci_ctl_info *, char *);
87 ssize_t(*store) (struct edac_pci_ctl_info *, const char *, size_t); 95 ssize_t(*store) (struct edac_pci_ctl_info *, const char *, size_t);
88}; 96};
89 97
90/* Function to 'show' fields from the edac_pci 'instance' structure */ 98/* Function to 'show' fields from the edac_pci 'instance' structure */
@@ -112,6 +120,7 @@ static ssize_t edac_pci_instance_store(struct kobject *kobj,
112 return -EIO; 120 return -EIO;
113} 121}
114 122
123/* fs_ops table */
115static struct sysfs_ops pci_instance_ops = { 124static struct sysfs_ops pci_instance_ops = {
116 .show = edac_pci_instance_show, 125 .show = edac_pci_instance_show,
117 .store = edac_pci_instance_store 126 .store = edac_pci_instance_store
@@ -134,48 +143,82 @@ static struct instance_attribute *pci_instance_attr[] = {
134 NULL 143 NULL
135}; 144};
136 145
137/* the ktype for pci instance */ 146/* the ktype for a pci instance */
138static struct kobj_type ktype_pci_instance = { 147static struct kobj_type ktype_pci_instance = {
139 .release = edac_pci_instance_release, 148 .release = edac_pci_instance_release,
140 .sysfs_ops = &pci_instance_ops, 149 .sysfs_ops = &pci_instance_ops,
141 .default_attrs = (struct attribute **)pci_instance_attr, 150 .default_attrs = (struct attribute **)pci_instance_attr,
142}; 151};
143 152
153/*
154 * edac_pci_create_instance_kobj
155 *
156 * construct one EDAC PCI instance's kobject for use
157 */
144static int edac_pci_create_instance_kobj(struct edac_pci_ctl_info *pci, int idx) 158static int edac_pci_create_instance_kobj(struct edac_pci_ctl_info *pci, int idx)
145{ 159{
160 struct kobject *main_kobj;
146 int err; 161 int err;
147 162
148 pci->kobj.parent = &edac_pci_kobj; 163 debugf0("%s()\n", __func__);
164
165 /* Set the parent and the instance's ktype */
166 pci->kobj.parent = &edac_pci_top_main_kobj;
149 pci->kobj.ktype = &ktype_pci_instance; 167 pci->kobj.ktype = &ktype_pci_instance;
150 168
151 err = kobject_set_name(&pci->kobj, "pci%d", idx); 169 err = kobject_set_name(&pci->kobj, "pci%d", idx);
152 if (err) 170 if (err)
153 return err; 171 return err;
154 172
173 /* First bump the ref count on the top main kobj, which will
174 * track the number of PCI instances we have, and thus nest
175 * properly on keeping the module loaded
176 */
177 main_kobj = kobject_get(&edac_pci_top_main_kobj);
178 if (!main_kobj) {
179 err = -ENODEV;
180 goto error_out;
181 }
182
183 /* And now register this new kobject under the main kobj */
155 err = kobject_register(&pci->kobj); 184 err = kobject_register(&pci->kobj);
156 if (err != 0) { 185 if (err != 0) {
157 debugf2("%s() failed to register instance pci%d\n", 186 debugf2("%s() failed to register instance pci%d\n",
158 __func__, idx); 187 __func__, idx);
159 return err; 188 kobject_put(&edac_pci_top_main_kobj);
189 goto error_out;
160 } 190 }
161 191
162 debugf1("%s() Register instance 'pci%d' kobject\n", __func__, idx); 192 debugf1("%s() Register instance 'pci%d' kobject\n", __func__, idx);
163 193
164 return 0; 194 return 0;
195
196 /* Error unwind statck */
197error_out:
198 return err;
165} 199}
166 200
167static void 201/*
168edac_pci_delete_instance_kobj(struct edac_pci_ctl_info *pci, int idx) 202 * edac_pci_unregister_sysfs_instance_kobj
203 *
204 * unregister the kobj for the EDAC PCI instance
205 */
206void edac_pci_unregister_sysfs_instance_kobj(struct edac_pci_ctl_info *pci)
169{ 207{
170 init_completion(&pci->kobj_complete); 208 debugf0("%s()\n", __func__);
209
210 /* Unregister the instance kobject and allow its release
211 * function release the main reference count and then
212 * kfree the memory
213 */
171 kobject_unregister(&pci->kobj); 214 kobject_unregister(&pci->kobj);
172 wait_for_completion(&pci->kobj_complete);
173} 215}
174 216
175/***************************** EDAC PCI sysfs root **********************/ 217/***************************** EDAC PCI sysfs root **********************/
176#define to_edacpci(k) container_of(k, struct edac_pci_ctl_info, kobj) 218#define to_edacpci(k) container_of(k, struct edac_pci_ctl_info, kobj)
177#define to_edacpci_attr(a) container_of(a, struct edac_pci_attr, attr) 219#define to_edacpci_attr(a) container_of(a, struct edac_pci_attr, attr)
178 220
221/* simple show/store functions for attributes */
179static ssize_t edac_pci_int_show(void *ptr, char *buffer) 222static ssize_t edac_pci_int_show(void *ptr, char *buffer)
180{ 223{
181 int *value = ptr; 224 int *value = ptr;
@@ -267,118 +310,189 @@ static struct edac_pci_dev_attribute *edac_pci_attr[] = {
267 NULL, 310 NULL,
268}; 311};
269 312
270/* No memory to release */ 313/*
271static void edac_pci_release(struct kobject *kobj) 314 * edac_pci_release_main_kobj
315 *
316 * This release function is called when the reference count to the
317 * passed kobj goes to zero.
318 *
319 * This kobj is the 'main' kobject that EDAC PCI instances
320 * link to, and thus provide for proper nesting counts
321 */
322static void edac_pci_release_main_kobj(struct kobject *kobj)
272{ 323{
273 struct edac_pci_ctl_info *pci;
274 324
275 pci = to_edacpci(kobj); 325 debugf0("%s() here to module_put(THIS_MODULE)\n", __func__);
276 326
277 debugf1("%s()\n", __func__); 327 /* last reference to top EDAC PCI kobject has been removed,
278 complete(&pci->kobj_complete); 328 * NOW release our ref count on the core module
329 */
330 module_put(THIS_MODULE);
279} 331}
280 332
281static struct kobj_type ktype_edac_pci = { 333/* ktype struct for the EDAC PCI main kobj */
282 .release = edac_pci_release, 334static struct kobj_type ktype_edac_pci_main_kobj = {
335 .release = edac_pci_release_main_kobj,
283 .sysfs_ops = &edac_pci_sysfs_ops, 336 .sysfs_ops = &edac_pci_sysfs_ops,
284 .default_attrs = (struct attribute **)edac_pci_attr, 337 .default_attrs = (struct attribute **)edac_pci_attr,
285}; 338};
286 339
287/** 340/**
288 * edac_sysfs_pci_setup() 341 * edac_pci_main_kobj_setup()
289 * 342 *
290 * setup the sysfs for EDAC PCI attributes 343 * setup the sysfs for EDAC PCI attributes
291 * assumes edac_class has already been initialized 344 * assumes edac_class has already been initialized
292 */ 345 */
293int edac_pci_register_main_kobj(void) 346int edac_pci_main_kobj_setup(void)
294{ 347{
295 int err; 348 int err;
296 struct sysdev_class *edac_class; 349 struct sysdev_class *edac_class;
297 350
298 debugf1("%s()\n", __func__); 351 debugf0("%s()\n", __func__);
352
353 /* check and count if we have already created the main kobject */
354 if (atomic_inc_return(&edac_pci_sysfs_refcount) != 1)
355 return 0;
299 356
357 /* First time, so create the main kobject and its
358 * controls and atributes
359 */
300 edac_class = edac_get_edac_class(); 360 edac_class = edac_get_edac_class();
301 if (edac_class == NULL) { 361 if (edac_class == NULL) {
302 debugf1("%s() no edac_class\n", __func__); 362 debugf1("%s() no edac_class\n", __func__);
303 return -ENODEV; 363 err = -ENODEV;
364 goto decrement_count_fail;
304 } 365 }
305 366
306 edac_pci_kobj.ktype = &ktype_edac_pci; 367 /* Need the kobject hook ups, and name setting */
368 edac_pci_top_main_kobj.ktype = &ktype_edac_pci_main_kobj;
369 edac_pci_top_main_kobj.parent = &edac_class->kset.kobj;
307 370
308 edac_pci_kobj.parent = &edac_class->kset.kobj; 371 err = kobject_set_name(&edac_pci_top_main_kobj, "pci");
309
310 err = kobject_set_name(&edac_pci_kobj, "pci");
311 if (err) 372 if (err)
312 return err; 373 goto decrement_count_fail;
374
375 /* Bump the reference count on this module to ensure the
376 * modules isn't unloaded until we deconstruct the top
377 * level main kobj for EDAC PCI
378 */
379 if (!try_module_get(THIS_MODULE)) {
380 debugf1("%s() try_module_get() failed\n", __func__);
381 err = -ENODEV;
382 goto decrement_count_fail;
383 }
313 384
314 /* Instanstiate the pci object */ 385 /* Instanstiate the pci object */
315 /* FIXME: maybe new sysdev_create_subdir() */ 386 /* FIXME: maybe new sysdev_create_subdir() */
316 err = kobject_register(&edac_pci_kobj); 387 err = kobject_register(&edac_pci_top_main_kobj);
317
318 if (err) { 388 if (err) {
319 debugf1("Failed to register '.../edac/pci'\n"); 389 debugf1("Failed to register '.../edac/pci'\n");
320 return err; 390 goto kobject_register_fail;
321 } 391 }
322 392
393 /* At this point, to 'release' the top level kobject
394 * for EDAC PCI, then edac_pci_main_kobj_teardown()
395 * must be used, for resources to be cleaned up properly
396 */
323 debugf1("Registered '.../edac/pci' kobject\n"); 397 debugf1("Registered '.../edac/pci' kobject\n");
324 398
325 return 0; 399 return 0;
400
401 /* Error unwind statck */
402kobject_register_fail:
403 module_put(THIS_MODULE);
404
405decrement_count_fail:
406 /* if are on this error exit, nothing to tear down */
407 atomic_dec(&edac_pci_sysfs_refcount);
408
409 return err;
326} 410}
327 411
328/* 412/*
329 * edac_pci_unregister_main_kobj() 413 * edac_pci_main_kobj_teardown()
330 * 414 *
331 * perform the sysfs teardown for the PCI attributes 415 * if no longer linked (needed) remove the top level EDAC PCI
416 * kobject with its controls and attributes
332 */ 417 */
333void edac_pci_unregister_main_kobj(void) 418static void edac_pci_main_kobj_teardown(void)
334{ 419{
335 debugf0("%s()\n", __func__); 420 debugf0("%s()\n", __func__);
336 init_completion(&edac_pci_kobj_complete); 421
337 kobject_unregister(&edac_pci_kobj); 422 /* Decrement the count and only if no more controller instances
338 wait_for_completion(&edac_pci_kobj_complete); 423 * are connected perform the unregisteration of the top level
424 * main kobj
425 */
426 if (atomic_dec_return(&edac_pci_sysfs_refcount) == 0) {
427 debugf0("%s() called kobject_unregister on main kobj\n",
428 __func__);
429 kobject_unregister(&edac_pci_top_main_kobj);
430 }
339} 431}
340 432
433/*
434 *
435 * edac_pci_create_sysfs
436 *
437 * Create the controls/attributes for the specified EDAC PCI device
438 */
341int edac_pci_create_sysfs(struct edac_pci_ctl_info *pci) 439int edac_pci_create_sysfs(struct edac_pci_ctl_info *pci)
342{ 440{
343 int err; 441 int err;
344 struct kobject *edac_kobj = &pci->kobj; 442 struct kobject *edac_kobj = &pci->kobj;
345 443
346 if (atomic_inc_return(&edac_pci_sysfs_refcount) == 1) { 444 debugf0("%s() idx=%d\n", __func__, pci->pci_idx);
347 err = edac_pci_register_main_kobj();
348 if (err) {
349 atomic_dec(&edac_pci_sysfs_refcount);
350 return err;
351 }
352 }
353 445
354 err = edac_pci_create_instance_kobj(pci, pci->pci_idx); 446 /* create the top main EDAC PCI kobject, IF needed */
355 if (err) { 447 err = edac_pci_main_kobj_setup();
356 if (atomic_dec_return(&edac_pci_sysfs_refcount) == 0) 448 if (err)
357 edac_pci_unregister_main_kobj(); 449 return err;
358 }
359 450
360 debugf0("%s() idx=%d\n", __func__, pci->pci_idx); 451 /* Create this instance's kobject under the MAIN kobject */
452 err = edac_pci_create_instance_kobj(pci, pci->pci_idx);
453 if (err)
454 goto unregister_cleanup;
361 455
362 err = sysfs_create_link(edac_kobj, &pci->dev->kobj, EDAC_PCI_SYMLINK); 456 err = sysfs_create_link(edac_kobj, &pci->dev->kobj, EDAC_PCI_SYMLINK);
363 if (err) { 457 if (err) {
364 debugf0("%s() sysfs_create_link() returned err= %d\n", 458 debugf0("%s() sysfs_create_link() returned err= %d\n",
365 __func__, err); 459 __func__, err);
366 return err; 460 goto symlink_fail;
367 } 461 }
368 462
369 return 0; 463 return 0;
464
465 /* Error unwind stack */
466symlink_fail:
467 edac_pci_unregister_sysfs_instance_kobj(pci);
468
469unregister_cleanup:
470 edac_pci_main_kobj_teardown();
471
472 return err;
370} 473}
371 474
475/*
476 * edac_pci_remove_sysfs
477 *
478 * remove the controls and attributes for this EDAC PCI device
479 */
372void edac_pci_remove_sysfs(struct edac_pci_ctl_info *pci) 480void edac_pci_remove_sysfs(struct edac_pci_ctl_info *pci)
373{ 481{
374 debugf0("%s()\n", __func__); 482 debugf0("%s() index=%d\n", __func__, pci->pci_idx);
375
376 edac_pci_delete_instance_kobj(pci, pci->pci_idx);
377 483
484 /* Remove the symlink */
378 sysfs_remove_link(&pci->kobj, EDAC_PCI_SYMLINK); 485 sysfs_remove_link(&pci->kobj, EDAC_PCI_SYMLINK);
379 486
380 if (atomic_dec_return(&edac_pci_sysfs_refcount) == 0) 487 /* remove this PCI instance's sysfs entries */
381 edac_pci_unregister_main_kobj(); 488 edac_pci_unregister_sysfs_instance_kobj(pci);
489
490 /* Call the main unregister function, which will determine
491 * if this 'pci' is the last instance.
492 * If it is, the main kobject will be unregistered as a result
493 */
494 debugf0("%s() calling edac_pci_main_kobj_teardown()\n", __func__);
495 edac_pci_main_kobj_teardown();
382} 496}
383 497
384/************************ PCI error handling *************************/ 498/************************ PCI error handling *************************/
@@ -414,13 +528,14 @@ static u16 get_pci_parity_status(struct pci_dev *dev, int secondary)
414 return status; 528 return status;
415} 529}
416 530
417typedef void (*pci_parity_check_fn_t) (struct pci_dev * dev);
418 531
419/* Clear any PCI parity errors logged by this device. */ 532/* Clear any PCI parity errors logged by this device. */
420static void edac_pci_dev_parity_clear(struct pci_dev *dev) 533static void edac_pci_dev_parity_clear(struct pci_dev *dev)
421{ 534{
422 u8 header_type; 535 u8 header_type;
423 536
537 debugf0("%s()\n", __func__);
538
424 get_pci_parity_status(dev, 0); 539 get_pci_parity_status(dev, 0);
425 540
426 /* read the device TYPE, looking for bridges */ 541 /* read the device TYPE, looking for bridges */
@@ -433,17 +548,28 @@ static void edac_pci_dev_parity_clear(struct pci_dev *dev)
433/* 548/*
434 * PCI Parity polling 549 * PCI Parity polling
435 * 550 *
551 * Fucntion to retrieve the current parity status
552 * and decode it
553 *
436 */ 554 */
437static void edac_pci_dev_parity_test(struct pci_dev *dev) 555static void edac_pci_dev_parity_test(struct pci_dev *dev)
438{ 556{
557 unsigned long flags;
439 u16 status; 558 u16 status;
440 u8 header_type; 559 u8 header_type;
441 560
442 /* read the STATUS register on this device 561 /* stop any interrupts until we can acquire the status */
443 */ 562 local_irq_save(flags);
563
564 /* read the STATUS register on this device */
444 status = get_pci_parity_status(dev, 0); 565 status = get_pci_parity_status(dev, 0);
445 566
446 debugf2("PCI STATUS= 0x%04x %s\n", status, dev->dev.bus_id); 567 /* read the device TYPE, looking for bridges */
568 pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type);
569
570 local_irq_restore(flags);
571
572 debugf4("PCI STATUS= 0x%04x %s\n", status, dev->dev.bus_id);
447 573
448 /* check the status reg for errors */ 574 /* check the status reg for errors */
449 if (status) { 575 if (status) {
@@ -471,16 +597,14 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
471 } 597 }
472 } 598 }
473 599
474 /* read the device TYPE, looking for bridges */
475 pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type);
476 600
477 debugf2("PCI HEADER TYPE= 0x%02x %s\n", header_type, dev->dev.bus_id); 601 debugf4("PCI HEADER TYPE= 0x%02x %s\n", header_type, dev->dev.bus_id);
478 602
479 if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) { 603 if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) {
480 /* On bridges, need to examine secondary status register */ 604 /* On bridges, need to examine secondary status register */
481 status = get_pci_parity_status(dev, 1); 605 status = get_pci_parity_status(dev, 1);
482 606
483 debugf2("PCI SEC_STATUS= 0x%04x %s\n", status, dev->dev.bus_id); 607 debugf4("PCI SEC_STATUS= 0x%04x %s\n", status, dev->dev.bus_id);
484 608
485 /* check the secondary status reg for errors */ 609 /* check the secondary status reg for errors */
486 if (status) { 610 if (status) {
@@ -510,9 +634,12 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
510 } 634 }
511} 635}
512 636
637/* reduce some complexity in definition of the iterator */
638typedef void (*pci_parity_check_fn_t) (struct pci_dev *dev);
639
513/* 640/*
514 * pci_dev parity list iterator 641 * pci_dev parity list iterator
515 * Scan the PCI device list for one iteration, looking for SERRORs 642 * Scan the PCI device list for one pass, looking for SERRORs
516 * Master Parity ERRORS or Parity ERRORs on primary or secondary devices 643 * Master Parity ERRORS or Parity ERRORs on primary or secondary devices
517 */ 644 */
518static inline void edac_pci_dev_parity_iterator(pci_parity_check_fn_t fn) 645static inline void edac_pci_dev_parity_iterator(pci_parity_check_fn_t fn)
@@ -535,22 +662,22 @@ static inline void edac_pci_dev_parity_iterator(pci_parity_check_fn_t fn)
535 */ 662 */
536void edac_pci_do_parity_check(void) 663void edac_pci_do_parity_check(void)
537{ 664{
538 unsigned long flags;
539 int before_count; 665 int before_count;
540 666
541 debugf3("%s()\n", __func__); 667 debugf3("%s()\n", __func__);
542 668
669 /* if policy has PCI check off, leave now */
543 if (!check_pci_errors) 670 if (!check_pci_errors)
544 return; 671 return;
545 672
546 before_count = atomic_read(&pci_parity_count); 673 before_count = atomic_read(&pci_parity_count);
547 674
548 /* scan all PCI devices looking for a Parity Error on devices and 675 /* scan all PCI devices looking for a Parity Error on devices and
549 * bridges 676 * bridges.
677 * The iterator calls pci_get_device() which might sleep, thus
678 * we cannot disable interrupts in this scan.
550 */ 679 */
551 local_irq_save(flags);
552 edac_pci_dev_parity_iterator(edac_pci_dev_parity_test); 680 edac_pci_dev_parity_iterator(edac_pci_dev_parity_test);
553 local_irq_restore(flags);
554 681
555 /* Only if operator has selected panic on PCI Error */ 682 /* Only if operator has selected panic on PCI Error */
556 if (edac_pci_get_panic_on_pe()) { 683 if (edac_pci_get_panic_on_pe()) {
@@ -560,6 +687,12 @@ void edac_pci_do_parity_check(void)
560 } 687 }
561} 688}
562 689
690/*
691 * edac_pci_clear_parity_errors
692 *
693 * function to perform an iteration over the PCI devices
694 * and clearn their current status
695 */
563void edac_pci_clear_parity_errors(void) 696void edac_pci_clear_parity_errors(void)
564{ 697{
565 /* Clear any PCI bus parity errors that devices initially have logged 698 /* Clear any PCI bus parity errors that devices initially have logged
@@ -567,6 +700,12 @@ void edac_pci_clear_parity_errors(void)
567 */ 700 */
568 edac_pci_dev_parity_iterator(edac_pci_dev_parity_clear); 701 edac_pci_dev_parity_iterator(edac_pci_dev_parity_clear);
569} 702}
703
704/*
705 * edac_pci_handle_pe
706 *
707 * Called to handle a PARITY ERROR event
708 */
570void edac_pci_handle_pe(struct edac_pci_ctl_info *pci, const char *msg) 709void edac_pci_handle_pe(struct edac_pci_ctl_info *pci, const char *msg)
571{ 710{
572 711
@@ -584,9 +723,14 @@ void edac_pci_handle_pe(struct edac_pci_ctl_info *pci, const char *msg)
584 */ 723 */
585 edac_pci_do_parity_check(); 724 edac_pci_do_parity_check();
586} 725}
587
588EXPORT_SYMBOL_GPL(edac_pci_handle_pe); 726EXPORT_SYMBOL_GPL(edac_pci_handle_pe);
589 727
728
729/*
730 * edac_pci_handle_npe
731 *
732 * Called to handle a NON-PARITY ERROR event
733 */
590void edac_pci_handle_npe(struct edac_pci_ctl_info *pci, const char *msg) 734void edac_pci_handle_npe(struct edac_pci_ctl_info *pci, const char *msg)
591{ 735{
592 736
@@ -604,7 +748,6 @@ void edac_pci_handle_npe(struct edac_pci_ctl_info *pci, const char *msg)
604 */ 748 */
605 edac_pci_do_parity_check(); 749 edac_pci_do_parity_check();
606} 750}
607
608EXPORT_SYMBOL_GPL(edac_pci_handle_npe); 751EXPORT_SYMBOL_GPL(edac_pci_handle_npe);
609 752
610/* 753/*
diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
index 0ecfdc432f87..e895f9f887ab 100644
--- a/drivers/edac/i3000_edac.c
+++ b/drivers/edac/i3000_edac.c
@@ -275,7 +275,7 @@ static int i3000_probe1(struct pci_dev *pdev, int dev_idx)
275 unsigned char *c0dra = dra, *c1dra = &dra[I3000_RANKS_PER_CHANNEL / 2]; 275 unsigned char *c0dra = dra, *c1dra = &dra[I3000_RANKS_PER_CHANNEL / 2];
276 unsigned char *c0drb = drb, *c1drb = &drb[I3000_RANKS_PER_CHANNEL]; 276 unsigned char *c0drb = drb, *c1drb = &drb[I3000_RANKS_PER_CHANNEL];
277 unsigned long mchbar; 277 unsigned long mchbar;
278 void *window; 278 void __iomem *window;
279 279
280 debugf0("MC: %s()\n", __func__); 280 debugf0("MC: %s()\n", __func__);
281 281
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index da1647869f91..1842f523c23d 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -92,9 +92,9 @@ config I2C_AU1550
92 92
93config I2C_BLACKFIN_TWI 93config I2C_BLACKFIN_TWI
94 tristate "Blackfin TWI I2C support" 94 tristate "Blackfin TWI I2C support"
95 depends on BF534 || BF536 || BF537 95 depends on BF534 || BF536 || BF537 || BF54x
96 help 96 help
97 This is the TWI I2C device driver for Blackfin 534/536/537. 97 This is the TWI I2C device driver for Blackfin 534/536/537/54x.
98 This driver can also be built as a module. If so, the module 98 This driver can also be built as a module. If so, the module
99 will be called i2c-bfin-twi. 99 will be called i2c-bfin-twi.
100 100
diff --git a/drivers/i2c/chips/ds1682.c b/drivers/i2c/chips/ds1682.c
index 5879f0f25495..9e94542c18a2 100644
--- a/drivers/i2c/chips/ds1682.c
+++ b/drivers/i2c/chips/ds1682.c
@@ -75,7 +75,8 @@ static ssize_t ds1682_show(struct device *dev, struct device_attribute *attr,
75 /* Special case: the 32 bit regs are time values with 1/4s 75 /* Special case: the 32 bit regs are time values with 1/4s
76 * resolution, scale them up to milliseconds */ 76 * resolution, scale them up to milliseconds */
77 if (sattr->nr == 4) 77 if (sattr->nr == 4)
78 return sprintf(buf, "%llu\n", ((u64) le32_to_cpu(val)) * 250); 78 return sprintf(buf, "%llu\n",
79 ((unsigned long long)le32_to_cpu(val)) * 250);
79 80
80 /* Format the output string and return # of bytes */ 81 /* Format the output string and return # of bytes */
81 return sprintf(buf, "%li\n", (long)le32_to_cpu(val)); 82 return sprintf(buf, "%li\n", (long)le32_to_cpu(val));
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c
index 3c3f2ebf3fc9..503ffec2ce07 100644
--- a/drivers/i2c/chips/tps65010.c
+++ b/drivers/i2c/chips/tps65010.c
@@ -352,7 +352,7 @@ static void tps65010_interrupt(struct tps65010 *tps)
352 /* REVISIT: this might need its own workqueue 352 /* REVISIT: this might need its own workqueue
353 * plus tweaks including deadlock avoidance ... 353 * plus tweaks including deadlock avoidance ...
354 * also needs to get error handling and probably 354 * also needs to get error handling and probably
355 * an #ifdef CONFIG_SOFTWARE_SUSPEND 355 * an #ifdef CONFIG_HIBERNATION
356 */ 356 */
357 hibernate(); 357 hibernate();
358#endif 358#endif
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 1486eb212ccc..ca843522f91d 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -3071,7 +3071,7 @@ static inline void ide_cdrom_add_settings(ide_drive_t *drive) { ; }
3071/* 3071/*
3072 * standard prep_rq_fn that builds 10 byte cmds 3072 * standard prep_rq_fn that builds 10 byte cmds
3073 */ 3073 */
3074static int ide_cdrom_prep_fs(request_queue_t *q, struct request *rq) 3074static int ide_cdrom_prep_fs(struct request_queue *q, struct request *rq)
3075{ 3075{
3076 int hard_sect = queue_hardsect_size(q); 3076 int hard_sect = queue_hardsect_size(q);
3077 long block = (long)rq->hard_sector / (hard_sect >> 9); 3077 long block = (long)rq->hard_sector / (hard_sect >> 9);
@@ -3137,7 +3137,7 @@ static int ide_cdrom_prep_pc(struct request *rq)
3137 return BLKPREP_OK; 3137 return BLKPREP_OK;
3138} 3138}
3139 3139
3140static int ide_cdrom_prep_fn(request_queue_t *q, struct request *rq) 3140static int ide_cdrom_prep_fn(struct request_queue *q, struct request *rq)
3141{ 3141{
3142 if (blk_fs_request(rq)) 3142 if (blk_fs_request(rq))
3143 return ide_cdrom_prep_fs(q, rq); 3143 return ide_cdrom_prep_fs(q, rq);
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index b1304a7f3e0a..5ce4216f72a2 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -679,7 +679,7 @@ static ide_proc_entry_t idedisk_proc[] = {
679}; 679};
680#endif /* CONFIG_IDE_PROC_FS */ 680#endif /* CONFIG_IDE_PROC_FS */
681 681
682static void idedisk_prepare_flush(request_queue_t *q, struct request *rq) 682static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
683{ 683{
684 ide_drive_t *drive = q->queuedata; 684 ide_drive_t *drive = q->queuedata;
685 685
@@ -697,7 +697,7 @@ static void idedisk_prepare_flush(request_queue_t *q, struct request *rq)
697 rq->buffer = rq->cmd; 697 rq->buffer = rq->cmd;
698} 698}
699 699
700static int idedisk_issue_flush(request_queue_t *q, struct gendisk *disk, 700static int idedisk_issue_flush(struct request_queue *q, struct gendisk *disk,
701 sector_t *error_sector) 701 sector_t *error_sector)
702{ 702{
703 ide_drive_t *drive = q->queuedata; 703 ide_drive_t *drive = q->queuedata;
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index 484c50e71446..aa9f5f0b1e67 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -1327,7 +1327,7 @@ static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
1327/* 1327/*
1328 * Passes the stuff to ide_do_request 1328 * Passes the stuff to ide_do_request
1329 */ 1329 */
1330void do_ide_request(request_queue_t *q) 1330void do_ide_request(struct request_queue *q)
1331{ 1331{
1332 ide_drive_t *drive = q->queuedata; 1332 ide_drive_t *drive = q->queuedata;
1333 1333
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 5a4c5ea12f89..3a2a9a338fd9 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -945,7 +945,7 @@ static void save_match(ide_hwif_t *hwif, ide_hwif_t *new, ide_hwif_t **match)
945 */ 945 */
946static int ide_init_queue(ide_drive_t *drive) 946static int ide_init_queue(ide_drive_t *drive)
947{ 947{
948 request_queue_t *q; 948 struct request_queue *q;
949 ide_hwif_t *hwif = HWIF(drive); 949 ide_hwif_t *hwif = HWIF(drive);
950 int max_sectors = 256; 950 int max_sectors = 256;
951 int max_sg_entries = PRD_ENTRIES; 951 int max_sg_entries = PRD_ENTRIES;
diff --git a/drivers/ide/legacy/hd.c b/drivers/ide/legacy/hd.c
index 8f2db8dd35f7..8e05d88e81ba 100644
--- a/drivers/ide/legacy/hd.c
+++ b/drivers/ide/legacy/hd.c
@@ -652,7 +652,7 @@ repeat:
652 } 652 }
653} 653}
654 654
655static void do_hd_request (request_queue_t * q) 655static void do_hd_request (struct request_queue * q)
656{ 656{
657 disable_irq(HD_IRQ); 657 disable_irq(HD_IRQ);
658 hd_request(); 658 hd_request();
diff --git a/drivers/ide/pci/scc_pata.c b/drivers/ide/pci/scc_pata.c
index f668d235e6be..bf19ddfa6cda 100644
--- a/drivers/ide/pci/scc_pata.c
+++ b/drivers/ide/pci/scc_pata.c
@@ -551,8 +551,8 @@ static int setup_mmio_scc (struct pci_dev *dev, const char *name)
551 unsigned long dma_base = pci_resource_start(dev, 1); 551 unsigned long dma_base = pci_resource_start(dev, 1);
552 unsigned long ctl_size = pci_resource_len(dev, 0); 552 unsigned long ctl_size = pci_resource_len(dev, 0);
553 unsigned long dma_size = pci_resource_len(dev, 1); 553 unsigned long dma_size = pci_resource_len(dev, 1);
554 void *ctl_addr; 554 void __iomem *ctl_addr;
555 void *dma_addr; 555 void __iomem *dma_addr;
556 int i; 556 int i;
557 557
558 for (i = 0; i < MAX_HWIFS; i++) { 558 for (i = 0; i < MAX_HWIFS; i++) {
diff --git a/drivers/ieee1394/raw1394.c b/drivers/ieee1394/raw1394.c
index 336e5ff4cfcf..cadf0479cce5 100644
--- a/drivers/ieee1394/raw1394.c
+++ b/drivers/ieee1394/raw1394.c
@@ -2677,7 +2677,7 @@ static long raw1394_iso_xmit_recv_packets32(struct file *file, unsigned int cmd,
2677 struct raw1394_iso_packets32 __user *arg) 2677 struct raw1394_iso_packets32 __user *arg)
2678{ 2678{
2679 compat_uptr_t infos32; 2679 compat_uptr_t infos32;
2680 void *infos; 2680 void __user *infos;
2681 long err = -EFAULT; 2681 long err = -EFAULT;
2682 struct raw1394_iso_packets __user *dst = compat_alloc_user_space(sizeof(struct raw1394_iso_packets)); 2682 struct raw1394_iso_packets __user *dst = compat_alloc_user_space(sizeof(struct raw1394_iso_packets));
2683 2683
diff --git a/drivers/infiniband/hw/ipath/ipath_diag.c b/drivers/infiniband/hw/ipath/ipath_diag.c
index a698f1949d10..cf25cdab02f9 100644
--- a/drivers/infiniband/hw/ipath/ipath_diag.c
+++ b/drivers/infiniband/hw/ipath/ipath_diag.c
@@ -44,6 +44,7 @@
44#include <linux/io.h> 44#include <linux/io.h>
45#include <linux/pci.h> 45#include <linux/pci.h>
46#include <linux/vmalloc.h> 46#include <linux/vmalloc.h>
47#include <linux/fs.h>
47#include <asm/uaccess.h> 48#include <asm/uaccess.h>
48 49
49#include "ipath_kernel.h" 50#include "ipath_kernel.h"
diff --git a/drivers/input/misc/atlas_btns.c b/drivers/input/misc/atlas_btns.c
index 0acc3a123604..e43e92fd9e23 100644
--- a/drivers/input/misc/atlas_btns.c
+++ b/drivers/input/misc/atlas_btns.c
@@ -31,7 +31,6 @@
31 31
32#define ACPI_ATLAS_NAME "Atlas ACPI" 32#define ACPI_ATLAS_NAME "Atlas ACPI"
33#define ACPI_ATLAS_CLASS "Atlas" 33#define ACPI_ATLAS_CLASS "Atlas"
34#define ACPI_ATLAS_BUTTON_HID "ASIM0000"
35 34
36static struct input_dev *input_dev; 35static struct input_dev *input_dev;
37 36
@@ -130,10 +129,16 @@ static int atlas_acpi_button_remove(struct acpi_device *device, int type)
130 return status; 129 return status;
131} 130}
132 131
132static const struct acpi_device_id atlas_device_ids[] = {
133 {"ASIM0000", 0},
134 {"", 0},
135};
136MODULE_DEVICE_TABLE(acpi, atlas_device_ids);
137
133static struct acpi_driver atlas_acpi_driver = { 138static struct acpi_driver atlas_acpi_driver = {
134 .name = ACPI_ATLAS_NAME, 139 .name = ACPI_ATLAS_NAME,
135 .class = ACPI_ATLAS_CLASS, 140 .class = ACPI_ATLAS_CLASS,
136 .ids = ACPI_ATLAS_BUTTON_HID, 141 .ids = atlas_device_ids,
137 .ops = { 142 .ops = {
138 .add = atlas_acpi_button_add, 143 .add = atlas_acpi_button_add,
139 .remove = atlas_acpi_button_remove, 144 .remove = atlas_acpi_button_remove,
diff --git a/drivers/input/serio/Kconfig b/drivers/input/serio/Kconfig
index adef447f23ea..5ce632ca6815 100644
--- a/drivers/input/serio/Kconfig
+++ b/drivers/input/serio/Kconfig
@@ -21,7 +21,7 @@ if SERIO
21config SERIO_I8042 21config SERIO_I8042
22 tristate "i8042 PC Keyboard controller" if EMBEDDED || !X86 22 tristate "i8042 PC Keyboard controller" if EMBEDDED || !X86
23 default y 23 default y
24 depends on !PARISC && (!ARM || ARCH_SHARK || FOOTBRIDGE_HOST) && !M68K 24 depends on !PARISC && (!ARM || ARCH_SHARK || FOOTBRIDGE_HOST) && !M68K && !BFIN
25 ---help--- 25 ---help---
26 i8042 is the chip over which the standard AT keyboard and PS/2 26 i8042 is the chip over which the standard AT keyboard and PS/2
27 mouse are connected to the computer. If you use these devices, 27 mouse are connected to the computer. If you use these devices,
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index bcbe6835beb4..96856097d15b 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -297,9 +297,6 @@ static struct kvm *kvm_create_vm(void)
297 kvm_io_bus_init(&kvm->pio_bus); 297 kvm_io_bus_init(&kvm->pio_bus);
298 spin_lock_init(&kvm->lock); 298 spin_lock_init(&kvm->lock);
299 INIT_LIST_HEAD(&kvm->active_mmu_pages); 299 INIT_LIST_HEAD(&kvm->active_mmu_pages);
300 spin_lock(&kvm_lock);
301 list_add(&kvm->vm_list, &vm_list);
302 spin_unlock(&kvm_lock);
303 kvm_io_bus_init(&kvm->mmio_bus); 300 kvm_io_bus_init(&kvm->mmio_bus);
304 for (i = 0; i < KVM_MAX_VCPUS; ++i) { 301 for (i = 0; i < KVM_MAX_VCPUS; ++i) {
305 struct kvm_vcpu *vcpu = &kvm->vcpus[i]; 302 struct kvm_vcpu *vcpu = &kvm->vcpus[i];
@@ -309,6 +306,9 @@ static struct kvm *kvm_create_vm(void)
309 vcpu->kvm = kvm; 306 vcpu->kvm = kvm;
310 vcpu->mmu.root_hpa = INVALID_PAGE; 307 vcpu->mmu.root_hpa = INVALID_PAGE;
311 } 308 }
309 spin_lock(&kvm_lock);
310 list_add(&kvm->vm_list, &vm_list);
311 spin_unlock(&kvm_lock);
312 return kvm; 312 return kvm;
313} 313}
314 314
@@ -1070,18 +1070,16 @@ static int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
1070 return 0; 1070 return 0;
1071 mark_page_dirty(vcpu->kvm, gpa >> PAGE_SHIFT); 1071 mark_page_dirty(vcpu->kvm, gpa >> PAGE_SHIFT);
1072 virt = kmap_atomic(page, KM_USER0); 1072 virt = kmap_atomic(page, KM_USER0);
1073 if (memcmp(virt + offset_in_page(gpa), val, bytes)) { 1073 kvm_mmu_pte_write(vcpu, gpa, virt + offset, val, bytes);
1074 kvm_mmu_pte_write(vcpu, gpa, virt + offset, val, bytes); 1074 memcpy(virt + offset_in_page(gpa), val, bytes);
1075 memcpy(virt + offset_in_page(gpa), val, bytes);
1076 }
1077 kunmap_atomic(virt, KM_USER0); 1075 kunmap_atomic(virt, KM_USER0);
1078 return 1; 1076 return 1;
1079} 1077}
1080 1078
1081static int emulator_write_emulated(unsigned long addr, 1079static int emulator_write_emulated_onepage(unsigned long addr,
1082 const void *val, 1080 const void *val,
1083 unsigned int bytes, 1081 unsigned int bytes,
1084 struct x86_emulate_ctxt *ctxt) 1082 struct x86_emulate_ctxt *ctxt)
1085{ 1083{
1086 struct kvm_vcpu *vcpu = ctxt->vcpu; 1084 struct kvm_vcpu *vcpu = ctxt->vcpu;
1087 struct kvm_io_device *mmio_dev; 1085 struct kvm_io_device *mmio_dev;
@@ -1113,6 +1111,26 @@ static int emulator_write_emulated(unsigned long addr,
1113 return X86EMUL_CONTINUE; 1111 return X86EMUL_CONTINUE;
1114} 1112}
1115 1113
1114static int emulator_write_emulated(unsigned long addr,
1115 const void *val,
1116 unsigned int bytes,
1117 struct x86_emulate_ctxt *ctxt)
1118{
1119 /* Crossing a page boundary? */
1120 if (((addr + bytes - 1) ^ addr) & PAGE_MASK) {
1121 int rc, now;
1122
1123 now = -addr & ~PAGE_MASK;
1124 rc = emulator_write_emulated_onepage(addr, val, now, ctxt);
1125 if (rc != X86EMUL_CONTINUE)
1126 return rc;
1127 addr += now;
1128 val += now;
1129 bytes -= now;
1130 }
1131 return emulator_write_emulated_onepage(addr, val, bytes, ctxt);
1132}
1133
1116static int emulator_cmpxchg_emulated(unsigned long addr, 1134static int emulator_cmpxchg_emulated(unsigned long addr,
1117 const void *old, 1135 const void *old,
1118 const void *new, 1136 const void *new,
@@ -2414,9 +2432,9 @@ static void cpuid_fix_nx_cap(struct kvm_vcpu *vcpu)
2414 break; 2432 break;
2415 } 2433 }
2416 } 2434 }
2417 if (entry && (entry->edx & EFER_NX) && !(efer & EFER_NX)) { 2435 if (entry && (entry->edx & (1 << 20)) && !(efer & EFER_NX)) {
2418 entry->edx &= ~(1 << 20); 2436 entry->edx &= ~(1 << 20);
2419 printk(KERN_INFO ": guest NX capability removed\n"); 2437 printk(KERN_INFO "kvm: guest NX capability removed\n");
2420 } 2438 }
2421} 2439}
2422 2440
diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c
index 1b800fc00342..1f979cb0df31 100644
--- a/drivers/kvm/x86_emulate.c
+++ b/drivers/kvm/x86_emulate.c
@@ -1178,6 +1178,8 @@ pop_instruction:
1178twobyte_insn: 1178twobyte_insn:
1179 switch (b) { 1179 switch (b) {
1180 case 0x01: /* lgdt, lidt, lmsw */ 1180 case 0x01: /* lgdt, lidt, lmsw */
1181 /* Disable writeback. */
1182 no_wb = 1;
1181 switch (modrm_reg) { 1183 switch (modrm_reg) {
1182 u16 size; 1184 u16 size;
1183 unsigned long address; 1185 unsigned long address;
diff --git a/drivers/lguest/Makefile b/drivers/lguest/Makefile
index 55382c7d799c..e5047471c334 100644
--- a/drivers/lguest/Makefile
+++ b/drivers/lguest/Makefile
@@ -5,3 +5,15 @@ obj-$(CONFIG_LGUEST_GUEST) += lguest.o lguest_asm.o lguest_bus.o
5obj-$(CONFIG_LGUEST) += lg.o 5obj-$(CONFIG_LGUEST) += lg.o
6lg-y := core.o hypercalls.o page_tables.o interrupts_and_traps.o \ 6lg-y := core.o hypercalls.o page_tables.o interrupts_and_traps.o \
7 segments.o io.o lguest_user.o switcher.o 7 segments.o io.o lguest_user.o switcher.o
8
9Preparation Preparation!: PREFIX=P
10Guest: PREFIX=G
11Drivers: PREFIX=D
12Launcher: PREFIX=L
13Host: PREFIX=H
14Switcher: PREFIX=S
15Mastery: PREFIX=M
16Beer:
17 @for f in Preparation Guest Drivers Launcher Host Switcher Mastery; do echo "{==- $$f -==}"; make -s $$f; done; echo "{==-==}"
18Preparation Preparation! Guest Drivers Launcher Host Switcher Mastery:
19 @sh ../../Documentation/lguest/extract $(PREFIX) `find ../../* -name '*.[chS]' -wholename '*lguest*'`
diff --git a/drivers/lguest/README b/drivers/lguest/README
new file mode 100644
index 000000000000..b7db39a64c66
--- /dev/null
+++ b/drivers/lguest/README
@@ -0,0 +1,47 @@
1Welcome, friend reader, to lguest.
2
3Lguest is an adventure, with you, the reader, as Hero. I can't think of many
45000-line projects which offer both such capability and glimpses of future
5potential; it is an exciting time to be delving into the source!
6
7But be warned; this is an arduous journey of several hours or more! And as we
8know, all true Heroes are driven by a Noble Goal. Thus I offer a Beer (or
9equivalent) to anyone I meet who has completed this documentation.
10
11So get comfortable and keep your wits about you (both quick and humorous).
12Along your way to the Noble Goal, you will also gain masterly insight into
13lguest, and hypervisors and x86 virtualization in general.
14
15Our Quest is in seven parts: (best read with C highlighting turned on)
16
17I) Preparation
18 - In which our potential hero is flown quickly over the landscape for a
19 taste of its scope. Suitable for the armchair coders and other such
20 persons of faint constitution.
21
22II) Guest
23 - Where we encounter the first tantalising wisps of code, and come to
24 understand the details of the life of a Guest kernel.
25
26III) Drivers
27 - Whereby the Guest finds its voice and become useful, and our
28 understanding of the Guest is completed.
29
30IV) Launcher
31 - Where we trace back to the creation of the Guest, and thus begin our
32 understanding of the Host.
33
34V) Host
35 - Where we master the Host code, through a long and tortuous journey.
36 Indeed, it is here that our hero is tested in the Bit of Despair.
37
38VI) Switcher
39 - Where our understanding of the intertwined nature of Guests and Hosts
40 is completed.
41
42VII) Mastery
43 - Where our fully fledged hero grapples with the Great Question:
44 "What next?"
45
46make Preparation!
47Rusty Russell.
diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
index ce909ec57499..0a46e8837d9a 100644
--- a/drivers/lguest/core.c
+++ b/drivers/lguest/core.c
@@ -1,5 +1,8 @@
1/* World's simplest hypervisor, to test paravirt_ops and show 1/*P:400 This contains run_guest() which actually calls into the Host<->Guest
2 * unbelievers that virtualization is the future. Plus, it's fun! */ 2 * Switcher and analyzes the return, such as determining if the Guest wants the
3 * Host to do something. This file also contains useful helper routines, and a
4 * couple of non-obvious setup and teardown pieces which were implemented after
5 * days of debugging pain. :*/
3#include <linux/module.h> 6#include <linux/module.h>
4#include <linux/stringify.h> 7#include <linux/stringify.h>
5#include <linux/stddef.h> 8#include <linux/stddef.h>
@@ -61,11 +64,33 @@ static struct lguest_pages *lguest_pages(unsigned int cpu)
61 (SWITCHER_ADDR + SHARED_SWITCHER_PAGES*PAGE_SIZE))[cpu]); 64 (SWITCHER_ADDR + SHARED_SWITCHER_PAGES*PAGE_SIZE))[cpu]);
62} 65}
63 66
67/*H:010 We need to set up the Switcher at a high virtual address. Remember the
68 * Switcher is a few hundred bytes of assembler code which actually changes the
69 * CPU to run the Guest, and then changes back to the Host when a trap or
70 * interrupt happens.
71 *
72 * The Switcher code must be at the same virtual address in the Guest as the
73 * Host since it will be running as the switchover occurs.
74 *
75 * Trying to map memory at a particular address is an unusual thing to do, so
76 * it's not a simple one-liner. We also set up the per-cpu parts of the
77 * Switcher here.
78 */
64static __init int map_switcher(void) 79static __init int map_switcher(void)
65{ 80{
66 int i, err; 81 int i, err;
67 struct page **pagep; 82 struct page **pagep;
68 83
84 /*
85 * Map the Switcher in to high memory.
86 *
87 * It turns out that if we choose the address 0xFFC00000 (4MB under the
88 * top virtual address), it makes setting up the page tables really
89 * easy.
90 */
91
92 /* We allocate an array of "struct page"s. map_vm_area() wants the
93 * pages in this form, rather than just an array of pointers. */
69 switcher_page = kmalloc(sizeof(switcher_page[0])*TOTAL_SWITCHER_PAGES, 94 switcher_page = kmalloc(sizeof(switcher_page[0])*TOTAL_SWITCHER_PAGES,
70 GFP_KERNEL); 95 GFP_KERNEL);
71 if (!switcher_page) { 96 if (!switcher_page) {
@@ -73,6 +98,8 @@ static __init int map_switcher(void)
73 goto out; 98 goto out;
74 } 99 }
75 100
101 /* Now we actually allocate the pages. The Guest will see these pages,
102 * so we make sure they're zeroed. */
76 for (i = 0; i < TOTAL_SWITCHER_PAGES; i++) { 103 for (i = 0; i < TOTAL_SWITCHER_PAGES; i++) {
77 unsigned long addr = get_zeroed_page(GFP_KERNEL); 104 unsigned long addr = get_zeroed_page(GFP_KERNEL);
78 if (!addr) { 105 if (!addr) {
@@ -82,6 +109,9 @@ static __init int map_switcher(void)
82 switcher_page[i] = virt_to_page(addr); 109 switcher_page[i] = virt_to_page(addr);
83 } 110 }
84 111
112 /* Now we reserve the "virtual memory area" we want: 0xFFC00000
113 * (SWITCHER_ADDR). We might not get it in theory, but in practice
114 * it's worked so far. */
85 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE, 115 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
86 VM_ALLOC, SWITCHER_ADDR, VMALLOC_END); 116 VM_ALLOC, SWITCHER_ADDR, VMALLOC_END);
87 if (!switcher_vma) { 117 if (!switcher_vma) {
@@ -90,49 +120,105 @@ static __init int map_switcher(void)
90 goto free_pages; 120 goto free_pages;
91 } 121 }
92 122
123 /* This code actually sets up the pages we've allocated to appear at
124 * SWITCHER_ADDR. map_vm_area() takes the vma we allocated above, the
125 * kind of pages we're mapping (kernel pages), and a pointer to our
126 * array of struct pages. It increments that pointer, but we don't
127 * care. */
93 pagep = switcher_page; 128 pagep = switcher_page;
94 err = map_vm_area(switcher_vma, PAGE_KERNEL, &pagep); 129 err = map_vm_area(switcher_vma, PAGE_KERNEL, &pagep);
95 if (err) { 130 if (err) {
96 printk("lguest: map_vm_area failed: %i\n", err); 131 printk("lguest: map_vm_area failed: %i\n", err);
97 goto free_vma; 132 goto free_vma;
98 } 133 }
134
135 /* Now the switcher is mapped at the right address, we can't fail!
136 * Copy in the compiled-in Switcher code (from switcher.S). */
99 memcpy(switcher_vma->addr, start_switcher_text, 137 memcpy(switcher_vma->addr, start_switcher_text,
100 end_switcher_text - start_switcher_text); 138 end_switcher_text - start_switcher_text);
101 139
102 /* Fix up IDT entries to point into copied text. */ 140 /* Most of the switcher.S doesn't care that it's been moved; on Intel,
141 * jumps are relative, and it doesn't access any references to external
142 * code or data.
143 *
144 * The only exception is the interrupt handlers in switcher.S: their
145 * addresses are placed in a table (default_idt_entries), so we need to
146 * update the table with the new addresses. switcher_offset() is a
147 * convenience function which returns the distance between the builtin
148 * switcher code and the high-mapped copy we just made. */
103 for (i = 0; i < IDT_ENTRIES; i++) 149 for (i = 0; i < IDT_ENTRIES; i++)
104 default_idt_entries[i] += switcher_offset(); 150 default_idt_entries[i] += switcher_offset();
105 151
152 /*
153 * Set up the Switcher's per-cpu areas.
154 *
155 * Each CPU gets two pages of its own within the high-mapped region
156 * (aka. "struct lguest_pages"). Much of this can be initialized now,
157 * but some depends on what Guest we are running (which is set up in
158 * copy_in_guest_info()).
159 */
106 for_each_possible_cpu(i) { 160 for_each_possible_cpu(i) {
161 /* lguest_pages() returns this CPU's two pages. */
107 struct lguest_pages *pages = lguest_pages(i); 162 struct lguest_pages *pages = lguest_pages(i);
163 /* This is a convenience pointer to make the code fit one
164 * statement to a line. */
108 struct lguest_ro_state *state = &pages->state; 165 struct lguest_ro_state *state = &pages->state;
109 166
110 /* These fields are static: rest done in copy_in_guest_info */ 167 /* The Global Descriptor Table: the Host has a different one
168 * for each CPU. We keep a descriptor for the GDT which says
169 * where it is and how big it is (the size is actually the last
170 * byte, not the size, hence the "-1"). */
111 state->host_gdt_desc.size = GDT_SIZE-1; 171 state->host_gdt_desc.size = GDT_SIZE-1;
112 state->host_gdt_desc.address = (long)get_cpu_gdt_table(i); 172 state->host_gdt_desc.address = (long)get_cpu_gdt_table(i);
173
174 /* All CPUs on the Host use the same Interrupt Descriptor
175 * Table, so we just use store_idt(), which gets this CPU's IDT
176 * descriptor. */
113 store_idt(&state->host_idt_desc); 177 store_idt(&state->host_idt_desc);
178
179 /* The descriptors for the Guest's GDT and IDT can be filled
180 * out now, too. We copy the GDT & IDT into ->guest_gdt and
181 * ->guest_idt before actually running the Guest. */
114 state->guest_idt_desc.size = sizeof(state->guest_idt)-1; 182 state->guest_idt_desc.size = sizeof(state->guest_idt)-1;
115 state->guest_idt_desc.address = (long)&state->guest_idt; 183 state->guest_idt_desc.address = (long)&state->guest_idt;
116 state->guest_gdt_desc.size = sizeof(state->guest_gdt)-1; 184 state->guest_gdt_desc.size = sizeof(state->guest_gdt)-1;
117 state->guest_gdt_desc.address = (long)&state->guest_gdt; 185 state->guest_gdt_desc.address = (long)&state->guest_gdt;
186
187 /* We know where we want the stack to be when the Guest enters
188 * the switcher: in pages->regs. The stack grows upwards, so
189 * we start it at the end of that structure. */
118 state->guest_tss.esp0 = (long)(&pages->regs + 1); 190 state->guest_tss.esp0 = (long)(&pages->regs + 1);
191 /* And this is the GDT entry to use for the stack: we keep a
192 * couple of special LGUEST entries. */
119 state->guest_tss.ss0 = LGUEST_DS; 193 state->guest_tss.ss0 = LGUEST_DS;
120 /* No I/O for you! */ 194
195 /* x86 can have a finegrained bitmap which indicates what I/O
196 * ports the process can use. We set it to the end of our
197 * structure, meaning "none". */
121 state->guest_tss.io_bitmap_base = sizeof(state->guest_tss); 198 state->guest_tss.io_bitmap_base = sizeof(state->guest_tss);
199
200 /* Some GDT entries are the same across all Guests, so we can
201 * set them up now. */
122 setup_default_gdt_entries(state); 202 setup_default_gdt_entries(state);
203 /* Most IDT entries are the same for all Guests, too.*/
123 setup_default_idt_entries(state, default_idt_entries); 204 setup_default_idt_entries(state, default_idt_entries);
124 205
125 /* Setup LGUEST segments on all cpus */ 206 /* The Host needs to be able to use the LGUEST segments on this
207 * CPU, too, so put them in the Host GDT. */
126 get_cpu_gdt_table(i)[GDT_ENTRY_LGUEST_CS] = FULL_EXEC_SEGMENT; 208 get_cpu_gdt_table(i)[GDT_ENTRY_LGUEST_CS] = FULL_EXEC_SEGMENT;
127 get_cpu_gdt_table(i)[GDT_ENTRY_LGUEST_DS] = FULL_SEGMENT; 209 get_cpu_gdt_table(i)[GDT_ENTRY_LGUEST_DS] = FULL_SEGMENT;
128 } 210 }
129 211
130 /* Initialize entry point into switcher. */ 212 /* In the Switcher, we want the %cs segment register to use the
213 * LGUEST_CS GDT entry: we've put that in the Host and Guest GDTs, so
214 * it will be undisturbed when we switch. To change %cs and jump we
215 * need this structure to feed to Intel's "lcall" instruction. */
131 lguest_entry.offset = (long)switch_to_guest + switcher_offset(); 216 lguest_entry.offset = (long)switch_to_guest + switcher_offset();
132 lguest_entry.segment = LGUEST_CS; 217 lguest_entry.segment = LGUEST_CS;
133 218
134 printk(KERN_INFO "lguest: mapped switcher at %p\n", 219 printk(KERN_INFO "lguest: mapped switcher at %p\n",
135 switcher_vma->addr); 220 switcher_vma->addr);
221 /* And we succeeded... */
136 return 0; 222 return 0;
137 223
138free_vma: 224free_vma:
@@ -146,35 +232,58 @@ free_some_pages:
146out: 232out:
147 return err; 233 return err;
148} 234}
235/*:*/
149 236
237/* Cleaning up the mapping when the module is unloaded is almost...
238 * too easy. */
150static void unmap_switcher(void) 239static void unmap_switcher(void)
151{ 240{
152 unsigned int i; 241 unsigned int i;
153 242
243 /* vunmap() undoes *both* map_vm_area() and __get_vm_area(). */
154 vunmap(switcher_vma->addr); 244 vunmap(switcher_vma->addr);
245 /* Now we just need to free the pages we copied the switcher into */
155 for (i = 0; i < TOTAL_SWITCHER_PAGES; i++) 246 for (i = 0; i < TOTAL_SWITCHER_PAGES; i++)
156 __free_pages(switcher_page[i], 0); 247 __free_pages(switcher_page[i], 0);
157} 248}
158 249
159/* IN/OUT insns: enough to get us past boot-time probing. */ 250/*H:130 Our Guest is usually so well behaved; it never tries to do things it
251 * isn't allowed to. Unfortunately, "struct paravirt_ops" isn't quite
252 * complete, because it doesn't contain replacements for the Intel I/O
253 * instructions. As a result, the Guest sometimes fumbles across one during
254 * the boot process as it probes for various things which are usually attached
255 * to a PC.
256 *
257 * When the Guest uses one of these instructions, we get trap #13 (General
258 * Protection Fault) and come here. We see if it's one of those troublesome
259 * instructions and skip over it. We return true if we did. */
160static int emulate_insn(struct lguest *lg) 260static int emulate_insn(struct lguest *lg)
161{ 261{
162 u8 insn; 262 u8 insn;
163 unsigned int insnlen = 0, in = 0, shift = 0; 263 unsigned int insnlen = 0, in = 0, shift = 0;
264 /* The eip contains the *virtual* address of the Guest's instruction:
265 * guest_pa just subtracts the Guest's page_offset. */
164 unsigned long physaddr = guest_pa(lg, lg->regs->eip); 266 unsigned long physaddr = guest_pa(lg, lg->regs->eip);
165 267
166 /* This only works for addresses in linear mapping... */ 268 /* The guest_pa() function only works for Guest kernel addresses, but
269 * that's all we're trying to do anyway. */
167 if (lg->regs->eip < lg->page_offset) 270 if (lg->regs->eip < lg->page_offset)
168 return 0; 271 return 0;
272
273 /* Decoding x86 instructions is icky. */
169 lgread(lg, &insn, physaddr, 1); 274 lgread(lg, &insn, physaddr, 1);
170 275
171 /* Operand size prefix means it's actually for ax. */ 276 /* 0x66 is an "operand prefix". It means it's using the upper 16 bits
277 of the eax register. */
172 if (insn == 0x66) { 278 if (insn == 0x66) {
173 shift = 16; 279 shift = 16;
280 /* The instruction is 1 byte so far, read the next byte. */
174 insnlen = 1; 281 insnlen = 1;
175 lgread(lg, &insn, physaddr + insnlen, 1); 282 lgread(lg, &insn, physaddr + insnlen, 1);
176 } 283 }
177 284
285 /* We can ignore the lower bit for the moment and decode the 4 opcodes
286 * we need to emulate. */
178 switch (insn & 0xFE) { 287 switch (insn & 0xFE) {
179 case 0xE4: /* in <next byte>,%al */ 288 case 0xE4: /* in <next byte>,%al */
180 insnlen += 2; 289 insnlen += 2;
@@ -191,9 +300,13 @@ static int emulate_insn(struct lguest *lg)
191 insnlen += 1; 300 insnlen += 1;
192 break; 301 break;
193 default: 302 default:
303 /* OK, we don't know what this is, can't emulate. */
194 return 0; 304 return 0;
195 } 305 }
196 306
307 /* If it was an "IN" instruction, they expect the result to be read
308 * into %eax, so we change %eax. We always return all-ones, which
309 * traditionally means "there's nothing there". */
197 if (in) { 310 if (in) {
198 /* Lower bit tells is whether it's a 16 or 32 bit access */ 311 /* Lower bit tells is whether it's a 16 or 32 bit access */
199 if (insn & 0x1) 312 if (insn & 0x1)
@@ -201,28 +314,46 @@ static int emulate_insn(struct lguest *lg)
201 else 314 else
202 lg->regs->eax |= (0xFFFF << shift); 315 lg->regs->eax |= (0xFFFF << shift);
203 } 316 }
317 /* Finally, we've "done" the instruction, so move past it. */
204 lg->regs->eip += insnlen; 318 lg->regs->eip += insnlen;
319 /* Success! */
205 return 1; 320 return 1;
206} 321}
207 322/*:*/
323
324/*L:305
325 * Dealing With Guest Memory.
326 *
327 * When the Guest gives us (what it thinks is) a physical address, we can use
328 * the normal copy_from_user() & copy_to_user() on that address: remember,
329 * Guest physical == Launcher virtual.
330 *
331 * But we can't trust the Guest: it might be trying to access the Launcher
332 * code. We have to check that the range is below the pfn_limit the Launcher
333 * gave us. We have to make sure that addr + len doesn't give us a false
334 * positive by overflowing, too. */
208int lguest_address_ok(const struct lguest *lg, 335int lguest_address_ok(const struct lguest *lg,
209 unsigned long addr, unsigned long len) 336 unsigned long addr, unsigned long len)
210{ 337{
211 return (addr+len) / PAGE_SIZE < lg->pfn_limit && (addr+len >= addr); 338 return (addr+len) / PAGE_SIZE < lg->pfn_limit && (addr+len >= addr);
212} 339}
213 340
214/* Just like get_user, but don't let guest access lguest binary. */ 341/* This is a convenient routine to get a 32-bit value from the Guest (a very
342 * common operation). Here we can see how useful the kill_lguest() routine we
343 * met in the Launcher can be: we return a random value (0) instead of needing
344 * to return an error. */
215u32 lgread_u32(struct lguest *lg, unsigned long addr) 345u32 lgread_u32(struct lguest *lg, unsigned long addr)
216{ 346{
217 u32 val = 0; 347 u32 val = 0;
218 348
219 /* Don't let them access lguest binary */ 349 /* Don't let them access lguest binary. */
220 if (!lguest_address_ok(lg, addr, sizeof(val)) 350 if (!lguest_address_ok(lg, addr, sizeof(val))
221 || get_user(val, (u32 __user *)addr) != 0) 351 || get_user(val, (u32 __user *)addr) != 0)
222 kill_guest(lg, "bad read address %#lx", addr); 352 kill_guest(lg, "bad read address %#lx", addr);
223 return val; 353 return val;
224} 354}
225 355
356/* Same thing for writing a value. */
226void lgwrite_u32(struct lguest *lg, unsigned long addr, u32 val) 357void lgwrite_u32(struct lguest *lg, unsigned long addr, u32 val)
227{ 358{
228 if (!lguest_address_ok(lg, addr, sizeof(val)) 359 if (!lguest_address_ok(lg, addr, sizeof(val))
@@ -230,6 +361,9 @@ void lgwrite_u32(struct lguest *lg, unsigned long addr, u32 val)
230 kill_guest(lg, "bad write address %#lx", addr); 361 kill_guest(lg, "bad write address %#lx", addr);
231} 362}
232 363
364/* This routine is more generic, and copies a range of Guest bytes into a
365 * buffer. If the copy_from_user() fails, we fill the buffer with zeroes, so
366 * the caller doesn't end up using uninitialized kernel memory. */
233void lgread(struct lguest *lg, void *b, unsigned long addr, unsigned bytes) 367void lgread(struct lguest *lg, void *b, unsigned long addr, unsigned bytes)
234{ 368{
235 if (!lguest_address_ok(lg, addr, bytes) 369 if (!lguest_address_ok(lg, addr, bytes)
@@ -240,6 +374,7 @@ void lgread(struct lguest *lg, void *b, unsigned long addr, unsigned bytes)
240 } 374 }
241} 375}
242 376
377/* Similarly, our generic routine to copy into a range of Guest bytes. */
243void lgwrite(struct lguest *lg, unsigned long addr, const void *b, 378void lgwrite(struct lguest *lg, unsigned long addr, const void *b,
244 unsigned bytes) 379 unsigned bytes)
245{ 380{
@@ -247,6 +382,7 @@ void lgwrite(struct lguest *lg, unsigned long addr, const void *b,
247 || copy_to_user((void __user *)addr, b, bytes) != 0) 382 || copy_to_user((void __user *)addr, b, bytes) != 0)
248 kill_guest(lg, "bad write address %#lx len %u", addr, bytes); 383 kill_guest(lg, "bad write address %#lx len %u", addr, bytes);
249} 384}
385/* (end of memory access helper routines) :*/
250 386
251static void set_ts(void) 387static void set_ts(void)
252{ 388{
@@ -257,54 +393,108 @@ static void set_ts(void)
257 write_cr0(cr0|8); 393 write_cr0(cr0|8);
258} 394}
259 395
396/*S:010
397 * We are getting close to the Switcher.
398 *
399 * Remember that each CPU has two pages which are visible to the Guest when it
400 * runs on that CPU. This has to contain the state for that Guest: we copy the
401 * state in just before we run the Guest.
402 *
403 * Each Guest has "changed" flags which indicate what has changed in the Guest
404 * since it last ran. We saw this set in interrupts_and_traps.c and
405 * segments.c.
406 */
260static void copy_in_guest_info(struct lguest *lg, struct lguest_pages *pages) 407static void copy_in_guest_info(struct lguest *lg, struct lguest_pages *pages)
261{ 408{
409 /* Copying all this data can be quite expensive. We usually run the
410 * same Guest we ran last time (and that Guest hasn't run anywhere else
411 * meanwhile). If that's not the case, we pretend everything in the
412 * Guest has changed. */
262 if (__get_cpu_var(last_guest) != lg || lg->last_pages != pages) { 413 if (__get_cpu_var(last_guest) != lg || lg->last_pages != pages) {
263 __get_cpu_var(last_guest) = lg; 414 __get_cpu_var(last_guest) = lg;
264 lg->last_pages = pages; 415 lg->last_pages = pages;
265 lg->changed = CHANGED_ALL; 416 lg->changed = CHANGED_ALL;
266 } 417 }
267 418
268 /* These are pretty cheap, so we do them unconditionally. */ 419 /* These copies are pretty cheap, so we do them unconditionally: */
420 /* Save the current Host top-level page directory. */
269 pages->state.host_cr3 = __pa(current->mm->pgd); 421 pages->state.host_cr3 = __pa(current->mm->pgd);
422 /* Set up the Guest's page tables to see this CPU's pages (and no
423 * other CPU's pages). */
270 map_switcher_in_guest(lg, pages); 424 map_switcher_in_guest(lg, pages);
425 /* Set up the two "TSS" members which tell the CPU what stack to use
426 * for traps which do directly into the Guest (ie. traps at privilege
427 * level 1). */
271 pages->state.guest_tss.esp1 = lg->esp1; 428 pages->state.guest_tss.esp1 = lg->esp1;
272 pages->state.guest_tss.ss1 = lg->ss1; 429 pages->state.guest_tss.ss1 = lg->ss1;
273 430
274 /* Copy direct trap entries. */ 431 /* Copy direct-to-Guest trap entries. */
275 if (lg->changed & CHANGED_IDT) 432 if (lg->changed & CHANGED_IDT)
276 copy_traps(lg, pages->state.guest_idt, default_idt_entries); 433 copy_traps(lg, pages->state.guest_idt, default_idt_entries);
277 434
278 /* Copy all GDT entries but the TSS. */ 435 /* Copy all GDT entries which the Guest can change. */
279 if (lg->changed & CHANGED_GDT) 436 if (lg->changed & CHANGED_GDT)
280 copy_gdt(lg, pages->state.guest_gdt); 437 copy_gdt(lg, pages->state.guest_gdt);
281 /* If only the TLS entries have changed, copy them. */ 438 /* If only the TLS entries have changed, copy them. */
282 else if (lg->changed & CHANGED_GDT_TLS) 439 else if (lg->changed & CHANGED_GDT_TLS)
283 copy_gdt_tls(lg, pages->state.guest_gdt); 440 copy_gdt_tls(lg, pages->state.guest_gdt);
284 441
442 /* Mark the Guest as unchanged for next time. */
285 lg->changed = 0; 443 lg->changed = 0;
286} 444}
287 445
446/* Finally: the code to actually call into the Switcher to run the Guest. */
288static void run_guest_once(struct lguest *lg, struct lguest_pages *pages) 447static void run_guest_once(struct lguest *lg, struct lguest_pages *pages)
289{ 448{
449 /* This is a dummy value we need for GCC's sake. */
290 unsigned int clobber; 450 unsigned int clobber;
291 451
452 /* Copy the guest-specific information into this CPU's "struct
453 * lguest_pages". */
292 copy_in_guest_info(lg, pages); 454 copy_in_guest_info(lg, pages);
293 455
294 /* Put eflags on stack, lcall does rest: suitable for iret return. */ 456 /* Now: we push the "eflags" register on the stack, then do an "lcall".
457 * This is how we change from using the kernel code segment to using
458 * the dedicated lguest code segment, as well as jumping into the
459 * Switcher.
460 *
461 * The lcall also pushes the old code segment (KERNEL_CS) onto the
462 * stack, then the address of this call. This stack layout happens to
463 * exactly match the stack of an interrupt... */
295 asm volatile("pushf; lcall *lguest_entry" 464 asm volatile("pushf; lcall *lguest_entry"
465 /* This is how we tell GCC that %eax ("a") and %ebx ("b")
466 * are changed by this routine. The "=" means output. */
296 : "=a"(clobber), "=b"(clobber) 467 : "=a"(clobber), "=b"(clobber)
468 /* %eax contains the pages pointer. ("0" refers to the
469 * 0-th argument above, ie "a"). %ebx contains the
470 * physical address of the Guest's top-level page
471 * directory. */
297 : "0"(pages), "1"(__pa(lg->pgdirs[lg->pgdidx].pgdir)) 472 : "0"(pages), "1"(__pa(lg->pgdirs[lg->pgdidx].pgdir))
473 /* We tell gcc that all these registers could change,
474 * which means we don't have to save and restore them in
475 * the Switcher. */
298 : "memory", "%edx", "%ecx", "%edi", "%esi"); 476 : "memory", "%edx", "%ecx", "%edi", "%esi");
299} 477}
478/*:*/
300 479
480/*H:030 Let's jump straight to the the main loop which runs the Guest.
481 * Remember, this is called by the Launcher reading /dev/lguest, and we keep
482 * going around and around until something interesting happens. */
301int run_guest(struct lguest *lg, unsigned long __user *user) 483int run_guest(struct lguest *lg, unsigned long __user *user)
302{ 484{
485 /* We stop running once the Guest is dead. */
303 while (!lg->dead) { 486 while (!lg->dead) {
487 /* We need to initialize this, otherwise gcc complains. It's
488 * not (yet) clever enough to see that it's initialized when we
489 * need it. */
304 unsigned int cr2 = 0; /* Damn gcc */ 490 unsigned int cr2 = 0; /* Damn gcc */
305 491
306 /* Hypercalls first: we might have been out to userspace */ 492 /* First we run any hypercalls the Guest wants done: either in
493 * the hypercall ring in "struct lguest_data", or directly by
494 * using int 31 (LGUEST_TRAP_ENTRY). */
307 do_hypercalls(lg); 495 do_hypercalls(lg);
496 /* It's possible the Guest did a SEND_DMA hypercall to the
497 * Launcher, in which case we return from the read() now. */
308 if (lg->dma_is_pending) { 498 if (lg->dma_is_pending) {
309 if (put_user(lg->pending_dma, user) || 499 if (put_user(lg->pending_dma, user) ||
310 put_user(lg->pending_key, user+1)) 500 put_user(lg->pending_key, user+1))
@@ -312,6 +502,7 @@ int run_guest(struct lguest *lg, unsigned long __user *user)
312 return sizeof(unsigned long)*2; 502 return sizeof(unsigned long)*2;
313 } 503 }
314 504
505 /* Check for signals */
315 if (signal_pending(current)) 506 if (signal_pending(current))
316 return -ERESTARTSYS; 507 return -ERESTARTSYS;
317 508
@@ -319,77 +510,154 @@ int run_guest(struct lguest *lg, unsigned long __user *user)
319 if (lg->break_out) 510 if (lg->break_out)
320 return -EAGAIN; 511 return -EAGAIN;
321 512
513 /* Check if there are any interrupts which can be delivered
514 * now: if so, this sets up the hander to be executed when we
515 * next run the Guest. */
322 maybe_do_interrupt(lg); 516 maybe_do_interrupt(lg);
323 517
518 /* All long-lived kernel loops need to check with this horrible
519 * thing called the freezer. If the Host is trying to suspend,
520 * it stops us. */
324 try_to_freeze(); 521 try_to_freeze();
325 522
523 /* Just make absolutely sure the Guest is still alive. One of
524 * those hypercalls could have been fatal, for example. */
326 if (lg->dead) 525 if (lg->dead)
327 break; 526 break;
328 527
528 /* If the Guest asked to be stopped, we sleep. The Guest's
529 * clock timer or LHCALL_BREAK from the Waker will wake us. */
329 if (lg->halted) { 530 if (lg->halted) {
330 set_current_state(TASK_INTERRUPTIBLE); 531 set_current_state(TASK_INTERRUPTIBLE);
331 schedule(); 532 schedule();
332 continue; 533 continue;
333 } 534 }
334 535
536 /* OK, now we're ready to jump into the Guest. First we put up
537 * the "Do Not Disturb" sign: */
335 local_irq_disable(); 538 local_irq_disable();
336 539
337 /* Even if *we* don't want FPU trap, guest might... */ 540 /* Remember the awfully-named TS bit? If the Guest has asked
541 * to set it we set it now, so we can trap and pass that trap
542 * to the Guest if it uses the FPU. */
338 if (lg->ts) 543 if (lg->ts)
339 set_ts(); 544 set_ts();
340 545
341 /* Don't let Guest do SYSENTER: we can't handle it. */ 546 /* SYSENTER is an optimized way of doing system calls. We
547 * can't allow it because it always jumps to privilege level 0.
548 * A normal Guest won't try it because we don't advertise it in
549 * CPUID, but a malicious Guest (or malicious Guest userspace
550 * program) could, so we tell the CPU to disable it before
551 * running the Guest. */
342 if (boot_cpu_has(X86_FEATURE_SEP)) 552 if (boot_cpu_has(X86_FEATURE_SEP))
343 wrmsr(MSR_IA32_SYSENTER_CS, 0, 0); 553 wrmsr(MSR_IA32_SYSENTER_CS, 0, 0);
344 554
555 /* Now we actually run the Guest. It will pop back out when
556 * something interesting happens, and we can examine its
557 * registers to see what it was doing. */
345 run_guest_once(lg, lguest_pages(raw_smp_processor_id())); 558 run_guest_once(lg, lguest_pages(raw_smp_processor_id()));
346 559
347 /* Save cr2 now if we page-faulted. */ 560 /* The "regs" pointer contains two extra entries which are not
561 * really registers: a trap number which says what interrupt or
562 * trap made the switcher code come back, and an error code
563 * which some traps set. */
564
565 /* If the Guest page faulted, then the cr2 register will tell
566 * us the bad virtual address. We have to grab this now,
567 * because once we re-enable interrupts an interrupt could
568 * fault and thus overwrite cr2, or we could even move off to a
569 * different CPU. */
348 if (lg->regs->trapnum == 14) 570 if (lg->regs->trapnum == 14)
349 cr2 = read_cr2(); 571 cr2 = read_cr2();
572 /* Similarly, if we took a trap because the Guest used the FPU,
573 * we have to restore the FPU it expects to see. */
350 else if (lg->regs->trapnum == 7) 574 else if (lg->regs->trapnum == 7)
351 math_state_restore(); 575 math_state_restore();
352 576
577 /* Restore SYSENTER if it's supposed to be on. */
353 if (boot_cpu_has(X86_FEATURE_SEP)) 578 if (boot_cpu_has(X86_FEATURE_SEP))
354 wrmsr(MSR_IA32_SYSENTER_CS, __KERNEL_CS, 0); 579 wrmsr(MSR_IA32_SYSENTER_CS, __KERNEL_CS, 0);
580
581 /* Now we're ready to be interrupted or moved to other CPUs */
355 local_irq_enable(); 582 local_irq_enable();
356 583
584 /* OK, so what happened? */
357 switch (lg->regs->trapnum) { 585 switch (lg->regs->trapnum) {
358 case 13: /* We've intercepted a GPF. */ 586 case 13: /* We've intercepted a GPF. */
587 /* Check if this was one of those annoying IN or OUT
588 * instructions which we need to emulate. If so, we
589 * just go back into the Guest after we've done it. */
359 if (lg->regs->errcode == 0) { 590 if (lg->regs->errcode == 0) {
360 if (emulate_insn(lg)) 591 if (emulate_insn(lg))
361 continue; 592 continue;
362 } 593 }
363 break; 594 break;
364 case 14: /* We've intercepted a page fault. */ 595 case 14: /* We've intercepted a page fault. */
596 /* The Guest accessed a virtual address that wasn't
597 * mapped. This happens a lot: we don't actually set
598 * up most of the page tables for the Guest at all when
599 * we start: as it runs it asks for more and more, and
600 * we set them up as required. In this case, we don't
601 * even tell the Guest that the fault happened.
602 *
603 * The errcode tells whether this was a read or a
604 * write, and whether kernel or userspace code. */
365 if (demand_page(lg, cr2, lg->regs->errcode)) 605 if (demand_page(lg, cr2, lg->regs->errcode))
366 continue; 606 continue;
367 607
368 /* If lguest_data is NULL, this won't hurt. */ 608 /* OK, it's really not there (or not OK): the Guest
609 * needs to know. We write out the cr2 value so it
610 * knows where the fault occurred.
611 *
612 * Note that if the Guest were really messed up, this
613 * could happen before it's done the INITIALIZE
614 * hypercall, so lg->lguest_data will be NULL, so
615 * &lg->lguest_data->cr2 will be address 8. Writing
616 * into that address won't hurt the Host at all,
617 * though. */
369 if (put_user(cr2, &lg->lguest_data->cr2)) 618 if (put_user(cr2, &lg->lguest_data->cr2))
370 kill_guest(lg, "Writing cr2"); 619 kill_guest(lg, "Writing cr2");
371 break; 620 break;
372 case 7: /* We've intercepted a Device Not Available fault. */ 621 case 7: /* We've intercepted a Device Not Available fault. */
373 /* If they don't want to know, just absorb it. */ 622 /* If the Guest doesn't want to know, we already
623 * restored the Floating Point Unit, so we just
624 * continue without telling it. */
374 if (!lg->ts) 625 if (!lg->ts)
375 continue; 626 continue;
376 break; 627 break;
377 case 32 ... 255: /* Real interrupt, fall thru */ 628 case 32 ... 255:
629 /* These values mean a real interrupt occurred, in
630 * which case the Host handler has already been run.
631 * We just do a friendly check if another process
632 * should now be run, then fall through to loop
633 * around: */
378 cond_resched(); 634 cond_resched();
379 case LGUEST_TRAP_ENTRY: /* Handled at top of loop */ 635 case LGUEST_TRAP_ENTRY: /* Handled at top of loop */
380 continue; 636 continue;
381 } 637 }
382 638
639 /* If we get here, it's a trap the Guest wants to know
640 * about. */
383 if (deliver_trap(lg, lg->regs->trapnum)) 641 if (deliver_trap(lg, lg->regs->trapnum))
384 continue; 642 continue;
385 643
644 /* If the Guest doesn't have a handler (either it hasn't
645 * registered any yet, or it's one of the faults we don't let
646 * it handle), it dies with a cryptic error message. */
386 kill_guest(lg, "unhandled trap %li at %#lx (%#lx)", 647 kill_guest(lg, "unhandled trap %li at %#lx (%#lx)",
387 lg->regs->trapnum, lg->regs->eip, 648 lg->regs->trapnum, lg->regs->eip,
388 lg->regs->trapnum == 14 ? cr2 : lg->regs->errcode); 649 lg->regs->trapnum == 14 ? cr2 : lg->regs->errcode);
389 } 650 }
651 /* The Guest is dead => "No such file or directory" */
390 return -ENOENT; 652 return -ENOENT;
391} 653}
392 654
655/* Now we can look at each of the routines this calls, in increasing order of
656 * complexity: do_hypercalls(), emulate_insn(), maybe_do_interrupt(),
657 * deliver_trap() and demand_page(). After all those, we'll be ready to
658 * examine the Switcher, and our philosophical understanding of the Host/Guest
659 * duality will be complete. :*/
660
393int find_free_guest(void) 661int find_free_guest(void)
394{ 662{
395 unsigned int i; 663 unsigned int i;
@@ -407,55 +675,96 @@ static void adjust_pge(void *on)
407 write_cr4(read_cr4() & ~X86_CR4_PGE); 675 write_cr4(read_cr4() & ~X86_CR4_PGE);
408} 676}
409 677
678/*H:000
679 * Welcome to the Host!
680 *
681 * By this point your brain has been tickled by the Guest code and numbed by
682 * the Launcher code; prepare for it to be stretched by the Host code. This is
683 * the heart. Let's begin at the initialization routine for the Host's lg
684 * module.
685 */
410static int __init init(void) 686static int __init init(void)
411{ 687{
412 int err; 688 int err;
413 689
690 /* Lguest can't run under Xen, VMI or itself. It does Tricky Stuff. */
414 if (paravirt_enabled()) { 691 if (paravirt_enabled()) {
415 printk("lguest is afraid of %s\n", paravirt_ops.name); 692 printk("lguest is afraid of %s\n", paravirt_ops.name);
416 return -EPERM; 693 return -EPERM;
417 } 694 }
418 695
696 /* First we put the Switcher up in very high virtual memory. */
419 err = map_switcher(); 697 err = map_switcher();
420 if (err) 698 if (err)
421 return err; 699 return err;
422 700
701 /* Now we set up the pagetable implementation for the Guests. */
423 err = init_pagetables(switcher_page, SHARED_SWITCHER_PAGES); 702 err = init_pagetables(switcher_page, SHARED_SWITCHER_PAGES);
424 if (err) { 703 if (err) {
425 unmap_switcher(); 704 unmap_switcher();
426 return err; 705 return err;
427 } 706 }
707
708 /* The I/O subsystem needs some things initialized. */
428 lguest_io_init(); 709 lguest_io_init();
429 710
711 /* /dev/lguest needs to be registered. */
430 err = lguest_device_init(); 712 err = lguest_device_init();
431 if (err) { 713 if (err) {
432 free_pagetables(); 714 free_pagetables();
433 unmap_switcher(); 715 unmap_switcher();
434 return err; 716 return err;
435 } 717 }
718
719 /* Finally, we need to turn off "Page Global Enable". PGE is an
720 * optimization where page table entries are specially marked to show
721 * they never change. The Host kernel marks all the kernel pages this
722 * way because it's always present, even when userspace is running.
723 *
724 * Lguest breaks this: unbeknownst to the rest of the Host kernel, we
725 * switch to the Guest kernel. If you don't disable this on all CPUs,
726 * you'll get really weird bugs that you'll chase for two days.
727 *
728 * I used to turn PGE off every time we switched to the Guest and back
729 * on when we return, but that slowed the Switcher down noticibly. */
730
731 /* We don't need the complexity of CPUs coming and going while we're
732 * doing this. */
436 lock_cpu_hotplug(); 733 lock_cpu_hotplug();
437 if (cpu_has_pge) { /* We have a broader idea of "global". */ 734 if (cpu_has_pge) { /* We have a broader idea of "global". */
735 /* Remember that this was originally set (for cleanup). */
438 cpu_had_pge = 1; 736 cpu_had_pge = 1;
737 /* adjust_pge is a helper function which sets or unsets the PGE
738 * bit on its CPU, depending on the argument (0 == unset). */
439 on_each_cpu(adjust_pge, (void *)0, 0, 1); 739 on_each_cpu(adjust_pge, (void *)0, 0, 1);
740 /* Turn off the feature in the global feature set. */
440 clear_bit(X86_FEATURE_PGE, boot_cpu_data.x86_capability); 741 clear_bit(X86_FEATURE_PGE, boot_cpu_data.x86_capability);
441 } 742 }
442 unlock_cpu_hotplug(); 743 unlock_cpu_hotplug();
744
745 /* All good! */
443 return 0; 746 return 0;
444} 747}
445 748
749/* Cleaning up is just the same code, backwards. With a little French. */
446static void __exit fini(void) 750static void __exit fini(void)
447{ 751{
448 lguest_device_remove(); 752 lguest_device_remove();
449 free_pagetables(); 753 free_pagetables();
450 unmap_switcher(); 754 unmap_switcher();
755
756 /* If we had PGE before we started, turn it back on now. */
451 lock_cpu_hotplug(); 757 lock_cpu_hotplug();
452 if (cpu_had_pge) { 758 if (cpu_had_pge) {
453 set_bit(X86_FEATURE_PGE, boot_cpu_data.x86_capability); 759 set_bit(X86_FEATURE_PGE, boot_cpu_data.x86_capability);
760 /* adjust_pge's argument "1" means set PGE. */
454 on_each_cpu(adjust_pge, (void *)1, 0, 1); 761 on_each_cpu(adjust_pge, (void *)1, 0, 1);
455 } 762 }
456 unlock_cpu_hotplug(); 763 unlock_cpu_hotplug();
457} 764}
458 765
766/* The Host side of lguest can be a module. This is a nice way for people to
767 * play with it. */
459module_init(init); 768module_init(init);
460module_exit(fini); 769module_exit(fini);
461MODULE_LICENSE("GPL"); 770MODULE_LICENSE("GPL");
diff --git a/drivers/lguest/hypercalls.c b/drivers/lguest/hypercalls.c
index ea52ca451f74..db6caace3b9c 100644
--- a/drivers/lguest/hypercalls.c
+++ b/drivers/lguest/hypercalls.c
@@ -1,5 +1,10 @@
1/* Actual hypercalls, which allow guests to actually do something. 1/*P:500 Just as userspace programs request kernel operations through a system
2 Copyright (C) 2006 Rusty Russell IBM Corporation 2 * call, the Guest requests Host operations through a "hypercall". You might
3 * notice this nomenclature doesn't really follow any logic, but the name has
4 * been around for long enough that we're stuck with it. As you'd expect, this
5 * code is basically a one big switch statement. :*/
6
7/* Copyright (C) 2006 Rusty Russell IBM Corporation
3 8
4 This program is free software; you can redistribute it and/or modify 9 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
@@ -23,37 +28,55 @@
23#include <irq_vectors.h> 28#include <irq_vectors.h>
24#include "lg.h" 29#include "lg.h"
25 30
31/*H:120 This is the core hypercall routine: where the Guest gets what it
32 * wants. Or gets killed. Or, in the case of LHCALL_CRASH, both.
33 *
34 * Remember from the Guest: %eax == which call to make, and the arguments are
35 * packed into %edx, %ebx and %ecx if needed. */
26static void do_hcall(struct lguest *lg, struct lguest_regs *regs) 36static void do_hcall(struct lguest *lg, struct lguest_regs *regs)
27{ 37{
28 switch (regs->eax) { 38 switch (regs->eax) {
29 case LHCALL_FLUSH_ASYNC: 39 case LHCALL_FLUSH_ASYNC:
40 /* This call does nothing, except by breaking out of the Guest
41 * it makes us process all the asynchronous hypercalls. */
30 break; 42 break;
31 case LHCALL_LGUEST_INIT: 43 case LHCALL_LGUEST_INIT:
44 /* You can't get here unless you're already initialized. Don't
45 * do that. */
32 kill_guest(lg, "already have lguest_data"); 46 kill_guest(lg, "already have lguest_data");
33 break; 47 break;
34 case LHCALL_CRASH: { 48 case LHCALL_CRASH: {
49 /* Crash is such a trivial hypercall that we do it in four
50 * lines right here. */
35 char msg[128]; 51 char msg[128];
52 /* If the lgread fails, it will call kill_guest() itself; the
53 * kill_guest() with the message will be ignored. */
36 lgread(lg, msg, regs->edx, sizeof(msg)); 54 lgread(lg, msg, regs->edx, sizeof(msg));
37 msg[sizeof(msg)-1] = '\0'; 55 msg[sizeof(msg)-1] = '\0';
38 kill_guest(lg, "CRASH: %s", msg); 56 kill_guest(lg, "CRASH: %s", msg);
39 break; 57 break;
40 } 58 }
41 case LHCALL_FLUSH_TLB: 59 case LHCALL_FLUSH_TLB:
60 /* FLUSH_TLB comes in two flavors, depending on the
61 * argument: */
42 if (regs->edx) 62 if (regs->edx)
43 guest_pagetable_clear_all(lg); 63 guest_pagetable_clear_all(lg);
44 else 64 else
45 guest_pagetable_flush_user(lg); 65 guest_pagetable_flush_user(lg);
46 break; 66 break;
47 case LHCALL_GET_WALLCLOCK: {
48 struct timespec ts;
49 ktime_get_real_ts(&ts);
50 regs->eax = ts.tv_sec;
51 break;
52 }
53 case LHCALL_BIND_DMA: 67 case LHCALL_BIND_DMA:
68 /* BIND_DMA really wants four arguments, but it's the only call
69 * which does. So the Guest packs the number of buffers and
70 * the interrupt number into the final argument, and we decode
71 * it here. This can legitimately fail, since we currently
72 * place a limit on the number of DMA pools a Guest can have.
73 * So we return true or false from this call. */
54 regs->eax = bind_dma(lg, regs->edx, regs->ebx, 74 regs->eax = bind_dma(lg, regs->edx, regs->ebx,
55 regs->ecx >> 8, regs->ecx & 0xFF); 75 regs->ecx >> 8, regs->ecx & 0xFF);
56 break; 76 break;
77
78 /* All these calls simply pass the arguments through to the right
79 * routines. */
57 case LHCALL_SEND_DMA: 80 case LHCALL_SEND_DMA:
58 send_dma(lg, regs->edx, regs->ebx); 81 send_dma(lg, regs->edx, regs->ebx);
59 break; 82 break;
@@ -81,10 +104,13 @@ static void do_hcall(struct lguest *lg, struct lguest_regs *regs)
81 case LHCALL_SET_CLOCKEVENT: 104 case LHCALL_SET_CLOCKEVENT:
82 guest_set_clockevent(lg, regs->edx); 105 guest_set_clockevent(lg, regs->edx);
83 break; 106 break;
107
84 case LHCALL_TS: 108 case LHCALL_TS:
109 /* This sets the TS flag, as we saw used in run_guest(). */
85 lg->ts = regs->edx; 110 lg->ts = regs->edx;
86 break; 111 break;
87 case LHCALL_HALT: 112 case LHCALL_HALT:
113 /* Similarly, this sets the halted flag for run_guest(). */
88 lg->halted = 1; 114 lg->halted = 1;
89 break; 115 break;
90 default: 116 default:
@@ -92,25 +118,42 @@ static void do_hcall(struct lguest *lg, struct lguest_regs *regs)
92 } 118 }
93} 119}
94 120
95/* We always do queued calls before actual hypercall. */ 121/* Asynchronous hypercalls are easy: we just look in the array in the Guest's
122 * "struct lguest_data" and see if there are any new ones marked "ready".
123 *
124 * We are careful to do these in order: obviously we respect the order the
125 * Guest put them in the ring, but we also promise the Guest that they will
126 * happen before any normal hypercall (which is why we check this before
127 * checking for a normal hcall). */
96static void do_async_hcalls(struct lguest *lg) 128static void do_async_hcalls(struct lguest *lg)
97{ 129{
98 unsigned int i; 130 unsigned int i;
99 u8 st[LHCALL_RING_SIZE]; 131 u8 st[LHCALL_RING_SIZE];
100 132
133 /* For simplicity, we copy the entire call status array in at once. */
101 if (copy_from_user(&st, &lg->lguest_data->hcall_status, sizeof(st))) 134 if (copy_from_user(&st, &lg->lguest_data->hcall_status, sizeof(st)))
102 return; 135 return;
103 136
137
138 /* We process "struct lguest_data"s hcalls[] ring once. */
104 for (i = 0; i < ARRAY_SIZE(st); i++) { 139 for (i = 0; i < ARRAY_SIZE(st); i++) {
105 struct lguest_regs regs; 140 struct lguest_regs regs;
141 /* We remember where we were up to from last time. This makes
142 * sure that the hypercalls are done in the order the Guest
143 * places them in the ring. */
106 unsigned int n = lg->next_hcall; 144 unsigned int n = lg->next_hcall;
107 145
146 /* 0xFF means there's no call here (yet). */
108 if (st[n] == 0xFF) 147 if (st[n] == 0xFF)
109 break; 148 break;
110 149
150 /* OK, we have hypercall. Increment the "next_hcall" cursor,
151 * and wrap back to 0 if we reach the end. */
111 if (++lg->next_hcall == LHCALL_RING_SIZE) 152 if (++lg->next_hcall == LHCALL_RING_SIZE)
112 lg->next_hcall = 0; 153 lg->next_hcall = 0;
113 154
155 /* We copy the hypercall arguments into a fake register
156 * structure. This makes life simple for do_hcall(). */
114 if (get_user(regs.eax, &lg->lguest_data->hcalls[n].eax) 157 if (get_user(regs.eax, &lg->lguest_data->hcalls[n].eax)
115 || get_user(regs.edx, &lg->lguest_data->hcalls[n].edx) 158 || get_user(regs.edx, &lg->lguest_data->hcalls[n].edx)
116 || get_user(regs.ecx, &lg->lguest_data->hcalls[n].ecx) 159 || get_user(regs.ecx, &lg->lguest_data->hcalls[n].ecx)
@@ -119,74 +162,139 @@ static void do_async_hcalls(struct lguest *lg)
119 break; 162 break;
120 } 163 }
121 164
165 /* Do the hypercall, same as a normal one. */
122 do_hcall(lg, &regs); 166 do_hcall(lg, &regs);
167
168 /* Mark the hypercall done. */
123 if (put_user(0xFF, &lg->lguest_data->hcall_status[n])) { 169 if (put_user(0xFF, &lg->lguest_data->hcall_status[n])) {
124 kill_guest(lg, "Writing result for async hypercall"); 170 kill_guest(lg, "Writing result for async hypercall");
125 break; 171 break;
126 } 172 }
127 173
174 /* Stop doing hypercalls if we've just done a DMA to the
175 * Launcher: it needs to service this first. */
128 if (lg->dma_is_pending) 176 if (lg->dma_is_pending)
129 break; 177 break;
130 } 178 }
131} 179}
132 180
181/* Last of all, we look at what happens first of all. The very first time the
182 * Guest makes a hypercall, we end up here to set things up: */
133static void initialize(struct lguest *lg) 183static void initialize(struct lguest *lg)
134{ 184{
135 u32 tsc_speed; 185 u32 tsc_speed;
136 186
187 /* You can't do anything until you're initialized. The Guest knows the
188 * rules, so we're unforgiving here. */
137 if (lg->regs->eax != LHCALL_LGUEST_INIT) { 189 if (lg->regs->eax != LHCALL_LGUEST_INIT) {
138 kill_guest(lg, "hypercall %li before LGUEST_INIT", 190 kill_guest(lg, "hypercall %li before LGUEST_INIT",
139 lg->regs->eax); 191 lg->regs->eax);
140 return; 192 return;
141 } 193 }
142 194
143 /* We only tell the guest to use the TSC if it's reliable. */ 195 /* We insist that the Time Stamp Counter exist and doesn't change with
196 * cpu frequency. Some devious chip manufacturers decided that TSC
197 * changes could be handled in software. I decided that time going
198 * backwards might be good for benchmarks, but it's bad for users.
199 *
200 * We also insist that the TSC be stable: the kernel detects unreliable
201 * TSCs for its own purposes, and we use that here. */
144 if (boot_cpu_has(X86_FEATURE_CONSTANT_TSC) && !check_tsc_unstable()) 202 if (boot_cpu_has(X86_FEATURE_CONSTANT_TSC) && !check_tsc_unstable())
145 tsc_speed = tsc_khz; 203 tsc_speed = tsc_khz;
146 else 204 else
147 tsc_speed = 0; 205 tsc_speed = 0;
148 206
207 /* The pointer to the Guest's "struct lguest_data" is the only
208 * argument. */
149 lg->lguest_data = (struct lguest_data __user *)lg->regs->edx; 209 lg->lguest_data = (struct lguest_data __user *)lg->regs->edx;
150 /* We check here so we can simply copy_to_user/from_user */ 210 /* If we check the address they gave is OK now, we can simply
211 * copy_to_user/from_user from now on rather than using lgread/lgwrite.
212 * I put this in to show that I'm not immune to writing stupid
213 * optimizations. */
151 if (!lguest_address_ok(lg, lg->regs->edx, sizeof(*lg->lguest_data))) { 214 if (!lguest_address_ok(lg, lg->regs->edx, sizeof(*lg->lguest_data))) {
152 kill_guest(lg, "bad guest page %p", lg->lguest_data); 215 kill_guest(lg, "bad guest page %p", lg->lguest_data);
153 return; 216 return;
154 } 217 }
218 /* The Guest tells us where we're not to deliver interrupts by putting
219 * the range of addresses into "struct lguest_data". */
155 if (get_user(lg->noirq_start, &lg->lguest_data->noirq_start) 220 if (get_user(lg->noirq_start, &lg->lguest_data->noirq_start)
156 || get_user(lg->noirq_end, &lg->lguest_data->noirq_end) 221 || get_user(lg->noirq_end, &lg->lguest_data->noirq_end)
157 /* We reserve the top pgd entry. */ 222 /* We tell the Guest that it can't use the top 4MB of virtual
223 * addresses used by the Switcher. */
158 || put_user(4U*1024*1024, &lg->lguest_data->reserve_mem) 224 || put_user(4U*1024*1024, &lg->lguest_data->reserve_mem)
159 || put_user(tsc_speed, &lg->lguest_data->tsc_khz) 225 || put_user(tsc_speed, &lg->lguest_data->tsc_khz)
226 /* We also give the Guest a unique id, as used in lguest_net.c. */
160 || put_user(lg->guestid, &lg->lguest_data->guestid)) 227 || put_user(lg->guestid, &lg->lguest_data->guestid))
161 kill_guest(lg, "bad guest page %p", lg->lguest_data); 228 kill_guest(lg, "bad guest page %p", lg->lguest_data);
162 229
163 /* This is the one case where the above accesses might have 230 /* We write the current time into the Guest's data page once now. */
164 * been the first write to a Guest page. This may have caused 231 write_timestamp(lg);
165 * a copy-on-write fault, but the Guest might be referring to 232
166 * the old (read-only) page. */ 233 /* This is the one case where the above accesses might have been the
234 * first write to a Guest page. This may have caused a copy-on-write
235 * fault, but the Guest might be referring to the old (read-only)
236 * page. */
167 guest_pagetable_clear_all(lg); 237 guest_pagetable_clear_all(lg);
168} 238}
239/* Now we've examined the hypercall code; our Guest can make requests. There
240 * is one other way we can do things for the Guest, as we see in
241 * emulate_insn(). */
169 242
170/* Even if we go out to userspace and come back, we don't want to do 243/*H:110 Tricky point: we mark the hypercall as "done" once we've done it.
171 * the hypercall again. */ 244 * Normally we don't need to do this: the Guest will run again and update the
245 * trap number before we come back around the run_guest() loop to
246 * do_hypercalls().
247 *
248 * However, if we are signalled or the Guest sends DMA to the Launcher, that
249 * loop will exit without running the Guest. When it comes back it would try
250 * to re-run the hypercall. */
172static void clear_hcall(struct lguest *lg) 251static void clear_hcall(struct lguest *lg)
173{ 252{
174 lg->regs->trapnum = 255; 253 lg->regs->trapnum = 255;
175} 254}
176 255
256/*H:100
257 * Hypercalls
258 *
259 * Remember from the Guest, hypercalls come in two flavors: normal and
260 * asynchronous. This file handles both of types.
261 */
177void do_hypercalls(struct lguest *lg) 262void do_hypercalls(struct lguest *lg)
178{ 263{
264 /* Not initialized yet? */
179 if (unlikely(!lg->lguest_data)) { 265 if (unlikely(!lg->lguest_data)) {
266 /* Did the Guest make a hypercall? We might have come back for
267 * some other reason (an interrupt, a different trap). */
180 if (lg->regs->trapnum == LGUEST_TRAP_ENTRY) { 268 if (lg->regs->trapnum == LGUEST_TRAP_ENTRY) {
269 /* Set up the "struct lguest_data" */
181 initialize(lg); 270 initialize(lg);
271 /* The hypercall is done. */
182 clear_hcall(lg); 272 clear_hcall(lg);
183 } 273 }
184 return; 274 return;
185 } 275 }
186 276
277 /* The Guest has initialized.
278 *
279 * Look in the hypercall ring for the async hypercalls: */
187 do_async_hcalls(lg); 280 do_async_hcalls(lg);
281
282 /* If we stopped reading the hypercall ring because the Guest did a
283 * SEND_DMA to the Launcher, we want to return now. Otherwise if the
284 * Guest asked us to do a hypercall, we do it. */
188 if (!lg->dma_is_pending && lg->regs->trapnum == LGUEST_TRAP_ENTRY) { 285 if (!lg->dma_is_pending && lg->regs->trapnum == LGUEST_TRAP_ENTRY) {
189 do_hcall(lg, lg->regs); 286 do_hcall(lg, lg->regs);
287 /* The hypercall is done. */
190 clear_hcall(lg); 288 clear_hcall(lg);
191 } 289 }
192} 290}
291
292/* This routine supplies the Guest with time: it's used for wallclock time at
293 * initial boot and as a rough time source if the TSC isn't available. */
294void write_timestamp(struct lguest *lg)
295{
296 struct timespec now;
297 ktime_get_real_ts(&now);
298 if (put_user(now, &lg->lguest_data->time))
299 kill_guest(lg, "Writing timestamp");
300}
diff --git a/drivers/lguest/interrupts_and_traps.c b/drivers/lguest/interrupts_and_traps.c
index bee029bb2c7b..49787e964a0d 100644
--- a/drivers/lguest/interrupts_and_traps.c
+++ b/drivers/lguest/interrupts_and_traps.c
@@ -1,100 +1,160 @@
1/*P:800 Interrupts (traps) are complicated enough to earn their own file.
2 * There are three classes of interrupts:
3 *
4 * 1) Real hardware interrupts which occur while we're running the Guest,
5 * 2) Interrupts for virtual devices attached to the Guest, and
6 * 3) Traps and faults from the Guest.
7 *
8 * Real hardware interrupts must be delivered to the Host, not the Guest.
9 * Virtual interrupts must be delivered to the Guest, but we make them look
10 * just like real hardware would deliver them. Traps from the Guest can be set
11 * up to go directly back into the Guest, but sometimes the Host wants to see
12 * them first, so we also have a way of "reflecting" them into the Guest as if
13 * they had been delivered to it directly. :*/
1#include <linux/uaccess.h> 14#include <linux/uaccess.h>
2#include "lg.h" 15#include "lg.h"
3 16
17/* The address of the interrupt handler is split into two bits: */
4static unsigned long idt_address(u32 lo, u32 hi) 18static unsigned long idt_address(u32 lo, u32 hi)
5{ 19{
6 return (lo & 0x0000FFFF) | (hi & 0xFFFF0000); 20 return (lo & 0x0000FFFF) | (hi & 0xFFFF0000);
7} 21}
8 22
23/* The "type" of the interrupt handler is a 4 bit field: we only support a
24 * couple of types. */
9static int idt_type(u32 lo, u32 hi) 25static int idt_type(u32 lo, u32 hi)
10{ 26{
11 return (hi >> 8) & 0xF; 27 return (hi >> 8) & 0xF;
12} 28}
13 29
30/* An IDT entry can't be used unless the "present" bit is set. */
14static int idt_present(u32 lo, u32 hi) 31static int idt_present(u32 lo, u32 hi)
15{ 32{
16 return (hi & 0x8000); 33 return (hi & 0x8000);
17} 34}
18 35
36/* We need a helper to "push" a value onto the Guest's stack, since that's a
37 * big part of what delivering an interrupt does. */
19static void push_guest_stack(struct lguest *lg, unsigned long *gstack, u32 val) 38static void push_guest_stack(struct lguest *lg, unsigned long *gstack, u32 val)
20{ 39{
40 /* Stack grows upwards: move stack then write value. */
21 *gstack -= 4; 41 *gstack -= 4;
22 lgwrite_u32(lg, *gstack, val); 42 lgwrite_u32(lg, *gstack, val);
23} 43}
24 44
45/*H:210 The set_guest_interrupt() routine actually delivers the interrupt or
46 * trap. The mechanics of delivering traps and interrupts to the Guest are the
47 * same, except some traps have an "error code" which gets pushed onto the
48 * stack as well: the caller tells us if this is one.
49 *
50 * "lo" and "hi" are the two parts of the Interrupt Descriptor Table for this
51 * interrupt or trap. It's split into two parts for traditional reasons: gcc
52 * on i386 used to be frightened by 64 bit numbers.
53 *
54 * We set up the stack just like the CPU does for a real interrupt, so it's
55 * identical for the Guest (and the standard "iret" instruction will undo
56 * it). */
25static void set_guest_interrupt(struct lguest *lg, u32 lo, u32 hi, int has_err) 57static void set_guest_interrupt(struct lguest *lg, u32 lo, u32 hi, int has_err)
26{ 58{
27 unsigned long gstack; 59 unsigned long gstack;
28 u32 eflags, ss, irq_enable; 60 u32 eflags, ss, irq_enable;
29 61
30 /* If they want a ring change, we use new stack and push old ss/esp */ 62 /* There are two cases for interrupts: one where the Guest is already
63 * in the kernel, and a more complex one where the Guest is in
64 * userspace. We check the privilege level to find out. */
31 if ((lg->regs->ss&0x3) != GUEST_PL) { 65 if ((lg->regs->ss&0x3) != GUEST_PL) {
66 /* The Guest told us their kernel stack with the SET_STACK
67 * hypercall: both the virtual address and the segment */
32 gstack = guest_pa(lg, lg->esp1); 68 gstack = guest_pa(lg, lg->esp1);
33 ss = lg->ss1; 69 ss = lg->ss1;
70 /* We push the old stack segment and pointer onto the new
71 * stack: when the Guest does an "iret" back from the interrupt
72 * handler the CPU will notice they're dropping privilege
73 * levels and expect these here. */
34 push_guest_stack(lg, &gstack, lg->regs->ss); 74 push_guest_stack(lg, &gstack, lg->regs->ss);
35 push_guest_stack(lg, &gstack, lg->regs->esp); 75 push_guest_stack(lg, &gstack, lg->regs->esp);
36 } else { 76 } else {
77 /* We're staying on the same Guest (kernel) stack. */
37 gstack = guest_pa(lg, lg->regs->esp); 78 gstack = guest_pa(lg, lg->regs->esp);
38 ss = lg->regs->ss; 79 ss = lg->regs->ss;
39 } 80 }
40 81
41 /* We use IF bit in eflags to indicate whether irqs were enabled 82 /* Remember that we never let the Guest actually disable interrupts, so
42 (it's always 1, since irqs are enabled when guest is running). */ 83 * the "Interrupt Flag" bit is always set. We copy that bit from the
84 * Guest's "irq_enabled" field into the eflags word: the Guest copies
85 * it back in "lguest_iret". */
43 eflags = lg->regs->eflags; 86 eflags = lg->regs->eflags;
44 if (get_user(irq_enable, &lg->lguest_data->irq_enabled) == 0 87 if (get_user(irq_enable, &lg->lguest_data->irq_enabled) == 0
45 && !(irq_enable & X86_EFLAGS_IF)) 88 && !(irq_enable & X86_EFLAGS_IF))
46 eflags &= ~X86_EFLAGS_IF; 89 eflags &= ~X86_EFLAGS_IF;
47 90
91 /* An interrupt is expected to push three things on the stack: the old
92 * "eflags" word, the old code segment, and the old instruction
93 * pointer. */
48 push_guest_stack(lg, &gstack, eflags); 94 push_guest_stack(lg, &gstack, eflags);
49 push_guest_stack(lg, &gstack, lg->regs->cs); 95 push_guest_stack(lg, &gstack, lg->regs->cs);
50 push_guest_stack(lg, &gstack, lg->regs->eip); 96 push_guest_stack(lg, &gstack, lg->regs->eip);
51 97
98 /* For the six traps which supply an error code, we push that, too. */
52 if (has_err) 99 if (has_err)
53 push_guest_stack(lg, &gstack, lg->regs->errcode); 100 push_guest_stack(lg, &gstack, lg->regs->errcode);
54 101
55 /* Change the real stack so switcher returns to trap handler */ 102 /* Now we've pushed all the old state, we change the stack, the code
103 * segment and the address to execute. */
56 lg->regs->ss = ss; 104 lg->regs->ss = ss;
57 lg->regs->esp = gstack + lg->page_offset; 105 lg->regs->esp = gstack + lg->page_offset;
58 lg->regs->cs = (__KERNEL_CS|GUEST_PL); 106 lg->regs->cs = (__KERNEL_CS|GUEST_PL);
59 lg->regs->eip = idt_address(lo, hi); 107 lg->regs->eip = idt_address(lo, hi);
60 108
61 /* Disable interrupts for an interrupt gate. */ 109 /* There are two kinds of interrupt handlers: 0xE is an "interrupt
110 * gate" which expects interrupts to be disabled on entry. */
62 if (idt_type(lo, hi) == 0xE) 111 if (idt_type(lo, hi) == 0xE)
63 if (put_user(0, &lg->lguest_data->irq_enabled)) 112 if (put_user(0, &lg->lguest_data->irq_enabled))
64 kill_guest(lg, "Disabling interrupts"); 113 kill_guest(lg, "Disabling interrupts");
65} 114}
66 115
116/*H:200
117 * Virtual Interrupts.
118 *
119 * maybe_do_interrupt() gets called before every entry to the Guest, to see if
120 * we should divert the Guest to running an interrupt handler. */
67void maybe_do_interrupt(struct lguest *lg) 121void maybe_do_interrupt(struct lguest *lg)
68{ 122{
69 unsigned int irq; 123 unsigned int irq;
70 DECLARE_BITMAP(blk, LGUEST_IRQS); 124 DECLARE_BITMAP(blk, LGUEST_IRQS);
71 struct desc_struct *idt; 125 struct desc_struct *idt;
72 126
127 /* If the Guest hasn't even initialized yet, we can do nothing. */
73 if (!lg->lguest_data) 128 if (!lg->lguest_data)
74 return; 129 return;
75 130
76 /* Mask out any interrupts they have blocked. */ 131 /* Take our "irqs_pending" array and remove any interrupts the Guest
132 * wants blocked: the result ends up in "blk". */
77 if (copy_from_user(&blk, lg->lguest_data->blocked_interrupts, 133 if (copy_from_user(&blk, lg->lguest_data->blocked_interrupts,
78 sizeof(blk))) 134 sizeof(blk)))
79 return; 135 return;
80 136
81 bitmap_andnot(blk, lg->irqs_pending, blk, LGUEST_IRQS); 137 bitmap_andnot(blk, lg->irqs_pending, blk, LGUEST_IRQS);
82 138
139 /* Find the first interrupt. */
83 irq = find_first_bit(blk, LGUEST_IRQS); 140 irq = find_first_bit(blk, LGUEST_IRQS);
141 /* None? Nothing to do */
84 if (irq >= LGUEST_IRQS) 142 if (irq >= LGUEST_IRQS)
85 return; 143 return;
86 144
145 /* They may be in the middle of an iret, where they asked us never to
146 * deliver interrupts. */
87 if (lg->regs->eip >= lg->noirq_start && lg->regs->eip < lg->noirq_end) 147 if (lg->regs->eip >= lg->noirq_start && lg->regs->eip < lg->noirq_end)
88 return; 148 return;
89 149
90 /* If they're halted, we re-enable interrupts. */ 150 /* If they're halted, interrupts restart them. */
91 if (lg->halted) { 151 if (lg->halted) {
92 /* Re-enable interrupts. */ 152 /* Re-enable interrupts. */
93 if (put_user(X86_EFLAGS_IF, &lg->lguest_data->irq_enabled)) 153 if (put_user(X86_EFLAGS_IF, &lg->lguest_data->irq_enabled))
94 kill_guest(lg, "Re-enabling interrupts"); 154 kill_guest(lg, "Re-enabling interrupts");
95 lg->halted = 0; 155 lg->halted = 0;
96 } else { 156 } else {
97 /* Maybe they have interrupts disabled? */ 157 /* Otherwise we check if they have interrupts disabled. */
98 u32 irq_enabled; 158 u32 irq_enabled;
99 if (get_user(irq_enabled, &lg->lguest_data->irq_enabled)) 159 if (get_user(irq_enabled, &lg->lguest_data->irq_enabled))
100 irq_enabled = 0; 160 irq_enabled = 0;
@@ -102,112 +162,218 @@ void maybe_do_interrupt(struct lguest *lg)
102 return; 162 return;
103 } 163 }
104 164
165 /* Look at the IDT entry the Guest gave us for this interrupt. The
166 * first 32 (FIRST_EXTERNAL_VECTOR) entries are for traps, so we skip
167 * over them. */
105 idt = &lg->idt[FIRST_EXTERNAL_VECTOR+irq]; 168 idt = &lg->idt[FIRST_EXTERNAL_VECTOR+irq];
169 /* If they don't have a handler (yet?), we just ignore it */
106 if (idt_present(idt->a, idt->b)) { 170 if (idt_present(idt->a, idt->b)) {
171 /* OK, mark it no longer pending and deliver it. */
107 clear_bit(irq, lg->irqs_pending); 172 clear_bit(irq, lg->irqs_pending);
173 /* set_guest_interrupt() takes the interrupt descriptor and a
174 * flag to say whether this interrupt pushes an error code onto
175 * the stack as well: virtual interrupts never do. */
108 set_guest_interrupt(lg, idt->a, idt->b, 0); 176 set_guest_interrupt(lg, idt->a, idt->b, 0);
109 } 177 }
178
179 /* Every time we deliver an interrupt, we update the timestamp in the
180 * Guest's lguest_data struct. It would be better for the Guest if we
181 * did this more often, but it can actually be quite slow: doing it
182 * here is a compromise which means at least it gets updated every
183 * timer interrupt. */
184 write_timestamp(lg);
110} 185}
111 186
187/*H:220 Now we've got the routines to deliver interrupts, delivering traps
188 * like page fault is easy. The only trick is that Intel decided that some
189 * traps should have error codes: */
112static int has_err(unsigned int trap) 190static int has_err(unsigned int trap)
113{ 191{
114 return (trap == 8 || (trap >= 10 && trap <= 14) || trap == 17); 192 return (trap == 8 || (trap >= 10 && trap <= 14) || trap == 17);
115} 193}
116 194
195/* deliver_trap() returns true if it could deliver the trap. */
117int deliver_trap(struct lguest *lg, unsigned int num) 196int deliver_trap(struct lguest *lg, unsigned int num)
118{ 197{
119 u32 lo = lg->idt[num].a, hi = lg->idt[num].b; 198 u32 lo = lg->idt[num].a, hi = lg->idt[num].b;
120 199
200 /* Early on the Guest hasn't set the IDT entries (or maybe it put a
201 * bogus one in): if we fail here, the Guest will be killed. */
121 if (!idt_present(lo, hi)) 202 if (!idt_present(lo, hi))
122 return 0; 203 return 0;
123 set_guest_interrupt(lg, lo, hi, has_err(num)); 204 set_guest_interrupt(lg, lo, hi, has_err(num));
124 return 1; 205 return 1;
125} 206}
126 207
208/*H:250 Here's the hard part: returning to the Host every time a trap happens
209 * and then calling deliver_trap() and re-entering the Guest is slow.
210 * Particularly because Guest userspace system calls are traps (trap 128).
211 *
212 * So we'd like to set up the IDT to tell the CPU to deliver traps directly
213 * into the Guest. This is possible, but the complexities cause the size of
214 * this file to double! However, 150 lines of code is worth writing for taking
215 * system calls down from 1750ns to 270ns. Plus, if lguest didn't do it, all
216 * the other hypervisors would tease it.
217 *
218 * This routine determines if a trap can be delivered directly. */
127static int direct_trap(const struct lguest *lg, 219static int direct_trap(const struct lguest *lg,
128 const struct desc_struct *trap, 220 const struct desc_struct *trap,
129 unsigned int num) 221 unsigned int num)
130{ 222{
131 /* Hardware interrupts don't go to guest (except syscall). */ 223 /* Hardware interrupts don't go to the Guest at all (except system
224 * call). */
132 if (num >= FIRST_EXTERNAL_VECTOR && num != SYSCALL_VECTOR) 225 if (num >= FIRST_EXTERNAL_VECTOR && num != SYSCALL_VECTOR)
133 return 0; 226 return 0;
134 227
135 /* We intercept page fault (demand shadow paging & cr2 saving) 228 /* The Host needs to see page faults (for shadow paging and to save the
136 protection fault (in/out emulation) and device not 229 * fault address), general protection faults (in/out emulation) and
137 available (TS handling), and hypercall */ 230 * device not available (TS handling), and of course, the hypercall
231 * trap. */
138 if (num == 14 || num == 13 || num == 7 || num == LGUEST_TRAP_ENTRY) 232 if (num == 14 || num == 13 || num == 7 || num == LGUEST_TRAP_ENTRY)
139 return 0; 233 return 0;
140 234
141 /* Interrupt gates (0xE) or not present (0x0) can't go direct. */ 235 /* Only trap gates (type 15) can go direct to the Guest. Interrupt
236 * gates (type 14) disable interrupts as they are entered, which we
237 * never let the Guest do. Not present entries (type 0x0) also can't
238 * go direct, of course 8) */
142 return idt_type(trap->a, trap->b) == 0xF; 239 return idt_type(trap->a, trap->b) == 0xF;
143} 240}
144 241/*:*/
242
243/*M:005 The Guest has the ability to turn its interrupt gates into trap gates,
244 * if it is careful. The Host will let trap gates can go directly to the
245 * Guest, but the Guest needs the interrupts atomically disabled for an
246 * interrupt gate. It can do this by pointing the trap gate at instructions
247 * within noirq_start and noirq_end, where it can safely disable interrupts. */
248
249/*M:006 The Guests do not use the sysenter (fast system call) instruction,
250 * because it's hardcoded to enter privilege level 0 and so can't go direct.
251 * It's about twice as fast as the older "int 0x80" system call, so it might
252 * still be worthwhile to handle it in the Switcher and lcall down to the
253 * Guest. The sysenter semantics are hairy tho: search for that keyword in
254 * entry.S :*/
255
256/*H:260 When we make traps go directly into the Guest, we need to make sure
257 * the kernel stack is valid (ie. mapped in the page tables). Otherwise, the
258 * CPU trying to deliver the trap will fault while trying to push the interrupt
259 * words on the stack: this is called a double fault, and it forces us to kill
260 * the Guest.
261 *
262 * Which is deeply unfair, because (literally!) it wasn't the Guests' fault. */
145void pin_stack_pages(struct lguest *lg) 263void pin_stack_pages(struct lguest *lg)
146{ 264{
147 unsigned int i; 265 unsigned int i;
148 266
267 /* Depending on the CONFIG_4KSTACKS option, the Guest can have one or
268 * two pages of stack space. */
149 for (i = 0; i < lg->stack_pages; i++) 269 for (i = 0; i < lg->stack_pages; i++)
270 /* The stack grows *upwards*, hence the subtraction */
150 pin_page(lg, lg->esp1 - i * PAGE_SIZE); 271 pin_page(lg, lg->esp1 - i * PAGE_SIZE);
151} 272}
152 273
274/* Direct traps also mean that we need to know whenever the Guest wants to use
275 * a different kernel stack, so we can change the IDT entries to use that
276 * stack. The IDT entries expect a virtual address, so unlike most addresses
277 * the Guest gives us, the "esp" (stack pointer) value here is virtual, not
278 * physical.
279 *
280 * In Linux each process has its own kernel stack, so this happens a lot: we
281 * change stacks on each context switch. */
153void guest_set_stack(struct lguest *lg, u32 seg, u32 esp, unsigned int pages) 282void guest_set_stack(struct lguest *lg, u32 seg, u32 esp, unsigned int pages)
154{ 283{
155 /* You cannot have a stack segment with priv level 0. */ 284 /* You are not allowd have a stack segment with privilege level 0: bad
285 * Guest! */
156 if ((seg & 0x3) != GUEST_PL) 286 if ((seg & 0x3) != GUEST_PL)
157 kill_guest(lg, "bad stack segment %i", seg); 287 kill_guest(lg, "bad stack segment %i", seg);
288 /* We only expect one or two stack pages. */
158 if (pages > 2) 289 if (pages > 2)
159 kill_guest(lg, "bad stack pages %u", pages); 290 kill_guest(lg, "bad stack pages %u", pages);
291 /* Save where the stack is, and how many pages */
160 lg->ss1 = seg; 292 lg->ss1 = seg;
161 lg->esp1 = esp; 293 lg->esp1 = esp;
162 lg->stack_pages = pages; 294 lg->stack_pages = pages;
295 /* Make sure the new stack pages are mapped */
163 pin_stack_pages(lg); 296 pin_stack_pages(lg);
164} 297}
165 298
166/* Set up trap in IDT. */ 299/* All this reference to mapping stacks leads us neatly into the other complex
300 * part of the Host: page table handling. */
301
302/*H:235 This is the routine which actually checks the Guest's IDT entry and
303 * transfers it into our entry in "struct lguest": */
167static void set_trap(struct lguest *lg, struct desc_struct *trap, 304static void set_trap(struct lguest *lg, struct desc_struct *trap,
168 unsigned int num, u32 lo, u32 hi) 305 unsigned int num, u32 lo, u32 hi)
169{ 306{
170 u8 type = idt_type(lo, hi); 307 u8 type = idt_type(lo, hi);
171 308
309 /* We zero-out a not-present entry */
172 if (!idt_present(lo, hi)) { 310 if (!idt_present(lo, hi)) {
173 trap->a = trap->b = 0; 311 trap->a = trap->b = 0;
174 return; 312 return;
175 } 313 }
176 314
315 /* We only support interrupt and trap gates. */
177 if (type != 0xE && type != 0xF) 316 if (type != 0xE && type != 0xF)
178 kill_guest(lg, "bad IDT type %i", type); 317 kill_guest(lg, "bad IDT type %i", type);
179 318
319 /* We only copy the handler address, present bit, privilege level and
320 * type. The privilege level controls where the trap can be triggered
321 * manually with an "int" instruction. This is usually GUEST_PL,
322 * except for system calls which userspace can use. */
180 trap->a = ((__KERNEL_CS|GUEST_PL)<<16) | (lo&0x0000FFFF); 323 trap->a = ((__KERNEL_CS|GUEST_PL)<<16) | (lo&0x0000FFFF);
181 trap->b = (hi&0xFFFFEF00); 324 trap->b = (hi&0xFFFFEF00);
182} 325}
183 326
327/*H:230 While we're here, dealing with delivering traps and interrupts to the
328 * Guest, we might as well complete the picture: how the Guest tells us where
329 * it wants them to go. This would be simple, except making traps fast
330 * requires some tricks.
331 *
332 * We saw the Guest setting Interrupt Descriptor Table (IDT) entries with the
333 * LHCALL_LOAD_IDT_ENTRY hypercall before: that comes here. */
184void load_guest_idt_entry(struct lguest *lg, unsigned int num, u32 lo, u32 hi) 334void load_guest_idt_entry(struct lguest *lg, unsigned int num, u32 lo, u32 hi)
185{ 335{
186 /* Guest never handles: NMI, doublefault, hypercall, spurious irq. */ 336 /* Guest never handles: NMI, doublefault, spurious interrupt or
337 * hypercall. We ignore when it tries to set them. */
187 if (num == 2 || num == 8 || num == 15 || num == LGUEST_TRAP_ENTRY) 338 if (num == 2 || num == 8 || num == 15 || num == LGUEST_TRAP_ENTRY)
188 return; 339 return;
189 340
341 /* Mark the IDT as changed: next time the Guest runs we'll know we have
342 * to copy this again. */
190 lg->changed |= CHANGED_IDT; 343 lg->changed |= CHANGED_IDT;
344
345 /* The IDT which we keep in "struct lguest" only contains 32 entries
346 * for the traps and LGUEST_IRQS (32) entries for interrupts. We
347 * ignore attempts to set handlers for higher interrupt numbers, except
348 * for the system call "interrupt" at 128: we have a special IDT entry
349 * for that. */
191 if (num < ARRAY_SIZE(lg->idt)) 350 if (num < ARRAY_SIZE(lg->idt))
192 set_trap(lg, &lg->idt[num], num, lo, hi); 351 set_trap(lg, &lg->idt[num], num, lo, hi);
193 else if (num == SYSCALL_VECTOR) 352 else if (num == SYSCALL_VECTOR)
194 set_trap(lg, &lg->syscall_idt, num, lo, hi); 353 set_trap(lg, &lg->syscall_idt, num, lo, hi);
195} 354}
196 355
356/* The default entry for each interrupt points into the Switcher routines which
357 * simply return to the Host. The run_guest() loop will then call
358 * deliver_trap() to bounce it back into the Guest. */
197static void default_idt_entry(struct desc_struct *idt, 359static void default_idt_entry(struct desc_struct *idt,
198 int trap, 360 int trap,
199 const unsigned long handler) 361 const unsigned long handler)
200{ 362{
363 /* A present interrupt gate. */
201 u32 flags = 0x8e00; 364 u32 flags = 0x8e00;
202 365
203 /* They can't "int" into any of them except hypercall. */ 366 /* Set the privilege level on the entry for the hypercall: this allows
367 * the Guest to use the "int" instruction to trigger it. */
204 if (trap == LGUEST_TRAP_ENTRY) 368 if (trap == LGUEST_TRAP_ENTRY)
205 flags |= (GUEST_PL << 13); 369 flags |= (GUEST_PL << 13);
206 370
371 /* Now pack it into the IDT entry in its weird format. */
207 idt->a = (LGUEST_CS<<16) | (handler&0x0000FFFF); 372 idt->a = (LGUEST_CS<<16) | (handler&0x0000FFFF);
208 idt->b = (handler&0xFFFF0000) | flags; 373 idt->b = (handler&0xFFFF0000) | flags;
209} 374}
210 375
376/* When the Guest first starts, we put default entries into the IDT. */
211void setup_default_idt_entries(struct lguest_ro_state *state, 377void setup_default_idt_entries(struct lguest_ro_state *state,
212 const unsigned long *def) 378 const unsigned long *def)
213{ 379{
@@ -217,19 +383,25 @@ void setup_default_idt_entries(struct lguest_ro_state *state,
217 default_idt_entry(&state->guest_idt[i], i, def[i]); 383 default_idt_entry(&state->guest_idt[i], i, def[i]);
218} 384}
219 385
386/*H:240 We don't use the IDT entries in the "struct lguest" directly, instead
387 * we copy them into the IDT which we've set up for Guests on this CPU, just
388 * before we run the Guest. This routine does that copy. */
220void copy_traps(const struct lguest *lg, struct desc_struct *idt, 389void copy_traps(const struct lguest *lg, struct desc_struct *idt,
221 const unsigned long *def) 390 const unsigned long *def)
222{ 391{
223 unsigned int i; 392 unsigned int i;
224 393
225 /* All hardware interrupts are same whatever the guest: only the 394 /* We can simply copy the direct traps, otherwise we use the default
226 * traps might be different. */ 395 * ones in the Switcher: they will return to the Host. */
227 for (i = 0; i < FIRST_EXTERNAL_VECTOR; i++) { 396 for (i = 0; i < FIRST_EXTERNAL_VECTOR; i++) {
228 if (direct_trap(lg, &lg->idt[i], i)) 397 if (direct_trap(lg, &lg->idt[i], i))
229 idt[i] = lg->idt[i]; 398 idt[i] = lg->idt[i];
230 else 399 else
231 default_idt_entry(&idt[i], i, def[i]); 400 default_idt_entry(&idt[i], i, def[i]);
232 } 401 }
402
403 /* Don't forget the system call trap! The IDT entries for other
404 * interupts never change, so no need to copy them. */
233 i = SYSCALL_VECTOR; 405 i = SYSCALL_VECTOR;
234 if (direct_trap(lg, &lg->syscall_idt, i)) 406 if (direct_trap(lg, &lg->syscall_idt, i))
235 idt[i] = lg->syscall_idt; 407 idt[i] = lg->syscall_idt;
diff --git a/drivers/lguest/io.c b/drivers/lguest/io.c
index c8eb79266991..ea68613b43f6 100644
--- a/drivers/lguest/io.c
+++ b/drivers/lguest/io.c
@@ -1,5 +1,9 @@
1/* Simple I/O model for guests, based on shared memory. 1/*P:300 The I/O mechanism in lguest is simple yet flexible, allowing the Guest
2 * Copyright (C) 2006 Rusty Russell IBM Corporation 2 * to talk to the Launcher or directly to another Guest. It uses familiar
3 * concepts of DMA and interrupts, plus some neat code stolen from
4 * futexes... :*/
5
6/* Copyright (C) 2006 Rusty Russell IBM Corporation
3 * 7 *
4 * 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
5 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
@@ -23,8 +27,36 @@
23#include <linux/uaccess.h> 27#include <linux/uaccess.h>
24#include "lg.h" 28#include "lg.h"
25 29
30/*L:300
31 * I/O
32 *
33 * Getting data in and out of the Guest is quite an art. There are numerous
34 * ways to do it, and they all suck differently. We try to keep things fairly
35 * close to "real" hardware so our Guest's drivers don't look like an alien
36 * visitation in the middle of the Linux code, and yet make sure that Guests
37 * can talk directly to other Guests, not just the Launcher.
38 *
39 * To do this, the Guest gives us a key when it binds or sends DMA buffers.
40 * The key corresponds to a "physical" address inside the Guest (ie. a virtual
41 * address inside the Launcher process). We don't, however, use this key
42 * directly.
43 *
44 * We want Guests which share memory to be able to DMA to each other: two
45 * Launchers can mmap memory the same file, then the Guests can communicate.
46 * Fortunately, the futex code provides us with a way to get a "union
47 * futex_key" corresponding to the memory lying at a virtual address: if the
48 * two processes share memory, the "union futex_key" for that memory will match
49 * even if the memory is mapped at different addresses in each. So we always
50 * convert the keys to "union futex_key"s to compare them.
51 *
52 * Before we dive into this though, we need to look at another set of helper
53 * routines used throughout the Host kernel code to access Guest memory.
54 :*/
26static struct list_head dma_hash[61]; 55static struct list_head dma_hash[61];
27 56
57/* An unfortunate side effect of the Linux double-linked list implementation is
58 * that there's no good way to statically initialize an array of linked
59 * lists. */
28void lguest_io_init(void) 60void lguest_io_init(void)
29{ 61{
30 unsigned int i; 62 unsigned int i;
@@ -56,6 +88,19 @@ kill:
56 return 0; 88 return 0;
57} 89}
58 90
91/*L:330 This is our hash function, using the wonderful Jenkins hash.
92 *
93 * The futex key is a union with three parts: an unsigned long word, a pointer,
94 * and an int "offset". We could use jhash_2words() which takes three u32s.
95 * (Ok, the hash functions are great: the naming sucks though).
96 *
97 * It's nice to be portable to 64-bit platforms, so we use the more generic
98 * jhash2(), which takes an array of u32, the number of u32s, and an initial
99 * u32 to roll in. This is uglier, but breaks down to almost the same code on
100 * 32-bit platforms like this one.
101 *
102 * We want a position in the array, so we modulo ARRAY_SIZE(dma_hash) (ie. 61).
103 */
59static unsigned int hash(const union futex_key *key) 104static unsigned int hash(const union futex_key *key)
60{ 105{
61 return jhash2((u32*)&key->both.word, 106 return jhash2((u32*)&key->both.word,
@@ -64,6 +109,9 @@ static unsigned int hash(const union futex_key *key)
64 % ARRAY_SIZE(dma_hash); 109 % ARRAY_SIZE(dma_hash);
65} 110}
66 111
112/* This is a convenience routine to compare two keys. It's a much bemoaned C
113 * weakness that it doesn't allow '==' on structures or unions, so we have to
114 * open-code it like this. */
67static inline int key_eq(const union futex_key *a, const union futex_key *b) 115static inline int key_eq(const union futex_key *a, const union futex_key *b)
68{ 116{
69 return (a->both.word == b->both.word 117 return (a->both.word == b->both.word
@@ -71,22 +119,36 @@ static inline int key_eq(const union futex_key *a, const union futex_key *b)
71 && a->both.offset == b->both.offset); 119 && a->both.offset == b->both.offset);
72} 120}
73 121
74/* Must hold read lock on dmainfo owner's current->mm->mmap_sem */ 122/*L:360 OK, when we need to actually free up a Guest's DMA array we do several
123 * things, so we have a convenient function to do it.
124 *
125 * The caller must hold a read lock on dmainfo owner's current->mm->mmap_sem
126 * for the drop_futex_key_refs(). */
75static void unlink_dma(struct lguest_dma_info *dmainfo) 127static void unlink_dma(struct lguest_dma_info *dmainfo)
76{ 128{
129 /* You locked this too, right? */
77 BUG_ON(!mutex_is_locked(&lguest_lock)); 130 BUG_ON(!mutex_is_locked(&lguest_lock));
131 /* This is how we know that the entry is free. */
78 dmainfo->interrupt = 0; 132 dmainfo->interrupt = 0;
133 /* Remove it from the hash table. */
79 list_del(&dmainfo->list); 134 list_del(&dmainfo->list);
135 /* Drop the references we were holding (to the inode or mm). */
80 drop_futex_key_refs(&dmainfo->key); 136 drop_futex_key_refs(&dmainfo->key);
81} 137}
82 138
139/*L:350 This is the routine which we call when the Guest asks to unregister a
140 * DMA array attached to a given key. Returns true if the array was found. */
83static int unbind_dma(struct lguest *lg, 141static int unbind_dma(struct lguest *lg,
84 const union futex_key *key, 142 const union futex_key *key,
85 unsigned long dmas) 143 unsigned long dmas)
86{ 144{
87 int i, ret = 0; 145 int i, ret = 0;
88 146
147 /* We don't bother with the hash table, just look through all this
148 * Guest's DMA arrays. */
89 for (i = 0; i < LGUEST_MAX_DMA; i++) { 149 for (i = 0; i < LGUEST_MAX_DMA; i++) {
150 /* In theory it could have more than one array on the same key,
151 * or one array on multiple keys, so we check both */
90 if (key_eq(key, &lg->dma[i].key) && dmas == lg->dma[i].dmas) { 152 if (key_eq(key, &lg->dma[i].key) && dmas == lg->dma[i].dmas) {
91 unlink_dma(&lg->dma[i]); 153 unlink_dma(&lg->dma[i]);
92 ret = 1; 154 ret = 1;
@@ -96,51 +158,91 @@ static int unbind_dma(struct lguest *lg,
96 return ret; 158 return ret;
97} 159}
98 160
161/*L:340 BIND_DMA: this is the hypercall which sets up an array of "struct
162 * lguest_dma" for receiving I/O.
163 *
164 * The Guest wants to bind an array of "struct lguest_dma"s to a particular key
165 * to receive input. This only happens when the Guest is setting up a new
166 * device, so it doesn't have to be very fast.
167 *
168 * It returns 1 on a successful registration (it can fail if we hit the limit
169 * of registrations for this Guest).
170 */
99int bind_dma(struct lguest *lg, 171int bind_dma(struct lguest *lg,
100 unsigned long ukey, unsigned long dmas, u16 numdmas, u8 interrupt) 172 unsigned long ukey, unsigned long dmas, u16 numdmas, u8 interrupt)
101{ 173{
102 unsigned int i; 174 unsigned int i;
103 int ret = 0; 175 int ret = 0;
104 union futex_key key; 176 union futex_key key;
177 /* Futex code needs the mmap_sem. */
105 struct rw_semaphore *fshared = &current->mm->mmap_sem; 178 struct rw_semaphore *fshared = &current->mm->mmap_sem;
106 179
180 /* Invalid interrupt? (We could kill the guest here). */
107 if (interrupt >= LGUEST_IRQS) 181 if (interrupt >= LGUEST_IRQS)
108 return 0; 182 return 0;
109 183
184 /* We need to grab the Big Lguest Lock, because other Guests may be
185 * trying to look through this Guest's DMAs to send something while
186 * we're doing this. */
110 mutex_lock(&lguest_lock); 187 mutex_lock(&lguest_lock);
111 down_read(fshared); 188 down_read(fshared);
112 if (get_futex_key((u32 __user *)ukey, fshared, &key) != 0) { 189 if (get_futex_key((u32 __user *)ukey, fshared, &key) != 0) {
113 kill_guest(lg, "bad dma key %#lx", ukey); 190 kill_guest(lg, "bad dma key %#lx", ukey);
114 goto unlock; 191 goto unlock;
115 } 192 }
193
194 /* We want to keep this key valid once we drop mmap_sem, so we have to
195 * hold a reference. */
116 get_futex_key_refs(&key); 196 get_futex_key_refs(&key);
117 197
198 /* If the Guest specified an interrupt of 0, that means they want to
199 * unregister this array of "struct lguest_dma"s. */
118 if (interrupt == 0) 200 if (interrupt == 0)
119 ret = unbind_dma(lg, &key, dmas); 201 ret = unbind_dma(lg, &key, dmas);
120 else { 202 else {
203 /* Look through this Guest's dma array for an unused entry. */
121 for (i = 0; i < LGUEST_MAX_DMA; i++) { 204 for (i = 0; i < LGUEST_MAX_DMA; i++) {
205 /* If the interrupt is non-zero, the entry is already
206 * used. */
122 if (lg->dma[i].interrupt) 207 if (lg->dma[i].interrupt)
123 continue; 208 continue;
124 209
210 /* OK, a free one! Fill on our details. */
125 lg->dma[i].dmas = dmas; 211 lg->dma[i].dmas = dmas;
126 lg->dma[i].num_dmas = numdmas; 212 lg->dma[i].num_dmas = numdmas;
127 lg->dma[i].next_dma = 0; 213 lg->dma[i].next_dma = 0;
128 lg->dma[i].key = key; 214 lg->dma[i].key = key;
129 lg->dma[i].guestid = lg->guestid; 215 lg->dma[i].guestid = lg->guestid;
130 lg->dma[i].interrupt = interrupt; 216 lg->dma[i].interrupt = interrupt;
217
218 /* Now we add it to the hash table: the position
219 * depends on the futex key that we got. */
131 list_add(&lg->dma[i].list, &dma_hash[hash(&key)]); 220 list_add(&lg->dma[i].list, &dma_hash[hash(&key)]);
221 /* Success! */
132 ret = 1; 222 ret = 1;
133 goto unlock; 223 goto unlock;
134 } 224 }
135 } 225 }
226 /* If we didn't find a slot to put the key in, drop the reference
227 * again. */
136 drop_futex_key_refs(&key); 228 drop_futex_key_refs(&key);
137unlock: 229unlock:
230 /* Unlock and out. */
138 up_read(fshared); 231 up_read(fshared);
139 mutex_unlock(&lguest_lock); 232 mutex_unlock(&lguest_lock);
140 return ret; 233 return ret;
141} 234}
142 235
143/* lgread from another guest */ 236/*L:385 Note that our routines to access a different Guest's memory are called
237 * lgread_other() and lgwrite_other(): these names emphasize that they are only
238 * used when the Guest is *not* the current Guest.
239 *
240 * The interface for copying from another process's memory is called
241 * access_process_vm(), with a final argument of 0 for a read, and 1 for a
242 * write.
243 *
244 * We need lgread_other() to read the destination Guest's "struct lguest_dma"
245 * array. */
144static int lgread_other(struct lguest *lg, 246static int lgread_other(struct lguest *lg,
145 void *buf, u32 addr, unsigned bytes) 247 void *buf, u32 addr, unsigned bytes)
146{ 248{
@@ -153,7 +255,8 @@ static int lgread_other(struct lguest *lg,
153 return 1; 255 return 1;
154} 256}
155 257
156/* lgwrite to another guest */ 258/* "lgwrite()" to another Guest: used to update the destination "used_len" once
259 * we've transferred data into the buffer. */
157static int lgwrite_other(struct lguest *lg, u32 addr, 260static int lgwrite_other(struct lguest *lg, u32 addr,
158 const void *buf, unsigned bytes) 261 const void *buf, unsigned bytes)
159{ 262{
@@ -166,6 +269,15 @@ static int lgwrite_other(struct lguest *lg, u32 addr,
166 return 1; 269 return 1;
167} 270}
168 271
272/*L:400 This is the generic engine which copies from a source "struct
273 * lguest_dma" from this Guest into another Guest's "struct lguest_dma". The
274 * destination Guest's pages have already been mapped, as contained in the
275 * pages array.
276 *
277 * If you're wondering if there's a nice "copy from one process to another"
278 * routine, so was I. But Linux isn't really set up to copy between two
279 * unrelated processes, so we have to write it ourselves.
280 */
169static u32 copy_data(struct lguest *srclg, 281static u32 copy_data(struct lguest *srclg,
170 const struct lguest_dma *src, 282 const struct lguest_dma *src,
171 const struct lguest_dma *dst, 283 const struct lguest_dma *dst,
@@ -174,33 +286,59 @@ static u32 copy_data(struct lguest *srclg,
174 unsigned int totlen, si, di, srcoff, dstoff; 286 unsigned int totlen, si, di, srcoff, dstoff;
175 void *maddr = NULL; 287 void *maddr = NULL;
176 288
289 /* We return the total length transferred. */
177 totlen = 0; 290 totlen = 0;
291
292 /* We keep indexes into the source and destination "struct lguest_dma",
293 * and an offset within each region. */
178 si = di = 0; 294 si = di = 0;
179 srcoff = dstoff = 0; 295 srcoff = dstoff = 0;
296
297 /* We loop until the source or destination is exhausted. */
180 while (si < LGUEST_MAX_DMA_SECTIONS && src->len[si] 298 while (si < LGUEST_MAX_DMA_SECTIONS && src->len[si]
181 && di < LGUEST_MAX_DMA_SECTIONS && dst->len[di]) { 299 && di < LGUEST_MAX_DMA_SECTIONS && dst->len[di]) {
300 /* We can only transfer the rest of the src buffer, or as much
301 * as will fit into the destination buffer. */
182 u32 len = min(src->len[si] - srcoff, dst->len[di] - dstoff); 302 u32 len = min(src->len[si] - srcoff, dst->len[di] - dstoff);
183 303
304 /* For systems using "highmem" we need to use kmap() to access
305 * the page we want. We often use the same page over and over,
306 * so rather than kmap() it on every loop, we set the maddr
307 * pointer to NULL when we need to move to the next
308 * destination page. */
184 if (!maddr) 309 if (!maddr)
185 maddr = kmap(pages[di]); 310 maddr = kmap(pages[di]);
186 311
187 /* FIXME: This is not completely portable, since 312 /* Copy directly from (this Guest's) source address to the
188 archs do different things for copy_to_user_page. */ 313 * destination Guest's kmap()ed buffer. Note that maddr points
314 * to the start of the page: we need to add the offset of the
315 * destination address and offset within the buffer. */
316
317 /* FIXME: This is not completely portable. I looked at
318 * copy_to_user_page(), and some arch's seem to need special
319 * flushes. x86 is fine. */
189 if (copy_from_user(maddr + (dst->addr[di] + dstoff)%PAGE_SIZE, 320 if (copy_from_user(maddr + (dst->addr[di] + dstoff)%PAGE_SIZE,
190 (void __user *)src->addr[si], len) != 0) { 321 (void __user *)src->addr[si], len) != 0) {
322 /* If a copy failed, it's the source's fault. */
191 kill_guest(srclg, "bad address in sending DMA"); 323 kill_guest(srclg, "bad address in sending DMA");
192 totlen = 0; 324 totlen = 0;
193 break; 325 break;
194 } 326 }
195 327
328 /* Increment the total and src & dst offsets */
196 totlen += len; 329 totlen += len;
197 srcoff += len; 330 srcoff += len;
198 dstoff += len; 331 dstoff += len;
332
333 /* Presumably we reached the end of the src or dest buffers: */
199 if (srcoff == src->len[si]) { 334 if (srcoff == src->len[si]) {
335 /* Move to the next buffer at offset 0 */
200 si++; 336 si++;
201 srcoff = 0; 337 srcoff = 0;
202 } 338 }
203 if (dstoff == dst->len[di]) { 339 if (dstoff == dst->len[di]) {
340 /* We need to unmap that destination page and reset
341 * maddr ready for the next one. */
204 kunmap(pages[di]); 342 kunmap(pages[di]);
205 maddr = NULL; 343 maddr = NULL;
206 di++; 344 di++;
@@ -208,13 +346,15 @@ static u32 copy_data(struct lguest *srclg,
208 } 346 }
209 } 347 }
210 348
349 /* If we still had a page mapped at the end, unmap now. */
211 if (maddr) 350 if (maddr)
212 kunmap(pages[di]); 351 kunmap(pages[di]);
213 352
214 return totlen; 353 return totlen;
215} 354}
216 355
217/* Src is us, ie. current. */ 356/*L:390 This is how we transfer a "struct lguest_dma" from the source Guest
357 * (the current Guest which called SEND_DMA) to another Guest. */
218static u32 do_dma(struct lguest *srclg, const struct lguest_dma *src, 358static u32 do_dma(struct lguest *srclg, const struct lguest_dma *src,
219 struct lguest *dstlg, const struct lguest_dma *dst) 359 struct lguest *dstlg, const struct lguest_dma *dst)
220{ 360{
@@ -222,23 +362,31 @@ static u32 do_dma(struct lguest *srclg, const struct lguest_dma *src,
222 u32 ret; 362 u32 ret;
223 struct page *pages[LGUEST_MAX_DMA_SECTIONS]; 363 struct page *pages[LGUEST_MAX_DMA_SECTIONS];
224 364
365 /* We check that both source and destination "struct lguest_dma"s are
366 * within the bounds of the source and destination Guests */
225 if (!check_dma_list(dstlg, dst) || !check_dma_list(srclg, src)) 367 if (!check_dma_list(dstlg, dst) || !check_dma_list(srclg, src))
226 return 0; 368 return 0;
227 369
228 /* First get the destination pages */ 370 /* We need to map the pages which correspond to each parts of
371 * destination buffer. */
229 for (i = 0; i < LGUEST_MAX_DMA_SECTIONS; i++) { 372 for (i = 0; i < LGUEST_MAX_DMA_SECTIONS; i++) {
230 if (dst->len[i] == 0) 373 if (dst->len[i] == 0)
231 break; 374 break;
375 /* get_user_pages() is a complicated function, especially since
376 * we only want a single page. But it works, and returns the
377 * number of pages. Note that we're holding the destination's
378 * mmap_sem, as get_user_pages() requires. */
232 if (get_user_pages(dstlg->tsk, dstlg->mm, 379 if (get_user_pages(dstlg->tsk, dstlg->mm,
233 dst->addr[i], 1, 1, 1, pages+i, NULL) 380 dst->addr[i], 1, 1, 1, pages+i, NULL)
234 != 1) { 381 != 1) {
382 /* This means the destination gave us a bogus buffer */
235 kill_guest(dstlg, "Error mapping DMA pages"); 383 kill_guest(dstlg, "Error mapping DMA pages");
236 ret = 0; 384 ret = 0;
237 goto drop_pages; 385 goto drop_pages;
238 } 386 }
239 } 387 }
240 388
241 /* Now copy until we run out of src or dst. */ 389 /* Now copy the data until we run out of src or dst. */
242 ret = copy_data(srclg, src, dst, pages); 390 ret = copy_data(srclg, src, dst, pages);
243 391
244drop_pages: 392drop_pages:
@@ -247,6 +395,11 @@ drop_pages:
247 return ret; 395 return ret;
248} 396}
249 397
398/*L:380 Transferring data from one Guest to another is not as simple as I'd
399 * like. We've found the "struct lguest_dma_info" bound to the same address as
400 * the send, we need to copy into it.
401 *
402 * This function returns true if the destination array was empty. */
250static int dma_transfer(struct lguest *srclg, 403static int dma_transfer(struct lguest *srclg,
251 unsigned long udma, 404 unsigned long udma,
252 struct lguest_dma_info *dst) 405 struct lguest_dma_info *dst)
@@ -255,15 +408,23 @@ static int dma_transfer(struct lguest *srclg,
255 struct lguest *dstlg; 408 struct lguest *dstlg;
256 u32 i, dma = 0; 409 u32 i, dma = 0;
257 410
411 /* From the "struct lguest_dma_info" we found in the hash, grab the
412 * Guest. */
258 dstlg = &lguests[dst->guestid]; 413 dstlg = &lguests[dst->guestid];
259 /* Get our dma list. */ 414 /* Read in the source "struct lguest_dma" handed to SEND_DMA. */
260 lgread(srclg, &src_dma, udma, sizeof(src_dma)); 415 lgread(srclg, &src_dma, udma, sizeof(src_dma));
261 416
262 /* We can't deadlock against them dmaing to us, because this 417 /* We need the destination's mmap_sem, and we already hold the source's
263 * is all under the lguest_lock. */ 418 * mmap_sem for the futex key lookup. Normally this would suggest that
419 * we could deadlock if the destination Guest was trying to send to
420 * this source Guest at the same time, which is another reason that all
421 * I/O is done under the big lguest_lock. */
264 down_read(&dstlg->mm->mmap_sem); 422 down_read(&dstlg->mm->mmap_sem);
265 423
424 /* Look through the destination DMA array for an available buffer. */
266 for (i = 0; i < dst->num_dmas; i++) { 425 for (i = 0; i < dst->num_dmas; i++) {
426 /* We keep a "next_dma" pointer which often helps us avoid
427 * looking at lots of previously-filled entries. */
267 dma = (dst->next_dma + i) % dst->num_dmas; 428 dma = (dst->next_dma + i) % dst->num_dmas;
268 if (!lgread_other(dstlg, &dst_dma, 429 if (!lgread_other(dstlg, &dst_dma,
269 dst->dmas + dma * sizeof(struct lguest_dma), 430 dst->dmas + dma * sizeof(struct lguest_dma),
@@ -273,30 +434,46 @@ static int dma_transfer(struct lguest *srclg,
273 if (!dst_dma.used_len) 434 if (!dst_dma.used_len)
274 break; 435 break;
275 } 436 }
437
438 /* If we found a buffer, we do the actual data copy. */
276 if (i != dst->num_dmas) { 439 if (i != dst->num_dmas) {
277 unsigned long used_lenp; 440 unsigned long used_lenp;
278 unsigned int ret; 441 unsigned int ret;
279 442
280 ret = do_dma(srclg, &src_dma, dstlg, &dst_dma); 443 ret = do_dma(srclg, &src_dma, dstlg, &dst_dma);
281 /* Put used length in src. */ 444 /* Put used length in the source "struct lguest_dma"'s used_len
445 * field. It's a little tricky to figure out where that is,
446 * though. */
282 lgwrite_u32(srclg, 447 lgwrite_u32(srclg,
283 udma+offsetof(struct lguest_dma, used_len), ret); 448 udma+offsetof(struct lguest_dma, used_len), ret);
449 /* Tranferring 0 bytes is OK if the source buffer was empty. */
284 if (ret == 0 && src_dma.len[0] != 0) 450 if (ret == 0 && src_dma.len[0] != 0)
285 goto fail; 451 goto fail;
286 452
287 /* Make sure destination sees contents before length. */ 453 /* The destination Guest might be running on a different CPU:
454 * we have to make sure that it will see the "used_len" field
455 * change to non-zero *after* it sees the data we copied into
456 * the buffer. Hence a write memory barrier. */
288 wmb(); 457 wmb();
458 /* Figuring out where the destination's used_len field for this
459 * "struct lguest_dma" in the array is also a little ugly. */
289 used_lenp = dst->dmas 460 used_lenp = dst->dmas
290 + dma * sizeof(struct lguest_dma) 461 + dma * sizeof(struct lguest_dma)
291 + offsetof(struct lguest_dma, used_len); 462 + offsetof(struct lguest_dma, used_len);
292 lgwrite_other(dstlg, used_lenp, &ret, sizeof(ret)); 463 lgwrite_other(dstlg, used_lenp, &ret, sizeof(ret));
464 /* Move the cursor for next time. */
293 dst->next_dma++; 465 dst->next_dma++;
294 } 466 }
295 up_read(&dstlg->mm->mmap_sem); 467 up_read(&dstlg->mm->mmap_sem);
296 468
297 /* Do this last so dst doesn't simply sleep on lock. */ 469 /* We trigger the destination interrupt, even if the destination was
470 * empty and we didn't transfer anything: this gives them a chance to
471 * wake up and refill. */
298 set_bit(dst->interrupt, dstlg->irqs_pending); 472 set_bit(dst->interrupt, dstlg->irqs_pending);
473 /* Wake up the destination process. */
299 wake_up_process(dstlg->tsk); 474 wake_up_process(dstlg->tsk);
475 /* If we passed the last "struct lguest_dma", the receive had no
476 * buffers left. */
300 return i == dst->num_dmas; 477 return i == dst->num_dmas;
301 478
302fail: 479fail:
@@ -304,6 +481,8 @@ fail:
304 return 0; 481 return 0;
305} 482}
306 483
484/*L:370 This is the counter-side to the BIND_DMA hypercall; the SEND_DMA
485 * hypercall. We find out who's listening, and send to them. */
307void send_dma(struct lguest *lg, unsigned long ukey, unsigned long udma) 486void send_dma(struct lguest *lg, unsigned long ukey, unsigned long udma)
308{ 487{
309 union futex_key key; 488 union futex_key key;
@@ -313,31 +492,43 @@ void send_dma(struct lguest *lg, unsigned long ukey, unsigned long udma)
313again: 492again:
314 mutex_lock(&lguest_lock); 493 mutex_lock(&lguest_lock);
315 down_read(fshared); 494 down_read(fshared);
495 /* Get the futex key for the key the Guest gave us */
316 if (get_futex_key((u32 __user *)ukey, fshared, &key) != 0) { 496 if (get_futex_key((u32 __user *)ukey, fshared, &key) != 0) {
317 kill_guest(lg, "bad sending DMA key"); 497 kill_guest(lg, "bad sending DMA key");
318 goto unlock; 498 goto unlock;
319 } 499 }
320 /* Shared mapping? Look for other guests... */ 500 /* Since the key must be a multiple of 4, the futex key uses the lower
501 * bit of the "offset" field (which would always be 0) to indicate a
502 * mapping which is shared with other processes (ie. Guests). */
321 if (key.shared.offset & 1) { 503 if (key.shared.offset & 1) {
322 struct lguest_dma_info *i; 504 struct lguest_dma_info *i;
505 /* Look through the hash for other Guests. */
323 list_for_each_entry(i, &dma_hash[hash(&key)], list) { 506 list_for_each_entry(i, &dma_hash[hash(&key)], list) {
507 /* Don't send to ourselves. */
324 if (i->guestid == lg->guestid) 508 if (i->guestid == lg->guestid)
325 continue; 509 continue;
326 if (!key_eq(&key, &i->key)) 510 if (!key_eq(&key, &i->key))
327 continue; 511 continue;
328 512
513 /* If dma_transfer() tells us the destination has no
514 * available buffers, we increment "empty". */
329 empty += dma_transfer(lg, udma, i); 515 empty += dma_transfer(lg, udma, i);
330 break; 516 break;
331 } 517 }
518 /* If the destination is empty, we release our locks and
519 * give the destination Guest a brief chance to restock. */
332 if (empty == 1) { 520 if (empty == 1) {
333 /* Give any recipients one chance to restock. */ 521 /* Give any recipients one chance to restock. */
334 up_read(&current->mm->mmap_sem); 522 up_read(&current->mm->mmap_sem);
335 mutex_unlock(&lguest_lock); 523 mutex_unlock(&lguest_lock);
524 /* Next time, we won't try again. */
336 empty++; 525 empty++;
337 goto again; 526 goto again;
338 } 527 }
339 } else { 528 } else {
340 /* Private mapping: tell our userspace. */ 529 /* Private mapping: Guest is sending to its Launcher. We set
530 * the "dma_is_pending" flag so that the main loop will exit
531 * and the Launcher's read() from /dev/lguest will return. */
341 lg->dma_is_pending = 1; 532 lg->dma_is_pending = 1;
342 lg->pending_dma = udma; 533 lg->pending_dma = udma;
343 lg->pending_key = ukey; 534 lg->pending_key = ukey;
@@ -346,6 +537,7 @@ unlock:
346 up_read(fshared); 537 up_read(fshared);
347 mutex_unlock(&lguest_lock); 538 mutex_unlock(&lguest_lock);
348} 539}
540/*:*/
349 541
350void release_all_dma(struct lguest *lg) 542void release_all_dma(struct lguest *lg)
351{ 543{
@@ -361,7 +553,18 @@ void release_all_dma(struct lguest *lg)
361 up_read(&lg->mm->mmap_sem); 553 up_read(&lg->mm->mmap_sem);
362} 554}
363 555
364/* Userspace wants a dma buffer from this guest. */ 556/*M:007 We only return a single DMA buffer to the Launcher, but it would be
557 * more efficient to return a pointer to the entire array of DMA buffers, which
558 * it can cache and choose one whenever it wants.
559 *
560 * Currently the Launcher uses a write to /dev/lguest, and the return value is
561 * the address of the DMA structure with the interrupt number placed in
562 * dma->used_len. If we wanted to return the entire array, we need to return
563 * the address, array size and interrupt number: this seems to require an
564 * ioctl(). :*/
565
566/*L:320 This routine looks for a DMA buffer registered by the Guest on the
567 * given key (using the BIND_DMA hypercall). */
365unsigned long get_dma_buffer(struct lguest *lg, 568unsigned long get_dma_buffer(struct lguest *lg,
366 unsigned long ukey, unsigned long *interrupt) 569 unsigned long ukey, unsigned long *interrupt)
367{ 570{
@@ -370,15 +573,29 @@ unsigned long get_dma_buffer(struct lguest *lg,
370 struct lguest_dma_info *i; 573 struct lguest_dma_info *i;
371 struct rw_semaphore *fshared = &current->mm->mmap_sem; 574 struct rw_semaphore *fshared = &current->mm->mmap_sem;
372 575
576 /* Take the Big Lguest Lock to stop other Guests sending this Guest DMA
577 * at the same time. */
373 mutex_lock(&lguest_lock); 578 mutex_lock(&lguest_lock);
579 /* To match between Guests sharing the same underlying memory we steal
580 * code from the futex infrastructure. This requires that we hold the
581 * "mmap_sem" for our process (the Launcher), and pass it to the futex
582 * code. */
374 down_read(fshared); 583 down_read(fshared);
584
585 /* This can fail if it's not a valid address, or if the address is not
586 * divisible by 4 (the futex code needs that, we don't really). */
375 if (get_futex_key((u32 __user *)ukey, fshared, &key) != 0) { 587 if (get_futex_key((u32 __user *)ukey, fshared, &key) != 0) {
376 kill_guest(lg, "bad registered DMA buffer"); 588 kill_guest(lg, "bad registered DMA buffer");
377 goto unlock; 589 goto unlock;
378 } 590 }
591 /* Search the hash table for matching entries (the Launcher can only
592 * send to its own Guest for the moment, so the entry must be for this
593 * Guest) */
379 list_for_each_entry(i, &dma_hash[hash(&key)], list) { 594 list_for_each_entry(i, &dma_hash[hash(&key)], list) {
380 if (key_eq(&key, &i->key) && i->guestid == lg->guestid) { 595 if (key_eq(&key, &i->key) && i->guestid == lg->guestid) {
381 unsigned int j; 596 unsigned int j;
597 /* Look through the registered DMA array for an
598 * available buffer. */
382 for (j = 0; j < i->num_dmas; j++) { 599 for (j = 0; j < i->num_dmas; j++) {
383 struct lguest_dma dma; 600 struct lguest_dma dma;
384 601
@@ -387,6 +604,8 @@ unsigned long get_dma_buffer(struct lguest *lg,
387 if (dma.used_len == 0) 604 if (dma.used_len == 0)
388 break; 605 break;
389 } 606 }
607 /* Store the interrupt the Guest wants when the buffer
608 * is used. */
390 *interrupt = i->interrupt; 609 *interrupt = i->interrupt;
391 break; 610 break;
392 } 611 }
@@ -396,4 +615,12 @@ unlock:
396 mutex_unlock(&lguest_lock); 615 mutex_unlock(&lguest_lock);
397 return ret; 616 return ret;
398} 617}
618/*:*/
399 619
620/*L:410 This really has completed the Launcher. Not only have we now finished
621 * the longest chapter in our journey, but this also means we are over halfway
622 * through!
623 *
624 * Enough prevaricating around the bush: it is time for us to dive into the
625 * core of the Host, in "make Host".
626 */
diff --git a/drivers/lguest/lg.h b/drivers/lguest/lg.h
index 3e2ddfbc816e..64f0abed317c 100644
--- a/drivers/lguest/lg.h
+++ b/drivers/lguest/lg.h
@@ -58,9 +58,18 @@ struct lguest_dma_info
58 u8 interrupt; /* 0 when not registered */ 58 u8 interrupt; /* 0 when not registered */
59}; 59};
60 60
61/* We have separate types for the guest's ptes & pgds and the shadow ptes & 61/*H:310 The page-table code owes a great debt of gratitude to Andi Kleen. He
62 * pgds. Since this host might use three-level pagetables and the guest and 62 * reviewed the original code which used "u32" for all page table entries, and
63 * shadow pagetables don't, we can't use the normal pte_t/pgd_t. */ 63 * insisted that it would be far clearer with explicit typing. I thought it
64 * was overkill, but he was right: it is much clearer than it was before.
65 *
66 * We have separate types for the Guest's ptes & pgds and the shadow ptes &
67 * pgds. There's already a Linux type for these (pte_t and pgd_t) but they
68 * change depending on kernel config options (PAE). */
69
70/* Each entry is identical: lower 12 bits of flags and upper 20 bits for the
71 * "page frame number" (0 == first physical page, etc). They are different
72 * types so the compiler will warn us if we mix them improperly. */
64typedef union { 73typedef union {
65 struct { unsigned flags:12, pfn:20; }; 74 struct { unsigned flags:12, pfn:20; };
66 struct { unsigned long val; } raw; 75 struct { unsigned long val; } raw;
@@ -77,8 +86,12 @@ typedef union {
77 struct { unsigned flags:12, pfn:20; }; 86 struct { unsigned flags:12, pfn:20; };
78 struct { unsigned long val; } raw; 87 struct { unsigned long val; } raw;
79} gpte_t; 88} gpte_t;
89
90/* We have two convenient macros to convert a "raw" value as handed to us by
91 * the Guest into the correct Guest PGD or PTE type. */
80#define mkgpte(_val) ((gpte_t){.raw.val = _val}) 92#define mkgpte(_val) ((gpte_t){.raw.val = _val})
81#define mkgpgd(_val) ((gpgd_t){.raw.val = _val}) 93#define mkgpgd(_val) ((gpgd_t){.raw.val = _val})
94/*:*/
82 95
83struct pgdir 96struct pgdir
84{ 97{
@@ -243,7 +256,32 @@ unsigned long get_dma_buffer(struct lguest *lg, unsigned long key,
243 256
244/* hypercalls.c: */ 257/* hypercalls.c: */
245void do_hypercalls(struct lguest *lg); 258void do_hypercalls(struct lguest *lg);
246 259void write_timestamp(struct lguest *lg);
260
261/*L:035
262 * Let's step aside for the moment, to study one important routine that's used
263 * widely in the Host code.
264 *
265 * There are many cases where the Guest does something invalid, like pass crap
266 * to a hypercall. Since only the Guest kernel can make hypercalls, it's quite
267 * acceptable to simply terminate the Guest and give the Launcher a nicely
268 * formatted reason. It's also simpler for the Guest itself, which doesn't
269 * need to check most hypercalls for "success"; if you're still running, it
270 * succeeded.
271 *
272 * Once this is called, the Guest will never run again, so most Host code can
273 * call this then continue as if nothing had happened. This means many
274 * functions don't have to explicitly return an error code, which keeps the
275 * code simple.
276 *
277 * It also means that this can be called more than once: only the first one is
278 * remembered. The only trick is that we still need to kill the Guest even if
279 * we can't allocate memory to store the reason. Linux has a neat way of
280 * packing error codes into invalid pointers, so we use that here.
281 *
282 * Like any macro which uses an "if", it is safely wrapped in a run-once "do {
283 * } while(0)".
284 */
247#define kill_guest(lg, fmt...) \ 285#define kill_guest(lg, fmt...) \
248do { \ 286do { \
249 if (!(lg)->dead) { \ 287 if (!(lg)->dead) { \
@@ -252,6 +290,7 @@ do { \
252 (lg)->dead = ERR_PTR(-ENOMEM); \ 290 (lg)->dead = ERR_PTR(-ENOMEM); \
253 } \ 291 } \
254} while(0) 292} while(0)
293/* (End of aside) :*/
255 294
256static inline unsigned long guest_pa(struct lguest *lg, unsigned long vaddr) 295static inline unsigned long guest_pa(struct lguest *lg, unsigned long vaddr)
257{ 296{
diff --git a/drivers/lguest/lguest.c b/drivers/lguest/lguest.c
index 18dade06d4a9..1bc1546c7fd0 100644
--- a/drivers/lguest/lguest.c
+++ b/drivers/lguest/lguest.c
@@ -1,6 +1,32 @@
1/* 1/*P:010
2 * Lguest specific paravirt-ops implementation 2 * A hypervisor allows multiple Operating Systems to run on a single machine.
3 * To quote David Wheeler: "Any problem in computer science can be solved with
4 * another layer of indirection."
5 *
6 * We keep things simple in two ways. First, we start with a normal Linux
7 * kernel and insert a module (lg.ko) which allows us to run other Linux
8 * kernels the same way we'd run processes. We call the first kernel the Host,
9 * and the others the Guests. The program which sets up and configures Guests
10 * (such as the example in Documentation/lguest/lguest.c) is called the
11 * Launcher.
12 *
13 * Secondly, we only run specially modified Guests, not normal kernels. When
14 * you set CONFIG_LGUEST to 'y' or 'm', this automatically sets
15 * CONFIG_LGUEST_GUEST=y, which compiles this file into the kernel so it knows
16 * how to be a Guest. This means that you can use the same kernel you boot
17 * normally (ie. as a Host) as a Guest.
3 * 18 *
19 * These Guests know that they cannot do privileged operations, such as disable
20 * interrupts, and that they have to ask the Host to do such things explicitly.
21 * This file consists of all the replacements for such low-level native
22 * hardware operations: these special Guest versions call the Host.
23 *
24 * So how does the kernel know it's a Guest? The Guest starts at a special
25 * entry point marked with a magic string, which sets up a few things then
26 * calls here. We replace the native functions in "struct paravirt_ops"
27 * with our Guest versions, then boot like normal. :*/
28
29/*
4 * Copyright (C) 2006, Rusty Russell <rusty@rustcorp.com.au> IBM Corporation. 30 * Copyright (C) 2006, Rusty Russell <rusty@rustcorp.com.au> IBM Corporation.
5 * 31 *
6 * This program is free software; you can redistribute it and/or modify 32 * This program is free software; you can redistribute it and/or modify
@@ -40,6 +66,12 @@
40#include <asm/mce.h> 66#include <asm/mce.h>
41#include <asm/io.h> 67#include <asm/io.h>
42 68
69/*G:010 Welcome to the Guest!
70 *
71 * The Guest in our tale is a simple creature: identical to the Host but
72 * behaving in simplified but equivalent ways. In particular, the Guest is the
73 * same kernel as the Host (or at least, built from the same source code). :*/
74
43/* Declarations for definitions in lguest_guest.S */ 75/* Declarations for definitions in lguest_guest.S */
44extern char lguest_noirq_start[], lguest_noirq_end[]; 76extern char lguest_noirq_start[], lguest_noirq_end[];
45extern const char lgstart_cli[], lgend_cli[]; 77extern const char lgstart_cli[], lgend_cli[];
@@ -58,7 +90,26 @@ struct lguest_data lguest_data = {
58struct lguest_device_desc *lguest_devices; 90struct lguest_device_desc *lguest_devices;
59static cycle_t clock_base; 91static cycle_t clock_base;
60 92
61static enum paravirt_lazy_mode lazy_mode; 93/*G:035 Notice the lazy_hcall() above, rather than hcall(). This is our first
94 * real optimization trick!
95 *
96 * When lazy_mode is set, it means we're allowed to defer all hypercalls and do
97 * them as a batch when lazy_mode is eventually turned off. Because hypercalls
98 * are reasonably expensive, batching them up makes sense. For example, a
99 * large mmap might update dozens of page table entries: that code calls
100 * lguest_lazy_mode(PARAVIRT_LAZY_MMU), does the dozen updates, then calls
101 * lguest_lazy_mode(PARAVIRT_LAZY_NONE).
102 *
103 * So, when we're in lazy mode, we call async_hypercall() to store the call for
104 * future processing. When lazy mode is turned off we issue a hypercall to
105 * flush the stored calls.
106 *
107 * There's also a hack where "mode" is set to "PARAVIRT_LAZY_FLUSH" which
108 * indicates we're to flush any outstanding calls immediately. This is used
109 * when an interrupt handler does a kmap_atomic(): the page table changes must
110 * happen immediately even if we're in the middle of a batch. Usually we're
111 * not, though, so there's nothing to do. */
112static enum paravirt_lazy_mode lazy_mode; /* Note: not SMP-safe! */
62static void lguest_lazy_mode(enum paravirt_lazy_mode mode) 113static void lguest_lazy_mode(enum paravirt_lazy_mode mode)
63{ 114{
64 if (mode == PARAVIRT_LAZY_FLUSH) { 115 if (mode == PARAVIRT_LAZY_FLUSH) {
@@ -82,6 +133,16 @@ static void lazy_hcall(unsigned long call,
82 async_hcall(call, arg1, arg2, arg3); 133 async_hcall(call, arg1, arg2, arg3);
83} 134}
84 135
136/* async_hcall() is pretty simple: I'm quite proud of it really. We have a
137 * ring buffer of stored hypercalls which the Host will run though next time we
138 * do a normal hypercall. Each entry in the ring has 4 slots for the hypercall
139 * arguments, and a "hcall_status" word which is 0 if the call is ready to go,
140 * and 255 once the Host has finished with it.
141 *
142 * If we come around to a slot which hasn't been finished, then the table is
143 * full and we just make the hypercall directly. This has the nice side
144 * effect of causing the Host to run all the stored calls in the ring buffer
145 * which empties it for next time! */
85void async_hcall(unsigned long call, 146void async_hcall(unsigned long call,
86 unsigned long arg1, unsigned long arg2, unsigned long arg3) 147 unsigned long arg1, unsigned long arg2, unsigned long arg3)
87{ 148{
@@ -89,6 +150,9 @@ void async_hcall(unsigned long call,
89 static unsigned int next_call; 150 static unsigned int next_call;
90 unsigned long flags; 151 unsigned long flags;
91 152
153 /* Disable interrupts if not already disabled: we don't want an
154 * interrupt handler making a hypercall while we're already doing
155 * one! */
92 local_irq_save(flags); 156 local_irq_save(flags);
93 if (lguest_data.hcall_status[next_call] != 0xFF) { 157 if (lguest_data.hcall_status[next_call] != 0xFF) {
94 /* Table full, so do normal hcall which will flush table. */ 158 /* Table full, so do normal hcall which will flush table. */
@@ -98,7 +162,7 @@ void async_hcall(unsigned long call,
98 lguest_data.hcalls[next_call].edx = arg1; 162 lguest_data.hcalls[next_call].edx = arg1;
99 lguest_data.hcalls[next_call].ebx = arg2; 163 lguest_data.hcalls[next_call].ebx = arg2;
100 lguest_data.hcalls[next_call].ecx = arg3; 164 lguest_data.hcalls[next_call].ecx = arg3;
101 /* Make sure host sees arguments before "valid" flag. */ 165 /* Arguments must all be written before we mark it to go */
102 wmb(); 166 wmb();
103 lguest_data.hcall_status[next_call] = 0; 167 lguest_data.hcall_status[next_call] = 0;
104 if (++next_call == LHCALL_RING_SIZE) 168 if (++next_call == LHCALL_RING_SIZE)
@@ -106,9 +170,14 @@ void async_hcall(unsigned long call,
106 } 170 }
107 local_irq_restore(flags); 171 local_irq_restore(flags);
108} 172}
173/*:*/
109 174
175/* Wrappers for the SEND_DMA and BIND_DMA hypercalls. This is mainly because
176 * Jeff Garzik complained that __pa() should never appear in drivers, and this
177 * helps remove most of them. But also, it wraps some ugliness. */
110void lguest_send_dma(unsigned long key, struct lguest_dma *dma) 178void lguest_send_dma(unsigned long key, struct lguest_dma *dma)
111{ 179{
180 /* The hcall might not write this if something goes wrong */
112 dma->used_len = 0; 181 dma->used_len = 0;
113 hcall(LHCALL_SEND_DMA, key, __pa(dma), 0); 182 hcall(LHCALL_SEND_DMA, key, __pa(dma), 0);
114} 183}
@@ -116,11 +185,16 @@ void lguest_send_dma(unsigned long key, struct lguest_dma *dma)
116int lguest_bind_dma(unsigned long key, struct lguest_dma *dmas, 185int lguest_bind_dma(unsigned long key, struct lguest_dma *dmas,
117 unsigned int num, u8 irq) 186 unsigned int num, u8 irq)
118{ 187{
188 /* This is the only hypercall which actually wants 5 arguments, and we
189 * only support 4. Fortunately the interrupt number is always less
190 * than 256, so we can pack it with the number of dmas in the final
191 * argument. */
119 if (!hcall(LHCALL_BIND_DMA, key, __pa(dmas), (num << 8) | irq)) 192 if (!hcall(LHCALL_BIND_DMA, key, __pa(dmas), (num << 8) | irq))
120 return -ENOMEM; 193 return -ENOMEM;
121 return 0; 194 return 0;
122} 195}
123 196
197/* Unbinding is the same hypercall as binding, but with 0 num & irq. */
124void lguest_unbind_dma(unsigned long key, struct lguest_dma *dmas) 198void lguest_unbind_dma(unsigned long key, struct lguest_dma *dmas)
125{ 199{
126 hcall(LHCALL_BIND_DMA, key, __pa(dmas), 0); 200 hcall(LHCALL_BIND_DMA, key, __pa(dmas), 0);
@@ -138,35 +212,73 @@ void lguest_unmap(void *addr)
138 iounmap((__force void __iomem *)addr); 212 iounmap((__force void __iomem *)addr);
139} 213}
140 214
215/*G:033
216 * Here are our first native-instruction replacements: four functions for
217 * interrupt control.
218 *
219 * The simplest way of implementing these would be to have "turn interrupts
220 * off" and "turn interrupts on" hypercalls. Unfortunately, this is too slow:
221 * these are by far the most commonly called functions of those we override.
222 *
223 * So instead we keep an "irq_enabled" field inside our "struct lguest_data",
224 * which the Guest can update with a single instruction. The Host knows to
225 * check there when it wants to deliver an interrupt.
226 */
227
228/* save_flags() is expected to return the processor state (ie. "eflags"). The
229 * eflags word contains all kind of stuff, but in practice Linux only cares
230 * about the interrupt flag. Our "save_flags()" just returns that. */
141static unsigned long save_fl(void) 231static unsigned long save_fl(void)
142{ 232{
143 return lguest_data.irq_enabled; 233 return lguest_data.irq_enabled;
144} 234}
145 235
236/* "restore_flags" just sets the flags back to the value given. */
146static void restore_fl(unsigned long flags) 237static void restore_fl(unsigned long flags)
147{ 238{
148 /* FIXME: Check if interrupt pending... */
149 lguest_data.irq_enabled = flags; 239 lguest_data.irq_enabled = flags;
150} 240}
151 241
242/* Interrupts go off... */
152static void irq_disable(void) 243static void irq_disable(void)
153{ 244{
154 lguest_data.irq_enabled = 0; 245 lguest_data.irq_enabled = 0;
155} 246}
156 247
248/* Interrupts go on... */
157static void irq_enable(void) 249static void irq_enable(void)
158{ 250{
159 /* FIXME: Check if interrupt pending... */
160 lguest_data.irq_enabled = X86_EFLAGS_IF; 251 lguest_data.irq_enabled = X86_EFLAGS_IF;
161} 252}
162 253/*:*/
254/*M:003 Note that we don't check for outstanding interrupts when we re-enable
255 * them (or when we unmask an interrupt). This seems to work for the moment,
256 * since interrupts are rare and we'll just get the interrupt on the next timer
257 * tick, but when we turn on CONFIG_NO_HZ, we should revisit this. One way
258 * would be to put the "irq_enabled" field in a page by itself, and have the
259 * Host write-protect it when an interrupt comes in when irqs are disabled.
260 * There will then be a page fault as soon as interrupts are re-enabled. :*/
261
262/*G:034
263 * The Interrupt Descriptor Table (IDT).
264 *
265 * The IDT tells the processor what to do when an interrupt comes in. Each
266 * entry in the table is a 64-bit descriptor: this holds the privilege level,
267 * address of the handler, and... well, who cares? The Guest just asks the
268 * Host to make the change anyway, because the Host controls the real IDT.
269 */
163static void lguest_write_idt_entry(struct desc_struct *dt, 270static void lguest_write_idt_entry(struct desc_struct *dt,
164 int entrynum, u32 low, u32 high) 271 int entrynum, u32 low, u32 high)
165{ 272{
273 /* Keep the local copy up to date. */
166 write_dt_entry(dt, entrynum, low, high); 274 write_dt_entry(dt, entrynum, low, high);
275 /* Tell Host about this new entry. */
167 hcall(LHCALL_LOAD_IDT_ENTRY, entrynum, low, high); 276 hcall(LHCALL_LOAD_IDT_ENTRY, entrynum, low, high);
168} 277}
169 278
279/* Changing to a different IDT is very rare: we keep the IDT up-to-date every
280 * time it is written, so we can simply loop through all entries and tell the
281 * Host about them. */
170static void lguest_load_idt(const struct Xgt_desc_struct *desc) 282static void lguest_load_idt(const struct Xgt_desc_struct *desc)
171{ 283{
172 unsigned int i; 284 unsigned int i;
@@ -176,12 +288,29 @@ static void lguest_load_idt(const struct Xgt_desc_struct *desc)
176 hcall(LHCALL_LOAD_IDT_ENTRY, i, idt[i].a, idt[i].b); 288 hcall(LHCALL_LOAD_IDT_ENTRY, i, idt[i].a, idt[i].b);
177} 289}
178 290
291/*
292 * The Global Descriptor Table.
293 *
294 * The Intel architecture defines another table, called the Global Descriptor
295 * Table (GDT). You tell the CPU where it is (and its size) using the "lgdt"
296 * instruction, and then several other instructions refer to entries in the
297 * table. There are three entries which the Switcher needs, so the Host simply
298 * controls the entire thing and the Guest asks it to make changes using the
299 * LOAD_GDT hypercall.
300 *
301 * This is the opposite of the IDT code where we have a LOAD_IDT_ENTRY
302 * hypercall and use that repeatedly to load a new IDT. I don't think it
303 * really matters, but wouldn't it be nice if they were the same?
304 */
179static void lguest_load_gdt(const struct Xgt_desc_struct *desc) 305static void lguest_load_gdt(const struct Xgt_desc_struct *desc)
180{ 306{
181 BUG_ON((desc->size+1)/8 != GDT_ENTRIES); 307 BUG_ON((desc->size+1)/8 != GDT_ENTRIES);
182 hcall(LHCALL_LOAD_GDT, __pa(desc->address), GDT_ENTRIES, 0); 308 hcall(LHCALL_LOAD_GDT, __pa(desc->address), GDT_ENTRIES, 0);
183} 309}
184 310
311/* For a single GDT entry which changes, we do the lazy thing: alter our GDT,
312 * then tell the Host to reload the entire thing. This operation is so rare
313 * that this naive implementation is reasonable. */
185static void lguest_write_gdt_entry(struct desc_struct *dt, 314static void lguest_write_gdt_entry(struct desc_struct *dt,
186 int entrynum, u32 low, u32 high) 315 int entrynum, u32 low, u32 high)
187{ 316{
@@ -189,19 +318,58 @@ static void lguest_write_gdt_entry(struct desc_struct *dt,
189 hcall(LHCALL_LOAD_GDT, __pa(dt), GDT_ENTRIES, 0); 318 hcall(LHCALL_LOAD_GDT, __pa(dt), GDT_ENTRIES, 0);
190} 319}
191 320
321/* OK, I lied. There are three "thread local storage" GDT entries which change
322 * on every context switch (these three entries are how glibc implements
323 * __thread variables). So we have a hypercall specifically for this case. */
192static void lguest_load_tls(struct thread_struct *t, unsigned int cpu) 324static void lguest_load_tls(struct thread_struct *t, unsigned int cpu)
193{ 325{
194 lazy_hcall(LHCALL_LOAD_TLS, __pa(&t->tls_array), cpu, 0); 326 lazy_hcall(LHCALL_LOAD_TLS, __pa(&t->tls_array), cpu, 0);
195} 327}
328/*:*/
196 329
330/*G:038 That's enough excitement for now, back to ploughing through each of
331 * the paravirt_ops (we're about 1/3 of the way through).
332 *
333 * This is the Local Descriptor Table, another weird Intel thingy. Linux only
334 * uses this for some strange applications like Wine. We don't do anything
335 * here, so they'll get an informative and friendly Segmentation Fault. */
197static void lguest_set_ldt(const void *addr, unsigned entries) 336static void lguest_set_ldt(const void *addr, unsigned entries)
198{ 337{
199} 338}
200 339
340/* This loads a GDT entry into the "Task Register": that entry points to a
341 * structure called the Task State Segment. Some comments scattered though the
342 * kernel code indicate that this used for task switching in ages past, along
343 * with blood sacrifice and astrology.
344 *
345 * Now there's nothing interesting in here that we don't get told elsewhere.
346 * But the native version uses the "ltr" instruction, which makes the Host
347 * complain to the Guest about a Segmentation Fault and it'll oops. So we
348 * override the native version with a do-nothing version. */
201static void lguest_load_tr_desc(void) 349static void lguest_load_tr_desc(void)
202{ 350{
203} 351}
204 352
353/* The "cpuid" instruction is a way of querying both the CPU identity
354 * (manufacturer, model, etc) and its features. It was introduced before the
355 * Pentium in 1993 and keeps getting extended by both Intel and AMD. As you
356 * might imagine, after a decade and a half this treatment, it is now a giant
357 * ball of hair. Its entry in the current Intel manual runs to 28 pages.
358 *
359 * This instruction even it has its own Wikipedia entry. The Wikipedia entry
360 * has been translated into 4 languages. I am not making this up!
361 *
362 * We could get funky here and identify ourselves as "GenuineLguest", but
363 * instead we just use the real "cpuid" instruction. Then I pretty much turned
364 * off feature bits until the Guest booted. (Don't say that: you'll damage
365 * lguest sales!) Shut up, inner voice! (Hey, just pointing out that this is
366 * hardly future proof.) Noone's listening! They don't like you anyway,
367 * parenthetic weirdo!
368 *
369 * Replacing the cpuid so we can turn features off is great for the kernel, but
370 * anyone (including userspace) can just use the raw "cpuid" instruction and
371 * the Host won't even notice since it isn't privileged. So we try not to get
372 * too worked up about it. */
205static void lguest_cpuid(unsigned int *eax, unsigned int *ebx, 373static void lguest_cpuid(unsigned int *eax, unsigned int *ebx,
206 unsigned int *ecx, unsigned int *edx) 374 unsigned int *ecx, unsigned int *edx)
207{ 375{
@@ -214,21 +382,43 @@ static void lguest_cpuid(unsigned int *eax, unsigned int *ebx,
214 *ecx &= 0x00002201; 382 *ecx &= 0x00002201;
215 /* SSE, SSE2, FXSR, MMX, CMOV, CMPXCHG8B, FPU. */ 383 /* SSE, SSE2, FXSR, MMX, CMOV, CMPXCHG8B, FPU. */
216 *edx &= 0x07808101; 384 *edx &= 0x07808101;
217 /* Host wants to know when we flush kernel pages: set PGE. */ 385 /* The Host can do a nice optimization if it knows that the
386 * kernel mappings (addresses above 0xC0000000 or whatever
387 * PAGE_OFFSET is set to) haven't changed. But Linux calls
388 * flush_tlb_user() for both user and kernel mappings unless
389 * the Page Global Enable (PGE) feature bit is set. */
218 *edx |= 0x00002000; 390 *edx |= 0x00002000;
219 break; 391 break;
220 case 0x80000000: 392 case 0x80000000:
221 /* Futureproof this a little: if they ask how much extended 393 /* Futureproof this a little: if they ask how much extended
222 * processor information, limit it to known fields. */ 394 * processor information there is, limit it to known fields. */
223 if (*eax > 0x80000008) 395 if (*eax > 0x80000008)
224 *eax = 0x80000008; 396 *eax = 0x80000008;
225 break; 397 break;
226 } 398 }
227} 399}
228 400
401/* Intel has four control registers, imaginatively named cr0, cr2, cr3 and cr4.
402 * I assume there's a cr1, but it hasn't bothered us yet, so we'll not bother
403 * it. The Host needs to know when the Guest wants to change them, so we have
404 * a whole series of functions like read_cr0() and write_cr0().
405 *
406 * We start with CR0. CR0 allows you to turn on and off all kinds of basic
407 * features, but Linux only really cares about one: the horrifically-named Task
408 * Switched (TS) bit at bit 3 (ie. 8)
409 *
410 * What does the TS bit do? Well, it causes the CPU to trap (interrupt 7) if
411 * the floating point unit is used. Which allows us to restore FPU state
412 * lazily after a task switch, and Linux uses that gratefully, but wouldn't a
413 * name like "FPUTRAP bit" be a little less cryptic?
414 *
415 * We store cr0 (and cr3) locally, because the Host never changes it. The
416 * Guest sometimes wants to read it and we'd prefer not to bother the Host
417 * unnecessarily. */
229static unsigned long current_cr0, current_cr3; 418static unsigned long current_cr0, current_cr3;
230static void lguest_write_cr0(unsigned long val) 419static void lguest_write_cr0(unsigned long val)
231{ 420{
421 /* 8 == TS bit. */
232 lazy_hcall(LHCALL_TS, val & 8, 0, 0); 422 lazy_hcall(LHCALL_TS, val & 8, 0, 0);
233 current_cr0 = val; 423 current_cr0 = val;
234} 424}
@@ -238,17 +428,25 @@ static unsigned long lguest_read_cr0(void)
238 return current_cr0; 428 return current_cr0;
239} 429}
240 430
431/* Intel provided a special instruction to clear the TS bit for people too cool
432 * to use write_cr0() to do it. This "clts" instruction is faster, because all
433 * the vowels have been optimized out. */
241static void lguest_clts(void) 434static void lguest_clts(void)
242{ 435{
243 lazy_hcall(LHCALL_TS, 0, 0, 0); 436 lazy_hcall(LHCALL_TS, 0, 0, 0);
244 current_cr0 &= ~8U; 437 current_cr0 &= ~8U;
245} 438}
246 439
440/* CR2 is the virtual address of the last page fault, which the Guest only ever
441 * reads. The Host kindly writes this into our "struct lguest_data", so we
442 * just read it out of there. */
247static unsigned long lguest_read_cr2(void) 443static unsigned long lguest_read_cr2(void)
248{ 444{
249 return lguest_data.cr2; 445 return lguest_data.cr2;
250} 446}
251 447
448/* CR3 is the current toplevel pagetable page: the principle is the same as
449 * cr0. Keep a local copy, and tell the Host when it changes. */
252static void lguest_write_cr3(unsigned long cr3) 450static void lguest_write_cr3(unsigned long cr3)
253{ 451{
254 lazy_hcall(LHCALL_NEW_PGTABLE, cr3, 0, 0); 452 lazy_hcall(LHCALL_NEW_PGTABLE, cr3, 0, 0);
@@ -260,7 +458,7 @@ static unsigned long lguest_read_cr3(void)
260 return current_cr3; 458 return current_cr3;
261} 459}
262 460
263/* Used to enable/disable PGE, but we don't care. */ 461/* CR4 is used to enable and disable PGE, but we don't care. */
264static unsigned long lguest_read_cr4(void) 462static unsigned long lguest_read_cr4(void)
265{ 463{
266 return 0; 464 return 0;
@@ -270,6 +468,59 @@ static void lguest_write_cr4(unsigned long val)
270{ 468{
271} 469}
272 470
471/*
472 * Page Table Handling.
473 *
474 * Now would be a good time to take a rest and grab a coffee or similarly
475 * relaxing stimulant. The easy parts are behind us, and the trek gradually
476 * winds uphill from here.
477 *
478 * Quick refresher: memory is divided into "pages" of 4096 bytes each. The CPU
479 * maps virtual addresses to physical addresses using "page tables". We could
480 * use one huge index of 1 million entries: each address is 4 bytes, so that's
481 * 1024 pages just to hold the page tables. But since most virtual addresses
482 * are unused, we use a two level index which saves space. The CR3 register
483 * contains the physical address of the top level "page directory" page, which
484 * contains physical addresses of up to 1024 second-level pages. Each of these
485 * second level pages contains up to 1024 physical addresses of actual pages,
486 * or Page Table Entries (PTEs).
487 *
488 * Here's a diagram, where arrows indicate physical addresses:
489 *
490 * CR3 ---> +---------+
491 * | --------->+---------+
492 * | | | PADDR1 |
493 * Top-level | | PADDR2 |
494 * (PMD) page | | |
495 * | | Lower-level |
496 * | | (PTE) page |
497 * | | | |
498 * .... ....
499 *
500 * So to convert a virtual address to a physical address, we look up the top
501 * level, which points us to the second level, which gives us the physical
502 * address of that page. If the top level entry was not present, or the second
503 * level entry was not present, then the virtual address is invalid (we
504 * say "the page was not mapped").
505 *
506 * Put another way, a 32-bit virtual address is divided up like so:
507 *
508 * 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
509 * |<---- 10 bits ---->|<---- 10 bits ---->|<------ 12 bits ------>|
510 * Index into top Index into second Offset within page
511 * page directory page pagetable page
512 *
513 * The kernel spends a lot of time changing both the top-level page directory
514 * and lower-level pagetable pages. The Guest doesn't know physical addresses,
515 * so while it maintains these page tables exactly like normal, it also needs
516 * to keep the Host informed whenever it makes a change: the Host will create
517 * the real page tables based on the Guests'.
518 */
519
520/* The Guest calls this to set a second-level entry (pte), ie. to map a page
521 * into a process' address space. We set the entry then tell the Host the
522 * toplevel and address this corresponds to. The Guest uses one pagetable per
523 * process, so we need to tell the Host which one we're changing (mm->pgd). */
273static void lguest_set_pte_at(struct mm_struct *mm, unsigned long addr, 524static void lguest_set_pte_at(struct mm_struct *mm, unsigned long addr,
274 pte_t *ptep, pte_t pteval) 525 pte_t *ptep, pte_t pteval)
275{ 526{
@@ -277,7 +528,9 @@ static void lguest_set_pte_at(struct mm_struct *mm, unsigned long addr,
277 lazy_hcall(LHCALL_SET_PTE, __pa(mm->pgd), addr, pteval.pte_low); 528 lazy_hcall(LHCALL_SET_PTE, __pa(mm->pgd), addr, pteval.pte_low);
278} 529}
279 530
280/* We only support two-level pagetables at the moment. */ 531/* The Guest calls this to set a top-level entry. Again, we set the entry then
532 * tell the Host which top-level page we changed, and the index of the entry we
533 * changed. */
281static void lguest_set_pmd(pmd_t *pmdp, pmd_t pmdval) 534static void lguest_set_pmd(pmd_t *pmdp, pmd_t pmdval)
282{ 535{
283 *pmdp = pmdval; 536 *pmdp = pmdval;
@@ -285,7 +538,15 @@ static void lguest_set_pmd(pmd_t *pmdp, pmd_t pmdval)
285 (__pa(pmdp)&(PAGE_SIZE-1))/4, 0); 538 (__pa(pmdp)&(PAGE_SIZE-1))/4, 0);
286} 539}
287 540
288/* FIXME: Eliminate all callers of this. */ 541/* There are a couple of legacy places where the kernel sets a PTE, but we
542 * don't know the top level any more. This is useless for us, since we don't
543 * know which pagetable is changing or what address, so we just tell the Host
544 * to forget all of them. Fortunately, this is very rare.
545 *
546 * ... except in early boot when the kernel sets up the initial pagetables,
547 * which makes booting astonishingly slow. So we don't even tell the Host
548 * anything changed until we've done the first page table switch.
549 */
289static void lguest_set_pte(pte_t *ptep, pte_t pteval) 550static void lguest_set_pte(pte_t *ptep, pte_t pteval)
290{ 551{
291 *ptep = pteval; 552 *ptep = pteval;
@@ -294,22 +555,51 @@ static void lguest_set_pte(pte_t *ptep, pte_t pteval)
294 lazy_hcall(LHCALL_FLUSH_TLB, 1, 0, 0); 555 lazy_hcall(LHCALL_FLUSH_TLB, 1, 0, 0);
295} 556}
296 557
558/* Unfortunately for Lguest, the paravirt_ops for page tables were based on
559 * native page table operations. On native hardware you can set a new page
560 * table entry whenever you want, but if you want to remove one you have to do
561 * a TLB flush (a TLB is a little cache of page table entries kept by the CPU).
562 *
563 * So the lguest_set_pte_at() and lguest_set_pmd() functions above are only
564 * called when a valid entry is written, not when it's removed (ie. marked not
565 * present). Instead, this is where we come when the Guest wants to remove a
566 * page table entry: we tell the Host to set that entry to 0 (ie. the present
567 * bit is zero). */
297static void lguest_flush_tlb_single(unsigned long addr) 568static void lguest_flush_tlb_single(unsigned long addr)
298{ 569{
299 /* Simply set it to zero, and it will fault back in. */ 570 /* Simply set it to zero: if it was not, it will fault back in. */
300 lazy_hcall(LHCALL_SET_PTE, current_cr3, addr, 0); 571 lazy_hcall(LHCALL_SET_PTE, current_cr3, addr, 0);
301} 572}
302 573
574/* This is what happens after the Guest has removed a large number of entries.
575 * This tells the Host that any of the page table entries for userspace might
576 * have changed, ie. virtual addresses below PAGE_OFFSET. */
303static void lguest_flush_tlb_user(void) 577static void lguest_flush_tlb_user(void)
304{ 578{
305 lazy_hcall(LHCALL_FLUSH_TLB, 0, 0, 0); 579 lazy_hcall(LHCALL_FLUSH_TLB, 0, 0, 0);
306} 580}
307 581
582/* This is called when the kernel page tables have changed. That's not very
583 * common (unless the Guest is using highmem, which makes the Guest extremely
584 * slow), so it's worth separating this from the user flushing above. */
308static void lguest_flush_tlb_kernel(void) 585static void lguest_flush_tlb_kernel(void)
309{ 586{
310 lazy_hcall(LHCALL_FLUSH_TLB, 1, 0, 0); 587 lazy_hcall(LHCALL_FLUSH_TLB, 1, 0, 0);
311} 588}
312 589
590/*
591 * The Unadvanced Programmable Interrupt Controller.
592 *
593 * This is an attempt to implement the simplest possible interrupt controller.
594 * I spent some time looking though routines like set_irq_chip_and_handler,
595 * set_irq_chip_and_handler_name, set_irq_chip_data and set_phasers_to_stun and
596 * I *think* this is as simple as it gets.
597 *
598 * We can tell the Host what interrupts we want blocked ready for using the
599 * lguest_data.interrupts bitmap, so disabling (aka "masking") them is as
600 * simple as setting a bit. We don't actually "ack" interrupts as such, we
601 * just mask and unmask them. I wonder if we should be cleverer?
602 */
313static void disable_lguest_irq(unsigned int irq) 603static void disable_lguest_irq(unsigned int irq)
314{ 604{
315 set_bit(irq, lguest_data.blocked_interrupts); 605 set_bit(irq, lguest_data.blocked_interrupts);
@@ -318,9 +608,9 @@ static void disable_lguest_irq(unsigned int irq)
318static void enable_lguest_irq(unsigned int irq) 608static void enable_lguest_irq(unsigned int irq)
319{ 609{
320 clear_bit(irq, lguest_data.blocked_interrupts); 610 clear_bit(irq, lguest_data.blocked_interrupts);
321 /* FIXME: If it's pending? */
322} 611}
323 612
613/* This structure describes the lguest IRQ controller. */
324static struct irq_chip lguest_irq_controller = { 614static struct irq_chip lguest_irq_controller = {
325 .name = "lguest", 615 .name = "lguest",
326 .mask = disable_lguest_irq, 616 .mask = disable_lguest_irq,
@@ -328,6 +618,10 @@ static struct irq_chip lguest_irq_controller = {
328 .unmask = enable_lguest_irq, 618 .unmask = enable_lguest_irq,
329}; 619};
330 620
621/* This sets up the Interrupt Descriptor Table (IDT) entry for each hardware
622 * interrupt (except 128, which is used for system calls), and then tells the
623 * Linux infrastructure that each interrupt is controlled by our level-based
624 * lguest interrupt controller. */
331static void __init lguest_init_IRQ(void) 625static void __init lguest_init_IRQ(void)
332{ 626{
333 unsigned int i; 627 unsigned int i;
@@ -340,20 +634,51 @@ static void __init lguest_init_IRQ(void)
340 handle_level_irq); 634 handle_level_irq);
341 } 635 }
342 } 636 }
637 /* This call is required to set up for 4k stacks, where we have
638 * separate stacks for hard and soft interrupts. */
343 irq_ctx_init(smp_processor_id()); 639 irq_ctx_init(smp_processor_id());
344} 640}
345 641
642/*
643 * Time.
644 *
645 * It would be far better for everyone if the Guest had its own clock, but
646 * until then the Host gives us the time on every interrupt.
647 */
346static unsigned long lguest_get_wallclock(void) 648static unsigned long lguest_get_wallclock(void)
347{ 649{
348 return hcall(LHCALL_GET_WALLCLOCK, 0, 0, 0); 650 return lguest_data.time.tv_sec;
349} 651}
350 652
351static cycle_t lguest_clock_read(void) 653static cycle_t lguest_clock_read(void)
352{ 654{
655 unsigned long sec, nsec;
656
657 /* If the Host tells the TSC speed, we can trust that. */
353 if (lguest_data.tsc_khz) 658 if (lguest_data.tsc_khz)
354 return native_read_tsc(); 659 return native_read_tsc();
355 else 660
356 return jiffies; 661 /* If we can't use the TSC, we read the time value written by the Host.
662 * Since it's in two parts (seconds and nanoseconds), we risk reading
663 * it just as it's changing from 99 & 0.999999999 to 100 and 0, and
664 * getting 99 and 0. As Linux tends to come apart under the stress of
665 * time travel, we must be careful: */
666 do {
667 /* First we read the seconds part. */
668 sec = lguest_data.time.tv_sec;
669 /* This read memory barrier tells the compiler and the CPU that
670 * this can't be reordered: we have to complete the above
671 * before going on. */
672 rmb();
673 /* Now we read the nanoseconds part. */
674 nsec = lguest_data.time.tv_nsec;
675 /* Make sure we've done that. */
676 rmb();
677 /* Now if the seconds part has changed, try again. */
678 } while (unlikely(lguest_data.time.tv_sec != sec));
679
680 /* Our non-TSC clock is in real nanoseconds. */
681 return sec*1000000000ULL + nsec;
357} 682}
358 683
359/* This is what we tell the kernel is our clocksource. */ 684/* This is what we tell the kernel is our clocksource. */
@@ -361,8 +686,11 @@ static struct clocksource lguest_clock = {
361 .name = "lguest", 686 .name = "lguest",
362 .rating = 400, 687 .rating = 400,
363 .read = lguest_clock_read, 688 .read = lguest_clock_read,
689 .mask = CLOCKSOURCE_MASK(64),
690 .mult = 1,
364}; 691};
365 692
693/* The "scheduler clock" is just our real clock, adjusted to start at zero */
366static unsigned long long lguest_sched_clock(void) 694static unsigned long long lguest_sched_clock(void)
367{ 695{
368 return cyc2ns(&lguest_clock, lguest_clock_read() - clock_base); 696 return cyc2ns(&lguest_clock, lguest_clock_read() - clock_base);
@@ -428,34 +756,55 @@ static void lguest_time_irq(unsigned int irq, struct irq_desc *desc)
428 local_irq_restore(flags); 756 local_irq_restore(flags);
429} 757}
430 758
759/* At some point in the boot process, we get asked to set up our timing
760 * infrastructure. The kernel doesn't expect timer interrupts before this, but
761 * we cleverly initialized the "blocked_interrupts" field of "struct
762 * lguest_data" so that timer interrupts were blocked until now. */
431static void lguest_time_init(void) 763static void lguest_time_init(void)
432{ 764{
765 /* Set up the timer interrupt (0) to go to our simple timer routine */
433 set_irq_handler(0, lguest_time_irq); 766 set_irq_handler(0, lguest_time_irq);
434 767
435 /* We use the TSC if the Host tells us we can, otherwise a dumb 768 /* Our clock structure look like arch/i386/kernel/tsc.c if we can use
436 * jiffies-based clock. */ 769 * the TSC, otherwise it's a dumb nanosecond-resolution clock. Either
770 * way, the "rating" is initialized so high that it's always chosen
771 * over any other clocksource. */
437 if (lguest_data.tsc_khz) { 772 if (lguest_data.tsc_khz) {
438 lguest_clock.shift = 22; 773 lguest_clock.shift = 22;
439 lguest_clock.mult = clocksource_khz2mult(lguest_data.tsc_khz, 774 lguest_clock.mult = clocksource_khz2mult(lguest_data.tsc_khz,
440 lguest_clock.shift); 775 lguest_clock.shift);
441 lguest_clock.mask = CLOCKSOURCE_MASK(64);
442 lguest_clock.flags = CLOCK_SOURCE_IS_CONTINUOUS; 776 lguest_clock.flags = CLOCK_SOURCE_IS_CONTINUOUS;
443 } else {
444 /* To understand this, start at kernel/time/jiffies.c... */
445 lguest_clock.shift = 8;
446 lguest_clock.mult = (((u64)NSEC_PER_SEC<<8)/ACTHZ) << 8;
447 lguest_clock.mask = CLOCKSOURCE_MASK(32);
448 } 777 }
449 clock_base = lguest_clock_read(); 778 clock_base = lguest_clock_read();
450 clocksource_register(&lguest_clock); 779 clocksource_register(&lguest_clock);
451 780
452 /* We can't set cpumask in the initializer: damn C limitations! */ 781 /* Now we've set up our clock, we can use it as the scheduler clock */
782 paravirt_ops.sched_clock = lguest_sched_clock;
783
784 /* We can't set cpumask in the initializer: damn C limitations! Set it
785 * here and register our timer device. */
453 lguest_clockevent.cpumask = cpumask_of_cpu(0); 786 lguest_clockevent.cpumask = cpumask_of_cpu(0);
454 clockevents_register_device(&lguest_clockevent); 787 clockevents_register_device(&lguest_clockevent);
455 788
789 /* Finally, we unblock the timer interrupt. */
456 enable_lguest_irq(0); 790 enable_lguest_irq(0);
457} 791}
458 792
793/*
794 * Miscellaneous bits and pieces.
795 *
796 * Here is an oddball collection of functions which the Guest needs for things
797 * to work. They're pretty simple.
798 */
799
800/* The Guest needs to tell the host what stack it expects traps to use. For
801 * native hardware, this is part of the Task State Segment mentioned above in
802 * lguest_load_tr_desc(), but to help hypervisors there's this special call.
803 *
804 * We tell the Host the segment we want to use (__KERNEL_DS is the kernel data
805 * segment), the privilege level (we're privilege level 1, the Host is 0 and
806 * will not tolerate us trying to use that), the stack pointer, and the number
807 * of pages in the stack. */
459static void lguest_load_esp0(struct tss_struct *tss, 808static void lguest_load_esp0(struct tss_struct *tss,
460 struct thread_struct *thread) 809 struct thread_struct *thread)
461{ 810{
@@ -463,15 +812,31 @@ static void lguest_load_esp0(struct tss_struct *tss,
463 THREAD_SIZE/PAGE_SIZE); 812 THREAD_SIZE/PAGE_SIZE);
464} 813}
465 814
815/* Let's just say, I wouldn't do debugging under a Guest. */
466static void lguest_set_debugreg(int regno, unsigned long value) 816static void lguest_set_debugreg(int regno, unsigned long value)
467{ 817{
468 /* FIXME: Implement */ 818 /* FIXME: Implement */
469} 819}
470 820
821/* There are times when the kernel wants to make sure that no memory writes are
822 * caught in the cache (that they've all reached real hardware devices). This
823 * doesn't matter for the Guest which has virtual hardware.
824 *
825 * On the Pentium 4 and above, cpuid() indicates that the Cache Line Flush
826 * (clflush) instruction is available and the kernel uses that. Otherwise, it
827 * uses the older "Write Back and Invalidate Cache" (wbinvd) instruction.
828 * Unlike clflush, wbinvd can only be run at privilege level 0. So we can
829 * ignore clflush, but replace wbinvd.
830 */
471static void lguest_wbinvd(void) 831static void lguest_wbinvd(void)
472{ 832{
473} 833}
474 834
835/* If the Guest expects to have an Advanced Programmable Interrupt Controller,
836 * we play dumb by ignoring writes and returning 0 for reads. So it's no
837 * longer Programmable nor Controlling anything, and I don't think 8 lines of
838 * code qualifies for Advanced. It will also never interrupt anything. It
839 * does, however, allow us to get through the Linux boot code. */
475#ifdef CONFIG_X86_LOCAL_APIC 840#ifdef CONFIG_X86_LOCAL_APIC
476static void lguest_apic_write(unsigned long reg, unsigned long v) 841static void lguest_apic_write(unsigned long reg, unsigned long v)
477{ 842{
@@ -483,19 +848,32 @@ static unsigned long lguest_apic_read(unsigned long reg)
483} 848}
484#endif 849#endif
485 850
851/* STOP! Until an interrupt comes in. */
486static void lguest_safe_halt(void) 852static void lguest_safe_halt(void)
487{ 853{
488 hcall(LHCALL_HALT, 0, 0, 0); 854 hcall(LHCALL_HALT, 0, 0, 0);
489} 855}
490 856
857/* Perhaps CRASH isn't the best name for this hypercall, but we use it to get a
858 * message out when we're crashing as well as elegant termination like powering
859 * off.
860 *
861 * Note that the Host always prefers that the Guest speak in physical addresses
862 * rather than virtual addresses, so we use __pa() here. */
491static void lguest_power_off(void) 863static void lguest_power_off(void)
492{ 864{
493 hcall(LHCALL_CRASH, __pa("Power down"), 0, 0); 865 hcall(LHCALL_CRASH, __pa("Power down"), 0, 0);
494} 866}
495 867
868/*
869 * Panicing.
870 *
871 * Don't. But if you did, this is what happens.
872 */
496static int lguest_panic(struct notifier_block *nb, unsigned long l, void *p) 873static int lguest_panic(struct notifier_block *nb, unsigned long l, void *p)
497{ 874{
498 hcall(LHCALL_CRASH, __pa(p), 0, 0); 875 hcall(LHCALL_CRASH, __pa(p), 0, 0);
876 /* The hcall won't return, but to keep gcc happy, we're "done". */
499 return NOTIFY_DONE; 877 return NOTIFY_DONE;
500} 878}
501 879
@@ -503,15 +881,45 @@ static struct notifier_block paniced = {
503 .notifier_call = lguest_panic 881 .notifier_call = lguest_panic
504}; 882};
505 883
884/* Setting up memory is fairly easy. */
506static __init char *lguest_memory_setup(void) 885static __init char *lguest_memory_setup(void)
507{ 886{
508 /* We do this here because lockcheck barfs if before start_kernel */ 887 /* We do this here and not earlier because lockcheck barfs if we do it
888 * before start_kernel() */
509 atomic_notifier_chain_register(&panic_notifier_list, &paniced); 889 atomic_notifier_chain_register(&panic_notifier_list, &paniced);
510 890
891 /* The Linux bootloader header contains an "e820" memory map: the
892 * Launcher populated the first entry with our memory limit. */
511 add_memory_region(E820_MAP->addr, E820_MAP->size, E820_MAP->type); 893 add_memory_region(E820_MAP->addr, E820_MAP->size, E820_MAP->type);
894
895 /* This string is for the boot messages. */
512 return "LGUEST"; 896 return "LGUEST";
513} 897}
514 898
899/*G:050
900 * Patching (Powerfully Placating Performance Pedants)
901 *
902 * We have already seen that "struct paravirt_ops" lets us replace simple
903 * native instructions with calls to the appropriate back end all throughout
904 * the kernel. This allows the same kernel to run as a Guest and as a native
905 * kernel, but it's slow because of all the indirect branches.
906 *
907 * Remember that David Wheeler quote about "Any problem in computer science can
908 * be solved with another layer of indirection"? The rest of that quote is
909 * "... But that usually will create another problem." This is the first of
910 * those problems.
911 *
912 * Our current solution is to allow the paravirt back end to optionally patch
913 * over the indirect calls to replace them with something more efficient. We
914 * patch the four most commonly called functions: disable interrupts, enable
915 * interrupts, restore interrupts and save interrupts. We usually have 10
916 * bytes to patch into: the Guest versions of these operations are small enough
917 * that we can fit comfortably.
918 *
919 * First we need assembly templates of each of the patchable Guest operations,
920 * and these are in lguest_asm.S. */
921
922/*G:060 We construct a table from the assembler templates: */
515static const struct lguest_insns 923static const struct lguest_insns
516{ 924{
517 const char *start, *end; 925 const char *start, *end;
@@ -521,35 +929,52 @@ static const struct lguest_insns
521 [PARAVIRT_PATCH(restore_fl)] = { lgstart_popf, lgend_popf }, 929 [PARAVIRT_PATCH(restore_fl)] = { lgstart_popf, lgend_popf },
522 [PARAVIRT_PATCH(save_fl)] = { lgstart_pushf, lgend_pushf }, 930 [PARAVIRT_PATCH(save_fl)] = { lgstart_pushf, lgend_pushf },
523}; 931};
932
933/* Now our patch routine is fairly simple (based on the native one in
934 * paravirt.c). If we have a replacement, we copy it in and return how much of
935 * the available space we used. */
524static unsigned lguest_patch(u8 type, u16 clobber, void *insns, unsigned len) 936static unsigned lguest_patch(u8 type, u16 clobber, void *insns, unsigned len)
525{ 937{
526 unsigned int insn_len; 938 unsigned int insn_len;
527 939
528 /* Don't touch it if we don't have a replacement */ 940 /* Don't do anything special if we don't have a replacement */
529 if (type >= ARRAY_SIZE(lguest_insns) || !lguest_insns[type].start) 941 if (type >= ARRAY_SIZE(lguest_insns) || !lguest_insns[type].start)
530 return paravirt_patch_default(type, clobber, insns, len); 942 return paravirt_patch_default(type, clobber, insns, len);
531 943
532 insn_len = lguest_insns[type].end - lguest_insns[type].start; 944 insn_len = lguest_insns[type].end - lguest_insns[type].start;
533 945
534 /* Similarly if we can't fit replacement. */ 946 /* Similarly if we can't fit replacement (shouldn't happen, but let's
947 * be thorough). */
535 if (len < insn_len) 948 if (len < insn_len)
536 return paravirt_patch_default(type, clobber, insns, len); 949 return paravirt_patch_default(type, clobber, insns, len);
537 950
951 /* Copy in our instructions. */
538 memcpy(insns, lguest_insns[type].start, insn_len); 952 memcpy(insns, lguest_insns[type].start, insn_len);
539 return insn_len; 953 return insn_len;
540} 954}
541 955
956/*G:030 Once we get to lguest_init(), we know we're a Guest. The paravirt_ops
957 * structure in the kernel provides a single point for (almost) every routine
958 * we have to override to avoid privileged instructions. */
542__init void lguest_init(void *boot) 959__init void lguest_init(void *boot)
543{ 960{
544 /* Copy boot parameters first. */ 961 /* Copy boot parameters first: the Launcher put the physical location
962 * in %esi, and head.S converted that to a virtual address and handed
963 * it to us. */
545 memcpy(&boot_params, boot, PARAM_SIZE); 964 memcpy(&boot_params, boot, PARAM_SIZE);
965 /* The boot parameters also tell us where the command-line is: save
966 * that, too. */
546 memcpy(boot_command_line, __va(boot_params.hdr.cmd_line_ptr), 967 memcpy(boot_command_line, __va(boot_params.hdr.cmd_line_ptr),
547 COMMAND_LINE_SIZE); 968 COMMAND_LINE_SIZE);
548 969
970 /* We're under lguest, paravirt is enabled, and we're running at
971 * privilege level 1, not 0 as normal. */
549 paravirt_ops.name = "lguest"; 972 paravirt_ops.name = "lguest";
550 paravirt_ops.paravirt_enabled = 1; 973 paravirt_ops.paravirt_enabled = 1;
551 paravirt_ops.kernel_rpl = 1; 974 paravirt_ops.kernel_rpl = 1;
552 975
976 /* We set up all the lguest overrides for sensitive operations. These
977 * are detailed with the operations themselves. */
553 paravirt_ops.save_fl = save_fl; 978 paravirt_ops.save_fl = save_fl;
554 paravirt_ops.restore_fl = restore_fl; 979 paravirt_ops.restore_fl = restore_fl;
555 paravirt_ops.irq_disable = irq_disable; 980 paravirt_ops.irq_disable = irq_disable;
@@ -592,21 +1017,50 @@ __init void lguest_init(void *boot)
592 paravirt_ops.time_init = lguest_time_init; 1017 paravirt_ops.time_init = lguest_time_init;
593 paravirt_ops.set_lazy_mode = lguest_lazy_mode; 1018 paravirt_ops.set_lazy_mode = lguest_lazy_mode;
594 paravirt_ops.wbinvd = lguest_wbinvd; 1019 paravirt_ops.wbinvd = lguest_wbinvd;
595 paravirt_ops.sched_clock = lguest_sched_clock; 1020 /* Now is a good time to look at the implementations of these functions
596 1021 * before returning to the rest of lguest_init(). */
1022
1023 /*G:070 Now we've seen all the paravirt_ops, we return to
1024 * lguest_init() where the rest of the fairly chaotic boot setup
1025 * occurs.
1026 *
1027 * The Host expects our first hypercall to tell it where our "struct
1028 * lguest_data" is, so we do that first. */
597 hcall(LHCALL_LGUEST_INIT, __pa(&lguest_data), 0, 0); 1029 hcall(LHCALL_LGUEST_INIT, __pa(&lguest_data), 0, 0);
598 1030
599 /* We use top of mem for initial pagetables. */ 1031 /* The native boot code sets up initial page tables immediately after
1032 * the kernel itself, and sets init_pg_tables_end so they're not
1033 * clobbered. The Launcher places our initial pagetables somewhere at
1034 * the top of our physical memory, so we don't need extra space: set
1035 * init_pg_tables_end to the end of the kernel. */
600 init_pg_tables_end = __pa(pg0); 1036 init_pg_tables_end = __pa(pg0);
601 1037
1038 /* Load the %fs segment register (the per-cpu segment register) with
1039 * the normal data segment to get through booting. */
602 asm volatile ("mov %0, %%fs" : : "r" (__KERNEL_DS) : "memory"); 1040 asm volatile ("mov %0, %%fs" : : "r" (__KERNEL_DS) : "memory");
603 1041
1042 /* Clear the part of the kernel data which is expected to be zero.
1043 * Normally it will be anyway, but if we're loading from a bzImage with
1044 * CONFIG_RELOCATALE=y, the relocations will be sitting here. */
1045 memset(__bss_start, 0, __bss_stop - __bss_start);
1046
1047 /* The Host uses the top of the Guest's virtual address space for the
1048 * Host<->Guest Switcher, and it tells us how much it needs in
1049 * lguest_data.reserve_mem, set up on the LGUEST_INIT hypercall. */
604 reserve_top_address(lguest_data.reserve_mem); 1050 reserve_top_address(lguest_data.reserve_mem);
605 1051
1052 /* If we don't initialize the lock dependency checker now, it crashes
1053 * paravirt_disable_iospace. */
606 lockdep_init(); 1054 lockdep_init();
607 1055
1056 /* The IDE code spends about 3 seconds probing for disks: if we reserve
1057 * all the I/O ports up front it can't get them and so doesn't probe.
1058 * Other device drivers are similar (but less severe). This cuts the
1059 * kernel boot time on my machine from 4.1 seconds to 0.45 seconds. */
608 paravirt_disable_iospace(); 1060 paravirt_disable_iospace();
609 1061
1062 /* This is messy CPU setup stuff which the native boot code does before
1063 * start_kernel, so we have to do, too: */
610 cpu_detect(&new_cpu_data); 1064 cpu_detect(&new_cpu_data);
611 /* head.S usually sets up the first capability word, so do it here. */ 1065 /* head.S usually sets up the first capability word, so do it here. */
612 new_cpu_data.x86_capability[0] = cpuid_edx(1); 1066 new_cpu_data.x86_capability[0] = cpuid_edx(1);
@@ -617,14 +1071,27 @@ __init void lguest_init(void *boot)
617#ifdef CONFIG_X86_MCE 1071#ifdef CONFIG_X86_MCE
618 mce_disabled = 1; 1072 mce_disabled = 1;
619#endif 1073#endif
620
621#ifdef CONFIG_ACPI 1074#ifdef CONFIG_ACPI
622 acpi_disabled = 1; 1075 acpi_disabled = 1;
623 acpi_ht = 0; 1076 acpi_ht = 0;
624#endif 1077#endif
625 1078
1079 /* We set the perferred console to "hvc". This is the "hypervisor
1080 * virtual console" driver written by the PowerPC people, which we also
1081 * adapted for lguest's use. */
626 add_preferred_console("hvc", 0, NULL); 1082 add_preferred_console("hvc", 0, NULL);
627 1083
1084 /* Last of all, we set the power management poweroff hook to point to
1085 * the Guest routine to power off. */
628 pm_power_off = lguest_power_off; 1086 pm_power_off = lguest_power_off;
1087
1088 /* Now we're set up, call start_kernel() in init/main.c and we proceed
1089 * to boot as normal. It never returns. */
629 start_kernel(); 1090 start_kernel();
630} 1091}
1092/*
1093 * This marks the end of stage II of our journey, The Guest.
1094 *
1095 * It is now time for us to explore the nooks and crannies of the three Guest
1096 * devices and complete our understanding of the Guest in "make Drivers".
1097 */
diff --git a/drivers/lguest/lguest_asm.S b/drivers/lguest/lguest_asm.S
index a3dbf22ee365..f182c6a36209 100644
--- a/drivers/lguest/lguest_asm.S
+++ b/drivers/lguest/lguest_asm.S
@@ -4,15 +4,15 @@
4#include <asm/thread_info.h> 4#include <asm/thread_info.h>
5#include <asm/processor-flags.h> 5#include <asm/processor-flags.h>
6 6
7/* 7/*G:020 This is where we begin: we have a magic signature which the launcher
8 * This is where we begin: we have a magic signature which the launcher looks 8 * looks for. The plan is that the Linux boot protocol will be extended with a
9 * for. The plan is that the Linux boot protocol will be extended with a
10 * "platform type" field which will guide us here from the normal entry point, 9 * "platform type" field which will guide us here from the normal entry point,
11 * but for the moment this suffices. We pass the virtual address of the boot 10 * but for the moment this suffices. The normal boot code uses %esi for the
12 * info to lguest_init(). 11 * boot header, so we do too. We convert it to a virtual address by adding
12 * PAGE_OFFSET, and hand it to lguest_init() as its argument (ie. %eax).
13 * 13 *
14 * We put it in .init.text will be discarded after boot. 14 * The .section line puts this code in .init.text so it will be discarded after
15 */ 15 * boot. */
16.section .init.text, "ax", @progbits 16.section .init.text, "ax", @progbits
17.ascii "GenuineLguest" 17.ascii "GenuineLguest"
18 /* Set up initial stack. */ 18 /* Set up initial stack. */
@@ -21,7 +21,9 @@
21 addl $__PAGE_OFFSET, %eax 21 addl $__PAGE_OFFSET, %eax
22 jmp lguest_init 22 jmp lguest_init
23 23
24/* The templates for inline patching. */ 24/*G:055 We create a macro which puts the assembler code between lgstart_ and
25 * lgend_ markers. These templates end up in the .init.text section, so they
26 * are discarded after boot. */
25#define LGUEST_PATCH(name, insns...) \ 27#define LGUEST_PATCH(name, insns...) \
26 lgstart_##name: insns; lgend_##name:; \ 28 lgstart_##name: insns; lgend_##name:; \
27 .globl lgstart_##name; .globl lgend_##name 29 .globl lgstart_##name; .globl lgend_##name
@@ -30,24 +32,61 @@ LGUEST_PATCH(cli, movl $0, lguest_data+LGUEST_DATA_irq_enabled)
30LGUEST_PATCH(sti, movl $X86_EFLAGS_IF, lguest_data+LGUEST_DATA_irq_enabled) 32LGUEST_PATCH(sti, movl $X86_EFLAGS_IF, lguest_data+LGUEST_DATA_irq_enabled)
31LGUEST_PATCH(popf, movl %eax, lguest_data+LGUEST_DATA_irq_enabled) 33LGUEST_PATCH(popf, movl %eax, lguest_data+LGUEST_DATA_irq_enabled)
32LGUEST_PATCH(pushf, movl lguest_data+LGUEST_DATA_irq_enabled, %eax) 34LGUEST_PATCH(pushf, movl lguest_data+LGUEST_DATA_irq_enabled, %eax)
35/*:*/
33 36
34.text 37.text
35/* These demark the EIP range where host should never deliver interrupts. */ 38/* These demark the EIP range where host should never deliver interrupts. */
36.global lguest_noirq_start 39.global lguest_noirq_start
37.global lguest_noirq_end 40.global lguest_noirq_end
38 41
39/* 42/*M:004 When the Host reflects a trap or injects an interrupt into the Guest,
40 * We move eflags word to lguest_data.irq_enabled to restore interrupt state. 43 * it sets the eflags interrupt bit on the stack based on
41 * For page faults, gpfs and virtual interrupts, the hypervisor has saved 44 * lguest_data.irq_enabled, so the Guest iret logic does the right thing when
42 * eflags manually, otherwise it was delivered directly and so eflags reflects 45 * restoring it. However, when the Host sets the Guest up for direct traps,
43 * the real machine IF state, ie. interrupts on. Since the kernel always dies 46 * such as system calls, the processor is the one to push eflags onto the
44 * if it takes such a trap with interrupts disabled anyway, turning interrupts 47 * stack, and the interrupt bit will be 1 (in reality, interrupts are always
45 * back on unconditionally here is OK. 48 * enabled in the Guest).
46 */ 49 *
50 * This turns out to be harmless: the only trap which should happen under Linux
51 * with interrupts disabled is Page Fault (due to our lazy mapping of vmalloc
52 * regions), which has to be reflected through the Host anyway. If another
53 * trap *does* go off when interrupts are disabled, the Guest will panic, and
54 * we'll never get to this iret! :*/
55
56/*G:045 There is one final paravirt_op that the Guest implements, and glancing
57 * at it you can see why I left it to last. It's *cool*! It's in *assembler*!
58 *
59 * The "iret" instruction is used to return from an interrupt or trap. The
60 * stack looks like this:
61 * old address
62 * old code segment & privilege level
63 * old processor flags ("eflags")
64 *
65 * The "iret" instruction pops those values off the stack and restores them all
66 * at once. The only problem is that eflags includes the Interrupt Flag which
67 * the Guest can't change: the CPU will simply ignore it when we do an "iret".
68 * So we have to copy eflags from the stack to lguest_data.irq_enabled before
69 * we do the "iret".
70 *
71 * There are two problems with this: firstly, we need to use a register to do
72 * the copy and secondly, the whole thing needs to be atomic. The first
73 * problem is easy to solve: push %eax on the stack so we can use it, and then
74 * restore it at the end just before the real "iret".
75 *
76 * The second is harder: copying eflags to lguest_data.irq_enabled will turn
77 * interrupts on before we're finished, so we could be interrupted before we
78 * return to userspace or wherever. Our solution to this is to surround the
79 * code with lguest_noirq_start: and lguest_noirq_end: labels. We tell the
80 * Host that it is *never* to interrupt us there, even if interrupts seem to be
81 * enabled. */
47ENTRY(lguest_iret) 82ENTRY(lguest_iret)
48 pushl %eax 83 pushl %eax
49 movl 12(%esp), %eax 84 movl 12(%esp), %eax
50lguest_noirq_start: 85lguest_noirq_start:
86 /* Note the %ss: segment prefix here. Normal data accesses use the
87 * "ds" segment, but that will have already been restored for whatever
88 * we're returning to (such as userspace): we can't trust it. The %ss:
89 * prefix makes sure we use the stack segment, which is still valid. */
51 movl %eax,%ss:lguest_data+LGUEST_DATA_irq_enabled 90 movl %eax,%ss:lguest_data+LGUEST_DATA_irq_enabled
52 popl %eax 91 popl %eax
53 iret 92 iret
diff --git a/drivers/lguest/lguest_bus.c b/drivers/lguest/lguest_bus.c
index 18d6ab21a43b..55a7940ca732 100644
--- a/drivers/lguest/lguest_bus.c
+++ b/drivers/lguest/lguest_bus.c
@@ -1,3 +1,6 @@
1/*P:050 Lguest guests use a very simple bus for devices. It's a simple array
2 * of device descriptors contained just above the top of normal memory. The
3 * lguest bus is 80% tedious boilerplate code. :*/
1#include <linux/init.h> 4#include <linux/init.h>
2#include <linux/bootmem.h> 5#include <linux/bootmem.h>
3#include <linux/lguest_bus.h> 6#include <linux/lguest_bus.h>
@@ -43,6 +46,10 @@ static struct device_attribute lguest_dev_attrs[] = {
43 __ATTR_NULL 46 __ATTR_NULL
44}; 47};
45 48
49/*D:130 The generic bus infrastructure requires a function which says whether a
50 * device matches a driver. For us, it is simple: "struct lguest_driver"
51 * contains a "device_type" field which indicates what type of device it can
52 * handle, so we just cast the args and compare: */
46static int lguest_dev_match(struct device *_dev, struct device_driver *_drv) 53static int lguest_dev_match(struct device *_dev, struct device_driver *_drv)
47{ 54{
48 struct lguest_device *dev = container_of(_dev,struct lguest_device,dev); 55 struct lguest_device *dev = container_of(_dev,struct lguest_device,dev);
@@ -50,6 +57,7 @@ static int lguest_dev_match(struct device *_dev, struct device_driver *_drv)
50 57
51 return (drv->device_type == lguest_devices[dev->index].type); 58 return (drv->device_type == lguest_devices[dev->index].type);
52} 59}
60/*:*/
53 61
54struct lguest_bus { 62struct lguest_bus {
55 struct bus_type bus; 63 struct bus_type bus;
@@ -68,11 +76,24 @@ static struct lguest_bus lguest_bus = {
68 } 76 }
69}; 77};
70 78
79/*D:140 This is the callback which occurs once the bus infrastructure matches
80 * up a device and driver, ie. in response to add_lguest_device() calling
81 * device_register(), or register_lguest_driver() calling driver_register().
82 *
83 * At the moment it's always the latter: the devices are added first, since
84 * scan_devices() is called from a "core_initcall", and the drivers themselves
85 * called later as a normal "initcall". But it would work the other way too.
86 *
87 * So now we have the happy couple, we add the status bit to indicate that we
88 * found a driver. If the driver truly loves the device, it will return
89 * happiness from its probe function (ok, perhaps this wasn't my greatest
90 * analogy), and we set the final "driver ok" bit so the Host sees it's all
91 * green. */
71static int lguest_dev_probe(struct device *_dev) 92static int lguest_dev_probe(struct device *_dev)
72{ 93{
73 int ret; 94 int ret;
74 struct lguest_device *dev = container_of(_dev,struct lguest_device,dev); 95 struct lguest_device*dev = container_of(_dev,struct lguest_device,dev);
75 struct lguest_driver *drv = container_of(dev->dev.driver, 96 struct lguest_driver*drv = container_of(dev->dev.driver,
76 struct lguest_driver, drv); 97 struct lguest_driver, drv);
77 98
78 lguest_devices[dev->index].status |= LGUEST_DEVICE_S_DRIVER; 99 lguest_devices[dev->index].status |= LGUEST_DEVICE_S_DRIVER;
@@ -82,6 +103,10 @@ static int lguest_dev_probe(struct device *_dev)
82 return ret; 103 return ret;
83} 104}
84 105
106/* The last part of the bus infrastructure is the function lguest drivers use
107 * to register themselves. Firstly, we do nothing if there's no lguest bus
108 * (ie. this is not a Guest), otherwise we fill in the embedded generic "struct
109 * driver" fields and call the generic driver_register(). */
85int register_lguest_driver(struct lguest_driver *drv) 110int register_lguest_driver(struct lguest_driver *drv)
86{ 111{
87 if (!lguest_devices) 112 if (!lguest_devices)
@@ -94,12 +119,36 @@ int register_lguest_driver(struct lguest_driver *drv)
94 119
95 return driver_register(&drv->drv); 120 return driver_register(&drv->drv);
96} 121}
122
123/* At the moment we build all the drivers into the kernel because they're so
124 * simple: 8144 bytes for all three of them as I type this. And as the console
125 * really needs to be built in, it's actually only 3527 bytes for the network
126 * and block drivers.
127 *
128 * If they get complex it will make sense for them to be modularized, so we
129 * need to explicitly export the symbol.
130 *
131 * I don't think non-GPL modules make sense, so it's a GPL-only export.
132 */
97EXPORT_SYMBOL_GPL(register_lguest_driver); 133EXPORT_SYMBOL_GPL(register_lguest_driver);
98 134
135/*D:120 This is the core of the lguest bus: actually adding a new device.
136 * It's a separate function because it's neater that way, and because an
137 * earlier version of the code supported hotplug and unplug. They were removed
138 * early on because they were never used.
139 *
140 * As Andrew Tridgell says, "Untested code is buggy code".
141 *
142 * It's worth reading this carefully: we start with an index into the array of
143 * "struct lguest_device_desc"s indicating the device which is new: */
99static void add_lguest_device(unsigned int index) 144static void add_lguest_device(unsigned int index)
100{ 145{
101 struct lguest_device *new; 146 struct lguest_device *new;
102 147
148 /* Each "struct lguest_device_desc" has a "status" field, which the
149 * Guest updates as the device is probed. In the worst case, the Host
150 * can look at these bits to tell what part of device setup failed,
151 * even if the console isn't available. */
103 lguest_devices[index].status |= LGUEST_DEVICE_S_ACKNOWLEDGE; 152 lguest_devices[index].status |= LGUEST_DEVICE_S_ACKNOWLEDGE;
104 new = kmalloc(sizeof(struct lguest_device), GFP_KERNEL); 153 new = kmalloc(sizeof(struct lguest_device), GFP_KERNEL);
105 if (!new) { 154 if (!new) {
@@ -108,12 +157,17 @@ static void add_lguest_device(unsigned int index)
108 return; 157 return;
109 } 158 }
110 159
160 /* The "struct lguest_device" setup is pretty straight-forward example
161 * code. */
111 new->index = index; 162 new->index = index;
112 new->private = NULL; 163 new->private = NULL;
113 memset(&new->dev, 0, sizeof(new->dev)); 164 memset(&new->dev, 0, sizeof(new->dev));
114 new->dev.parent = &lguest_bus.dev; 165 new->dev.parent = &lguest_bus.dev;
115 new->dev.bus = &lguest_bus.bus; 166 new->dev.bus = &lguest_bus.bus;
116 sprintf(new->dev.bus_id, "%u", index); 167 sprintf(new->dev.bus_id, "%u", index);
168
169 /* device_register() causes the bus infrastructure to look for a
170 * matching driver. */
117 if (device_register(&new->dev) != 0) { 171 if (device_register(&new->dev) != 0) {
118 printk(KERN_EMERG "Cannot register lguest device %u\n", index); 172 printk(KERN_EMERG "Cannot register lguest device %u\n", index);
119 lguest_devices[index].status |= LGUEST_DEVICE_S_FAILED; 173 lguest_devices[index].status |= LGUEST_DEVICE_S_FAILED;
@@ -121,6 +175,9 @@ static void add_lguest_device(unsigned int index)
121 } 175 }
122} 176}
123 177
178/*D:110 scan_devices() simply iterates through the device array. The type 0
179 * is reserved to mean "no device", and anything else means we have found a
180 * device: add it. */
124static void scan_devices(void) 181static void scan_devices(void)
125{ 182{
126 unsigned int i; 183 unsigned int i;
@@ -130,12 +187,23 @@ static void scan_devices(void)
130 add_lguest_device(i); 187 add_lguest_device(i);
131} 188}
132 189
190/*D:100 Fairly early in boot, lguest_bus_init() is called to set up the lguest
191 * bus. We check that we are a Guest by checking paravirt_ops.name: there are
192 * other ways of checking, but this seems most obvious to me.
193 *
194 * So we can access the array of "struct lguest_device_desc"s easily, we map
195 * that memory and store the pointer in the global "lguest_devices". Then we
196 * register the bus with the core. Doing two registrations seems clunky to me,
197 * but it seems to be the correct sysfs incantation.
198 *
199 * Finally we call scan_devices() which adds all the devices found in the
200 * "struct lguest_device_desc" array. */
133static int __init lguest_bus_init(void) 201static int __init lguest_bus_init(void)
134{ 202{
135 if (strcmp(paravirt_ops.name, "lguest") != 0) 203 if (strcmp(paravirt_ops.name, "lguest") != 0)
136 return 0; 204 return 0;
137 205
138 /* Devices are in page above top of "normal" mem. */ 206 /* Devices are in a single page above top of "normal" mem */
139 lguest_devices = lguest_map(max_pfn<<PAGE_SHIFT, 1); 207 lguest_devices = lguest_map(max_pfn<<PAGE_SHIFT, 1);
140 208
141 if (bus_register(&lguest_bus.bus) != 0 209 if (bus_register(&lguest_bus.bus) != 0
@@ -145,4 +213,5 @@ static int __init lguest_bus_init(void)
145 scan_devices(); 213 scan_devices();
146 return 0; 214 return 0;
147} 215}
216/* Do this after core stuff, before devices. */
148postcore_initcall(lguest_bus_init); 217postcore_initcall(lguest_bus_init);
diff --git a/drivers/lguest/lguest_user.c b/drivers/lguest/lguest_user.c
index e90d7a783daf..80d1b58c7698 100644
--- a/drivers/lguest/lguest_user.c
+++ b/drivers/lguest/lguest_user.c
@@ -1,36 +1,70 @@
1/* Userspace control of the guest, via /dev/lguest. */ 1/*P:200 This contains all the /dev/lguest code, whereby the userspace launcher
2 * controls and communicates with the Guest. For example, the first write will
3 * tell us the memory size, pagetable, entry point and kernel address offset.
4 * A read will run the Guest until a signal is pending (-EINTR), or the Guest
5 * does a DMA out to the Launcher. Writes are also used to get a DMA buffer
6 * registered by the Guest and to send the Guest an interrupt. :*/
2#include <linux/uaccess.h> 7#include <linux/uaccess.h>
3#include <linux/miscdevice.h> 8#include <linux/miscdevice.h>
4#include <linux/fs.h> 9#include <linux/fs.h>
5#include "lg.h" 10#include "lg.h"
6 11
12/*L:030 setup_regs() doesn't really belong in this file, but it gives us an
13 * early glimpse deeper into the Host so it's worth having here.
14 *
15 * Most of the Guest's registers are left alone: we used get_zeroed_page() to
16 * allocate the structure, so they will be 0. */
7static void setup_regs(struct lguest_regs *regs, unsigned long start) 17static void setup_regs(struct lguest_regs *regs, unsigned long start)
8{ 18{
9 /* Write out stack in format lguest expects, so we can switch to it. */ 19 /* There are four "segment" registers which the Guest needs to boot:
20 * The "code segment" register (cs) refers to the kernel code segment
21 * __KERNEL_CS, and the "data", "extra" and "stack" segment registers
22 * refer to the kernel data segment __KERNEL_DS.
23 *
24 * The privilege level is packed into the lower bits. The Guest runs
25 * at privilege level 1 (GUEST_PL).*/
10 regs->ds = regs->es = regs->ss = __KERNEL_DS|GUEST_PL; 26 regs->ds = regs->es = regs->ss = __KERNEL_DS|GUEST_PL;
11 regs->cs = __KERNEL_CS|GUEST_PL; 27 regs->cs = __KERNEL_CS|GUEST_PL;
12 regs->eflags = 0x202; /* Interrupts enabled. */ 28
29 /* The "eflags" register contains miscellaneous flags. Bit 1 (0x002)
30 * is supposed to always be "1". Bit 9 (0x200) controls whether
31 * interrupts are enabled. We always leave interrupts enabled while
32 * running the Guest. */
33 regs->eflags = 0x202;
34
35 /* The "Extended Instruction Pointer" register says where the Guest is
36 * running. */
13 regs->eip = start; 37 regs->eip = start;
14 /* esi points to our boot information (physical address 0) */ 38
39 /* %esi points to our boot information, at physical address 0, so don't
40 * touch it. */
15} 41}
16 42
17/* + addr */ 43/*L:310 To send DMA into the Guest, the Launcher needs to be able to ask for a
44 * DMA buffer. This is done by writing LHREQ_GETDMA and the key to
45 * /dev/lguest. */
18static long user_get_dma(struct lguest *lg, const u32 __user *input) 46static long user_get_dma(struct lguest *lg, const u32 __user *input)
19{ 47{
20 unsigned long key, udma, irq; 48 unsigned long key, udma, irq;
21 49
50 /* Fetch the key they wrote to us. */
22 if (get_user(key, input) != 0) 51 if (get_user(key, input) != 0)
23 return -EFAULT; 52 return -EFAULT;
53 /* Look for a free Guest DMA buffer bound to that key. */
24 udma = get_dma_buffer(lg, key, &irq); 54 udma = get_dma_buffer(lg, key, &irq);
25 if (!udma) 55 if (!udma)
26 return -ENOENT; 56 return -ENOENT;
27 57
28 /* We put irq number in udma->used_len. */ 58 /* We need to tell the Launcher what interrupt the Guest expects after
59 * the buffer is filled. We stash it in udma->used_len. */
29 lgwrite_u32(lg, udma + offsetof(struct lguest_dma, used_len), irq); 60 lgwrite_u32(lg, udma + offsetof(struct lguest_dma, used_len), irq);
61
62 /* The (guest-physical) address of the DMA buffer is returned from
63 * the write(). */
30 return udma; 64 return udma;
31} 65}
32 66
33/* To force the Guest to stop running and return to the Launcher, the 67/*L:315 To force the Guest to stop running and return to the Launcher, the
34 * Waker sets writes LHREQ_BREAK and the value "1" to /dev/lguest. The 68 * Waker sets writes LHREQ_BREAK and the value "1" to /dev/lguest. The
35 * Launcher then writes LHREQ_BREAK and "0" to release the Waker. */ 69 * Launcher then writes LHREQ_BREAK and "0" to release the Waker. */
36static int break_guest_out(struct lguest *lg, const u32 __user *input) 70static int break_guest_out(struct lguest *lg, const u32 __user *input)
@@ -54,7 +88,8 @@ static int break_guest_out(struct lguest *lg, const u32 __user *input)
54 } 88 }
55} 89}
56 90
57/* + irq */ 91/*L:050 Sending an interrupt is done by writing LHREQ_IRQ and an interrupt
92 * number to /dev/lguest. */
58static int user_send_irq(struct lguest *lg, const u32 __user *input) 93static int user_send_irq(struct lguest *lg, const u32 __user *input)
59{ 94{
60 u32 irq; 95 u32 irq;
@@ -63,14 +98,19 @@ static int user_send_irq(struct lguest *lg, const u32 __user *input)
63 return -EFAULT; 98 return -EFAULT;
64 if (irq >= LGUEST_IRQS) 99 if (irq >= LGUEST_IRQS)
65 return -EINVAL; 100 return -EINVAL;
101 /* Next time the Guest runs, the core code will see if it can deliver
102 * this interrupt. */
66 set_bit(irq, lg->irqs_pending); 103 set_bit(irq, lg->irqs_pending);
67 return 0; 104 return 0;
68} 105}
69 106
107/*L:040 Once our Guest is initialized, the Launcher makes it run by reading
108 * from /dev/lguest. */
70static ssize_t read(struct file *file, char __user *user, size_t size,loff_t*o) 109static ssize_t read(struct file *file, char __user *user, size_t size,loff_t*o)
71{ 110{
72 struct lguest *lg = file->private_data; 111 struct lguest *lg = file->private_data;
73 112
113 /* You must write LHREQ_INITIALIZE first! */
74 if (!lg) 114 if (!lg)
75 return -EINVAL; 115 return -EINVAL;
76 116
@@ -78,27 +118,52 @@ static ssize_t read(struct file *file, char __user *user, size_t size,loff_t*o)
78 if (current != lg->tsk) 118 if (current != lg->tsk)
79 return -EPERM; 119 return -EPERM;
80 120
121 /* If the guest is already dead, we indicate why */
81 if (lg->dead) { 122 if (lg->dead) {
82 size_t len; 123 size_t len;
83 124
125 /* lg->dead either contains an error code, or a string. */
84 if (IS_ERR(lg->dead)) 126 if (IS_ERR(lg->dead))
85 return PTR_ERR(lg->dead); 127 return PTR_ERR(lg->dead);
86 128
129 /* We can only return as much as the buffer they read with. */
87 len = min(size, strlen(lg->dead)+1); 130 len = min(size, strlen(lg->dead)+1);
88 if (copy_to_user(user, lg->dead, len) != 0) 131 if (copy_to_user(user, lg->dead, len) != 0)
89 return -EFAULT; 132 return -EFAULT;
90 return len; 133 return len;
91 } 134 }
92 135
136 /* If we returned from read() last time because the Guest sent DMA,
137 * clear the flag. */
93 if (lg->dma_is_pending) 138 if (lg->dma_is_pending)
94 lg->dma_is_pending = 0; 139 lg->dma_is_pending = 0;
95 140
141 /* Run the Guest until something interesting happens. */
96 return run_guest(lg, (unsigned long __user *)user); 142 return run_guest(lg, (unsigned long __user *)user);
97} 143}
98 144
99/* Take: pfnlimit, pgdir, start, pageoffset. */ 145/*L:020 The initialization write supplies 4 32-bit values (in addition to the
146 * 32-bit LHREQ_INITIALIZE value). These are:
147 *
148 * pfnlimit: The highest (Guest-physical) page number the Guest should be
149 * allowed to access. The Launcher has to live in Guest memory, so it sets
150 * this to ensure the Guest can't reach it.
151 *
152 * pgdir: The (Guest-physical) address of the top of the initial Guest
153 * pagetables (which are set up by the Launcher).
154 *
155 * start: The first instruction to execute ("eip" in x86-speak).
156 *
157 * page_offset: The PAGE_OFFSET constant in the Guest kernel. We should
158 * probably wean the code off this, but it's a very useful constant! Any
159 * address above this is within the Guest kernel, and any kernel address can
160 * quickly converted from physical to virtual by adding PAGE_OFFSET. It's
161 * 0xC0000000 (3G) by default, but it's configurable at kernel build time.
162 */
100static int initialize(struct file *file, const u32 __user *input) 163static int initialize(struct file *file, const u32 __user *input)
101{ 164{
165 /* "struct lguest" contains everything we (the Host) know about a
166 * Guest. */
102 struct lguest *lg; 167 struct lguest *lg;
103 int err, i; 168 int err, i;
104 u32 args[4]; 169 u32 args[4];
@@ -106,7 +171,7 @@ static int initialize(struct file *file, const u32 __user *input)
106 /* We grab the Big Lguest lock, which protects the global array 171 /* We grab the Big Lguest lock, which protects the global array
107 * "lguests" and multiple simultaneous initializations. */ 172 * "lguests" and multiple simultaneous initializations. */
108 mutex_lock(&lguest_lock); 173 mutex_lock(&lguest_lock);
109 174 /* You can't initialize twice! Close the device and start again... */
110 if (file->private_data) { 175 if (file->private_data) {
111 err = -EBUSY; 176 err = -EBUSY;
112 goto unlock; 177 goto unlock;
@@ -117,37 +182,70 @@ static int initialize(struct file *file, const u32 __user *input)
117 goto unlock; 182 goto unlock;
118 } 183 }
119 184
185 /* Find an unused guest. */
120 i = find_free_guest(); 186 i = find_free_guest();
121 if (i < 0) { 187 if (i < 0) {
122 err = -ENOSPC; 188 err = -ENOSPC;
123 goto unlock; 189 goto unlock;
124 } 190 }
191 /* OK, we have an index into the "lguest" array: "lg" is a convenient
192 * pointer. */
125 lg = &lguests[i]; 193 lg = &lguests[i];
194
195 /* Populate the easy fields of our "struct lguest" */
126 lg->guestid = i; 196 lg->guestid = i;
127 lg->pfn_limit = args[0]; 197 lg->pfn_limit = args[0];
128 lg->page_offset = args[3]; 198 lg->page_offset = args[3];
199
200 /* We need a complete page for the Guest registers: they are accessible
201 * to the Guest and we can only grant it access to whole pages. */
129 lg->regs_page = get_zeroed_page(GFP_KERNEL); 202 lg->regs_page = get_zeroed_page(GFP_KERNEL);
130 if (!lg->regs_page) { 203 if (!lg->regs_page) {
131 err = -ENOMEM; 204 err = -ENOMEM;
132 goto release_guest; 205 goto release_guest;
133 } 206 }
207 /* We actually put the registers at the bottom of the page. */
134 lg->regs = (void *)lg->regs_page + PAGE_SIZE - sizeof(*lg->regs); 208 lg->regs = (void *)lg->regs_page + PAGE_SIZE - sizeof(*lg->regs);
135 209
210 /* Initialize the Guest's shadow page tables, using the toplevel
211 * address the Launcher gave us. This allocates memory, so can
212 * fail. */
136 err = init_guest_pagetable(lg, args[1]); 213 err = init_guest_pagetable(lg, args[1]);
137 if (err) 214 if (err)
138 goto free_regs; 215 goto free_regs;
139 216
217 /* Now we initialize the Guest's registers, handing it the start
218 * address. */
140 setup_regs(lg->regs, args[2]); 219 setup_regs(lg->regs, args[2]);
220
221 /* There are a couple of GDT entries the Guest expects when first
222 * booting. */
141 setup_guest_gdt(lg); 223 setup_guest_gdt(lg);
224
225 /* The timer for lguest's clock needs initialization. */
142 init_clockdev(lg); 226 init_clockdev(lg);
227
228 /* We keep a pointer to the Launcher task (ie. current task) for when
229 * other Guests want to wake this one (inter-Guest I/O). */
143 lg->tsk = current; 230 lg->tsk = current;
231 /* We need to keep a pointer to the Launcher's memory map, because if
232 * the Launcher dies we need to clean it up. If we don't keep a
233 * reference, it is destroyed before close() is called. */
144 lg->mm = get_task_mm(lg->tsk); 234 lg->mm = get_task_mm(lg->tsk);
235
236 /* Initialize the queue for the waker to wait on */
145 init_waitqueue_head(&lg->break_wq); 237 init_waitqueue_head(&lg->break_wq);
238
239 /* We remember which CPU's pages this Guest used last, for optimization
240 * when the same Guest runs on the same CPU twice. */
146 lg->last_pages = NULL; 241 lg->last_pages = NULL;
242
243 /* We keep our "struct lguest" in the file's private_data. */
147 file->private_data = lg; 244 file->private_data = lg;
148 245
149 mutex_unlock(&lguest_lock); 246 mutex_unlock(&lguest_lock);
150 247
248 /* And because this is a write() call, we return the length used. */
151 return sizeof(args); 249 return sizeof(args);
152 250
153free_regs: 251free_regs:
@@ -159,9 +257,15 @@ unlock:
159 return err; 257 return err;
160} 258}
161 259
260/*L:010 The first operation the Launcher does must be a write. All writes
261 * start with a 32 bit number: for the first write this must be
262 * LHREQ_INITIALIZE to set up the Guest. After that the Launcher can use
263 * writes of other values to get DMA buffers and send interrupts. */
162static ssize_t write(struct file *file, const char __user *input, 264static ssize_t write(struct file *file, const char __user *input,
163 size_t size, loff_t *off) 265 size_t size, loff_t *off)
164{ 266{
267 /* Once the guest is initialized, we hold the "struct lguest" in the
268 * file private data. */
165 struct lguest *lg = file->private_data; 269 struct lguest *lg = file->private_data;
166 u32 req; 270 u32 req;
167 271
@@ -169,8 +273,11 @@ static ssize_t write(struct file *file, const char __user *input,
169 return -EFAULT; 273 return -EFAULT;
170 input += sizeof(req); 274 input += sizeof(req);
171 275
276 /* If you haven't initialized, you must do that first. */
172 if (req != LHREQ_INITIALIZE && !lg) 277 if (req != LHREQ_INITIALIZE && !lg)
173 return -EINVAL; 278 return -EINVAL;
279
280 /* Once the Guest is dead, all you can do is read() why it died. */
174 if (lg && lg->dead) 281 if (lg && lg->dead)
175 return -ENOENT; 282 return -ENOENT;
176 283
@@ -192,33 +299,72 @@ static ssize_t write(struct file *file, const char __user *input,
192 } 299 }
193} 300}
194 301
302/*L:060 The final piece of interface code is the close() routine. It reverses
303 * everything done in initialize(). This is usually called because the
304 * Launcher exited.
305 *
306 * Note that the close routine returns 0 or a negative error number: it can't
307 * really fail, but it can whine. I blame Sun for this wart, and K&R C for
308 * letting them do it. :*/
195static int close(struct inode *inode, struct file *file) 309static int close(struct inode *inode, struct file *file)
196{ 310{
197 struct lguest *lg = file->private_data; 311 struct lguest *lg = file->private_data;
198 312
313 /* If we never successfully initialized, there's nothing to clean up */
199 if (!lg) 314 if (!lg)
200 return 0; 315 return 0;
201 316
317 /* We need the big lock, to protect from inter-guest I/O and other
318 * Launchers initializing guests. */
202 mutex_lock(&lguest_lock); 319 mutex_lock(&lguest_lock);
203 /* Cancels the hrtimer set via LHCALL_SET_CLOCKEVENT. */ 320 /* Cancels the hrtimer set via LHCALL_SET_CLOCKEVENT. */
204 hrtimer_cancel(&lg->hrt); 321 hrtimer_cancel(&lg->hrt);
322 /* Free any DMA buffers the Guest had bound. */
205 release_all_dma(lg); 323 release_all_dma(lg);
324 /* Free up the shadow page tables for the Guest. */
206 free_guest_pagetable(lg); 325 free_guest_pagetable(lg);
326 /* Now all the memory cleanups are done, it's safe to release the
327 * Launcher's memory management structure. */
207 mmput(lg->mm); 328 mmput(lg->mm);
329 /* If lg->dead doesn't contain an error code it will be NULL or a
330 * kmalloc()ed string, either of which is ok to hand to kfree(). */
208 if (!IS_ERR(lg->dead)) 331 if (!IS_ERR(lg->dead))
209 kfree(lg->dead); 332 kfree(lg->dead);
333 /* We can free up the register page we allocated. */
210 free_page(lg->regs_page); 334 free_page(lg->regs_page);
335 /* We clear the entire structure, which also marks it as free for the
336 * next user. */
211 memset(lg, 0, sizeof(*lg)); 337 memset(lg, 0, sizeof(*lg));
338 /* Release lock and exit. */
212 mutex_unlock(&lguest_lock); 339 mutex_unlock(&lguest_lock);
340
213 return 0; 341 return 0;
214} 342}
215 343
344/*L:000
345 * Welcome to our journey through the Launcher!
346 *
347 * The Launcher is the Host userspace program which sets up, runs and services
348 * the Guest. In fact, many comments in the Drivers which refer to "the Host"
349 * doing things are inaccurate: the Launcher does all the device handling for
350 * the Guest. The Guest can't tell what's done by the the Launcher and what by
351 * the Host.
352 *
353 * Just to confuse you: to the Host kernel, the Launcher *is* the Guest and we
354 * shall see more of that later.
355 *
356 * We begin our understanding with the Host kernel interface which the Launcher
357 * uses: reading and writing a character device called /dev/lguest. All the
358 * work happens in the read(), write() and close() routines: */
216static struct file_operations lguest_fops = { 359static struct file_operations lguest_fops = {
217 .owner = THIS_MODULE, 360 .owner = THIS_MODULE,
218 .release = close, 361 .release = close,
219 .write = write, 362 .write = write,
220 .read = read, 363 .read = read,
221}; 364};
365
366/* This is a textbook example of a "misc" character device. Populate a "struct
367 * miscdevice" and register it with misc_register(). */
222static struct miscdevice lguest_dev = { 368static struct miscdevice lguest_dev = {
223 .minor = MISC_DYNAMIC_MINOR, 369 .minor = MISC_DYNAMIC_MINOR,
224 .name = "lguest", 370 .name = "lguest",
diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
index 1b0ba09b1269..b7a924ace684 100644
--- a/drivers/lguest/page_tables.c
+++ b/drivers/lguest/page_tables.c
@@ -1,5 +1,11 @@
1/* Shadow page table operations. 1/*P:700 The pagetable code, on the other hand, still shows the scars of
2 * Copyright (C) Rusty Russell IBM Corporation 2006. 2 * previous encounters. It's functional, and as neat as it can be in the
3 * circumstances, but be wary, for these things are subtle and break easily.
4 * The Guest provides a virtual to physical mapping, but we can neither trust
5 * it nor use it: we verify and convert it here to point the hardware to the
6 * actual Guest pages when running the Guest. :*/
7
8/* Copyright (C) Rusty Russell IBM Corporation 2006.
3 * GPL v2 and any later version */ 9 * GPL v2 and any later version */
4#include <linux/mm.h> 10#include <linux/mm.h>
5#include <linux/types.h> 11#include <linux/types.h>
@@ -9,38 +15,96 @@
9#include <asm/tlbflush.h> 15#include <asm/tlbflush.h>
10#include "lg.h" 16#include "lg.h"
11 17
18/*M:008 We hold reference to pages, which prevents them from being swapped.
19 * It'd be nice to have a callback in the "struct mm_struct" when Linux wants
20 * to swap out. If we had this, and a shrinker callback to trim PTE pages, we
21 * could probably consider launching Guests as non-root. :*/
22
23/*H:300
24 * The Page Table Code
25 *
26 * We use two-level page tables for the Guest. If you're not entirely
27 * comfortable with virtual addresses, physical addresses and page tables then
28 * I recommend you review lguest.c's "Page Table Handling" (with diagrams!).
29 *
30 * The Guest keeps page tables, but we maintain the actual ones here: these are
31 * called "shadow" page tables. Which is a very Guest-centric name: these are
32 * the real page tables the CPU uses, although we keep them up to date to
33 * reflect the Guest's. (See what I mean about weird naming? Since when do
34 * shadows reflect anything?)
35 *
36 * Anyway, this is the most complicated part of the Host code. There are seven
37 * parts to this:
38 * (i) Setting up a page table entry for the Guest when it faults,
39 * (ii) Setting up the page table entry for the Guest stack,
40 * (iii) Setting up a page table entry when the Guest tells us it has changed,
41 * (iv) Switching page tables,
42 * (v) Flushing (thowing away) page tables,
43 * (vi) Mapping the Switcher when the Guest is about to run,
44 * (vii) Setting up the page tables initially.
45 :*/
46
47/* Pages a 4k long, and each page table entry is 4 bytes long, giving us 1024
48 * (or 2^10) entries per page. */
12#define PTES_PER_PAGE_SHIFT 10 49#define PTES_PER_PAGE_SHIFT 10
13#define PTES_PER_PAGE (1 << PTES_PER_PAGE_SHIFT) 50#define PTES_PER_PAGE (1 << PTES_PER_PAGE_SHIFT)
51
52/* 1024 entries in a page table page maps 1024 pages: 4MB. The Switcher is
53 * conveniently placed at the top 4MB, so it uses a separate, complete PTE
54 * page. */
14#define SWITCHER_PGD_INDEX (PTES_PER_PAGE - 1) 55#define SWITCHER_PGD_INDEX (PTES_PER_PAGE - 1)
15 56
57/* We actually need a separate PTE page for each CPU. Remember that after the
58 * Switcher code itself comes two pages for each CPU, and we don't want this
59 * CPU's guest to see the pages of any other CPU. */
16static DEFINE_PER_CPU(spte_t *, switcher_pte_pages); 60static DEFINE_PER_CPU(spte_t *, switcher_pte_pages);
17#define switcher_pte_page(cpu) per_cpu(switcher_pte_pages, cpu) 61#define switcher_pte_page(cpu) per_cpu(switcher_pte_pages, cpu)
18 62
63/*H:320 With our shadow and Guest types established, we need to deal with
64 * them: the page table code is curly enough to need helper functions to keep
65 * it clear and clean.
66 *
67 * The first helper takes a virtual address, and says which entry in the top
68 * level page table deals with that address. Since each top level entry deals
69 * with 4M, this effectively divides by 4M. */
19static unsigned vaddr_to_pgd_index(unsigned long vaddr) 70static unsigned vaddr_to_pgd_index(unsigned long vaddr)
20{ 71{
21 return vaddr >> (PAGE_SHIFT + PTES_PER_PAGE_SHIFT); 72 return vaddr >> (PAGE_SHIFT + PTES_PER_PAGE_SHIFT);
22} 73}
23 74
24/* These access the shadow versions (ie. the ones used by the CPU). */ 75/* There are two functions which return pointers to the shadow (aka "real")
76 * page tables.
77 *
78 * spgd_addr() takes the virtual address and returns a pointer to the top-level
79 * page directory entry for that address. Since we keep track of several page
80 * tables, the "i" argument tells us which one we're interested in (it's
81 * usually the current one). */
25static spgd_t *spgd_addr(struct lguest *lg, u32 i, unsigned long vaddr) 82static spgd_t *spgd_addr(struct lguest *lg, u32 i, unsigned long vaddr)
26{ 83{
27 unsigned int index = vaddr_to_pgd_index(vaddr); 84 unsigned int index = vaddr_to_pgd_index(vaddr);
28 85
86 /* We kill any Guest trying to touch the Switcher addresses. */
29 if (index >= SWITCHER_PGD_INDEX) { 87 if (index >= SWITCHER_PGD_INDEX) {
30 kill_guest(lg, "attempt to access switcher pages"); 88 kill_guest(lg, "attempt to access switcher pages");
31 index = 0; 89 index = 0;
32 } 90 }
91 /* Return a pointer index'th pgd entry for the i'th page table. */
33 return &lg->pgdirs[i].pgdir[index]; 92 return &lg->pgdirs[i].pgdir[index];
34} 93}
35 94
95/* This routine then takes the PGD entry given above, which contains the
96 * address of the PTE page. It then returns a pointer to the PTE entry for the
97 * given address. */
36static spte_t *spte_addr(struct lguest *lg, spgd_t spgd, unsigned long vaddr) 98static spte_t *spte_addr(struct lguest *lg, spgd_t spgd, unsigned long vaddr)
37{ 99{
38 spte_t *page = __va(spgd.pfn << PAGE_SHIFT); 100 spte_t *page = __va(spgd.pfn << PAGE_SHIFT);
101 /* You should never call this if the PGD entry wasn't valid */
39 BUG_ON(!(spgd.flags & _PAGE_PRESENT)); 102 BUG_ON(!(spgd.flags & _PAGE_PRESENT));
40 return &page[(vaddr >> PAGE_SHIFT) % PTES_PER_PAGE]; 103 return &page[(vaddr >> PAGE_SHIFT) % PTES_PER_PAGE];
41} 104}
42 105
43/* These access the guest versions. */ 106/* These two functions just like the above two, except they access the Guest
107 * page tables. Hence they return a Guest address. */
44static unsigned long gpgd_addr(struct lguest *lg, unsigned long vaddr) 108static unsigned long gpgd_addr(struct lguest *lg, unsigned long vaddr)
45{ 109{
46 unsigned int index = vaddr >> (PAGE_SHIFT + PTES_PER_PAGE_SHIFT); 110 unsigned int index = vaddr >> (PAGE_SHIFT + PTES_PER_PAGE_SHIFT);
@@ -55,12 +119,24 @@ static unsigned long gpte_addr(struct lguest *lg,
55 return gpage + ((vaddr>>PAGE_SHIFT) % PTES_PER_PAGE) * sizeof(gpte_t); 119 return gpage + ((vaddr>>PAGE_SHIFT) % PTES_PER_PAGE) * sizeof(gpte_t);
56} 120}
57 121
58/* Do a virtual -> physical mapping on a user page. */ 122/*H:350 This routine takes a page number given by the Guest and converts it to
123 * an actual, physical page number. It can fail for several reasons: the
124 * virtual address might not be mapped by the Launcher, the write flag is set
125 * and the page is read-only, or the write flag was set and the page was
126 * shared so had to be copied, but we ran out of memory.
127 *
128 * This holds a reference to the page, so release_pte() is careful to
129 * put that back. */
59static unsigned long get_pfn(unsigned long virtpfn, int write) 130static unsigned long get_pfn(unsigned long virtpfn, int write)
60{ 131{
61 struct page *page; 132 struct page *page;
133 /* This value indicates failure. */
62 unsigned long ret = -1UL; 134 unsigned long ret = -1UL;
63 135
136 /* get_user_pages() is a complex interface: it gets the "struct
137 * vm_area_struct" and "struct page" assocated with a range of pages.
138 * It also needs the task's mmap_sem held, and is not very quick.
139 * It returns the number of pages it got. */
64 down_read(&current->mm->mmap_sem); 140 down_read(&current->mm->mmap_sem);
65 if (get_user_pages(current, current->mm, virtpfn << PAGE_SHIFT, 141 if (get_user_pages(current, current->mm, virtpfn << PAGE_SHIFT,
66 1, write, 1, &page, NULL) == 1) 142 1, write, 1, &page, NULL) == 1)
@@ -69,28 +145,47 @@ static unsigned long get_pfn(unsigned long virtpfn, int write)
69 return ret; 145 return ret;
70} 146}
71 147
148/*H:340 Converting a Guest page table entry to a shadow (ie. real) page table
149 * entry can be a little tricky. The flags are (almost) the same, but the
150 * Guest PTE contains a virtual page number: the CPU needs the real page
151 * number. */
72static spte_t gpte_to_spte(struct lguest *lg, gpte_t gpte, int write) 152static spte_t gpte_to_spte(struct lguest *lg, gpte_t gpte, int write)
73{ 153{
74 spte_t spte; 154 spte_t spte;
75 unsigned long pfn; 155 unsigned long pfn;
76 156
77 /* We ignore the global flag. */ 157 /* The Guest sets the global flag, because it thinks that it is using
158 * PGE. We only told it to use PGE so it would tell us whether it was
159 * flushing a kernel mapping or a userspace mapping. We don't actually
160 * use the global bit, so throw it away. */
78 spte.flags = (gpte.flags & ~_PAGE_GLOBAL); 161 spte.flags = (gpte.flags & ~_PAGE_GLOBAL);
162
163 /* We need a temporary "unsigned long" variable to hold the answer from
164 * get_pfn(), because it returns 0xFFFFFFFF on failure, which wouldn't
165 * fit in spte.pfn. get_pfn() finds the real physical number of the
166 * page, given the virtual number. */
79 pfn = get_pfn(gpte.pfn, write); 167 pfn = get_pfn(gpte.pfn, write);
80 if (pfn == -1UL) { 168 if (pfn == -1UL) {
81 kill_guest(lg, "failed to get page %u", gpte.pfn); 169 kill_guest(lg, "failed to get page %u", gpte.pfn);
82 /* Must not put_page() bogus page on cleanup. */ 170 /* When we destroy the Guest, we'll go through the shadow page
171 * tables and release_pte() them. Make sure we don't think
172 * this one is valid! */
83 spte.flags = 0; 173 spte.flags = 0;
84 } 174 }
175 /* Now we assign the page number, and our shadow PTE is complete. */
85 spte.pfn = pfn; 176 spte.pfn = pfn;
86 return spte; 177 return spte;
87} 178}
88 179
180/*H:460 And to complete the chain, release_pte() looks like this: */
89static void release_pte(spte_t pte) 181static void release_pte(spte_t pte)
90{ 182{
183 /* Remember that get_user_pages() took a reference to the page, in
184 * get_pfn()? We have to put it back now. */
91 if (pte.flags & _PAGE_PRESENT) 185 if (pte.flags & _PAGE_PRESENT)
92 put_page(pfn_to_page(pte.pfn)); 186 put_page(pfn_to_page(pte.pfn));
93} 187}
188/*:*/
94 189
95static void check_gpte(struct lguest *lg, gpte_t gpte) 190static void check_gpte(struct lguest *lg, gpte_t gpte)
96{ 191{
@@ -104,11 +199,16 @@ static void check_gpgd(struct lguest *lg, gpgd_t gpgd)
104 kill_guest(lg, "bad page directory entry"); 199 kill_guest(lg, "bad page directory entry");
105} 200}
106 201
107/* FIXME: We hold reference to pages, which prevents them from being 202/*H:330
108 swapped. It'd be nice to have a callback when Linux wants to swap out. */ 203 * (i) Setting up a page table entry for the Guest when it faults
109 204 *
110/* We fault pages in, which allows us to update accessed/dirty bits. 205 * We saw this call in run_guest(): when we see a page fault in the Guest, we
111 * Return true if we got page. */ 206 * come here. That's because we only set up the shadow page tables lazily as
207 * they're needed, so we get page faults all the time and quietly fix them up
208 * and return to the Guest without it knowing.
209 *
210 * If we fixed up the fault (ie. we mapped the address), this routine returns
211 * true. */
112int demand_page(struct lguest *lg, unsigned long vaddr, int errcode) 212int demand_page(struct lguest *lg, unsigned long vaddr, int errcode)
113{ 213{
114 gpgd_t gpgd; 214 gpgd_t gpgd;
@@ -117,106 +217,161 @@ int demand_page(struct lguest *lg, unsigned long vaddr, int errcode)
117 gpte_t gpte; 217 gpte_t gpte;
118 spte_t *spte; 218 spte_t *spte;
119 219
220 /* First step: get the top-level Guest page table entry. */
120 gpgd = mkgpgd(lgread_u32(lg, gpgd_addr(lg, vaddr))); 221 gpgd = mkgpgd(lgread_u32(lg, gpgd_addr(lg, vaddr)));
222 /* Toplevel not present? We can't map it in. */
121 if (!(gpgd.flags & _PAGE_PRESENT)) 223 if (!(gpgd.flags & _PAGE_PRESENT))
122 return 0; 224 return 0;
123 225
226 /* Now look at the matching shadow entry. */
124 spgd = spgd_addr(lg, lg->pgdidx, vaddr); 227 spgd = spgd_addr(lg, lg->pgdidx, vaddr);
125 if (!(spgd->flags & _PAGE_PRESENT)) { 228 if (!(spgd->flags & _PAGE_PRESENT)) {
126 /* Get a page of PTEs for them. */ 229 /* No shadow entry: allocate a new shadow PTE page. */
127 unsigned long ptepage = get_zeroed_page(GFP_KERNEL); 230 unsigned long ptepage = get_zeroed_page(GFP_KERNEL);
128 /* FIXME: Steal from self in this case? */ 231 /* This is not really the Guest's fault, but killing it is
232 * simple for this corner case. */
129 if (!ptepage) { 233 if (!ptepage) {
130 kill_guest(lg, "out of memory allocating pte page"); 234 kill_guest(lg, "out of memory allocating pte page");
131 return 0; 235 return 0;
132 } 236 }
237 /* We check that the Guest pgd is OK. */
133 check_gpgd(lg, gpgd); 238 check_gpgd(lg, gpgd);
239 /* And we copy the flags to the shadow PGD entry. The page
240 * number in the shadow PGD is the page we just allocated. */
134 spgd->raw.val = (__pa(ptepage) | gpgd.flags); 241 spgd->raw.val = (__pa(ptepage) | gpgd.flags);
135 } 242 }
136 243
244 /* OK, now we look at the lower level in the Guest page table: keep its
245 * address, because we might update it later. */
137 gpte_ptr = gpte_addr(lg, gpgd, vaddr); 246 gpte_ptr = gpte_addr(lg, gpgd, vaddr);
138 gpte = mkgpte(lgread_u32(lg, gpte_ptr)); 247 gpte = mkgpte(lgread_u32(lg, gpte_ptr));
139 248
140 /* No page? */ 249 /* If this page isn't in the Guest page tables, we can't page it in. */
141 if (!(gpte.flags & _PAGE_PRESENT)) 250 if (!(gpte.flags & _PAGE_PRESENT))
142 return 0; 251 return 0;
143 252
144 /* Write to read-only page? */ 253 /* Check they're not trying to write to a page the Guest wants
254 * read-only (bit 2 of errcode == write). */
145 if ((errcode & 2) && !(gpte.flags & _PAGE_RW)) 255 if ((errcode & 2) && !(gpte.flags & _PAGE_RW))
146 return 0; 256 return 0;
147 257
148 /* User access to a non-user page? */ 258 /* User access to a kernel page? (bit 3 == user access) */
149 if ((errcode & 4) && !(gpte.flags & _PAGE_USER)) 259 if ((errcode & 4) && !(gpte.flags & _PAGE_USER))
150 return 0; 260 return 0;
151 261
262 /* Check that the Guest PTE flags are OK, and the page number is below
263 * the pfn_limit (ie. not mapping the Launcher binary). */
152 check_gpte(lg, gpte); 264 check_gpte(lg, gpte);
265 /* Add the _PAGE_ACCESSED and (for a write) _PAGE_DIRTY flag */
153 gpte.flags |= _PAGE_ACCESSED; 266 gpte.flags |= _PAGE_ACCESSED;
154 if (errcode & 2) 267 if (errcode & 2)
155 gpte.flags |= _PAGE_DIRTY; 268 gpte.flags |= _PAGE_DIRTY;
156 269
157 /* We're done with the old pte. */ 270 /* Get the pointer to the shadow PTE entry we're going to set. */
158 spte = spte_addr(lg, *spgd, vaddr); 271 spte = spte_addr(lg, *spgd, vaddr);
272 /* If there was a valid shadow PTE entry here before, we release it.
273 * This can happen with a write to a previously read-only entry. */
159 release_pte(*spte); 274 release_pte(*spte);
160 275
161 /* We don't make it writable if this isn't a write: later 276 /* If this is a write, we insist that the Guest page is writable (the
162 * write will fault so we can set dirty bit in guest. */ 277 * final arg to gpte_to_spte()). */
163 if (gpte.flags & _PAGE_DIRTY) 278 if (gpte.flags & _PAGE_DIRTY)
164 *spte = gpte_to_spte(lg, gpte, 1); 279 *spte = gpte_to_spte(lg, gpte, 1);
165 else { 280 else {
281 /* If this is a read, don't set the "writable" bit in the page
282 * table entry, even if the Guest says it's writable. That way
283 * we come back here when a write does actually ocur, so we can
284 * update the Guest's _PAGE_DIRTY flag. */
166 gpte_t ro_gpte = gpte; 285 gpte_t ro_gpte = gpte;
167 ro_gpte.flags &= ~_PAGE_RW; 286 ro_gpte.flags &= ~_PAGE_RW;
168 *spte = gpte_to_spte(lg, ro_gpte, 0); 287 *spte = gpte_to_spte(lg, ro_gpte, 0);
169 } 288 }
170 289
171 /* Now we update dirty/accessed on guest. */ 290 /* Finally, we write the Guest PTE entry back: we've set the
291 * _PAGE_ACCESSED and maybe the _PAGE_DIRTY flags. */
172 lgwrite_u32(lg, gpte_ptr, gpte.raw.val); 292 lgwrite_u32(lg, gpte_ptr, gpte.raw.val);
293
294 /* We succeeded in mapping the page! */
173 return 1; 295 return 1;
174} 296}
175 297
176/* This is much faster than the full demand_page logic. */ 298/*H:360 (ii) Setting up the page table entry for the Guest stack.
299 *
300 * Remember pin_stack_pages() which makes sure the stack is mapped? It could
301 * simply call demand_page(), but as we've seen that logic is quite long, and
302 * usually the stack pages are already mapped anyway, so it's not required.
303 *
304 * This is a quick version which answers the question: is this virtual address
305 * mapped by the shadow page tables, and is it writable? */
177static int page_writable(struct lguest *lg, unsigned long vaddr) 306static int page_writable(struct lguest *lg, unsigned long vaddr)
178{ 307{
179 spgd_t *spgd; 308 spgd_t *spgd;
180 unsigned long flags; 309 unsigned long flags;
181 310
311 /* Look at the top level entry: is it present? */
182 spgd = spgd_addr(lg, lg->pgdidx, vaddr); 312 spgd = spgd_addr(lg, lg->pgdidx, vaddr);
183 if (!(spgd->flags & _PAGE_PRESENT)) 313 if (!(spgd->flags & _PAGE_PRESENT))
184 return 0; 314 return 0;
185 315
316 /* Check the flags on the pte entry itself: it must be present and
317 * writable. */
186 flags = spte_addr(lg, *spgd, vaddr)->flags; 318 flags = spte_addr(lg, *spgd, vaddr)->flags;
187 return (flags & (_PAGE_PRESENT|_PAGE_RW)) == (_PAGE_PRESENT|_PAGE_RW); 319 return (flags & (_PAGE_PRESENT|_PAGE_RW)) == (_PAGE_PRESENT|_PAGE_RW);
188} 320}
189 321
322/* So, when pin_stack_pages() asks us to pin a page, we check if it's already
323 * in the page tables, and if not, we call demand_page() with error code 2
324 * (meaning "write"). */
190void pin_page(struct lguest *lg, unsigned long vaddr) 325void pin_page(struct lguest *lg, unsigned long vaddr)
191{ 326{
192 if (!page_writable(lg, vaddr) && !demand_page(lg, vaddr, 2)) 327 if (!page_writable(lg, vaddr) && !demand_page(lg, vaddr, 2))
193 kill_guest(lg, "bad stack page %#lx", vaddr); 328 kill_guest(lg, "bad stack page %#lx", vaddr);
194} 329}
195 330
331/*H:450 If we chase down the release_pgd() code, it looks like this: */
196static void release_pgd(struct lguest *lg, spgd_t *spgd) 332static void release_pgd(struct lguest *lg, spgd_t *spgd)
197{ 333{
334 /* If the entry's not present, there's nothing to release. */
198 if (spgd->flags & _PAGE_PRESENT) { 335 if (spgd->flags & _PAGE_PRESENT) {
199 unsigned int i; 336 unsigned int i;
337 /* Converting the pfn to find the actual PTE page is easy: turn
338 * the page number into a physical address, then convert to a
339 * virtual address (easy for kernel pages like this one). */
200 spte_t *ptepage = __va(spgd->pfn << PAGE_SHIFT); 340 spte_t *ptepage = __va(spgd->pfn << PAGE_SHIFT);
341 /* For each entry in the page, we might need to release it. */
201 for (i = 0; i < PTES_PER_PAGE; i++) 342 for (i = 0; i < PTES_PER_PAGE; i++)
202 release_pte(ptepage[i]); 343 release_pte(ptepage[i]);
344 /* Now we can free the page of PTEs */
203 free_page((long)ptepage); 345 free_page((long)ptepage);
346 /* And zero out the PGD entry we we never release it twice. */
204 spgd->raw.val = 0; 347 spgd->raw.val = 0;
205 } 348 }
206} 349}
207 350
351/*H:440 (v) Flushing (thowing away) page tables,
352 *
353 * We saw flush_user_mappings() called when we re-used a top-level pgdir page.
354 * It simply releases every PTE page from 0 up to the kernel address. */
208static void flush_user_mappings(struct lguest *lg, int idx) 355static void flush_user_mappings(struct lguest *lg, int idx)
209{ 356{
210 unsigned int i; 357 unsigned int i;
358 /* Release every pgd entry up to the kernel's address. */
211 for (i = 0; i < vaddr_to_pgd_index(lg->page_offset); i++) 359 for (i = 0; i < vaddr_to_pgd_index(lg->page_offset); i++)
212 release_pgd(lg, lg->pgdirs[idx].pgdir + i); 360 release_pgd(lg, lg->pgdirs[idx].pgdir + i);
213} 361}
214 362
363/* The Guest also has a hypercall to do this manually: it's used when a large
364 * number of mappings have been changed. */
215void guest_pagetable_flush_user(struct lguest *lg) 365void guest_pagetable_flush_user(struct lguest *lg)
216{ 366{
367 /* Drop the userspace part of the current page table. */
217 flush_user_mappings(lg, lg->pgdidx); 368 flush_user_mappings(lg, lg->pgdidx);
218} 369}
370/*:*/
219 371
372/* We keep several page tables. This is a simple routine to find the page
373 * table (if any) corresponding to this top-level address the Guest has given
374 * us. */
220static unsigned int find_pgdir(struct lguest *lg, unsigned long pgtable) 375static unsigned int find_pgdir(struct lguest *lg, unsigned long pgtable)
221{ 376{
222 unsigned int i; 377 unsigned int i;
@@ -226,21 +381,30 @@ static unsigned int find_pgdir(struct lguest *lg, unsigned long pgtable)
226 return i; 381 return i;
227} 382}
228 383
384/*H:435 And this is us, creating the new page directory. If we really do
385 * allocate a new one (and so the kernel parts are not there), we set
386 * blank_pgdir. */
229static unsigned int new_pgdir(struct lguest *lg, 387static unsigned int new_pgdir(struct lguest *lg,
230 unsigned long cr3, 388 unsigned long cr3,
231 int *blank_pgdir) 389 int *blank_pgdir)
232{ 390{
233 unsigned int next; 391 unsigned int next;
234 392
393 /* We pick one entry at random to throw out. Choosing the Least
394 * Recently Used might be better, but this is easy. */
235 next = random32() % ARRAY_SIZE(lg->pgdirs); 395 next = random32() % ARRAY_SIZE(lg->pgdirs);
396 /* If it's never been allocated at all before, try now. */
236 if (!lg->pgdirs[next].pgdir) { 397 if (!lg->pgdirs[next].pgdir) {
237 lg->pgdirs[next].pgdir = (spgd_t *)get_zeroed_page(GFP_KERNEL); 398 lg->pgdirs[next].pgdir = (spgd_t *)get_zeroed_page(GFP_KERNEL);
399 /* If the allocation fails, just keep using the one we have */
238 if (!lg->pgdirs[next].pgdir) 400 if (!lg->pgdirs[next].pgdir)
239 next = lg->pgdidx; 401 next = lg->pgdidx;
240 else 402 else
241 /* There are no mappings: you'll need to re-pin */ 403 /* This is a blank page, so there are no kernel
404 * mappings: caller must map the stack! */
242 *blank_pgdir = 1; 405 *blank_pgdir = 1;
243 } 406 }
407 /* Record which Guest toplevel this shadows. */
244 lg->pgdirs[next].cr3 = cr3; 408 lg->pgdirs[next].cr3 = cr3;
245 /* Release all the non-kernel mappings. */ 409 /* Release all the non-kernel mappings. */
246 flush_user_mappings(lg, next); 410 flush_user_mappings(lg, next);
@@ -248,82 +412,161 @@ static unsigned int new_pgdir(struct lguest *lg,
248 return next; 412 return next;
249} 413}
250 414
415/*H:430 (iv) Switching page tables
416 *
417 * This is what happens when the Guest changes page tables (ie. changes the
418 * top-level pgdir). This happens on almost every context switch. */
251void guest_new_pagetable(struct lguest *lg, unsigned long pgtable) 419void guest_new_pagetable(struct lguest *lg, unsigned long pgtable)
252{ 420{
253 int newpgdir, repin = 0; 421 int newpgdir, repin = 0;
254 422
423 /* Look to see if we have this one already. */
255 newpgdir = find_pgdir(lg, pgtable); 424 newpgdir = find_pgdir(lg, pgtable);
425 /* If not, we allocate or mug an existing one: if it's a fresh one,
426 * repin gets set to 1. */
256 if (newpgdir == ARRAY_SIZE(lg->pgdirs)) 427 if (newpgdir == ARRAY_SIZE(lg->pgdirs))
257 newpgdir = new_pgdir(lg, pgtable, &repin); 428 newpgdir = new_pgdir(lg, pgtable, &repin);
429 /* Change the current pgd index to the new one. */
258 lg->pgdidx = newpgdir; 430 lg->pgdidx = newpgdir;
431 /* If it was completely blank, we map in the Guest kernel stack */
259 if (repin) 432 if (repin)
260 pin_stack_pages(lg); 433 pin_stack_pages(lg);
261} 434}
262 435
436/*H:470 Finally, a routine which throws away everything: all PGD entries in all
437 * the shadow page tables. This is used when we destroy the Guest. */
263static void release_all_pagetables(struct lguest *lg) 438static void release_all_pagetables(struct lguest *lg)
264{ 439{
265 unsigned int i, j; 440 unsigned int i, j;
266 441
442 /* Every shadow pagetable this Guest has */
267 for (i = 0; i < ARRAY_SIZE(lg->pgdirs); i++) 443 for (i = 0; i < ARRAY_SIZE(lg->pgdirs); i++)
268 if (lg->pgdirs[i].pgdir) 444 if (lg->pgdirs[i].pgdir)
445 /* Every PGD entry except the Switcher at the top */
269 for (j = 0; j < SWITCHER_PGD_INDEX; j++) 446 for (j = 0; j < SWITCHER_PGD_INDEX; j++)
270 release_pgd(lg, lg->pgdirs[i].pgdir + j); 447 release_pgd(lg, lg->pgdirs[i].pgdir + j);
271} 448}
272 449
450/* We also throw away everything when a Guest tells us it's changed a kernel
451 * mapping. Since kernel mappings are in every page table, it's easiest to
452 * throw them all away. This is amazingly slow, but thankfully rare. */
273void guest_pagetable_clear_all(struct lguest *lg) 453void guest_pagetable_clear_all(struct lguest *lg)
274{ 454{
275 release_all_pagetables(lg); 455 release_all_pagetables(lg);
456 /* We need the Guest kernel stack mapped again. */
276 pin_stack_pages(lg); 457 pin_stack_pages(lg);
277} 458}
278 459
460/*H:420 This is the routine which actually sets the page table entry for then
461 * "idx"'th shadow page table.
462 *
463 * Normally, we can just throw out the old entry and replace it with 0: if they
464 * use it demand_page() will put the new entry in. We need to do this anyway:
465 * The Guest expects _PAGE_ACCESSED to be set on its PTE the first time a page
466 * is read from, and _PAGE_DIRTY when it's written to.
467 *
468 * But Avi Kivity pointed out that most Operating Systems (Linux included) set
469 * these bits on PTEs immediately anyway. This is done to save the CPU from
470 * having to update them, but it helps us the same way: if they set
471 * _PAGE_ACCESSED then we can put a read-only PTE entry in immediately, and if
472 * they set _PAGE_DIRTY then we can put a writable PTE entry in immediately.
473 */
279static void do_set_pte(struct lguest *lg, int idx, 474static void do_set_pte(struct lguest *lg, int idx,
280 unsigned long vaddr, gpte_t gpte) 475 unsigned long vaddr, gpte_t gpte)
281{ 476{
477 /* Look up the matching shadow page directot entry. */
282 spgd_t *spgd = spgd_addr(lg, idx, vaddr); 478 spgd_t *spgd = spgd_addr(lg, idx, vaddr);
479
480 /* If the top level isn't present, there's no entry to update. */
283 if (spgd->flags & _PAGE_PRESENT) { 481 if (spgd->flags & _PAGE_PRESENT) {
482 /* Otherwise, we start by releasing the existing entry. */
284 spte_t *spte = spte_addr(lg, *spgd, vaddr); 483 spte_t *spte = spte_addr(lg, *spgd, vaddr);
285 release_pte(*spte); 484 release_pte(*spte);
485
486 /* If they're setting this entry as dirty or accessed, we might
487 * as well put that entry they've given us in now. This shaves
488 * 10% off a copy-on-write micro-benchmark. */
286 if (gpte.flags & (_PAGE_DIRTY | _PAGE_ACCESSED)) { 489 if (gpte.flags & (_PAGE_DIRTY | _PAGE_ACCESSED)) {
287 check_gpte(lg, gpte); 490 check_gpte(lg, gpte);
288 *spte = gpte_to_spte(lg, gpte, gpte.flags&_PAGE_DIRTY); 491 *spte = gpte_to_spte(lg, gpte, gpte.flags&_PAGE_DIRTY);
289 } else 492 } else
493 /* Otherwise we can demand_page() it in later. */
290 spte->raw.val = 0; 494 spte->raw.val = 0;
291 } 495 }
292} 496}
293 497
498/*H:410 Updating a PTE entry is a little trickier.
499 *
500 * We keep track of several different page tables (the Guest uses one for each
501 * process, so it makes sense to cache at least a few). Each of these have
502 * identical kernel parts: ie. every mapping above PAGE_OFFSET is the same for
503 * all processes. So when the page table above that address changes, we update
504 * all the page tables, not just the current one. This is rare.
505 *
506 * The benefit is that when we have to track a new page table, we can copy keep
507 * all the kernel mappings. This speeds up context switch immensely. */
294void guest_set_pte(struct lguest *lg, 508void guest_set_pte(struct lguest *lg,
295 unsigned long cr3, unsigned long vaddr, gpte_t gpte) 509 unsigned long cr3, unsigned long vaddr, gpte_t gpte)
296{ 510{
297 /* Kernel mappings must be changed on all top levels. */ 511 /* Kernel mappings must be changed on all top levels. Slow, but
512 * doesn't happen often. */
298 if (vaddr >= lg->page_offset) { 513 if (vaddr >= lg->page_offset) {
299 unsigned int i; 514 unsigned int i;
300 for (i = 0; i < ARRAY_SIZE(lg->pgdirs); i++) 515 for (i = 0; i < ARRAY_SIZE(lg->pgdirs); i++)
301 if (lg->pgdirs[i].pgdir) 516 if (lg->pgdirs[i].pgdir)
302 do_set_pte(lg, i, vaddr, gpte); 517 do_set_pte(lg, i, vaddr, gpte);
303 } else { 518 } else {
519 /* Is this page table one we have a shadow for? */
304 int pgdir = find_pgdir(lg, cr3); 520 int pgdir = find_pgdir(lg, cr3);
305 if (pgdir != ARRAY_SIZE(lg->pgdirs)) 521 if (pgdir != ARRAY_SIZE(lg->pgdirs))
522 /* If so, do the update. */
306 do_set_pte(lg, pgdir, vaddr, gpte); 523 do_set_pte(lg, pgdir, vaddr, gpte);
307 } 524 }
308} 525}
309 526
527/*H:400
528 * (iii) Setting up a page table entry when the Guest tells us it has changed.
529 *
530 * Just like we did in interrupts_and_traps.c, it makes sense for us to deal
531 * with the other side of page tables while we're here: what happens when the
532 * Guest asks for a page table to be updated?
533 *
534 * We already saw that demand_page() will fill in the shadow page tables when
535 * needed, so we can simply remove shadow page table entries whenever the Guest
536 * tells us they've changed. When the Guest tries to use the new entry it will
537 * fault and demand_page() will fix it up.
538 *
539 * So with that in mind here's our code to to update a (top-level) PGD entry:
540 */
310void guest_set_pmd(struct lguest *lg, unsigned long cr3, u32 idx) 541void guest_set_pmd(struct lguest *lg, unsigned long cr3, u32 idx)
311{ 542{
312 int pgdir; 543 int pgdir;
313 544
545 /* The kernel seems to try to initialize this early on: we ignore its
546 * attempts to map over the Switcher. */
314 if (idx >= SWITCHER_PGD_INDEX) 547 if (idx >= SWITCHER_PGD_INDEX)
315 return; 548 return;
316 549
550 /* If they're talking about a page table we have a shadow for... */
317 pgdir = find_pgdir(lg, cr3); 551 pgdir = find_pgdir(lg, cr3);
318 if (pgdir < ARRAY_SIZE(lg->pgdirs)) 552 if (pgdir < ARRAY_SIZE(lg->pgdirs))
553 /* ... throw it away. */
319 release_pgd(lg, lg->pgdirs[pgdir].pgdir + idx); 554 release_pgd(lg, lg->pgdirs[pgdir].pgdir + idx);
320} 555}
321 556
557/*H:500 (vii) Setting up the page tables initially.
558 *
559 * When a Guest is first created, the Launcher tells us where the toplevel of
560 * its first page table is. We set some things up here: */
322int init_guest_pagetable(struct lguest *lg, unsigned long pgtable) 561int init_guest_pagetable(struct lguest *lg, unsigned long pgtable)
323{ 562{
324 /* We assume this in flush_user_mappings, so check now */ 563 /* In flush_user_mappings() we loop from 0 to
564 * "vaddr_to_pgd_index(lg->page_offset)". This assumes it won't hit
565 * the Switcher mappings, so check that now. */
325 if (vaddr_to_pgd_index(lg->page_offset) >= SWITCHER_PGD_INDEX) 566 if (vaddr_to_pgd_index(lg->page_offset) >= SWITCHER_PGD_INDEX)
326 return -EINVAL; 567 return -EINVAL;
568 /* We start on the first shadow page table, and give it a blank PGD
569 * page. */
327 lg->pgdidx = 0; 570 lg->pgdidx = 0;
328 lg->pgdirs[lg->pgdidx].cr3 = pgtable; 571 lg->pgdirs[lg->pgdidx].cr3 = pgtable;
329 lg->pgdirs[lg->pgdidx].pgdir = (spgd_t*)get_zeroed_page(GFP_KERNEL); 572 lg->pgdirs[lg->pgdidx].pgdir = (spgd_t*)get_zeroed_page(GFP_KERNEL);
@@ -332,33 +575,48 @@ int init_guest_pagetable(struct lguest *lg, unsigned long pgtable)
332 return 0; 575 return 0;
333} 576}
334 577
578/* When a Guest dies, our cleanup is fairly simple. */
335void free_guest_pagetable(struct lguest *lg) 579void free_guest_pagetable(struct lguest *lg)
336{ 580{
337 unsigned int i; 581 unsigned int i;
338 582
583 /* Throw away all page table pages. */
339 release_all_pagetables(lg); 584 release_all_pagetables(lg);
585 /* Now free the top levels: free_page() can handle 0 just fine. */
340 for (i = 0; i < ARRAY_SIZE(lg->pgdirs); i++) 586 for (i = 0; i < ARRAY_SIZE(lg->pgdirs); i++)
341 free_page((long)lg->pgdirs[i].pgdir); 587 free_page((long)lg->pgdirs[i].pgdir);
342} 588}
343 589
344/* Caller must be preempt-safe */ 590/*H:480 (vi) Mapping the Switcher when the Guest is about to run.
591 *
592 * The Switcher and the two pages for this CPU need to be available to the
593 * Guest (and not the pages for other CPUs). We have the appropriate PTE pages
594 * for each CPU already set up, we just need to hook them in. */
345void map_switcher_in_guest(struct lguest *lg, struct lguest_pages *pages) 595void map_switcher_in_guest(struct lguest *lg, struct lguest_pages *pages)
346{ 596{
347 spte_t *switcher_pte_page = __get_cpu_var(switcher_pte_pages); 597 spte_t *switcher_pte_page = __get_cpu_var(switcher_pte_pages);
348 spgd_t switcher_pgd; 598 spgd_t switcher_pgd;
349 spte_t regs_pte; 599 spte_t regs_pte;
350 600
351 /* Since switcher less that 4MB, we simply mug top pte page. */ 601 /* Make the last PGD entry for this Guest point to the Switcher's PTE
602 * page for this CPU (with appropriate flags). */
352 switcher_pgd.pfn = __pa(switcher_pte_page) >> PAGE_SHIFT; 603 switcher_pgd.pfn = __pa(switcher_pte_page) >> PAGE_SHIFT;
353 switcher_pgd.flags = _PAGE_KERNEL; 604 switcher_pgd.flags = _PAGE_KERNEL;
354 lg->pgdirs[lg->pgdidx].pgdir[SWITCHER_PGD_INDEX] = switcher_pgd; 605 lg->pgdirs[lg->pgdidx].pgdir[SWITCHER_PGD_INDEX] = switcher_pgd;
355 606
356 /* Map our regs page over stack page. */ 607 /* We also change the Switcher PTE page. When we're running the Guest,
608 * we want the Guest's "regs" page to appear where the first Switcher
609 * page for this CPU is. This is an optimization: when the Switcher
610 * saves the Guest registers, it saves them into the first page of this
611 * CPU's "struct lguest_pages": if we make sure the Guest's register
612 * page is already mapped there, we don't have to copy them out
613 * again. */
357 regs_pte.pfn = __pa(lg->regs_page) >> PAGE_SHIFT; 614 regs_pte.pfn = __pa(lg->regs_page) >> PAGE_SHIFT;
358 regs_pte.flags = _PAGE_KERNEL; 615 regs_pte.flags = _PAGE_KERNEL;
359 switcher_pte_page[(unsigned long)pages/PAGE_SIZE%PTES_PER_PAGE] 616 switcher_pte_page[(unsigned long)pages/PAGE_SIZE%PTES_PER_PAGE]
360 = regs_pte; 617 = regs_pte;
361} 618}
619/*:*/
362 620
363static void free_switcher_pte_pages(void) 621static void free_switcher_pte_pages(void)
364{ 622{
@@ -368,6 +626,10 @@ static void free_switcher_pte_pages(void)
368 free_page((long)switcher_pte_page(i)); 626 free_page((long)switcher_pte_page(i));
369} 627}
370 628
629/*H:520 Setting up the Switcher PTE page for given CPU is fairly easy, given
630 * the CPU number and the "struct page"s for the Switcher code itself.
631 *
632 * Currently the Switcher is less than a page long, so "pages" is always 1. */
371static __init void populate_switcher_pte_page(unsigned int cpu, 633static __init void populate_switcher_pte_page(unsigned int cpu,
372 struct page *switcher_page[], 634 struct page *switcher_page[],
373 unsigned int pages) 635 unsigned int pages)
@@ -375,21 +637,26 @@ static __init void populate_switcher_pte_page(unsigned int cpu,
375 unsigned int i; 637 unsigned int i;
376 spte_t *pte = switcher_pte_page(cpu); 638 spte_t *pte = switcher_pte_page(cpu);
377 639
640 /* The first entries are easy: they map the Switcher code. */
378 for (i = 0; i < pages; i++) { 641 for (i = 0; i < pages; i++) {
379 pte[i].pfn = page_to_pfn(switcher_page[i]); 642 pte[i].pfn = page_to_pfn(switcher_page[i]);
380 pte[i].flags = _PAGE_PRESENT|_PAGE_ACCESSED; 643 pte[i].flags = _PAGE_PRESENT|_PAGE_ACCESSED;
381 } 644 }
382 645
383 /* We only map this CPU's pages, so guest can't see others. */ 646 /* The only other thing we map is this CPU's pair of pages. */
384 i = pages + cpu*2; 647 i = pages + cpu*2;
385 648
386 /* First page (regs) is rw, second (state) is ro. */ 649 /* First page (Guest registers) is writable from the Guest */
387 pte[i].pfn = page_to_pfn(switcher_page[i]); 650 pte[i].pfn = page_to_pfn(switcher_page[i]);
388 pte[i].flags = _PAGE_PRESENT|_PAGE_ACCESSED|_PAGE_RW; 651 pte[i].flags = _PAGE_PRESENT|_PAGE_ACCESSED|_PAGE_RW;
652 /* The second page contains the "struct lguest_ro_state", and is
653 * read-only. */
389 pte[i+1].pfn = page_to_pfn(switcher_page[i+1]); 654 pte[i+1].pfn = page_to_pfn(switcher_page[i+1]);
390 pte[i+1].flags = _PAGE_PRESENT|_PAGE_ACCESSED; 655 pte[i+1].flags = _PAGE_PRESENT|_PAGE_ACCESSED;
391} 656}
392 657
658/*H:510 At boot or module load time, init_pagetables() allocates and populates
659 * the Switcher PTE page for each CPU. */
393__init int init_pagetables(struct page **switcher_page, unsigned int pages) 660__init int init_pagetables(struct page **switcher_page, unsigned int pages)
394{ 661{
395 unsigned int i; 662 unsigned int i;
@@ -404,7 +671,9 @@ __init int init_pagetables(struct page **switcher_page, unsigned int pages)
404 } 671 }
405 return 0; 672 return 0;
406} 673}
674/*:*/
407 675
676/* Cleaning up simply involves freeing the PTE page for each CPU. */
408void free_pagetables(void) 677void free_pagetables(void)
409{ 678{
410 free_switcher_pte_pages(); 679 free_switcher_pte_pages();
diff --git a/drivers/lguest/segments.c b/drivers/lguest/segments.c
index 1b2cfe89dcd5..f675a41a80da 100644
--- a/drivers/lguest/segments.c
+++ b/drivers/lguest/segments.c
@@ -1,16 +1,68 @@
1/*P:600 The x86 architecture has segments, which involve a table of descriptors
2 * which can be used to do funky things with virtual address interpretation.
3 * We originally used to use segments so the Guest couldn't alter the
4 * Guest<->Host Switcher, and then we had to trim Guest segments, and restore
5 * for userspace per-thread segments, but trim again for on userspace->kernel
6 * transitions... This nightmarish creation was contained within this file,
7 * where we knew not to tread without heavy armament and a change of underwear.
8 *
9 * In these modern times, the segment handling code consists of simple sanity
10 * checks, and the worst you'll experience reading this code is butterfly-rash
11 * from frolicking through its parklike serenity. :*/
1#include "lg.h" 12#include "lg.h"
2 13
14/*H:600
15 * We've almost completed the Host; there's just one file to go!
16 *
17 * Segments & The Global Descriptor Table
18 *
19 * (That title sounds like a bad Nerdcore group. Not to suggest that there are
20 * any good Nerdcore groups, but in high school a friend of mine had a band
21 * called Joe Fish and the Chips, so there are definitely worse band names).
22 *
23 * To refresh: the GDT is a table of 8-byte values describing segments. Once
24 * set up, these segments can be loaded into one of the 6 "segment registers".
25 *
26 * GDT entries are passed around as "struct desc_struct"s, which like IDT
27 * entries are split into two 32-bit members, "a" and "b". One day, someone
28 * will clean that up, and be declared a Hero. (No pressure, I'm just saying).
29 *
30 * Anyway, the GDT entry contains a base (the start address of the segment), a
31 * limit (the size of the segment - 1), and some flags. Sounds simple, and it
32 * would be, except those zany Intel engineers decided that it was too boring
33 * to put the base at one end, the limit at the other, and the flags in
34 * between. They decided to shotgun the bits at random throughout the 8 bytes,
35 * like so:
36 *
37 * 0 16 40 48 52 56 63
38 * [ limit part 1 ][ base part 1 ][ flags ][li][fl][base ]
39 * mit ags part 2
40 * part 2
41 *
42 * As a result, this file contains a certain amount of magic numeracy. Let's
43 * begin.
44 */
45
46/* Is the descriptor the Guest wants us to put in OK?
47 *
48 * The flag which Intel says must be zero: must be zero. The descriptor must
49 * be present, (this is actually checked earlier but is here for thorougness),
50 * and the descriptor type must be 1 (a memory segment). */
3static int desc_ok(const struct desc_struct *gdt) 51static int desc_ok(const struct desc_struct *gdt)
4{ 52{
5 /* MBZ=0, P=1, DT=1 */
6 return ((gdt->b & 0x00209000) == 0x00009000); 53 return ((gdt->b & 0x00209000) == 0x00009000);
7} 54}
8 55
56/* Is the segment present? (Otherwise it can't be used by the Guest). */
9static int segment_present(const struct desc_struct *gdt) 57static int segment_present(const struct desc_struct *gdt)
10{ 58{
11 return gdt->b & 0x8000; 59 return gdt->b & 0x8000;
12} 60}
13 61
62/* There are several entries we don't let the Guest set. The TSS entry is the
63 * "Task State Segment" which controls all kinds of delicate things. The
64 * LGUEST_CS and LGUEST_DS entries are reserved for the Switcher, and the
65 * the Guest can't be trusted to deal with double faults. */
14static int ignored_gdt(unsigned int num) 66static int ignored_gdt(unsigned int num)
15{ 67{
16 return (num == GDT_ENTRY_TSS 68 return (num == GDT_ENTRY_TSS
@@ -19,9 +71,18 @@ static int ignored_gdt(unsigned int num)
19 || num == GDT_ENTRY_DOUBLEFAULT_TSS); 71 || num == GDT_ENTRY_DOUBLEFAULT_TSS);
20} 72}
21 73
22/* We don't allow removal of CS, DS or SS; it doesn't make sense. */ 74/* If the Guest asks us to remove an entry from the GDT, we have to be careful.
75 * If one of the segment registers is pointing at that entry the Switcher will
76 * crash when it tries to reload the segment registers for the Guest.
77 *
78 * It doesn't make much sense for the Guest to try to remove its own code, data
79 * or stack segments while they're in use: assume that's a Guest bug. If it's
80 * one of the lesser segment registers using the removed entry, we simply set
81 * that register to 0 (unusable). */
23static void check_segment_use(struct lguest *lg, unsigned int desc) 82static void check_segment_use(struct lguest *lg, unsigned int desc)
24{ 83{
84 /* GDT entries are 8 bytes long, so we divide to get the index and
85 * ignore the bottom bits. */
25 if (lg->regs->gs / 8 == desc) 86 if (lg->regs->gs / 8 == desc)
26 lg->regs->gs = 0; 87 lg->regs->gs = 0;
27 if (lg->regs->fs / 8 == desc) 88 if (lg->regs->fs / 8 == desc)
@@ -33,13 +94,21 @@ static void check_segment_use(struct lguest *lg, unsigned int desc)
33 || lg->regs->ss / 8 == desc) 94 || lg->regs->ss / 8 == desc)
34 kill_guest(lg, "Removed live GDT entry %u", desc); 95 kill_guest(lg, "Removed live GDT entry %u", desc);
35} 96}
36 97/*:*/
98/*M:009 We wouldn't need to check for removal of in-use segments if we handled
99 * faults in the Switcher. However, it's probably not a worthwhile
100 * optimization. :*/
101
102/*H:610 Once the GDT has been changed, we look through the changed entries and
103 * see if they're OK. If not, we'll call kill_guest() and the Guest will never
104 * get to use the invalid entries. */
37static void fixup_gdt_table(struct lguest *lg, unsigned start, unsigned end) 105static void fixup_gdt_table(struct lguest *lg, unsigned start, unsigned end)
38{ 106{
39 unsigned int i; 107 unsigned int i;
40 108
41 for (i = start; i < end; i++) { 109 for (i = start; i < end; i++) {
42 /* We never copy these ones to real gdt */ 110 /* We never copy these ones to real GDT, so we don't care what
111 * they say */
43 if (ignored_gdt(i)) 112 if (ignored_gdt(i))
44 continue; 113 continue;
45 114
@@ -53,41 +122,57 @@ static void fixup_gdt_table(struct lguest *lg, unsigned start, unsigned end)
53 if (!desc_ok(&lg->gdt[i])) 122 if (!desc_ok(&lg->gdt[i]))
54 kill_guest(lg, "Bad GDT descriptor %i", i); 123 kill_guest(lg, "Bad GDT descriptor %i", i);
55 124
56 /* DPL 0 presumably means "for use by guest". */ 125 /* Segment descriptors contain a privilege level: the Guest is
126 * sometimes careless and leaves this as 0, even though it's
127 * running at privilege level 1. If so, we fix it here. */
57 if ((lg->gdt[i].b & 0x00006000) == 0) 128 if ((lg->gdt[i].b & 0x00006000) == 0)
58 lg->gdt[i].b |= (GUEST_PL << 13); 129 lg->gdt[i].b |= (GUEST_PL << 13);
59 130
60 /* Set accessed bit, since gdt isn't writable. */ 131 /* Each descriptor has an "accessed" bit. If we don't set it
132 * now, the CPU will try to set it when the Guest first loads
133 * that entry into a segment register. But the GDT isn't
134 * writable by the Guest, so bad things can happen. */
61 lg->gdt[i].b |= 0x00000100; 135 lg->gdt[i].b |= 0x00000100;
62 } 136 }
63} 137}
64 138
139/* This routine is called at boot or modprobe time for each CPU to set up the
140 * "constant" GDT entries for Guests running on that CPU. */
65void setup_default_gdt_entries(struct lguest_ro_state *state) 141void setup_default_gdt_entries(struct lguest_ro_state *state)
66{ 142{
67 struct desc_struct *gdt = state->guest_gdt; 143 struct desc_struct *gdt = state->guest_gdt;
68 unsigned long tss = (unsigned long)&state->guest_tss; 144 unsigned long tss = (unsigned long)&state->guest_tss;
69 145
70 /* Hypervisor segments. */ 146 /* The hypervisor segments are full 0-4G segments, privilege level 0 */
71 gdt[GDT_ENTRY_LGUEST_CS] = FULL_EXEC_SEGMENT; 147 gdt[GDT_ENTRY_LGUEST_CS] = FULL_EXEC_SEGMENT;
72 gdt[GDT_ENTRY_LGUEST_DS] = FULL_SEGMENT; 148 gdt[GDT_ENTRY_LGUEST_DS] = FULL_SEGMENT;
73 149
74 /* This is the one which we *cannot* copy from guest, since tss 150 /* The TSS segment refers to the TSS entry for this CPU, so we cannot
75 is depended on this lguest_ro_state, ie. this cpu. */ 151 * copy it from the Guest. Forgive the magic flags */
76 gdt[GDT_ENTRY_TSS].a = 0x00000067 | (tss << 16); 152 gdt[GDT_ENTRY_TSS].a = 0x00000067 | (tss << 16);
77 gdt[GDT_ENTRY_TSS].b = 0x00008900 | (tss & 0xFF000000) 153 gdt[GDT_ENTRY_TSS].b = 0x00008900 | (tss & 0xFF000000)
78 | ((tss >> 16) & 0x000000FF); 154 | ((tss >> 16) & 0x000000FF);
79} 155}
80 156
157/* This routine is called before the Guest is run for the first time. */
81void setup_guest_gdt(struct lguest *lg) 158void setup_guest_gdt(struct lguest *lg)
82{ 159{
160 /* Start with full 0-4G segments... */
83 lg->gdt[GDT_ENTRY_KERNEL_CS] = FULL_EXEC_SEGMENT; 161 lg->gdt[GDT_ENTRY_KERNEL_CS] = FULL_EXEC_SEGMENT;
84 lg->gdt[GDT_ENTRY_KERNEL_DS] = FULL_SEGMENT; 162 lg->gdt[GDT_ENTRY_KERNEL_DS] = FULL_SEGMENT;
163 /* ...except the Guest is allowed to use them, so set the privilege
164 * level appropriately in the flags. */
85 lg->gdt[GDT_ENTRY_KERNEL_CS].b |= (GUEST_PL << 13); 165 lg->gdt[GDT_ENTRY_KERNEL_CS].b |= (GUEST_PL << 13);
86 lg->gdt[GDT_ENTRY_KERNEL_DS].b |= (GUEST_PL << 13); 166 lg->gdt[GDT_ENTRY_KERNEL_DS].b |= (GUEST_PL << 13);
87} 167}
88 168
89/* This is a fast version for the common case where only the three TLS entries 169/* Like the IDT, we never simply use the GDT the Guest gives us. We set up the
90 * have changed. */ 170 * GDTs for each CPU, then we copy across the entries each time we want to run
171 * a different Guest on that CPU. */
172
173/* A partial GDT load, for the three "thead-local storage" entries. Otherwise
174 * it's just like load_guest_gdt(). So much, in fact, it would probably be
175 * neater to have a single hypercall to cover both. */
91void copy_gdt_tls(const struct lguest *lg, struct desc_struct *gdt) 176void copy_gdt_tls(const struct lguest *lg, struct desc_struct *gdt)
92{ 177{
93 unsigned int i; 178 unsigned int i;
@@ -96,22 +181,31 @@ void copy_gdt_tls(const struct lguest *lg, struct desc_struct *gdt)
96 gdt[i] = lg->gdt[i]; 181 gdt[i] = lg->gdt[i];
97} 182}
98 183
184/* This is the full version */
99void copy_gdt(const struct lguest *lg, struct desc_struct *gdt) 185void copy_gdt(const struct lguest *lg, struct desc_struct *gdt)
100{ 186{
101 unsigned int i; 187 unsigned int i;
102 188
189 /* The default entries from setup_default_gdt_entries() are not
190 * replaced. See ignored_gdt() above. */
103 for (i = 0; i < GDT_ENTRIES; i++) 191 for (i = 0; i < GDT_ENTRIES; i++)
104 if (!ignored_gdt(i)) 192 if (!ignored_gdt(i))
105 gdt[i] = lg->gdt[i]; 193 gdt[i] = lg->gdt[i];
106} 194}
107 195
196/* This is where the Guest asks us to load a new GDT (LHCALL_LOAD_GDT). */
108void load_guest_gdt(struct lguest *lg, unsigned long table, u32 num) 197void load_guest_gdt(struct lguest *lg, unsigned long table, u32 num)
109{ 198{
199 /* We assume the Guest has the same number of GDT entries as the
200 * Host, otherwise we'd have to dynamically allocate the Guest GDT. */
110 if (num > ARRAY_SIZE(lg->gdt)) 201 if (num > ARRAY_SIZE(lg->gdt))
111 kill_guest(lg, "too many gdt entries %i", num); 202 kill_guest(lg, "too many gdt entries %i", num);
112 203
204 /* We read the whole thing in, then fix it up. */
113 lgread(lg, lg->gdt, table, num * sizeof(lg->gdt[0])); 205 lgread(lg, lg->gdt, table, num * sizeof(lg->gdt[0]));
114 fixup_gdt_table(lg, 0, ARRAY_SIZE(lg->gdt)); 206 fixup_gdt_table(lg, 0, ARRAY_SIZE(lg->gdt));
207 /* Mark that the GDT changed so the core knows it has to copy it again,
208 * even if the Guest is run on the same CPU. */
115 lg->changed |= CHANGED_GDT; 209 lg->changed |= CHANGED_GDT;
116} 210}
117 211
@@ -123,3 +217,13 @@ void guest_load_tls(struct lguest *lg, unsigned long gtls)
123 fixup_gdt_table(lg, GDT_ENTRY_TLS_MIN, GDT_ENTRY_TLS_MAX+1); 217 fixup_gdt_table(lg, GDT_ENTRY_TLS_MIN, GDT_ENTRY_TLS_MAX+1);
124 lg->changed |= CHANGED_GDT_TLS; 218 lg->changed |= CHANGED_GDT_TLS;
125} 219}
220
221/*
222 * With this, we have finished the Host.
223 *
224 * Five of the seven parts of our task are complete. You have made it through
225 * the Bit of Despair (I think that's somewhere in the page table code,
226 * myself).
227 *
228 * Next, we examine "make Switcher". It's short, but intense.
229 */
diff --git a/drivers/lguest/switcher.S b/drivers/lguest/switcher.S
index eadd4cc299d2..d418179ea6b5 100644
--- a/drivers/lguest/switcher.S
+++ b/drivers/lguest/switcher.S
@@ -1,45 +1,136 @@
1/* This code sits at 0xFFC00000 to do the low-level guest<->host switch. 1/*P:900 This is the Switcher: code which sits at 0xFFC00000 to do the low-level
2 * Guest<->Host switch. It is as simple as it can be made, but it's naturally
3 * very specific to x86.
4 *
5 * You have now completed Preparation. If this has whet your appetite; if you
6 * are feeling invigorated and refreshed then the next, more challenging stage
7 * can be found in "make Guest". :*/
2 8
3 There is are two pages above us for this CPU (struct lguest_pages). 9/*S:100
4 The second page (struct lguest_ro_state) becomes read-only after the 10 * Welcome to the Switcher itself!
5 context switch. The first page (the stack for traps) remains writable, 11 *
6 but while we're in here, the guest cannot be running. 12 * This file contains the low-level code which changes the CPU to run the Guest
7*/ 13 * code, and returns to the Host when something happens. Understand this, and
14 * you understand the heart of our journey.
15 *
16 * Because this is in assembler rather than C, our tale switches from prose to
17 * verse. First I tried limericks:
18 *
19 * There once was an eax reg,
20 * To which our pointer was fed,
21 * It needed an add,
22 * Which asm-offsets.h had
23 * But this limerick is hurting my head.
24 *
25 * Next I tried haikus, but fitting the required reference to the seasons in
26 * every stanza was quickly becoming tiresome:
27 *
28 * The %eax reg
29 * Holds "struct lguest_pages" now:
30 * Cherry blossoms fall.
31 *
32 * Then I started with Heroic Verse, but the rhyming requirement leeched away
33 * the content density and led to some uniquely awful oblique rhymes:
34 *
35 * These constants are coming from struct offsets
36 * For use within the asm switcher text.
37 *
38 * Finally, I settled for something between heroic hexameter, and normal prose
39 * with inappropriate linebreaks. Anyway, it aint no Shakespeare.
40 */
41
42// Not all kernel headers work from assembler
43// But these ones are needed: the ENTRY() define
44// And constants extracted from struct offsets
45// To avoid magic numbers and breakage:
46// Should they change the compiler can't save us
47// Down here in the depths of assembler code.
8#include <linux/linkage.h> 48#include <linux/linkage.h>
9#include <asm/asm-offsets.h> 49#include <asm/asm-offsets.h>
10#include "lg.h" 50#include "lg.h"
11 51
52// We mark the start of the code to copy
53// It's placed in .text tho it's never run here
54// You'll see the trick macro at the end
55// Which interleaves data and text to effect.
12.text 56.text
13ENTRY(start_switcher_text) 57ENTRY(start_switcher_text)
14 58
15/* %eax points to lguest pages for this CPU. %ebx contains cr3 value. 59// When we reach switch_to_guest we have just left
16 All normal registers can be clobbered! */ 60// The safe and comforting shores of C code
61// %eax has the "struct lguest_pages" to use
62// Where we save state and still see it from the Guest
63// And %ebx holds the Guest shadow pagetable:
64// Once set we have truly left Host behind.
17ENTRY(switch_to_guest) 65ENTRY(switch_to_guest)
18 /* Save host segments on host stack. */ 66 // We told gcc all its regs could fade,
67 // Clobbered by our journey into the Guest
68 // We could have saved them, if we tried
69 // But time is our master and cycles count.
70
71 // Segment registers must be saved for the Host
72 // We push them on the Host stack for later
19 pushl %es 73 pushl %es
20 pushl %ds 74 pushl %ds
21 pushl %gs 75 pushl %gs
22 pushl %fs 76 pushl %fs
23 /* With CONFIG_FRAME_POINTER, gcc doesn't let us clobber this! */ 77 // But the compiler is fickle, and heeds
78 // No warning of %ebp clobbers
79 // When frame pointers are used. That register
80 // Must be saved and restored or chaos strikes.
24 pushl %ebp 81 pushl %ebp
25 /* Save host stack. */ 82 // The Host's stack is done, now save it away
83 // In our "struct lguest_pages" at offset
84 // Distilled into asm-offsets.h
26 movl %esp, LGUEST_PAGES_host_sp(%eax) 85 movl %esp, LGUEST_PAGES_host_sp(%eax)
27 /* Switch to guest stack: if we get NMI we expect to be there. */ 86
87 // All saved and there's now five steps before us:
88 // Stack, GDT, IDT, TSS
89 // And last of all the page tables are flipped.
90
91 // Yet beware that our stack pointer must be
92 // Always valid lest an NMI hits
93 // %edx does the duty here as we juggle
94 // %eax is lguest_pages: our stack lies within.
28 movl %eax, %edx 95 movl %eax, %edx
29 addl $LGUEST_PAGES_regs, %edx 96 addl $LGUEST_PAGES_regs, %edx
30 movl %edx, %esp 97 movl %edx, %esp
31 /* Switch to guest's GDT, IDT. */ 98
99 // The Guest's GDT we so carefully
100 // Placed in the "struct lguest_pages" before
32 lgdt LGUEST_PAGES_guest_gdt_desc(%eax) 101 lgdt LGUEST_PAGES_guest_gdt_desc(%eax)
102
103 // The Guest's IDT we did partially
104 // Move to the "struct lguest_pages" as well.
33 lidt LGUEST_PAGES_guest_idt_desc(%eax) 105 lidt LGUEST_PAGES_guest_idt_desc(%eax)
34 /* Switch to guest's TSS while GDT still writable. */ 106
107 // The TSS entry which controls traps
108 // Must be loaded up with "ltr" now:
109 // For after we switch over our page tables
110 // It (as the rest) will be writable no more.
111 // (The GDT entry TSS needs
112 // Changes type when we load it: damn Intel!)
35 movl $(GDT_ENTRY_TSS*8), %edx 113 movl $(GDT_ENTRY_TSS*8), %edx
36 ltr %dx 114 ltr %dx
37 /* Set host's TSS GDT entry to available (clear byte 5 bit 2). */ 115
116 // Look back now, before we take this last step!
117 // The Host's TSS entry was also marked used;
118 // Let's clear it again, ere we return.
119 // The GDT descriptor of the Host
120 // Points to the table after two "size" bytes
38 movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx 121 movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
122 // Clear the type field of "used" (byte 5, bit 2)
39 andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx) 123 andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
40 /* Switch to guest page tables: lguest_pages->state now read-only. */ 124
125 // Once our page table's switched, the Guest is live!
126 // The Host fades as we run this final step.
127 // Our "struct lguest_pages" is now read-only.
41 movl %ebx, %cr3 128 movl %ebx, %cr3
42 /* Restore guest regs */ 129
130 // The page table change did one tricky thing:
131 // The Guest's register page has been mapped
132 // Writable onto our %esp (stack) --
133 // We can simply pop off all Guest regs.
43 popl %ebx 134 popl %ebx
44 popl %ecx 135 popl %ecx
45 popl %edx 136 popl %edx
@@ -51,12 +142,27 @@ ENTRY(switch_to_guest)
51 popl %fs 142 popl %fs
52 popl %ds 143 popl %ds
53 popl %es 144 popl %es
54 /* Skip error code and trap number */ 145
146 // Near the base of the stack lurk two strange fields
147 // Which we fill as we exit the Guest
148 // These are the trap number and its error
149 // We can simply step past them on our way.
55 addl $8, %esp 150 addl $8, %esp
151
152 // The last five stack slots hold return address
153 // And everything needed to change privilege
154 // Into the Guest privilege level of 1,
155 // And the stack where the Guest had last left it.
156 // Interrupts are turned back on: we are Guest.
56 iret 157 iret
57 158
159// There are two paths where we switch to the Host
160// So we put the routine in a macro.
161// We are on our way home, back to the Host
162// Interrupted out of the Guest, we come here.
58#define SWITCH_TO_HOST \ 163#define SWITCH_TO_HOST \
59 /* Save guest state */ \ 164 /* We save the Guest state: all registers first \
165 * Laid out just as "struct lguest_regs" defines */ \
60 pushl %es; \ 166 pushl %es; \
61 pushl %ds; \ 167 pushl %ds; \
62 pushl %fs; \ 168 pushl %fs; \
@@ -68,58 +174,119 @@ ENTRY(switch_to_guest)
68 pushl %edx; \ 174 pushl %edx; \
69 pushl %ecx; \ 175 pushl %ecx; \
70 pushl %ebx; \ 176 pushl %ebx; \
71 /* Load lguest ds segment for convenience. */ \ 177 /* Our stack and our code are using segments \
178 * Set in the TSS and IDT \
179 * Yet if we were to touch data we'd use \
180 * Whatever data segment the Guest had. \
181 * Load the lguest ds segment for now. */ \
72 movl $(LGUEST_DS), %eax; \ 182 movl $(LGUEST_DS), %eax; \
73 movl %eax, %ds; \ 183 movl %eax, %ds; \
74 /* Figure out where we are, based on stack (at top of regs). */ \ 184 /* So where are we? Which CPU, which struct? \
185 * The stack is our clue: our TSS sets \
186 * It at the end of "struct lguest_pages" \
187 * And we then pushed and pushed and pushed Guest regs: \
188 * Now stack points atop the "struct lguest_regs". \
189 * Subtract that offset, and we find our struct. */ \
75 movl %esp, %eax; \ 190 movl %esp, %eax; \
76 subl $LGUEST_PAGES_regs, %eax; \ 191 subl $LGUEST_PAGES_regs, %eax; \
77 /* Put trap number in %ebx before we switch cr3 and lose it. */ \ 192 /* Save our trap number: the switch will obscure it \
193 * (The Guest regs are not mapped here in the Host) \
194 * %ebx holds it safe for deliver_to_host */ \
78 movl LGUEST_PAGES_regs_trapnum(%eax), %ebx; \ 195 movl LGUEST_PAGES_regs_trapnum(%eax), %ebx; \
79 /* Switch to host page tables (host GDT, IDT and stack are in host \ 196 /* The Host GDT, IDT and stack! \
80 mem, so need this first) */ \ 197 * All these lie safely hidden from the Guest: \
198 * We must return to the Host page tables \
199 * (Hence that was saved in struct lguest_pages) */ \
81 movl LGUEST_PAGES_host_cr3(%eax), %edx; \ 200 movl LGUEST_PAGES_host_cr3(%eax), %edx; \
82 movl %edx, %cr3; \ 201 movl %edx, %cr3; \
83 /* Set guest's TSS to available (clear byte 5 bit 2). */ \ 202 /* As before, when we looked back at the Host \
203 * As we left and marked TSS unused \
204 * So must we now for the Guest left behind. */ \
84 andb $0xFD, (LGUEST_PAGES_guest_gdt+GDT_ENTRY_TSS*8+5)(%eax); \ 205 andb $0xFD, (LGUEST_PAGES_guest_gdt+GDT_ENTRY_TSS*8+5)(%eax); \
85 /* Switch to host's GDT & IDT. */ \ 206 /* Switch to Host's GDT, IDT. */ \
86 lgdt LGUEST_PAGES_host_gdt_desc(%eax); \ 207 lgdt LGUEST_PAGES_host_gdt_desc(%eax); \
87 lidt LGUEST_PAGES_host_idt_desc(%eax); \ 208 lidt LGUEST_PAGES_host_idt_desc(%eax); \
88 /* Switch to host's stack. */ \ 209 /* Restore the Host's stack where it's saved regs lie */ \
89 movl LGUEST_PAGES_host_sp(%eax), %esp; \ 210 movl LGUEST_PAGES_host_sp(%eax), %esp; \
90 /* Switch to host's TSS */ \ 211 /* Last the TSS: our Host is complete */ \
91 movl $(GDT_ENTRY_TSS*8), %edx; \ 212 movl $(GDT_ENTRY_TSS*8), %edx; \
92 ltr %dx; \ 213 ltr %dx; \
214 /* Restore now the regs saved right at the first. */ \
93 popl %ebp; \ 215 popl %ebp; \
94 popl %fs; \ 216 popl %fs; \
95 popl %gs; \ 217 popl %gs; \
96 popl %ds; \ 218 popl %ds; \
97 popl %es 219 popl %es
98 220
99/* Return to run_guest_once. */ 221// Here's where we come when the Guest has just trapped:
222// (Which trap we'll see has been pushed on the stack).
223// We need only switch back, and the Host will decode
224// Why we came home, and what needs to be done.
100return_to_host: 225return_to_host:
101 SWITCH_TO_HOST 226 SWITCH_TO_HOST
102 iret 227 iret
103 228
229// An interrupt, with some cause external
230// Has ajerked us rudely from the Guest's code
231// Again we must return home to the Host
104deliver_to_host: 232deliver_to_host:
105 SWITCH_TO_HOST 233 SWITCH_TO_HOST
106 /* Decode IDT and jump to hosts' irq handler. When that does iret, it 234 // But now we must go home via that place
107 * will return to run_guest_once. This is a feature. */ 235 // Where that interrupt was supposed to go
236 // Had we not been ensconced, running the Guest.
237 // Here we see the cleverness of our stack:
238 // The Host stack is formed like an interrupt
239 // With EIP, CS and EFLAGS layered.
240 // Interrupt handlers end with "iret"
241 // And that will take us home at long long last.
242
243 // But first we must find the handler to call!
244 // The IDT descriptor for the Host
245 // Has two bytes for size, and four for address:
246 // %edx will hold it for us for now.
108 movl (LGUEST_PAGES_host_idt_desc+2)(%eax), %edx 247 movl (LGUEST_PAGES_host_idt_desc+2)(%eax), %edx
248 // We now know the table address we need,
249 // And saved the trap's number inside %ebx.
250 // Yet the pointer to the handler is smeared
251 // Across the bits of the table entry.
252 // What oracle can tell us how to extract
253 // From such a convoluted encoding?
254 // I consulted gcc, and it gave
255 // These instructions, which I gladly credit:
109 leal (%edx,%ebx,8), %eax 256 leal (%edx,%ebx,8), %eax
110 movzwl (%eax),%edx 257 movzwl (%eax),%edx
111 movl 4(%eax), %eax 258 movl 4(%eax), %eax
112 xorw %ax, %ax 259 xorw %ax, %ax
113 orl %eax, %edx 260 orl %eax, %edx
261 // Now the address of the handler's in %edx
262 // We call it now: its "iret" takes us home.
114 jmp *%edx 263 jmp *%edx
115 264
116/* Real hardware interrupts are delivered straight to the host. Others 265// Every interrupt can come to us here
117 cause us to return to run_guest_once so it can decide what to do. Note 266// But we must truly tell each apart.
118 that some of these are overridden by the guest to deliver directly, and 267// They number two hundred and fifty six
119 never enter here (see load_guest_idt_entry). */ 268// And each must land in a different spot,
269// Push its number on stack, and join the stream.
270
271// And worse, a mere six of the traps stand apart
272// And push on their stack an addition:
273// An error number, thirty two bits long
274// So we punish the other two fifty
275// And make them push a zero so they match.
276
277// Yet two fifty six entries is long
278// And all will look most the same as the last
279// So we create a macro which can make
280// As many entries as we need to fill.
281
282// Note the change to .data then .text:
283// We plant the address of each entry
284// Into a (data) table for the Host
285// To know where each Guest interrupt should go.
120.macro IRQ_STUB N TARGET 286.macro IRQ_STUB N TARGET
121 .data; .long 1f; .text; 1: 287 .data; .long 1f; .text; 1:
122 /* Make an error number for most traps, which don't have one. */ 288 // Trap eight, ten through fourteen and seventeen
289 // Supply an error number. Else zero.
123 .if (\N <> 8) && (\N < 10 || \N > 14) && (\N <> 17) 290 .if (\N <> 8) && (\N < 10 || \N > 14) && (\N <> 17)
124 pushl $0 291 pushl $0
125 .endif 292 .endif
@@ -128,6 +295,8 @@ deliver_to_host:
128 ALIGN 295 ALIGN
129.endm 296.endm
130 297
298// This macro creates numerous entries
299// Using GAS macros which out-power C's.
131.macro IRQ_STUBS FIRST LAST TARGET 300.macro IRQ_STUBS FIRST LAST TARGET
132 irq=\FIRST 301 irq=\FIRST
133 .rept \LAST-\FIRST+1 302 .rept \LAST-\FIRST+1
@@ -136,24 +305,43 @@ deliver_to_host:
136 .endr 305 .endr
137.endm 306.endm
138 307
139/* We intercept every interrupt, because we may need to switch back to 308// Here's the marker for our pointer table
140 * host. Unfortunately we can't tell them apart except by entry 309// Laid in the data section just before
141 * point, so we need 256 entry points. 310// Each macro places the address of code
142 */ 311// Forming an array: each one points to text
312// Which handles interrupt in its turn.
143.data 313.data
144.global default_idt_entries 314.global default_idt_entries
145default_idt_entries: 315default_idt_entries:
146.text 316.text
147 IRQ_STUBS 0 1 return_to_host /* First two traps */ 317 // The first two traps go straight back to the Host
148 IRQ_STUB 2 handle_nmi /* NMI */ 318 IRQ_STUBS 0 1 return_to_host
149 IRQ_STUBS 3 31 return_to_host /* Rest of traps */ 319 // We'll say nothing, yet, about NMI
150 IRQ_STUBS 32 127 deliver_to_host /* Real interrupts */ 320 IRQ_STUB 2 handle_nmi
151 IRQ_STUB 128 return_to_host /* System call (overridden) */ 321 // Other traps also return to the Host
152 IRQ_STUBS 129 255 deliver_to_host /* Other real interrupts */ 322 IRQ_STUBS 3 31 return_to_host
153 323 // All interrupts go via their handlers
154/* We ignore NMI and return. */ 324 IRQ_STUBS 32 127 deliver_to_host
325 // 'Cept system calls coming from userspace
326 // Are to go to the Guest, never the Host.
327 IRQ_STUB 128 return_to_host
328 IRQ_STUBS 129 255 deliver_to_host
329
330// The NMI, what a fabulous beast
331// Which swoops in and stops us no matter that
332// We're suspended between heaven and hell,
333// (Or more likely between the Host and Guest)
334// When in it comes! We are dazed and confused
335// So we do the simplest thing which one can.
336// Though we've pushed the trap number and zero
337// We discard them, return, and hope we live.
155handle_nmi: 338handle_nmi:
156 addl $8, %esp 339 addl $8, %esp
157 iret 340 iret
158 341
342// We are done; all that's left is Mastery
343// And "make Mastery" is a journey long
344// Designed to make your fingers itch to code.
345
346// Here ends the text, the file and poem.
159ENTRY(end_switcher_text) 347ENTRY(end_switcher_text)
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 2fc199b0016b..2bcde5798b5a 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -526,7 +526,7 @@ static int __table_get_device(struct dm_table *t, struct dm_target *ti,
526 526
527void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev) 527void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev)
528{ 528{
529 request_queue_t *q = bdev_get_queue(bdev); 529 struct request_queue *q = bdev_get_queue(bdev);
530 struct io_restrictions *rs = &ti->limits; 530 struct io_restrictions *rs = &ti->limits;
531 531
532 /* 532 /*
@@ -979,7 +979,7 @@ int dm_table_any_congested(struct dm_table *t, int bdi_bits)
979 devices = dm_table_get_devices(t); 979 devices = dm_table_get_devices(t);
980 for (d = devices->next; d != devices; d = d->next) { 980 for (d = devices->next; d != devices; d = d->next) {
981 struct dm_dev *dd = list_entry(d, struct dm_dev, list); 981 struct dm_dev *dd = list_entry(d, struct dm_dev, list);
982 request_queue_t *q = bdev_get_queue(dd->bdev); 982 struct request_queue *q = bdev_get_queue(dd->bdev);
983 r |= bdi_congested(&q->backing_dev_info, bdi_bits); 983 r |= bdi_congested(&q->backing_dev_info, bdi_bits);
984 } 984 }
985 985
@@ -992,7 +992,7 @@ void dm_table_unplug_all(struct dm_table *t)
992 992
993 for (d = devices->next; d != devices; d = d->next) { 993 for (d = devices->next; d != devices; d = d->next) {
994 struct dm_dev *dd = list_entry(d, struct dm_dev, list); 994 struct dm_dev *dd = list_entry(d, struct dm_dev, list);
995 request_queue_t *q = bdev_get_queue(dd->bdev); 995 struct request_queue *q = bdev_get_queue(dd->bdev);
996 996
997 if (q->unplug_fn) 997 if (q->unplug_fn)
998 q->unplug_fn(q); 998 q->unplug_fn(q);
@@ -1011,7 +1011,7 @@ int dm_table_flush_all(struct dm_table *t)
1011 1011
1012 for (d = devices->next; d != devices; d = d->next) { 1012 for (d = devices->next; d != devices; d = d->next) {
1013 struct dm_dev *dd = list_entry(d, struct dm_dev, list); 1013 struct dm_dev *dd = list_entry(d, struct dm_dev, list);
1014 request_queue_t *q = bdev_get_queue(dd->bdev); 1014 struct request_queue *q = bdev_get_queue(dd->bdev);
1015 int err; 1015 int err;
1016 1016
1017 if (!q->issue_flush_fn) 1017 if (!q->issue_flush_fn)
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 846614e676c6..141ff9fa296e 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -80,7 +80,7 @@ struct mapped_device {
80 80
81 unsigned long flags; 81 unsigned long flags;
82 82
83 request_queue_t *queue; 83 struct request_queue *queue;
84 struct gendisk *disk; 84 struct gendisk *disk;
85 char name[16]; 85 char name[16];
86 86
@@ -792,7 +792,7 @@ static void __split_bio(struct mapped_device *md, struct bio *bio)
792 * The request function that just remaps the bio built up by 792 * The request function that just remaps the bio built up by
793 * dm_merge_bvec. 793 * dm_merge_bvec.
794 */ 794 */
795static int dm_request(request_queue_t *q, struct bio *bio) 795static int dm_request(struct request_queue *q, struct bio *bio)
796{ 796{
797 int r; 797 int r;
798 int rw = bio_data_dir(bio); 798 int rw = bio_data_dir(bio);
@@ -844,7 +844,7 @@ static int dm_request(request_queue_t *q, struct bio *bio)
844 return 0; 844 return 0;
845} 845}
846 846
847static int dm_flush_all(request_queue_t *q, struct gendisk *disk, 847static int dm_flush_all(struct request_queue *q, struct gendisk *disk,
848 sector_t *error_sector) 848 sector_t *error_sector)
849{ 849{
850 struct mapped_device *md = q->queuedata; 850 struct mapped_device *md = q->queuedata;
@@ -859,7 +859,7 @@ static int dm_flush_all(request_queue_t *q, struct gendisk *disk,
859 return ret; 859 return ret;
860} 860}
861 861
862static void dm_unplug_all(request_queue_t *q) 862static void dm_unplug_all(struct request_queue *q)
863{ 863{
864 struct mapped_device *md = q->queuedata; 864 struct mapped_device *md = q->queuedata;
865 struct dm_table *map = dm_get_table(md); 865 struct dm_table *map = dm_get_table(md);
@@ -1110,7 +1110,7 @@ static void __set_size(struct mapped_device *md, sector_t size)
1110 1110
1111static int __bind(struct mapped_device *md, struct dm_table *t) 1111static int __bind(struct mapped_device *md, struct dm_table *t)
1112{ 1112{
1113 request_queue_t *q = md->queue; 1113 struct request_queue *q = md->queue;
1114 sector_t size; 1114 sector_t size;
1115 1115
1116 size = dm_table_get_size(t); 1116 size = dm_table_get_size(t);
diff --git a/drivers/md/faulty.c b/drivers/md/faulty.c
index 4ebd0f2a75ec..cb059cf14c2e 100644
--- a/drivers/md/faulty.c
+++ b/drivers/md/faulty.c
@@ -167,7 +167,7 @@ static void add_sector(conf_t *conf, sector_t start, int mode)
167 conf->nfaults = n+1; 167 conf->nfaults = n+1;
168} 168}
169 169
170static int make_request(request_queue_t *q, struct bio *bio) 170static int make_request(struct request_queue *q, struct bio *bio)
171{ 171{
172 mddev_t *mddev = q->queuedata; 172 mddev_t *mddev = q->queuedata;
173 conf_t *conf = (conf_t*)mddev->private; 173 conf_t *conf = (conf_t*)mddev->private;
diff --git a/drivers/md/linear.c b/drivers/md/linear.c
index 192741083196..17f795c3e0ab 100644
--- a/drivers/md/linear.c
+++ b/drivers/md/linear.c
@@ -55,7 +55,7 @@ static inline dev_info_t *which_dev(mddev_t *mddev, sector_t sector)
55 * 55 *
56 * Return amount of bytes we can take at this offset 56 * Return amount of bytes we can take at this offset
57 */ 57 */
58static int linear_mergeable_bvec(request_queue_t *q, struct bio *bio, struct bio_vec *biovec) 58static int linear_mergeable_bvec(struct request_queue *q, struct bio *bio, struct bio_vec *biovec)
59{ 59{
60 mddev_t *mddev = q->queuedata; 60 mddev_t *mddev = q->queuedata;
61 dev_info_t *dev0; 61 dev_info_t *dev0;
@@ -79,20 +79,20 @@ static int linear_mergeable_bvec(request_queue_t *q, struct bio *bio, struct bio
79 return maxsectors << 9; 79 return maxsectors << 9;
80} 80}
81 81
82static void linear_unplug(request_queue_t *q) 82static void linear_unplug(struct request_queue *q)
83{ 83{
84 mddev_t *mddev = q->queuedata; 84 mddev_t *mddev = q->queuedata;
85 linear_conf_t *conf = mddev_to_conf(mddev); 85 linear_conf_t *conf = mddev_to_conf(mddev);
86 int i; 86 int i;
87 87
88 for (i=0; i < mddev->raid_disks; i++) { 88 for (i=0; i < mddev->raid_disks; i++) {
89 request_queue_t *r_queue = bdev_get_queue(conf->disks[i].rdev->bdev); 89 struct request_queue *r_queue = bdev_get_queue(conf->disks[i].rdev->bdev);
90 if (r_queue->unplug_fn) 90 if (r_queue->unplug_fn)
91 r_queue->unplug_fn(r_queue); 91 r_queue->unplug_fn(r_queue);
92 } 92 }
93} 93}
94 94
95static int linear_issue_flush(request_queue_t *q, struct gendisk *disk, 95static int linear_issue_flush(struct request_queue *q, struct gendisk *disk,
96 sector_t *error_sector) 96 sector_t *error_sector)
97{ 97{
98 mddev_t *mddev = q->queuedata; 98 mddev_t *mddev = q->queuedata;
@@ -101,7 +101,7 @@ static int linear_issue_flush(request_queue_t *q, struct gendisk *disk,
101 101
102 for (i=0; i < mddev->raid_disks && ret == 0; i++) { 102 for (i=0; i < mddev->raid_disks && ret == 0; i++) {
103 struct block_device *bdev = conf->disks[i].rdev->bdev; 103 struct block_device *bdev = conf->disks[i].rdev->bdev;
104 request_queue_t *r_queue = bdev_get_queue(bdev); 104 struct request_queue *r_queue = bdev_get_queue(bdev);
105 105
106 if (!r_queue->issue_flush_fn) 106 if (!r_queue->issue_flush_fn)
107 ret = -EOPNOTSUPP; 107 ret = -EOPNOTSUPP;
@@ -118,7 +118,7 @@ static int linear_congested(void *data, int bits)
118 int i, ret = 0; 118 int i, ret = 0;
119 119
120 for (i = 0; i < mddev->raid_disks && !ret ; i++) { 120 for (i = 0; i < mddev->raid_disks && !ret ; i++) {
121 request_queue_t *q = bdev_get_queue(conf->disks[i].rdev->bdev); 121 struct request_queue *q = bdev_get_queue(conf->disks[i].rdev->bdev);
122 ret |= bdi_congested(&q->backing_dev_info, bits); 122 ret |= bdi_congested(&q->backing_dev_info, bits);
123 } 123 }
124 return ret; 124 return ret;
@@ -330,7 +330,7 @@ static int linear_stop (mddev_t *mddev)
330 return 0; 330 return 0;
331} 331}
332 332
333static int linear_make_request (request_queue_t *q, struct bio *bio) 333static int linear_make_request (struct request_queue *q, struct bio *bio)
334{ 334{
335 const int rw = bio_data_dir(bio); 335 const int rw = bio_data_dir(bio);
336 mddev_t *mddev = q->queuedata; 336 mddev_t *mddev = q->queuedata;
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 65ddc887dfd7..f883b7e37f3d 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -211,7 +211,7 @@ static DEFINE_SPINLOCK(all_mddevs_lock);
211 ) 211 )
212 212
213 213
214static int md_fail_request (request_queue_t *q, struct bio *bio) 214static int md_fail_request (struct request_queue *q, struct bio *bio)
215{ 215{
216 bio_io_error(bio, bio->bi_size); 216 bio_io_error(bio, bio->bi_size);
217 return 0; 217 return 0;
diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index 14da37fee37b..1e2af43a73b9 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -125,7 +125,7 @@ static void unplug_slaves(mddev_t *mddev)
125 mdk_rdev_t *rdev = rcu_dereference(conf->multipaths[i].rdev); 125 mdk_rdev_t *rdev = rcu_dereference(conf->multipaths[i].rdev);
126 if (rdev && !test_bit(Faulty, &rdev->flags) 126 if (rdev && !test_bit(Faulty, &rdev->flags)
127 && atomic_read(&rdev->nr_pending)) { 127 && atomic_read(&rdev->nr_pending)) {
128 request_queue_t *r_queue = bdev_get_queue(rdev->bdev); 128 struct request_queue *r_queue = bdev_get_queue(rdev->bdev);
129 129
130 atomic_inc(&rdev->nr_pending); 130 atomic_inc(&rdev->nr_pending);
131 rcu_read_unlock(); 131 rcu_read_unlock();
@@ -140,13 +140,13 @@ static void unplug_slaves(mddev_t *mddev)
140 rcu_read_unlock(); 140 rcu_read_unlock();
141} 141}
142 142
143static void multipath_unplug(request_queue_t *q) 143static void multipath_unplug(struct request_queue *q)
144{ 144{
145 unplug_slaves(q->queuedata); 145 unplug_slaves(q->queuedata);
146} 146}
147 147
148 148
149static int multipath_make_request (request_queue_t *q, struct bio * bio) 149static int multipath_make_request (struct request_queue *q, struct bio * bio)
150{ 150{
151 mddev_t *mddev = q->queuedata; 151 mddev_t *mddev = q->queuedata;
152 multipath_conf_t *conf = mddev_to_conf(mddev); 152 multipath_conf_t *conf = mddev_to_conf(mddev);
@@ -199,7 +199,7 @@ static void multipath_status (struct seq_file *seq, mddev_t *mddev)
199 seq_printf (seq, "]"); 199 seq_printf (seq, "]");
200} 200}
201 201
202static int multipath_issue_flush(request_queue_t *q, struct gendisk *disk, 202static int multipath_issue_flush(struct request_queue *q, struct gendisk *disk,
203 sector_t *error_sector) 203 sector_t *error_sector)
204{ 204{
205 mddev_t *mddev = q->queuedata; 205 mddev_t *mddev = q->queuedata;
@@ -211,7 +211,7 @@ static int multipath_issue_flush(request_queue_t *q, struct gendisk *disk,
211 mdk_rdev_t *rdev = rcu_dereference(conf->multipaths[i].rdev); 211 mdk_rdev_t *rdev = rcu_dereference(conf->multipaths[i].rdev);
212 if (rdev && !test_bit(Faulty, &rdev->flags)) { 212 if (rdev && !test_bit(Faulty, &rdev->flags)) {
213 struct block_device *bdev = rdev->bdev; 213 struct block_device *bdev = rdev->bdev;
214 request_queue_t *r_queue = bdev_get_queue(bdev); 214 struct request_queue *r_queue = bdev_get_queue(bdev);
215 215
216 if (!r_queue->issue_flush_fn) 216 if (!r_queue->issue_flush_fn)
217 ret = -EOPNOTSUPP; 217 ret = -EOPNOTSUPP;
@@ -238,7 +238,7 @@ static int multipath_congested(void *data, int bits)
238 for (i = 0; i < mddev->raid_disks ; i++) { 238 for (i = 0; i < mddev->raid_disks ; i++) {
239 mdk_rdev_t *rdev = rcu_dereference(conf->multipaths[i].rdev); 239 mdk_rdev_t *rdev = rcu_dereference(conf->multipaths[i].rdev);
240 if (rdev && !test_bit(Faulty, &rdev->flags)) { 240 if (rdev && !test_bit(Faulty, &rdev->flags)) {
241 request_queue_t *q = bdev_get_queue(rdev->bdev); 241 struct request_queue *q = bdev_get_queue(rdev->bdev);
242 242
243 ret |= bdi_congested(&q->backing_dev_info, bits); 243 ret |= bdi_congested(&q->backing_dev_info, bits);
244 /* Just like multipath_map, we just check the 244 /* Just like multipath_map, we just check the
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 2c404f73a377..b8216bc6db45 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -25,7 +25,7 @@
25#define MD_DRIVER 25#define MD_DRIVER
26#define MD_PERSONALITY 26#define MD_PERSONALITY
27 27
28static void raid0_unplug(request_queue_t *q) 28static void raid0_unplug(struct request_queue *q)
29{ 29{
30 mddev_t *mddev = q->queuedata; 30 mddev_t *mddev = q->queuedata;
31 raid0_conf_t *conf = mddev_to_conf(mddev); 31 raid0_conf_t *conf = mddev_to_conf(mddev);
@@ -33,14 +33,14 @@ static void raid0_unplug(request_queue_t *q)
33 int i; 33 int i;
34 34
35 for (i=0; i<mddev->raid_disks; i++) { 35 for (i=0; i<mddev->raid_disks; i++) {
36 request_queue_t *r_queue = bdev_get_queue(devlist[i]->bdev); 36 struct request_queue *r_queue = bdev_get_queue(devlist[i]->bdev);
37 37
38 if (r_queue->unplug_fn) 38 if (r_queue->unplug_fn)
39 r_queue->unplug_fn(r_queue); 39 r_queue->unplug_fn(r_queue);
40 } 40 }
41} 41}
42 42
43static int raid0_issue_flush(request_queue_t *q, struct gendisk *disk, 43static int raid0_issue_flush(struct request_queue *q, struct gendisk *disk,
44 sector_t *error_sector) 44 sector_t *error_sector)
45{ 45{
46 mddev_t *mddev = q->queuedata; 46 mddev_t *mddev = q->queuedata;
@@ -50,7 +50,7 @@ static int raid0_issue_flush(request_queue_t *q, struct gendisk *disk,
50 50
51 for (i=0; i<mddev->raid_disks && ret == 0; i++) { 51 for (i=0; i<mddev->raid_disks && ret == 0; i++) {
52 struct block_device *bdev = devlist[i]->bdev; 52 struct block_device *bdev = devlist[i]->bdev;
53 request_queue_t *r_queue = bdev_get_queue(bdev); 53 struct request_queue *r_queue = bdev_get_queue(bdev);
54 54
55 if (!r_queue->issue_flush_fn) 55 if (!r_queue->issue_flush_fn)
56 ret = -EOPNOTSUPP; 56 ret = -EOPNOTSUPP;
@@ -68,7 +68,7 @@ static int raid0_congested(void *data, int bits)
68 int i, ret = 0; 68 int i, ret = 0;
69 69
70 for (i = 0; i < mddev->raid_disks && !ret ; i++) { 70 for (i = 0; i < mddev->raid_disks && !ret ; i++) {
71 request_queue_t *q = bdev_get_queue(devlist[i]->bdev); 71 struct request_queue *q = bdev_get_queue(devlist[i]->bdev);
72 72
73 ret |= bdi_congested(&q->backing_dev_info, bits); 73 ret |= bdi_congested(&q->backing_dev_info, bits);
74 } 74 }
@@ -268,7 +268,7 @@ static int create_strip_zones (mddev_t *mddev)
268 * 268 *
269 * Return amount of bytes we can accept at this offset 269 * Return amount of bytes we can accept at this offset
270 */ 270 */
271static int raid0_mergeable_bvec(request_queue_t *q, struct bio *bio, struct bio_vec *biovec) 271static int raid0_mergeable_bvec(struct request_queue *q, struct bio *bio, struct bio_vec *biovec)
272{ 272{
273 mddev_t *mddev = q->queuedata; 273 mddev_t *mddev = q->queuedata;
274 sector_t sector = bio->bi_sector + get_start_sect(bio->bi_bdev); 274 sector_t sector = bio->bi_sector + get_start_sect(bio->bi_bdev);
@@ -408,7 +408,7 @@ static int raid0_stop (mddev_t *mddev)
408 return 0; 408 return 0;
409} 409}
410 410
411static int raid0_make_request (request_queue_t *q, struct bio *bio) 411static int raid0_make_request (struct request_queue *q, struct bio *bio)
412{ 412{
413 mddev_t *mddev = q->queuedata; 413 mddev_t *mddev = q->queuedata;
414 unsigned int sect_in_chunk, chunksize_bits, chunk_size, chunk_sects; 414 unsigned int sect_in_chunk, chunksize_bits, chunk_size, chunk_sects;
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 00c78b77b13d..650991bddd8e 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -552,7 +552,7 @@ static void unplug_slaves(mddev_t *mddev)
552 for (i=0; i<mddev->raid_disks; i++) { 552 for (i=0; i<mddev->raid_disks; i++) {
553 mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev); 553 mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
554 if (rdev && !test_bit(Faulty, &rdev->flags) && atomic_read(&rdev->nr_pending)) { 554 if (rdev && !test_bit(Faulty, &rdev->flags) && atomic_read(&rdev->nr_pending)) {
555 request_queue_t *r_queue = bdev_get_queue(rdev->bdev); 555 struct request_queue *r_queue = bdev_get_queue(rdev->bdev);
556 556
557 atomic_inc(&rdev->nr_pending); 557 atomic_inc(&rdev->nr_pending);
558 rcu_read_unlock(); 558 rcu_read_unlock();
@@ -567,7 +567,7 @@ static void unplug_slaves(mddev_t *mddev)
567 rcu_read_unlock(); 567 rcu_read_unlock();
568} 568}
569 569
570static void raid1_unplug(request_queue_t *q) 570static void raid1_unplug(struct request_queue *q)
571{ 571{
572 mddev_t *mddev = q->queuedata; 572 mddev_t *mddev = q->queuedata;
573 573
@@ -575,7 +575,7 @@ static void raid1_unplug(request_queue_t *q)
575 md_wakeup_thread(mddev->thread); 575 md_wakeup_thread(mddev->thread);
576} 576}
577 577
578static int raid1_issue_flush(request_queue_t *q, struct gendisk *disk, 578static int raid1_issue_flush(struct request_queue *q, struct gendisk *disk,
579 sector_t *error_sector) 579 sector_t *error_sector)
580{ 580{
581 mddev_t *mddev = q->queuedata; 581 mddev_t *mddev = q->queuedata;
@@ -587,7 +587,7 @@ static int raid1_issue_flush(request_queue_t *q, struct gendisk *disk,
587 mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev); 587 mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
588 if (rdev && !test_bit(Faulty, &rdev->flags)) { 588 if (rdev && !test_bit(Faulty, &rdev->flags)) {
589 struct block_device *bdev = rdev->bdev; 589 struct block_device *bdev = rdev->bdev;
590 request_queue_t *r_queue = bdev_get_queue(bdev); 590 struct request_queue *r_queue = bdev_get_queue(bdev);
591 591
592 if (!r_queue->issue_flush_fn) 592 if (!r_queue->issue_flush_fn)
593 ret = -EOPNOTSUPP; 593 ret = -EOPNOTSUPP;
@@ -615,7 +615,7 @@ static int raid1_congested(void *data, int bits)
615 for (i = 0; i < mddev->raid_disks; i++) { 615 for (i = 0; i < mddev->raid_disks; i++) {
616 mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev); 616 mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
617 if (rdev && !test_bit(Faulty, &rdev->flags)) { 617 if (rdev && !test_bit(Faulty, &rdev->flags)) {
618 request_queue_t *q = bdev_get_queue(rdev->bdev); 618 struct request_queue *q = bdev_get_queue(rdev->bdev);
619 619
620 /* Note the '|| 1' - when read_balance prefers 620 /* Note the '|| 1' - when read_balance prefers
621 * non-congested targets, it can be removed 621 * non-congested targets, it can be removed
@@ -765,7 +765,7 @@ do_sync_io:
765 return NULL; 765 return NULL;
766} 766}
767 767
768static int make_request(request_queue_t *q, struct bio * bio) 768static int make_request(struct request_queue *q, struct bio * bio)
769{ 769{
770 mddev_t *mddev = q->queuedata; 770 mddev_t *mddev = q->queuedata;
771 conf_t *conf = mddev_to_conf(mddev); 771 conf_t *conf = mddev_to_conf(mddev);
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index a95ada1cfac4..f730a144baf1 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -453,7 +453,7 @@ static sector_t raid10_find_virt(conf_t *conf, sector_t sector, int dev)
453 * If near_copies == raid_disk, there are no striping issues, 453 * If near_copies == raid_disk, there are no striping issues,
454 * but in that case, the function isn't called at all. 454 * but in that case, the function isn't called at all.
455 */ 455 */
456static int raid10_mergeable_bvec(request_queue_t *q, struct bio *bio, 456static int raid10_mergeable_bvec(struct request_queue *q, struct bio *bio,
457 struct bio_vec *bio_vec) 457 struct bio_vec *bio_vec)
458{ 458{
459 mddev_t *mddev = q->queuedata; 459 mddev_t *mddev = q->queuedata;
@@ -595,7 +595,7 @@ static void unplug_slaves(mddev_t *mddev)
595 for (i=0; i<mddev->raid_disks; i++) { 595 for (i=0; i<mddev->raid_disks; i++) {
596 mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev); 596 mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
597 if (rdev && !test_bit(Faulty, &rdev->flags) && atomic_read(&rdev->nr_pending)) { 597 if (rdev && !test_bit(Faulty, &rdev->flags) && atomic_read(&rdev->nr_pending)) {
598 request_queue_t *r_queue = bdev_get_queue(rdev->bdev); 598 struct request_queue *r_queue = bdev_get_queue(rdev->bdev);
599 599
600 atomic_inc(&rdev->nr_pending); 600 atomic_inc(&rdev->nr_pending);
601 rcu_read_unlock(); 601 rcu_read_unlock();
@@ -610,7 +610,7 @@ static void unplug_slaves(mddev_t *mddev)
610 rcu_read_unlock(); 610 rcu_read_unlock();
611} 611}
612 612
613static void raid10_unplug(request_queue_t *q) 613static void raid10_unplug(struct request_queue *q)
614{ 614{
615 mddev_t *mddev = q->queuedata; 615 mddev_t *mddev = q->queuedata;
616 616
@@ -618,7 +618,7 @@ static void raid10_unplug(request_queue_t *q)
618 md_wakeup_thread(mddev->thread); 618 md_wakeup_thread(mddev->thread);
619} 619}
620 620
621static int raid10_issue_flush(request_queue_t *q, struct gendisk *disk, 621static int raid10_issue_flush(struct request_queue *q, struct gendisk *disk,
622 sector_t *error_sector) 622 sector_t *error_sector)
623{ 623{
624 mddev_t *mddev = q->queuedata; 624 mddev_t *mddev = q->queuedata;
@@ -630,7 +630,7 @@ static int raid10_issue_flush(request_queue_t *q, struct gendisk *disk,
630 mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev); 630 mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
631 if (rdev && !test_bit(Faulty, &rdev->flags)) { 631 if (rdev && !test_bit(Faulty, &rdev->flags)) {
632 struct block_device *bdev = rdev->bdev; 632 struct block_device *bdev = rdev->bdev;
633 request_queue_t *r_queue = bdev_get_queue(bdev); 633 struct request_queue *r_queue = bdev_get_queue(bdev);
634 634
635 if (!r_queue->issue_flush_fn) 635 if (!r_queue->issue_flush_fn)
636 ret = -EOPNOTSUPP; 636 ret = -EOPNOTSUPP;
@@ -658,7 +658,7 @@ static int raid10_congested(void *data, int bits)
658 for (i = 0; i < mddev->raid_disks && ret == 0; i++) { 658 for (i = 0; i < mddev->raid_disks && ret == 0; i++) {
659 mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev); 659 mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
660 if (rdev && !test_bit(Faulty, &rdev->flags)) { 660 if (rdev && !test_bit(Faulty, &rdev->flags)) {
661 request_queue_t *q = bdev_get_queue(rdev->bdev); 661 struct request_queue *q = bdev_get_queue(rdev->bdev);
662 662
663 ret |= bdi_congested(&q->backing_dev_info, bits); 663 ret |= bdi_congested(&q->backing_dev_info, bits);
664 } 664 }
@@ -772,7 +772,7 @@ static void unfreeze_array(conf_t *conf)
772 spin_unlock_irq(&conf->resync_lock); 772 spin_unlock_irq(&conf->resync_lock);
773} 773}
774 774
775static int make_request(request_queue_t *q, struct bio * bio) 775static int make_request(struct request_queue *q, struct bio * bio)
776{ 776{
777 mddev_t *mddev = q->queuedata; 777 mddev_t *mddev = q->queuedata;
778 conf_t *conf = mddev_to_conf(mddev); 778 conf_t *conf = mddev_to_conf(mddev);
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index d90ee145effe..2aff4be35dc4 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -289,7 +289,7 @@ static struct stripe_head *__find_stripe(raid5_conf_t *conf, sector_t sector, in
289} 289}
290 290
291static void unplug_slaves(mddev_t *mddev); 291static void unplug_slaves(mddev_t *mddev);
292static void raid5_unplug_device(request_queue_t *q); 292static void raid5_unplug_device(struct request_queue *q);
293 293
294static struct stripe_head *get_active_stripe(raid5_conf_t *conf, sector_t sector, int disks, 294static struct stripe_head *get_active_stripe(raid5_conf_t *conf, sector_t sector, int disks,
295 int pd_idx, int noblock) 295 int pd_idx, int noblock)
@@ -3182,7 +3182,7 @@ static void unplug_slaves(mddev_t *mddev)
3182 for (i=0; i<mddev->raid_disks; i++) { 3182 for (i=0; i<mddev->raid_disks; i++) {
3183 mdk_rdev_t *rdev = rcu_dereference(conf->disks[i].rdev); 3183 mdk_rdev_t *rdev = rcu_dereference(conf->disks[i].rdev);
3184 if (rdev && !test_bit(Faulty, &rdev->flags) && atomic_read(&rdev->nr_pending)) { 3184 if (rdev && !test_bit(Faulty, &rdev->flags) && atomic_read(&rdev->nr_pending)) {
3185 request_queue_t *r_queue = bdev_get_queue(rdev->bdev); 3185 struct request_queue *r_queue = bdev_get_queue(rdev->bdev);
3186 3186
3187 atomic_inc(&rdev->nr_pending); 3187 atomic_inc(&rdev->nr_pending);
3188 rcu_read_unlock(); 3188 rcu_read_unlock();
@@ -3197,7 +3197,7 @@ static void unplug_slaves(mddev_t *mddev)
3197 rcu_read_unlock(); 3197 rcu_read_unlock();
3198} 3198}
3199 3199
3200static void raid5_unplug_device(request_queue_t *q) 3200static void raid5_unplug_device(struct request_queue *q)
3201{ 3201{
3202 mddev_t *mddev = q->queuedata; 3202 mddev_t *mddev = q->queuedata;
3203 raid5_conf_t *conf = mddev_to_conf(mddev); 3203 raid5_conf_t *conf = mddev_to_conf(mddev);
@@ -3216,7 +3216,7 @@ static void raid5_unplug_device(request_queue_t *q)
3216 unplug_slaves(mddev); 3216 unplug_slaves(mddev);
3217} 3217}
3218 3218
3219static int raid5_issue_flush(request_queue_t *q, struct gendisk *disk, 3219static int raid5_issue_flush(struct request_queue *q, struct gendisk *disk,
3220 sector_t *error_sector) 3220 sector_t *error_sector)
3221{ 3221{
3222 mddev_t *mddev = q->queuedata; 3222 mddev_t *mddev = q->queuedata;
@@ -3228,7 +3228,7 @@ static int raid5_issue_flush(request_queue_t *q, struct gendisk *disk,
3228 mdk_rdev_t *rdev = rcu_dereference(conf->disks[i].rdev); 3228 mdk_rdev_t *rdev = rcu_dereference(conf->disks[i].rdev);
3229 if (rdev && !test_bit(Faulty, &rdev->flags)) { 3229 if (rdev && !test_bit(Faulty, &rdev->flags)) {
3230 struct block_device *bdev = rdev->bdev; 3230 struct block_device *bdev = rdev->bdev;
3231 request_queue_t *r_queue = bdev_get_queue(bdev); 3231 struct request_queue *r_queue = bdev_get_queue(bdev);
3232 3232
3233 if (!r_queue->issue_flush_fn) 3233 if (!r_queue->issue_flush_fn)
3234 ret = -EOPNOTSUPP; 3234 ret = -EOPNOTSUPP;
@@ -3267,7 +3267,7 @@ static int raid5_congested(void *data, int bits)
3267/* We want read requests to align with chunks where possible, 3267/* We want read requests to align with chunks where possible,
3268 * but write requests don't need to. 3268 * but write requests don't need to.
3269 */ 3269 */
3270static int raid5_mergeable_bvec(request_queue_t *q, struct bio *bio, struct bio_vec *biovec) 3270static int raid5_mergeable_bvec(struct request_queue *q, struct bio *bio, struct bio_vec *biovec)
3271{ 3271{
3272 mddev_t *mddev = q->queuedata; 3272 mddev_t *mddev = q->queuedata;
3273 sector_t sector = bio->bi_sector + get_start_sect(bio->bi_bdev); 3273 sector_t sector = bio->bi_sector + get_start_sect(bio->bi_bdev);
@@ -3377,7 +3377,7 @@ static int raid5_align_endio(struct bio *bi, unsigned int bytes, int error)
3377 3377
3378static int bio_fits_rdev(struct bio *bi) 3378static int bio_fits_rdev(struct bio *bi)
3379{ 3379{
3380 request_queue_t *q = bdev_get_queue(bi->bi_bdev); 3380 struct request_queue *q = bdev_get_queue(bi->bi_bdev);
3381 3381
3382 if ((bi->bi_size>>9) > q->max_sectors) 3382 if ((bi->bi_size>>9) > q->max_sectors)
3383 return 0; 3383 return 0;
@@ -3396,7 +3396,7 @@ static int bio_fits_rdev(struct bio *bi)
3396} 3396}
3397 3397
3398 3398
3399static int chunk_aligned_read(request_queue_t *q, struct bio * raid_bio) 3399static int chunk_aligned_read(struct request_queue *q, struct bio * raid_bio)
3400{ 3400{
3401 mddev_t *mddev = q->queuedata; 3401 mddev_t *mddev = q->queuedata;
3402 raid5_conf_t *conf = mddev_to_conf(mddev); 3402 raid5_conf_t *conf = mddev_to_conf(mddev);
@@ -3466,7 +3466,7 @@ static int chunk_aligned_read(request_queue_t *q, struct bio * raid_bio)
3466} 3466}
3467 3467
3468 3468
3469static int make_request(request_queue_t *q, struct bio * bi) 3469static int make_request(struct request_queue *q, struct bio * bi)
3470{ 3470{
3471 mddev_t *mddev = q->queuedata; 3471 mddev_t *mddev = q->queuedata;
3472 raid5_conf_t *conf = mddev_to_conf(mddev); 3472 raid5_conf_t *conf = mddev_to_conf(mddev);
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 9dcbffd0aa15..e204e7b4028a 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -509,7 +509,7 @@ config VIDEO_VINO
509 509
510config VIDEO_STRADIS 510config VIDEO_STRADIS
511 tristate "Stradis 4:2:2 MPEG-2 video driver (EXPERIMENTAL)" 511 tristate "Stradis 4:2:2 MPEG-2 video driver (EXPERIMENTAL)"
512 depends on EXPERIMENTAL && PCI && VIDEO_V4L1 && !PPC64 512 depends on EXPERIMENTAL && PCI && VIDEO_V4L1 && VIRT_TO_BUS
513 help 513 help
514 Say Y here to enable support for the Stradis 4:2:2 MPEG-2 video 514 Say Y here to enable support for the Stradis 4:2:2 MPEG-2 video
515 driver for PCI. There is a product page at 515 driver for PCI. There is a product page at
@@ -520,7 +520,7 @@ config VIDEO_ZORAN_ZR36060
520 520
521config VIDEO_ZORAN 521config VIDEO_ZORAN
522 tristate "Zoran ZR36057/36067 Video For Linux" 522 tristate "Zoran ZR36057/36067 Video For Linux"
523 depends on PCI && I2C_ALGOBIT && VIDEO_V4L1 && !PPC64 523 depends on PCI && I2C_ALGOBIT && VIDEO_V4L1 && VIRT_TO_BUS
524 help 524 help
525 Say Y for support for MJPEG capture cards based on the Zoran 525 Say Y for support for MJPEG capture cards based on the Zoran
526 36057/36067 PCI controller chipset. This includes the Iomega 526 36057/36067 PCI controller chipset. This includes the Iomega
diff --git a/drivers/message/i2o/i2o_block.c b/drivers/message/i2o/i2o_block.c
index 988c8ce47f58..5e1c99f83ab5 100644
--- a/drivers/message/i2o/i2o_block.c
+++ b/drivers/message/i2o/i2o_block.c
@@ -159,7 +159,7 @@ static int i2o_block_device_flush(struct i2o_device *dev)
159 * Returns 0 on success or negative error code on failure. 159 * Returns 0 on success or negative error code on failure.
160 */ 160 */
161 161
162static int i2o_block_issue_flush(request_queue_t * queue, struct gendisk *disk, 162static int i2o_block_issue_flush(struct request_queue * queue, struct gendisk *disk,
163 sector_t * error_sector) 163 sector_t * error_sector)
164{ 164{
165 struct i2o_block_device *i2o_blk_dev = queue->queuedata; 165 struct i2o_block_device *i2o_blk_dev = queue->queuedata;
@@ -445,7 +445,7 @@ static void i2o_block_end_request(struct request *req, int uptodate,
445{ 445{
446 struct i2o_block_request *ireq = req->special; 446 struct i2o_block_request *ireq = req->special;
447 struct i2o_block_device *dev = ireq->i2o_blk_dev; 447 struct i2o_block_device *dev = ireq->i2o_blk_dev;
448 request_queue_t *q = req->q; 448 struct request_queue *q = req->q;
449 unsigned long flags; 449 unsigned long flags;
450 450
451 if (end_that_request_chunk(req, uptodate, nr_bytes)) { 451 if (end_that_request_chunk(req, uptodate, nr_bytes)) {
diff --git a/drivers/misc/asus-laptop.c b/drivers/misc/asus-laptop.c
index f75306059971..d0fc4fd212e6 100644
--- a/drivers/misc/asus-laptop.c
+++ b/drivers/misc/asus-laptop.c
@@ -53,7 +53,6 @@
53#define ASUS_HOTK_NAME "Asus Laptop Support" 53#define ASUS_HOTK_NAME "Asus Laptop Support"
54#define ASUS_HOTK_CLASS "hotkey" 54#define ASUS_HOTK_CLASS "hotkey"
55#define ASUS_HOTK_DEVICE_NAME "Hotkey" 55#define ASUS_HOTK_DEVICE_NAME "Hotkey"
56#define ASUS_HOTK_HID "ATK0100"
57#define ASUS_HOTK_FILE "asus-laptop" 56#define ASUS_HOTK_FILE "asus-laptop"
58#define ASUS_HOTK_PREFIX "\\_SB.ATKD." 57#define ASUS_HOTK_PREFIX "\\_SB.ATKD."
59 58
@@ -197,12 +196,18 @@ static struct asus_hotk *hotk;
197/* 196/*
198 * The hotkey driver declaration 197 * The hotkey driver declaration
199 */ 198 */
199static const struct acpi_device_id asus_device_ids[] = {
200 {"ATK0100", 0},
201 {"", 0},
202};
203MODULE_DEVICE_TABLE(acpi, asus_device_ids);
204
200static int asus_hotk_add(struct acpi_device *device); 205static int asus_hotk_add(struct acpi_device *device);
201static int asus_hotk_remove(struct acpi_device *device, int type); 206static int asus_hotk_remove(struct acpi_device *device, int type);
202static struct acpi_driver asus_hotk_driver = { 207static struct acpi_driver asus_hotk_driver = {
203 .name = ASUS_HOTK_NAME, 208 .name = ASUS_HOTK_NAME,
204 .class = ASUS_HOTK_CLASS, 209 .class = ASUS_HOTK_CLASS,
205 .ids = ASUS_HOTK_HID, 210 .ids = asus_device_ids,
206 .ops = { 211 .ops = {
207 .add = asus_hotk_add, 212 .add = asus_hotk_add,
208 .remove = asus_hotk_remove, 213 .remove = asus_hotk_remove,
@@ -1067,19 +1072,16 @@ static void asus_backlight_exit(void)
1067} 1072}
1068 1073
1069#define ASUS_LED_UNREGISTER(object) \ 1074#define ASUS_LED_UNREGISTER(object) \
1070 if(object##_led.class_dev \ 1075 led_classdev_unregister(&object##_led)
1071 && !IS_ERR(object##_led.class_dev)) \
1072 led_classdev_unregister(&object##_led)
1073 1076
1074static void asus_led_exit(void) 1077static void asus_led_exit(void)
1075{ 1078{
1079 destroy_workqueue(led_workqueue);
1076 ASUS_LED_UNREGISTER(mled); 1080 ASUS_LED_UNREGISTER(mled);
1077 ASUS_LED_UNREGISTER(tled); 1081 ASUS_LED_UNREGISTER(tled);
1078 ASUS_LED_UNREGISTER(pled); 1082 ASUS_LED_UNREGISTER(pled);
1079 ASUS_LED_UNREGISTER(rled); 1083 ASUS_LED_UNREGISTER(rled);
1080 ASUS_LED_UNREGISTER(gled); 1084 ASUS_LED_UNREGISTER(gled);
1081
1082 destroy_workqueue(led_workqueue);
1083} 1085}
1084 1086
1085static void __exit asus_laptop_exit(void) 1087static void __exit asus_laptop_exit(void)
@@ -1135,29 +1137,42 @@ static int asus_led_init(struct device *dev)
1135 1137
1136 rv = ASUS_LED_REGISTER(mled, dev); 1138 rv = ASUS_LED_REGISTER(mled, dev);
1137 if (rv) 1139 if (rv)
1138 return rv; 1140 goto out;
1139 1141
1140 rv = ASUS_LED_REGISTER(tled, dev); 1142 rv = ASUS_LED_REGISTER(tled, dev);
1141 if (rv) 1143 if (rv)
1142 return rv; 1144 goto out1;
1143 1145
1144 rv = ASUS_LED_REGISTER(rled, dev); 1146 rv = ASUS_LED_REGISTER(rled, dev);
1145 if (rv) 1147 if (rv)
1146 return rv; 1148 goto out2;
1147 1149
1148 rv = ASUS_LED_REGISTER(pled, dev); 1150 rv = ASUS_LED_REGISTER(pled, dev);
1149 if (rv) 1151 if (rv)
1150 return rv; 1152 goto out3;
1151 1153
1152 rv = ASUS_LED_REGISTER(gled, dev); 1154 rv = ASUS_LED_REGISTER(gled, dev);
1153 if (rv) 1155 if (rv)
1154 return rv; 1156 goto out4;
1155 1157
1156 led_workqueue = create_singlethread_workqueue("led_workqueue"); 1158 led_workqueue = create_singlethread_workqueue("led_workqueue");
1157 if (!led_workqueue) 1159 if (!led_workqueue)
1158 return -ENOMEM; 1160 goto out5;
1159 1161
1160 return 0; 1162 return 0;
1163out5:
1164 rv = -ENOMEM;
1165 ASUS_LED_UNREGISTER(gled);
1166out4:
1167 ASUS_LED_UNREGISTER(pled);
1168out3:
1169 ASUS_LED_UNREGISTER(rled);
1170out2:
1171 ASUS_LED_UNREGISTER(tled);
1172out1:
1173 ASUS_LED_UNREGISTER(mled);
1174out:
1175 return rv;
1161} 1176}
1162 1177
1163static int __init asus_laptop_init(void) 1178static int __init asus_laptop_init(void)
diff --git a/drivers/misc/sony-laptop.c b/drivers/misc/sony-laptop.c
index 303e48ca0e8a..14ee06c8f127 100644
--- a/drivers/misc/sony-laptop.c
+++ b/drivers/misc/sony-laptop.c
@@ -1124,10 +1124,22 @@ static int sony_nc_remove(struct acpi_device *device, int type)
1124 return 0; 1124 return 0;
1125} 1125}
1126 1126
1127static const struct acpi_device_id sony_device_ids[] = {
1128 {SONY_NC_HID, 0},
1129 {SONY_PIC_HID, 0},
1130 {"", 0},
1131};
1132MODULE_DEVICE_TABLE(acpi, sony_device_ids);
1133
1134static const struct acpi_device_id sony_nc_device_ids[] = {
1135 {SONY_NC_HID, 0},
1136 {"", 0},
1137};
1138
1127static struct acpi_driver sony_nc_driver = { 1139static struct acpi_driver sony_nc_driver = {
1128 .name = SONY_NC_DRIVER_NAME, 1140 .name = SONY_NC_DRIVER_NAME,
1129 .class = SONY_NC_CLASS, 1141 .class = SONY_NC_CLASS,
1130 .ids = SONY_NC_HID, 1142 .ids = sony_nc_device_ids,
1131 .owner = THIS_MODULE, 1143 .owner = THIS_MODULE,
1132 .ops = { 1144 .ops = {
1133 .add = sony_nc_add, 1145 .add = sony_nc_add,
@@ -2470,10 +2482,15 @@ static int sony_pic_resume(struct acpi_device *device)
2470 return 0; 2482 return 0;
2471} 2483}
2472 2484
2485static const struct acpi_device_id sony_pic_device_ids[] = {
2486 {SONY_PIC_HID, 0},
2487 {"", 0},
2488};
2489
2473static struct acpi_driver sony_pic_driver = { 2490static struct acpi_driver sony_pic_driver = {
2474 .name = SONY_PIC_DRIVER_NAME, 2491 .name = SONY_PIC_DRIVER_NAME,
2475 .class = SONY_PIC_CLASS, 2492 .class = SONY_PIC_CLASS,
2476 .ids = SONY_PIC_HID, 2493 .ids = sony_pic_device_ids,
2477 .owner = THIS_MODULE, 2494 .owner = THIS_MODULE,
2478 .ops = { 2495 .ops = {
2479 .add = sony_pic_add, 2496 .add = sony_pic_add,
diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c
index f15a58f7403f..fa80f355e522 100644
--- a/drivers/misc/thinkpad_acpi.c
+++ b/drivers/misc/thinkpad_acpi.c
@@ -411,12 +411,13 @@ static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)
411 411
412 sprintf(ibm->acpi->driver->name, "%s_%s", IBM_NAME, ibm->name); 412 sprintf(ibm->acpi->driver->name, "%s_%s", IBM_NAME, ibm->name);
413 ibm->acpi->driver->ids = ibm->acpi->hid; 413 ibm->acpi->driver->ids = ibm->acpi->hid;
414
414 ibm->acpi->driver->ops.add = &tpacpi_device_add; 415 ibm->acpi->driver->ops.add = &tpacpi_device_add;
415 416
416 rc = acpi_bus_register_driver(ibm->acpi->driver); 417 rc = acpi_bus_register_driver(ibm->acpi->driver);
417 if (rc < 0) { 418 if (rc < 0) {
418 printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n", 419 printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n",
419 ibm->acpi->hid, rc); 420 ibm->name, rc);
420 kfree(ibm->acpi->driver); 421 kfree(ibm->acpi->driver);
421 ibm->acpi->driver = NULL; 422 ibm->acpi->driver = NULL;
422 } else if (!rc) 423 } else if (!rc)
@@ -1316,8 +1317,13 @@ errexit:
1316 return res; 1317 return res;
1317} 1318}
1318 1319
1320static const struct acpi_device_id ibm_htk_device_ids[] = {
1321 {IBM_HKEY_HID, 0},
1322 {"", 0},
1323};
1324
1319static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = { 1325static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = {
1320 .hid = IBM_HKEY_HID, 1326 .hid = ibm_htk_device_ids,
1321 .notify = hotkey_notify, 1327 .notify = hotkey_notify,
1322 .handle = &hkey_handle, 1328 .handle = &hkey_handle,
1323 .type = ACPI_DEVICE_NOTIFY, 1329 .type = ACPI_DEVICE_NOTIFY,
@@ -2080,6 +2086,11 @@ IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
2080/* don't list other alternatives as we install a notify handler on the 570 */ 2086/* don't list other alternatives as we install a notify handler on the 570 */
2081IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */ 2087IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */
2082 2088
2089static const struct acpi_device_id ibm_pci_device_ids[] = {
2090 {PCI_ROOT_HID_STRING, 0},
2091 {"", 0},
2092};
2093
2083static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = { 2094static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = {
2084 { 2095 {
2085 .notify = dock_notify, 2096 .notify = dock_notify,
@@ -2090,7 +2101,7 @@ static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = {
2090 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING. 2101 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
2091 * We just use it to get notifications of dock hotplug 2102 * We just use it to get notifications of dock hotplug
2092 * in very old thinkpads */ 2103 * in very old thinkpads */
2093 .hid = PCI_ROOT_HID_STRING, 2104 .hid = ibm_pci_device_ids,
2094 .notify = dock_notify, 2105 .notify = dock_notify,
2095 .handle = &pci_handle, 2106 .handle = &pci_handle,
2096 .type = ACPI_SYSTEM_NOTIFY, 2107 .type = ACPI_SYSTEM_NOTIFY,
@@ -2149,7 +2160,8 @@ static int __init dock_init2(struct ibm_init_struct *iibm)
2149static void dock_notify(struct ibm_struct *ibm, u32 event) 2160static void dock_notify(struct ibm_struct *ibm, u32 event)
2150{ 2161{
2151 int docked = dock_docked(); 2162 int docked = dock_docked();
2152 int pci = ibm->acpi->hid && strstr(ibm->acpi->hid, PCI_ROOT_HID_STRING); 2163 int pci = ibm->acpi->hid && ibm->acpi->device &&
2164 acpi_match_device_ids(ibm->acpi->device, ibm_pci_device_ids);
2153 2165
2154 if (event == 1 && !pci) /* 570 */ 2166 if (event == 1 && !pci) /* 570 */
2155 acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */ 2167 acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */
diff --git a/drivers/misc/thinkpad_acpi.h b/drivers/misc/thinkpad_acpi.h
index b7a4a888cc8b..88af089d6494 100644
--- a/drivers/misc/thinkpad_acpi.h
+++ b/drivers/misc/thinkpad_acpi.h
@@ -193,7 +193,7 @@ static void thinkpad_acpi_module_exit(void);
193struct ibm_struct; 193struct ibm_struct;
194 194
195struct tp_acpi_drv_struct { 195struct tp_acpi_drv_struct {
196 char *hid; 196 const struct acpi_device_id *hid;
197 struct acpi_driver *driver; 197 struct acpi_driver *driver;
198 198
199 void (*notify) (struct ibm_struct *, u32); 199 void (*notify) (struct ibm_struct *, u32);
diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
index b53dac8d1b69..c9a289c6c139 100644
--- a/drivers/mmc/card/queue.c
+++ b/drivers/mmc/card/queue.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/mmc/queue.c 2 * linux/drivers/mmc/card/queue.c
3 * 3 *
4 * Copyright (C) 2003 Russell King, All Rights Reserved. 4 * Copyright (C) 2003 Russell King, All Rights Reserved.
5 * Copyright 2006-2007 Pierre Ossman 5 * Copyright 2006-2007 Pierre Ossman
@@ -83,7 +83,7 @@ static int mmc_queue_thread(void *d)
83 * on any queue on this host, and attempt to issue it. This may 83 * on any queue on this host, and attempt to issue it. This may
84 * not be the queue we were asked to process. 84 * not be the queue we were asked to process.
85 */ 85 */
86static void mmc_request(request_queue_t *q) 86static void mmc_request(struct request_queue *q)
87{ 87{
88 struct mmc_queue *mq = q->queuedata; 88 struct mmc_queue *mq = q->queuedata;
89 struct request *req; 89 struct request *req;
@@ -211,7 +211,7 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock
211 211
212void mmc_cleanup_queue(struct mmc_queue *mq) 212void mmc_cleanup_queue(struct mmc_queue *mq)
213{ 213{
214 request_queue_t *q = mq->queue; 214 struct request_queue *q = mq->queue;
215 unsigned long flags; 215 unsigned long flags;
216 216
217 /* Mark that we should start throwing out stragglers */ 217 /* Mark that we should start throwing out stragglers */
@@ -252,7 +252,7 @@ EXPORT_SYMBOL(mmc_cleanup_queue);
252 */ 252 */
253void mmc_queue_suspend(struct mmc_queue *mq) 253void mmc_queue_suspend(struct mmc_queue *mq)
254{ 254{
255 request_queue_t *q = mq->queue; 255 struct request_queue *q = mq->queue;
256 unsigned long flags; 256 unsigned long flags;
257 257
258 if (!(mq->flags & MMC_QUEUE_SUSPENDED)) { 258 if (!(mq->flags & MMC_QUEUE_SUSPENDED)) {
@@ -272,7 +272,7 @@ void mmc_queue_suspend(struct mmc_queue *mq)
272 */ 272 */
273void mmc_queue_resume(struct mmc_queue *mq) 273void mmc_queue_resume(struct mmc_queue *mq)
274{ 274{
275 request_queue_t *q = mq->queue; 275 struct request_queue *q = mq->queue;
276 unsigned long flags; 276 unsigned long flags;
277 277
278 if (mq->flags & MMC_QUEUE_SUSPENDED) { 278 if (mq->flags & MMC_QUEUE_SUSPENDED) {
diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c
index 348b566bf4fd..fe0e785ed7d2 100644
--- a/drivers/mmc/core/bus.c
+++ b/drivers/mmc/core/bus.c
@@ -209,10 +209,30 @@ struct mmc_card *mmc_alloc_card(struct mmc_host *host)
209int mmc_add_card(struct mmc_card *card) 209int mmc_add_card(struct mmc_card *card)
210{ 210{
211 int ret; 211 int ret;
212 const char *type;
212 213
213 snprintf(card->dev.bus_id, sizeof(card->dev.bus_id), 214 snprintf(card->dev.bus_id, sizeof(card->dev.bus_id),
214 "%s:%04x", mmc_hostname(card->host), card->rca); 215 "%s:%04x", mmc_hostname(card->host), card->rca);
215 216
217 switch (card->type) {
218 case MMC_TYPE_MMC:
219 type = "MMC";
220 break;
221 case MMC_TYPE_SD:
222 type = "SD";
223 if (mmc_card_blockaddr(card))
224 type = "SDHC";
225 break;
226 default:
227 type = "?";
228 break;
229 }
230
231 printk(KERN_INFO "%s: new %s%s card at address %04x\n",
232 mmc_hostname(card->host),
233 mmc_card_highspeed(card) ? "high speed " : "",
234 type, card->rca);
235
216 card->dev.uevent_suppress = 1; 236 card->dev.uevent_suppress = 1;
217 237
218 ret = device_add(&card->dev); 238 ret = device_add(&card->dev);
@@ -243,6 +263,9 @@ int mmc_add_card(struct mmc_card *card)
243void mmc_remove_card(struct mmc_card *card) 263void mmc_remove_card(struct mmc_card *card)
244{ 264{
245 if (mmc_card_present(card)) { 265 if (mmc_card_present(card)) {
266 printk(KERN_INFO "%s: card %04x removed\n",
267 mmc_hostname(card->host), card->rca);
268
246 if (card->host->bus_ops->sysfs_remove) 269 if (card->host->bus_ops->sysfs_remove)
247 card->host->bus_ops->sysfs_remove(card->host, card); 270 card->host->bus_ops->sysfs_remove(card->host, card);
248 device_del(&card->dev); 271 device_del(&card->dev);
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index b5d8a6d90cca..bfd2ae5bd669 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -68,32 +68,41 @@ void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq)
68 struct mmc_command *cmd = mrq->cmd; 68 struct mmc_command *cmd = mrq->cmd;
69 int err = cmd->error; 69 int err = cmd->error;
70 70
71 pr_debug("%s: req done (CMD%u): %d/%d/%d: %08x %08x %08x %08x\n",
72 mmc_hostname(host), cmd->opcode, err,
73 mrq->data ? mrq->data->error : 0,
74 mrq->stop ? mrq->stop->error : 0,
75 cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3]);
76
77 if (err && cmd->retries) { 71 if (err && cmd->retries) {
72 pr_debug("%s: req failed (CMD%u): %d, retrying...\n",
73 mmc_hostname(host), cmd->opcode, err);
74
78 cmd->retries--; 75 cmd->retries--;
79 cmd->error = 0; 76 cmd->error = 0;
80 host->ops->request(host, mrq); 77 host->ops->request(host, mrq);
81 } else if (mrq->done) { 78 } else {
82 mrq->done(mrq); 79 pr_debug("%s: req done (CMD%u): %d: %08x %08x %08x %08x\n",
80 mmc_hostname(host), cmd->opcode, err,
81 cmd->resp[0], cmd->resp[1],
82 cmd->resp[2], cmd->resp[3]);
83
84 if (mrq->data) {
85 pr_debug("%s: %d bytes transferred: %d\n",
86 mmc_hostname(host),
87 mrq->data->bytes_xfered, mrq->data->error);
88 }
89
90 if (mrq->stop) {
91 pr_debug("%s: (CMD%u): %d: %08x %08x %08x %08x\n",
92 mmc_hostname(host), mrq->stop->opcode,
93 mrq->stop->error,
94 mrq->stop->resp[0], mrq->stop->resp[1],
95 mrq->stop->resp[2], mrq->stop->resp[3]);
96 }
97
98 if (mrq->done)
99 mrq->done(mrq);
83 } 100 }
84} 101}
85 102
86EXPORT_SYMBOL(mmc_request_done); 103EXPORT_SYMBOL(mmc_request_done);
87 104
88/** 105static void
89 * mmc_start_request - start a command on a host
90 * @host: MMC host to start command on
91 * @mrq: MMC request to start
92 *
93 * Queue a command on the specified host. We expect the
94 * caller to be holding the host lock with interrupts disabled.
95 */
96void
97mmc_start_request(struct mmc_host *host, struct mmc_request *mrq) 106mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
98{ 107{
99#ifdef CONFIG_MMC_DEBUG 108#ifdef CONFIG_MMC_DEBUG
@@ -104,6 +113,21 @@ mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
104 mmc_hostname(host), mrq->cmd->opcode, 113 mmc_hostname(host), mrq->cmd->opcode,
105 mrq->cmd->arg, mrq->cmd->flags); 114 mrq->cmd->arg, mrq->cmd->flags);
106 115
116 if (mrq->data) {
117 pr_debug("%s: blksz %d blocks %d flags %08x "
118 "tsac %d ms nsac %d\n",
119 mmc_hostname(host), mrq->data->blksz,
120 mrq->data->blocks, mrq->data->flags,
121 mrq->data->timeout_ns / 10000000,
122 mrq->data->timeout_clks);
123 }
124
125 if (mrq->stop) {
126 pr_debug("%s: CMD%u arg %08x flags %08x\n",
127 mmc_hostname(host), mrq->stop->opcode,
128 mrq->stop->arg, mrq->stop->flags);
129 }
130
107 WARN_ON(!host->claimed); 131 WARN_ON(!host->claimed);
108 132
109 mrq->cmd->error = 0; 133 mrq->cmd->error = 0;
@@ -133,14 +157,21 @@ mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
133 host->ops->request(host, mrq); 157 host->ops->request(host, mrq);
134} 158}
135 159
136EXPORT_SYMBOL(mmc_start_request);
137
138static void mmc_wait_done(struct mmc_request *mrq) 160static void mmc_wait_done(struct mmc_request *mrq)
139{ 161{
140 complete(mrq->done_data); 162 complete(mrq->done_data);
141} 163}
142 164
143int mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq) 165/**
166 * mmc_wait_for_req - start a request and wait for completion
167 * @host: MMC host to start command
168 * @mrq: MMC request to start
169 *
170 * Start a new MMC custom command request for a host, and wait
171 * for the command to complete. Does not attempt to parse the
172 * response.
173 */
174void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
144{ 175{
145 DECLARE_COMPLETION_ONSTACK(complete); 176 DECLARE_COMPLETION_ONSTACK(complete);
146 177
@@ -150,8 +181,6 @@ int mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
150 mmc_start_request(host, mrq); 181 mmc_start_request(host, mrq);
151 182
152 wait_for_completion(&complete); 183 wait_for_completion(&complete);
153
154 return 0;
155} 184}
156 185
157EXPORT_SYMBOL(mmc_wait_for_req); 186EXPORT_SYMBOL(mmc_wait_for_req);
@@ -192,6 +221,9 @@ EXPORT_SYMBOL(mmc_wait_for_cmd);
192 * @data: data phase for command 221 * @data: data phase for command
193 * @card: the MMC card associated with the data transfer 222 * @card: the MMC card associated with the data transfer
194 * @write: flag to differentiate reads from writes 223 * @write: flag to differentiate reads from writes
224 *
225 * Computes the data timeout parameters according to the
226 * correct algorithm given the card type.
195 */ 227 */
196void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card, 228void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card,
197 int write) 229 int write)
@@ -240,21 +272,18 @@ void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card,
240EXPORT_SYMBOL(mmc_set_data_timeout); 272EXPORT_SYMBOL(mmc_set_data_timeout);
241 273
242/** 274/**
243 * __mmc_claim_host - exclusively claim a host 275 * mmc_claim_host - exclusively claim a host
244 * @host: mmc host to claim 276 * @host: mmc host to claim
245 * @card: mmc card to claim host for
246 *
247 * Claim a host for a set of operations. If a valid card
248 * is passed and this wasn't the last card selected, select
249 * the card before returning.
250 * 277 *
251 * Note: you should use mmc_card_claim_host or mmc_claim_host. 278 * Claim a host for a set of operations.
252 */ 279 */
253void mmc_claim_host(struct mmc_host *host) 280void mmc_claim_host(struct mmc_host *host)
254{ 281{
255 DECLARE_WAITQUEUE(wait, current); 282 DECLARE_WAITQUEUE(wait, current);
256 unsigned long flags; 283 unsigned long flags;
257 284
285 might_sleep();
286
258 add_wait_queue(&host->wq, &wait); 287 add_wait_queue(&host->wq, &wait);
259 spin_lock_irqsave(&host->lock, flags); 288 spin_lock_irqsave(&host->lock, flags);
260 while (1) { 289 while (1) {
@@ -433,6 +462,45 @@ static void mmc_power_off(struct mmc_host *host)
433} 462}
434 463
435/* 464/*
465 * Cleanup when the last reference to the bus operator is dropped.
466 */
467void __mmc_release_bus(struct mmc_host *host)
468{
469 BUG_ON(!host);
470 BUG_ON(host->bus_refs);
471 BUG_ON(!host->bus_dead);
472
473 host->bus_ops = NULL;
474}
475
476/*
477 * Increase reference count of bus operator
478 */
479static inline void mmc_bus_get(struct mmc_host *host)
480{
481 unsigned long flags;
482
483 spin_lock_irqsave(&host->lock, flags);
484 host->bus_refs++;
485 spin_unlock_irqrestore(&host->lock, flags);
486}
487
488/*
489 * Decrease reference count of bus operator and free it if
490 * it is the last reference.
491 */
492static inline void mmc_bus_put(struct mmc_host *host)
493{
494 unsigned long flags;
495
496 spin_lock_irqsave(&host->lock, flags);
497 host->bus_refs--;
498 if ((host->bus_refs == 0) && host->bus_ops)
499 __mmc_release_bus(host);
500 spin_unlock_irqrestore(&host->lock, flags);
501}
502
503/*
436 * Assign a mmc bus handler to a host. Only one bus handler may control a 504 * Assign a mmc bus handler to a host. Only one bus handler may control a
437 * host at any given time. 505 * host at any given time.
438 */ 506 */
@@ -481,25 +549,15 @@ void mmc_detach_bus(struct mmc_host *host)
481 mmc_bus_put(host); 549 mmc_bus_put(host);
482} 550}
483 551
484/*
485 * Cleanup when the last reference to the bus operator is dropped.
486 */
487void __mmc_release_bus(struct mmc_host *host)
488{
489 BUG_ON(!host);
490 BUG_ON(host->bus_refs);
491 BUG_ON(!host->bus_dead);
492
493 host->bus_ops = NULL;
494}
495
496/** 552/**
497 * mmc_detect_change - process change of state on a MMC socket 553 * mmc_detect_change - process change of state on a MMC socket
498 * @host: host which changed state. 554 * @host: host which changed state.
499 * @delay: optional delay to wait before detection (jiffies) 555 * @delay: optional delay to wait before detection (jiffies)
500 * 556 *
501 * All we know is that card(s) have been inserted or removed 557 * MMC drivers should call this when they detect a card has been
502 * from the socket(s). We don't know which socket or cards. 558 * inserted or removed. The MMC layer will confirm that any
559 * present card is still functional, and initialize any newly
560 * inserted.
503 */ 561 */
504void mmc_detect_change(struct mmc_host *host, unsigned long delay) 562void mmc_detect_change(struct mmc_host *host, unsigned long delay)
505{ 563{
diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
index ae006b30dd86..bb2774af9ea9 100644
--- a/drivers/mmc/core/core.h
+++ b/drivers/mmc/core/core.h
@@ -27,28 +27,6 @@ struct mmc_bus_ops {
27void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops); 27void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops);
28void mmc_detach_bus(struct mmc_host *host); 28void mmc_detach_bus(struct mmc_host *host);
29 29
30void __mmc_release_bus(struct mmc_host *host);
31
32static inline void mmc_bus_get(struct mmc_host *host)
33{
34 unsigned long flags;
35
36 spin_lock_irqsave(&host->lock, flags);
37 host->bus_refs++;
38 spin_unlock_irqrestore(&host->lock, flags);
39}
40
41static inline void mmc_bus_put(struct mmc_host *host)
42{
43 unsigned long flags;
44
45 spin_lock_irqsave(&host->lock, flags);
46 host->bus_refs--;
47 if ((host->bus_refs == 0) && host->bus_ops)
48 __mmc_release_bus(host);
49 spin_unlock_irqrestore(&host->lock, flags);
50}
51
52void mmc_set_chip_select(struct mmc_host *host, int mode); 30void mmc_set_chip_select(struct mmc_host *host, int mode);
53void mmc_set_clock(struct mmc_host *host, unsigned int hz); 31void mmc_set_clock(struct mmc_host *host, unsigned int hz);
54void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode); 32void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode);
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index 1433d95c40bb..6a7e29849603 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -93,6 +93,10 @@ EXPORT_SYMBOL(mmc_alloc_host);
93/** 93/**
94 * mmc_add_host - initialise host hardware 94 * mmc_add_host - initialise host hardware
95 * @host: mmc host 95 * @host: mmc host
96 *
97 * Register the host with the driver model. The host must be
98 * prepared to start servicing requests before this function
99 * completes.
96 */ 100 */
97int mmc_add_host(struct mmc_host *host) 101int mmc_add_host(struct mmc_host *host)
98{ 102{
@@ -126,7 +130,8 @@ EXPORT_SYMBOL(mmc_add_host);
126 * @host: mmc host 130 * @host: mmc host
127 * 131 *
128 * Unregister and remove all cards associated with this host, 132 * Unregister and remove all cards associated with this host,
129 * and power down the MMC bus. 133 * and power down the MMC bus. No new requests will be issued
134 * after this function has returned.
130 */ 135 */
131void mmc_remove_host(struct mmc_host *host) 136void mmc_remove_host(struct mmc_host *host)
132{ 137{
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 66f85bfa8dbb..21d7f48e1d4e 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/mmc/mmc.c 2 * linux/drivers/mmc/core/mmc.c
3 * 3 *
4 * Copyright (C) 2003-2004 Russell King, All Rights Reserved. 4 * Copyright (C) 2003-2004 Russell King, All Rights Reserved.
5 * Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved. 5 * Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved.
@@ -100,7 +100,7 @@ static int mmc_decode_cid(struct mmc_card *card)
100 break; 100 break;
101 101
102 default: 102 default:
103 printk("%s: card has unknown MMCA version %d\n", 103 printk(KERN_ERR "%s: card has unknown MMCA version %d\n",
104 mmc_hostname(card->host), card->csd.mmca_vsn); 104 mmc_hostname(card->host), card->csd.mmca_vsn);
105 return -EINVAL; 105 return -EINVAL;
106 } 106 }
@@ -123,7 +123,7 @@ static int mmc_decode_csd(struct mmc_card *card)
123 */ 123 */
124 csd_struct = UNSTUFF_BITS(resp, 126, 2); 124 csd_struct = UNSTUFF_BITS(resp, 126, 2);
125 if (csd_struct != 1 && csd_struct != 2) { 125 if (csd_struct != 1 && csd_struct != 2) {
126 printk("%s: unrecognised CSD structure version %d\n", 126 printk(KERN_ERR "%s: unrecognised CSD structure version %d\n",
127 mmc_hostname(card->host), csd_struct); 127 mmc_hostname(card->host), csd_struct);
128 return -EINVAL; 128 return -EINVAL;
129 } 129 }
@@ -499,14 +499,17 @@ static void mmc_resume(struct mmc_host *host)
499 BUG_ON(!host->card); 499 BUG_ON(!host->card);
500 500
501 mmc_claim_host(host); 501 mmc_claim_host(host);
502
503 err = mmc_init_card(host, host->ocr, host->card); 502 err = mmc_init_card(host, host->ocr, host->card);
503 mmc_release_host(host);
504
504 if (err != MMC_ERR_NONE) { 505 if (err != MMC_ERR_NONE) {
505 mmc_remove(host); 506 mmc_remove(host);
507
508 mmc_claim_host(host);
506 mmc_detach_bus(host); 509 mmc_detach_bus(host);
510 mmc_release_host(host);
507 } 511 }
508 512
509 mmc_release_host(host);
510} 513}
511 514
512#else 515#else
@@ -553,8 +556,10 @@ int mmc_attach_mmc(struct mmc_host *host, u32 ocr)
553 /* 556 /*
554 * Can we support the voltage of the card? 557 * Can we support the voltage of the card?
555 */ 558 */
556 if (!host->ocr) 559 if (!host->ocr) {
560 err = -EINVAL;
557 goto err; 561 goto err;
562 }
558 563
559 /* 564 /*
560 * Detect and init the card. 565 * Detect and init the card.
@@ -567,18 +572,21 @@ int mmc_attach_mmc(struct mmc_host *host, u32 ocr)
567 572
568 err = mmc_add_card(host->card); 573 err = mmc_add_card(host->card);
569 if (err) 574 if (err)
570 goto reclaim_host; 575 goto remove_card;
571 576
572 return 0; 577 return 0;
573 578
574reclaim_host: 579remove_card:
575 mmc_claim_host(host);
576 mmc_remove_card(host->card); 580 mmc_remove_card(host->card);
577 host->card = NULL; 581 host->card = NULL;
582 mmc_claim_host(host);
578err: 583err:
579 mmc_detach_bus(host); 584 mmc_detach_bus(host);
580 mmc_release_host(host); 585 mmc_release_host(host);
581 586
587 printk(KERN_ERR "%s: error %d whilst initialising MMC card\n",
588 mmc_hostname(host), err);
589
582 return 0; 590 return 0;
583} 591}
584 592
diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index 7dd720fa5895..913e75f00843 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/mmc/mmc_ops.h 2 * linux/drivers/mmc/core/mmc_ops.h
3 * 3 *
4 * Copyright 2006-2007 Pierre Ossman 4 * Copyright 2006-2007 Pierre Ossman
5 * 5 *
diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h
index 7a481e8ca5ea..76d09a93c5d6 100644
--- a/drivers/mmc/core/mmc_ops.h
+++ b/drivers/mmc/core/mmc_ops.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/mmc/mmc_ops.h 2 * linux/drivers/mmc/core/mmc_ops.h
3 * 3 *
4 * Copyright 2006-2007 Pierre Ossman 4 * Copyright 2006-2007 Pierre Ossman
5 * 5 *
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index 1240684083f1..1edc62b1e5c6 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/mmc/sd.c 2 * linux/drivers/mmc/core/sd.c
3 * 3 *
4 * Copyright (C) 2003-2004 Russell King, All Rights Reserved. 4 * Copyright (C) 2003-2004 Russell King, All Rights Reserved.
5 * SD support Copyright (C) 2004 Ian Molton, All Rights Reserved. 5 * SD support Copyright (C) 2004 Ian Molton, All Rights Reserved.
@@ -149,7 +149,7 @@ static int mmc_decode_csd(struct mmc_card *card)
149 csd->write_partial = 0; 149 csd->write_partial = 0;
150 break; 150 break;
151 default: 151 default:
152 printk("%s: unrecognised CSD structure version %d\n", 152 printk(KERN_ERR "%s: unrecognised CSD structure version %d\n",
153 mmc_hostname(card->host), csd_struct); 153 mmc_hostname(card->host), csd_struct);
154 return -EINVAL; 154 return -EINVAL;
155 } 155 }
@@ -173,7 +173,7 @@ static int mmc_decode_scr(struct mmc_card *card)
173 173
174 scr_struct = UNSTUFF_BITS(resp, 60, 4); 174 scr_struct = UNSTUFF_BITS(resp, 60, 4);
175 if (scr_struct != 0) { 175 if (scr_struct != 0) {
176 printk("%s: unrecognised SCR structure version %d\n", 176 printk(KERN_ERR "%s: unrecognised SCR structure version %d\n",
177 mmc_hostname(card->host), scr_struct); 177 mmc_hostname(card->host), scr_struct);
178 return -EINVAL; 178 return -EINVAL;
179 } 179 }
@@ -206,9 +206,8 @@ static int mmc_read_switch(struct mmc_card *card)
206 206
207 status = kmalloc(64, GFP_KERNEL); 207 status = kmalloc(64, GFP_KERNEL);
208 if (!status) { 208 if (!status) {
209 printk("%s: could not allocate a buffer for switch " 209 printk(KERN_ERR "%s: could not allocate a buffer for "
210 "capabilities.\n", 210 "switch capabilities.\n", mmc_hostname(card->host));
211 mmc_hostname(card->host));
212 return err; 211 return err;
213 } 212 }
214 213
@@ -254,9 +253,8 @@ static int mmc_switch_hs(struct mmc_card *card)
254 253
255 status = kmalloc(64, GFP_KERNEL); 254 status = kmalloc(64, GFP_KERNEL);
256 if (!status) { 255 if (!status) {
257 printk("%s: could not allocate a buffer for switch " 256 printk(KERN_ERR "%s: could not allocate a buffer for "
258 "capabilities.\n", 257 "switch capabilities.\n", mmc_hostname(card->host));
259 mmc_hostname(card->host));
260 return err; 258 return err;
261 } 259 }
262 260
@@ -573,14 +571,17 @@ static void mmc_sd_resume(struct mmc_host *host)
573 BUG_ON(!host->card); 571 BUG_ON(!host->card);
574 572
575 mmc_claim_host(host); 573 mmc_claim_host(host);
576
577 err = mmc_sd_init_card(host, host->ocr, host->card); 574 err = mmc_sd_init_card(host, host->ocr, host->card);
575 mmc_release_host(host);
576
578 if (err != MMC_ERR_NONE) { 577 if (err != MMC_ERR_NONE) {
579 mmc_sd_remove(host); 578 mmc_sd_remove(host);
579
580 mmc_claim_host(host);
580 mmc_detach_bus(host); 581 mmc_detach_bus(host);
582 mmc_release_host(host);
581 } 583 }
582 584
583 mmc_release_host(host);
584} 585}
585 586
586#else 587#else
@@ -634,8 +635,10 @@ int mmc_attach_sd(struct mmc_host *host, u32 ocr)
634 /* 635 /*
635 * Can we support the voltage(s) of the card(s)? 636 * Can we support the voltage(s) of the card(s)?
636 */ 637 */
637 if (!host->ocr) 638 if (!host->ocr) {
639 err = -EINVAL;
638 goto err; 640 goto err;
641 }
639 642
640 /* 643 /*
641 * Detect and init the card. 644 * Detect and init the card.
@@ -648,18 +651,21 @@ int mmc_attach_sd(struct mmc_host *host, u32 ocr)
648 651
649 err = mmc_add_card(host->card); 652 err = mmc_add_card(host->card);
650 if (err) 653 if (err)
651 goto reclaim_host; 654 goto remove_card;
652 655
653 return 0; 656 return 0;
654 657
655reclaim_host: 658remove_card:
656 mmc_claim_host(host);
657 mmc_remove_card(host->card); 659 mmc_remove_card(host->card);
658 host->card = NULL; 660 host->card = NULL;
661 mmc_claim_host(host);
659err: 662err:
660 mmc_detach_bus(host); 663 mmc_detach_bus(host);
661 mmc_release_host(host); 664 mmc_release_host(host);
662 665
666 printk(KERN_ERR "%s: error %d whilst initialising SD card\n",
667 mmc_hostname(host), err);
668
663 return 0; 669 return 0;
664} 670}
665 671
diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c
index 9697ce581101..342f340ebc25 100644
--- a/drivers/mmc/core/sd_ops.c
+++ b/drivers/mmc/core/sd_ops.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/mmc/sd_ops.h 2 * linux/drivers/mmc/core/sd_ops.h
3 * 3 *
4 * Copyright 2006-2007 Pierre Ossman 4 * Copyright 2006-2007 Pierre Ossman
5 * 5 *
@@ -21,11 +21,40 @@
21#include "core.h" 21#include "core.h"
22#include "sd_ops.h" 22#include "sd_ops.h"
23 23
24static int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card)
25{
26 int err;
27 struct mmc_command cmd;
28
29 BUG_ON(!host);
30 BUG_ON(card && (card->host != host));
31
32 cmd.opcode = MMC_APP_CMD;
33
34 if (card) {
35 cmd.arg = card->rca << 16;
36 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
37 } else {
38 cmd.arg = 0;
39 cmd.flags = MMC_RSP_R1 | MMC_CMD_BCR;
40 }
41
42 err = mmc_wait_for_cmd(host, &cmd, 0);
43 if (err != MMC_ERR_NONE)
44 return err;
45
46 /* Check that card supported application commands */
47 if (!(cmd.resp[0] & R1_APP_CMD))
48 return MMC_ERR_FAILED;
49
50 return MMC_ERR_NONE;
51}
52
24/** 53/**
25 * mmc_wait_for_app_cmd - start an application command and wait for 54 * mmc_wait_for_app_cmd - start an application command and wait for
26 completion 55 completion
27 * @host: MMC host to start command 56 * @host: MMC host to start command
28 * @rca: RCA to send MMC_APP_CMD to 57 * @card: Card to send MMC_APP_CMD to
29 * @cmd: MMC command to start 58 * @cmd: MMC command to start
30 * @retries: maximum number of retries 59 * @retries: maximum number of retries
31 * 60 *
@@ -77,35 +106,6 @@ int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card,
77 106
78EXPORT_SYMBOL(mmc_wait_for_app_cmd); 107EXPORT_SYMBOL(mmc_wait_for_app_cmd);
79 108
80int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card)
81{
82 int err;
83 struct mmc_command cmd;
84
85 BUG_ON(!host);
86 BUG_ON(card && (card->host != host));
87
88 cmd.opcode = MMC_APP_CMD;
89
90 if (card) {
91 cmd.arg = card->rca << 16;
92 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
93 } else {
94 cmd.arg = 0;
95 cmd.flags = MMC_RSP_R1 | MMC_CMD_BCR;
96 }
97
98 err = mmc_wait_for_cmd(host, &cmd, 0);
99 if (err != MMC_ERR_NONE)
100 return err;
101
102 /* Check that card supported application commands */
103 if (!(cmd.resp[0] & R1_APP_CMD))
104 return MMC_ERR_FAILED;
105
106 return MMC_ERR_NONE;
107}
108
109int mmc_app_set_bus_width(struct mmc_card *card, int width) 109int mmc_app_set_bus_width(struct mmc_card *card, int width)
110{ 110{
111 int err; 111 int err;
diff --git a/drivers/mmc/core/sd_ops.h b/drivers/mmc/core/sd_ops.h
index 1240fddba5e3..9742d8a30664 100644
--- a/drivers/mmc/core/sd_ops.h
+++ b/drivers/mmc/core/sd_ops.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/mmc/sd_ops.h 2 * linux/drivers/mmc/core/sd_ops.h
3 * 3 *
4 * Copyright 2006-2007 Pierre Ossman 4 * Copyright 2006-2007 Pierre Ossman
5 * 5 *
@@ -12,7 +12,6 @@
12#ifndef _MMC_SD_OPS_H 12#ifndef _MMC_SD_OPS_H
13#define _MMC_SD_OPS_H 13#define _MMC_SD_OPS_H
14 14
15int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card);
16int mmc_app_set_bus_width(struct mmc_card *card, int width); 15int mmc_app_set_bus_width(struct mmc_card *card, int width);
17int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr); 16int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr);
18int mmc_send_if_cond(struct mmc_host *host, u32 ocr); 17int mmc_send_if_cond(struct mmc_host *host, u32 ocr);
diff --git a/drivers/mmc/host/at91_mci.c b/drivers/mmc/host/at91_mci.c
index 15aab374127e..62564ccde03a 100644
--- a/drivers/mmc/host/at91_mci.c
+++ b/drivers/mmc/host/at91_mci.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/mmc/at91_mci.c - ATMEL AT91 MCI Driver 2 * linux/drivers/mmc/host/at91_mci.c - ATMEL AT91 MCI Driver
3 * 3 *
4 * Copyright (C) 2005 Cougar Creek Computing Devices Ltd, All Rights Reserved 4 * Copyright (C) 2005 Cougar Creek Computing Devices Ltd, All Rights Reserved
5 * 5 *
diff --git a/drivers/mmc/host/au1xmmc.c b/drivers/mmc/host/au1xmmc.c
index 52b63f11ddd6..34c99d4ea041 100644
--- a/drivers/mmc/host/au1xmmc.c
+++ b/drivers/mmc/host/au1xmmc.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/mmc/au1xmmc.c - AU1XX0 MMC driver 2 * linux/drivers/mmc/host/au1xmmc.c - AU1XX0 MMC driver
3 * 3 *
4 * Copyright (c) 2005, Advanced Micro Devices, Inc. 4 * Copyright (c) 2005, Advanced Micro Devices, Inc.
5 * 5 *
diff --git a/drivers/mmc/host/imxmmc.c b/drivers/mmc/host/imxmmc.c
index 7ee2045acbef..54bfc9f25596 100644
--- a/drivers/mmc/host/imxmmc.c
+++ b/drivers/mmc/host/imxmmc.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/mmc/imxmmc.c - Motorola i.MX MMCI driver 2 * linux/drivers/mmc/host/imxmmc.c - Motorola i.MX MMCI driver
3 * 3 *
4 * Copyright (C) 2004 Sascha Hauer, Pengutronix <sascha@saschahauer.de> 4 * Copyright (C) 2004 Sascha Hauer, Pengutronix <sascha@saschahauer.de>
5 * Copyright (C) 2006 Pavel Pisa, PiKRON <ppisa@pikron.com> 5 * Copyright (C) 2006 Pavel Pisa, PiKRON <ppisa@pikron.com>
diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
index d11c2d23ceea..be730c0a0352 100644
--- a/drivers/mmc/host/mmci.c
+++ b/drivers/mmc/host/mmci.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/mmc/mmci.c - ARM PrimeCell MMCI PL180/1 driver 2 * linux/drivers/mmc/host/mmci.c - ARM PrimeCell MMCI PL180/1 driver
3 * 3 *
4 * Copyright (C) 2003 Deep Blue Solutions, Ltd, All Rights Reserved. 4 * Copyright (C) 2003 Deep Blue Solutions, Ltd, All Rights Reserved.
5 * 5 *
diff --git a/drivers/mmc/host/mmci.h b/drivers/mmc/host/mmci.h
index 6d7eadc9a678..000e6a919782 100644
--- a/drivers/mmc/host/mmci.h
+++ b/drivers/mmc/host/mmci.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/mmc/mmci.h - ARM PrimeCell MMCI PL180/1 driver 2 * linux/drivers/mmc/host/mmci.h - ARM PrimeCell MMCI PL180/1 driver
3 * 3 *
4 * Copyright (C) 2003 Deep Blue Solutions, Ltd, All Rights Reserved. 4 * Copyright (C) 2003 Deep Blue Solutions, Ltd, All Rights Reserved.
5 * 5 *
diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
index b0824a38f425..0cf97edc5f58 100644
--- a/drivers/mmc/host/omap.c
+++ b/drivers/mmc/host/omap.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/media/mmc/omap.c 2 * linux/drivers/mmc/host/omap.c
3 * 3 *
4 * Copyright (C) 2004 Nokia Corporation 4 * Copyright (C) 2004 Nokia Corporation
5 * Written by Tuukka Tikkanen and Juha Yrjölä<juha.yrjola@nokia.com> 5 * Written by Tuukka Tikkanen and Juha Yrjölä<juha.yrjola@nokia.com>
diff --git a/drivers/mmc/host/pxamci.c b/drivers/mmc/host/pxamci.c
index f8985c508bb9..ff960334b337 100644
--- a/drivers/mmc/host/pxamci.c
+++ b/drivers/mmc/host/pxamci.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/mmc/pxa.c - PXA MMCI driver 2 * linux/drivers/mmc/host/pxa.c - PXA MMCI driver
3 * 3 *
4 * Copyright (C) 2003 Russell King, All Rights Reserved. 4 * Copyright (C) 2003 Russell King, All Rights Reserved.
5 * 5 *
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 4a24db028d87..f2bc87ac24f7 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/mmc/sdhci.c - Secure Digital Host Controller Interface driver 2 * linux/drivers/mmc/host/sdhci.c - Secure Digital Host Controller Interface driver
3 * 3 *
4 * Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved. 4 * Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved.
5 * 5 *
@@ -34,6 +34,7 @@ static unsigned int debug_quirks = 0;
34/* Controller doesn't like some resets when there is no card inserted. */ 34/* Controller doesn't like some resets when there is no card inserted. */
35#define SDHCI_QUIRK_NO_CARD_NO_RESET (1<<2) 35#define SDHCI_QUIRK_NO_CARD_NO_RESET (1<<2)
36#define SDHCI_QUIRK_SINGLE_POWER_WRITE (1<<3) 36#define SDHCI_QUIRK_SINGLE_POWER_WRITE (1<<3)
37#define SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS (1<<4)
37 38
38static const struct pci_device_id pci_ids[] __devinitdata = { 39static const struct pci_device_id pci_ids[] __devinitdata = {
39 { 40 {
@@ -78,6 +79,24 @@ static const struct pci_device_id pci_ids[] __devinitdata = {
78 .driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE, 79 .driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE,
79 }, 80 },
80 81
82 {
83 .vendor = PCI_VENDOR_ID_ENE,
84 .device = PCI_DEVICE_ID_ENE_CB714_SD,
85 .subvendor = PCI_ANY_ID,
86 .subdevice = PCI_ANY_ID,
87 .driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE |
88 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS,
89 },
90
91 {
92 .vendor = PCI_VENDOR_ID_ENE,
93 .device = PCI_DEVICE_ID_ENE_CB714_SD_2,
94 .subvendor = PCI_ANY_ID,
95 .subdevice = PCI_ANY_ID,
96 .driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE |
97 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS,
98 },
99
81 { /* Generic SD host controller */ 100 { /* Generic SD host controller */
82 PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00) 101 PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00)
83 }, 102 },
@@ -361,11 +380,6 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)
361 if (data == NULL) 380 if (data == NULL)
362 return; 381 return;
363 382
364 DBG("blksz %04x blks %04x flags %08x\n",
365 data->blksz, data->blocks, data->flags);
366 DBG("tsac %d ms nsac %d clk\n",
367 data->timeout_ns / 1000000, data->timeout_clks);
368
369 /* Sanity checks */ 383 /* Sanity checks */
370 BUG_ON(data->blksz * data->blocks > 524288); 384 BUG_ON(data->blksz * data->blocks > 524288);
371 BUG_ON(data->blksz > host->mmc->max_blk_size); 385 BUG_ON(data->blksz > host->mmc->max_blk_size);
@@ -476,8 +490,6 @@ static void sdhci_finish_data(struct sdhci_host *host)
476 data->error = MMC_ERR_FAILED; 490 data->error = MMC_ERR_FAILED;
477 } 491 }
478 492
479 DBG("Ending data transfer (%d bytes)\n", data->bytes_xfered);
480
481 if (data->stop) { 493 if (data->stop) {
482 /* 494 /*
483 * The controller needs a reset of internal state machines 495 * The controller needs a reset of internal state machines
@@ -501,8 +513,6 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
501 513
502 WARN_ON(host->cmd); 514 WARN_ON(host->cmd);
503 515
504 DBG("Sending cmd (%x)\n", cmd->opcode);
505
506 /* Wait max 10 ms */ 516 /* Wait max 10 ms */
507 timeout = 10; 517 timeout = 10;
508 518
@@ -590,8 +600,6 @@ static void sdhci_finish_command(struct sdhci_host *host)
590 600
591 host->cmd->error = MMC_ERR_NONE; 601 host->cmd->error = MMC_ERR_NONE;
592 602
593 DBG("Ending cmd (%x)\n", host->cmd->opcode);
594
595 if (host->cmd->data) 603 if (host->cmd->data)
596 host->data = host->cmd->data; 604 host->data = host->cmd->data;
597 else 605 else
@@ -759,6 +767,14 @@ static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
759 767
760 writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL); 768 writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
761 769
770 /*
771 * Some (ENE) controllers go apeshit on some ios operation,
772 * signalling timeout and CRC errors even on CMD0. Resetting
773 * it on each ios seems to solve the problem.
774 */
775 if(host->chip->quirks & SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS)
776 sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
777
762 mmiowb(); 778 mmiowb();
763 spin_unlock_irqrestore(&host->lock, flags); 779 spin_unlock_irqrestore(&host->lock, flags);
764} 780}
@@ -835,8 +851,6 @@ static void sdhci_tasklet_finish(unsigned long param)
835 851
836 mrq = host->mrq; 852 mrq = host->mrq;
837 853
838 DBG("Ending request, cmd (%x)\n", mrq->cmd->opcode);
839
840 /* 854 /*
841 * The controller needs a reset of internal state machines 855 * The controller needs a reset of internal state machines
842 * upon error conditions. 856 * upon error conditions.
@@ -922,20 +936,17 @@ static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask)
922 return; 936 return;
923 } 937 }
924 938
925 if (intmask & SDHCI_INT_RESPONSE) 939 if (intmask & SDHCI_INT_TIMEOUT)
926 sdhci_finish_command(host); 940 host->cmd->error = MMC_ERR_TIMEOUT;
927 else { 941 else if (intmask & SDHCI_INT_CRC)
928 if (intmask & SDHCI_INT_TIMEOUT) 942 host->cmd->error = MMC_ERR_BADCRC;
929 host->cmd->error = MMC_ERR_TIMEOUT; 943 else if (intmask & (SDHCI_INT_END_BIT | SDHCI_INT_INDEX))
930 else if (intmask & SDHCI_INT_CRC) 944 host->cmd->error = MMC_ERR_FAILED;
931 host->cmd->error = MMC_ERR_BADCRC;
932 else if (intmask & (SDHCI_INT_END_BIT | SDHCI_INT_INDEX))
933 host->cmd->error = MMC_ERR_FAILED;
934 else
935 host->cmd->error = MMC_ERR_INVALID;
936 945
946 if (host->cmd->error != MMC_ERR_NONE)
937 tasklet_schedule(&host->finish_tasklet); 947 tasklet_schedule(&host->finish_tasklet);
938 } 948 else if (intmask & SDHCI_INT_RESPONSE)
949 sdhci_finish_command(host);
939} 950}
940 951
941static void sdhci_data_irq(struct sdhci_host *host, u32 intmask) 952static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index a6c870480b8a..d157776c1149 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/mmc/sdhci.h - Secure Digital Host Controller Interface driver 2 * linux/drivers/mmc/host/sdhci.h - Secure Digital Host Controller Interface driver
3 * 3 *
4 * Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved. 4 * Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved.
5 * 5 *
diff --git a/drivers/mmc/host/wbsd.c b/drivers/mmc/host/wbsd.c
index 867ca6a69298..e0c9808fd424 100644
--- a/drivers/mmc/host/wbsd.c
+++ b/drivers/mmc/host/wbsd.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/mmc/wbsd.c - Winbond W83L51xD SD/MMC driver 2 * linux/drivers/mmc/host/wbsd.c - Winbond W83L51xD SD/MMC driver
3 * 3 *
4 * Copyright (C) 2004-2007 Pierre Ossman, All Rights Reserved. 4 * Copyright (C) 2004-2007 Pierre Ossman, All Rights Reserved.
5 * 5 *
@@ -207,8 +207,6 @@ static void wbsd_request_end(struct wbsd_host *host, struct mmc_request *mrq)
207{ 207{
208 unsigned long dmaflags; 208 unsigned long dmaflags;
209 209
210 DBGF("Ending request, cmd (%x)\n", mrq->cmd->opcode);
211
212 if (host->dma >= 0) { 210 if (host->dma >= 0) {
213 /* 211 /*
214 * Release ISA DMA controller. 212 * Release ISA DMA controller.
@@ -360,8 +358,6 @@ static void wbsd_send_command(struct wbsd_host *host, struct mmc_command *cmd)
360 int i; 358 int i;
361 u8 status, isr; 359 u8 status, isr;
362 360
363 DBGF("Sending cmd (%x)\n", cmd->opcode);
364
365 /* 361 /*
366 * Clear accumulated ISR. The interrupt routine 362 * Clear accumulated ISR. The interrupt routine
367 * will fill this one with events that occur during 363 * will fill this one with events that occur during
@@ -411,8 +407,6 @@ static void wbsd_send_command(struct wbsd_host *host, struct mmc_command *cmd)
411 wbsd_get_short_reply(host, cmd); 407 wbsd_get_short_reply(host, cmd);
412 } 408 }
413 } 409 }
414
415 DBGF("Sent cmd (%x), res %d\n", cmd->opcode, cmd->error);
416} 410}
417 411
418/* 412/*
@@ -550,11 +544,6 @@ static void wbsd_prepare_data(struct wbsd_host *host, struct mmc_data *data)
550 unsigned long dmaflags; 544 unsigned long dmaflags;
551 unsigned int size; 545 unsigned int size;
552 546
553 DBGF("blksz %04x blks %04x flags %08x\n",
554 data->blksz, data->blocks, data->flags);
555 DBGF("tsac %d ms nsac %d clk\n",
556 data->timeout_ns / 1000000, data->timeout_clks);
557
558 /* 547 /*
559 * Calculate size. 548 * Calculate size.
560 */ 549 */
@@ -752,8 +741,6 @@ static void wbsd_finish_data(struct wbsd_host *host, struct mmc_data *data)
752 } 741 }
753 } 742 }
754 743
755 DBGF("Ending data transfer (%d bytes)\n", data->bytes_xfered);
756
757 wbsd_request_end(host, host->mrq); 744 wbsd_request_end(host, host->mrq);
758} 745}
759 746
diff --git a/drivers/mmc/host/wbsd.h b/drivers/mmc/host/wbsd.h
index 873bda1e59b4..0877866f8d28 100644
--- a/drivers/mmc/host/wbsd.h
+++ b/drivers/mmc/host/wbsd.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/mmc/wbsd.h - Winbond W83L51xD SD/MMC driver 2 * linux/drivers/mmc/host/wbsd.h - Winbond W83L51xD SD/MMC driver
3 * 3 *
4 * Copyright (C) 2004-2007 Pierre Ossman, All Rights Reserved. 4 * Copyright (C) 2004-2007 Pierre Ossman, All Rights Reserved.
5 * 5 *
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig
index f88ebc5b685e..cc6c73442435 100644
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -103,7 +103,7 @@ config MTD_PMC_MSP_RAMROOT
103 103
104config MTD_SUN_UFLASH 104config MTD_SUN_UFLASH
105 tristate "Sun Microsystems userflash support" 105 tristate "Sun Microsystems userflash support"
106 depends on SPARC && MTD_CFI 106 depends on SPARC && MTD_CFI && PCI
107 help 107 help
108 This provides a 'mapping' driver which supports the way in 108 This provides a 'mapping' driver which supports the way in
109 which user-programmable flash chips are connected on various 109 which user-programmable flash chips are connected on various
diff --git a/drivers/net/82596.c b/drivers/net/82596.c
index 3ff1155459a3..d915837193cc 100644
--- a/drivers/net/82596.c
+++ b/drivers/net/82596.c
@@ -57,6 +57,7 @@
57#include <asm/io.h> 57#include <asm/io.h>
58#include <asm/dma.h> 58#include <asm/dma.h>
59#include <asm/pgtable.h> 59#include <asm/pgtable.h>
60#include <asm/cacheflush.h>
60 61
61static char version[] __initdata = 62static char version[] __initdata =
62 "82596.c $Revision: 1.5 $\n"; 63 "82596.c $Revision: 1.5 $\n";
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index 336af0635df8..94b78cc5fe86 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -18,7 +18,7 @@ gianfar_driver-objs := gianfar.o \
18 gianfar_sysfs.o 18 gianfar_sysfs.o
19 19
20obj-$(CONFIG_UCC_GETH) += ucc_geth_driver.o 20obj-$(CONFIG_UCC_GETH) += ucc_geth_driver.o
21ucc_geth_driver-objs := ucc_geth.o ucc_geth_mii.o 21ucc_geth_driver-objs := ucc_geth.o ucc_geth_mii.o ucc_geth_ethtool.o
22 22
23# 23#
24# link order important here 24# link order important here
diff --git a/drivers/net/acenic.c b/drivers/net/acenic.c
index b78a4e5ceeb2..62e660a79387 100644
--- a/drivers/net/acenic.c
+++ b/drivers/net/acenic.c
@@ -3128,12 +3128,6 @@ static int __devinit read_eeprom_byte(struct net_device *dev,
3128 int result = 0; 3128 int result = 0;
3129 short i; 3129 short i;
3130 3130
3131 if (!dev) {
3132 printk(KERN_ERR "No device!\n");
3133 result = -ENODEV;
3134 goto out;
3135 }
3136
3137 /* 3131 /*
3138 * Don't take interrupts on this CPU will bit banging 3132 * Don't take interrupts on this CPU will bit banging
3139 * the %#%#@$ I2C device 3133 * the %#%#@$ I2C device
diff --git a/drivers/net/atl1/atl1_hw.h b/drivers/net/atl1/atl1_hw.h
index 100c09c66e64..939aa0f53f6e 100644
--- a/drivers/net/atl1/atl1_hw.h
+++ b/drivers/net/atl1/atl1_hw.h
@@ -680,11 +680,6 @@ void atl1_check_options(struct atl1_adapter *adapter);
680#define AUTONEG_ADVERTISE_10_100_ALL 0x000F /* All 10/100 speeds */ 680#define AUTONEG_ADVERTISE_10_100_ALL 0x000F /* All 10/100 speeds */
681#define AUTONEG_ADVERTISE_10_ALL 0x0003 /* 10Mbps Full & Half speeds */ 681#define AUTONEG_ADVERTISE_10_ALL 0x0003 /* 10Mbps Full & Half speeds */
682 682
683/* The size (in bytes) of a ethernet packet */
684#define ENET_HEADER_SIZE 14
685#define MAXIMUM_ETHERNET_FRAME_SIZE 1518 /* with FCS */
686#define MINIMUM_ETHERNET_FRAME_SIZE 64 /* with FCS */
687#define ETHERNET_FCS_SIZE 4
688#define MAX_JUMBO_FRAME_SIZE 0x2800 683#define MAX_JUMBO_FRAME_SIZE 0x2800
689 684
690#define PHY_AUTO_NEG_TIME 45 /* 4.5 Seconds */ 685#define PHY_AUTO_NEG_TIME 45 /* 4.5 Seconds */
@@ -929,8 +924,8 @@ enum atl1_dma_req_block {
929 atl1_dma_req_128 = 0, 924 atl1_dma_req_128 = 0,
930 atl1_dma_req_256 = 1, 925 atl1_dma_req_256 = 1,
931 atl1_dma_req_512 = 2, 926 atl1_dma_req_512 = 2,
932 atl1_dam_req_1024 = 3, 927 atl1_dma_req_1024 = 3,
933 atl1_dam_req_2048 = 4, 928 atl1_dma_req_2048 = 4,
934 atl1_dma_req_4096 = 5 929 atl1_dma_req_4096 = 5
935}; 930};
936 931
diff --git a/drivers/net/atl1/atl1_main.c b/drivers/net/atl1/atl1_main.c
index fd1e156f1747..56f6389a300e 100644
--- a/drivers/net/atl1/atl1_main.c
+++ b/drivers/net/atl1/atl1_main.c
@@ -59,6 +59,7 @@
59#include <linux/skbuff.h> 59#include <linux/skbuff.h>
60#include <linux/etherdevice.h> 60#include <linux/etherdevice.h>
61#include <linux/if_vlan.h> 61#include <linux/if_vlan.h>
62#include <linux/if_ether.h>
62#include <linux/irqreturn.h> 63#include <linux/irqreturn.h>
63#include <linux/workqueue.h> 64#include <linux/workqueue.h>
64#include <linux/timer.h> 65#include <linux/timer.h>
@@ -120,8 +121,8 @@ static int __devinit atl1_sw_init(struct atl1_adapter *adapter)
120 struct atl1_hw *hw = &adapter->hw; 121 struct atl1_hw *hw = &adapter->hw;
121 struct net_device *netdev = adapter->netdev; 122 struct net_device *netdev = adapter->netdev;
122 123
123 hw->max_frame_size = netdev->mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; 124 hw->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
124 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE; 125 hw->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
125 126
126 adapter->wol = 0; 127 adapter->wol = 0;
127 adapter->rx_buffer_len = (hw->max_frame_size + 7) & ~7; 128 adapter->rx_buffer_len = (hw->max_frame_size + 7) & ~7;
@@ -314,7 +315,7 @@ err_nomem:
314 return -ENOMEM; 315 return -ENOMEM;
315} 316}
316 317
317void atl1_init_ring_ptrs(struct atl1_adapter *adapter) 318static void atl1_init_ring_ptrs(struct atl1_adapter *adapter)
318{ 319{
319 struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring; 320 struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring;
320 struct atl1_rfd_ring *rfd_ring = &adapter->rfd_ring; 321 struct atl1_rfd_ring *rfd_ring = &adapter->rfd_ring;
@@ -688,9 +689,9 @@ static int atl1_change_mtu(struct net_device *netdev, int new_mtu)
688{ 689{
689 struct atl1_adapter *adapter = netdev_priv(netdev); 690 struct atl1_adapter *adapter = netdev_priv(netdev);
690 int old_mtu = netdev->mtu; 691 int old_mtu = netdev->mtu;
691 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; 692 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
692 693
693 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) || 694 if ((max_frame < ETH_ZLEN + ETH_FCS_LEN) ||
694 (max_frame > MAX_JUMBO_FRAME_SIZE)) { 695 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
695 dev_warn(&adapter->pdev->dev, "invalid MTU setting\n"); 696 dev_warn(&adapter->pdev->dev, "invalid MTU setting\n");
696 return -EINVAL; 697 return -EINVAL;
@@ -908,8 +909,8 @@ static u32 atl1_configure(struct atl1_adapter *adapter)
908 /* config DMA Engine */ 909 /* config DMA Engine */
909 value = ((((u32) hw->dmar_block) & DMA_CTRL_DMAR_BURST_LEN_MASK) 910 value = ((((u32) hw->dmar_block) & DMA_CTRL_DMAR_BURST_LEN_MASK)
910 << DMA_CTRL_DMAR_BURST_LEN_SHIFT) | 911 << DMA_CTRL_DMAR_BURST_LEN_SHIFT) |
911 ((((u32) hw->dmaw_block) & DMA_CTRL_DMAR_BURST_LEN_MASK) 912 ((((u32) hw->dmaw_block) & DMA_CTRL_DMAW_BURST_LEN_MASK)
912 << DMA_CTRL_DMAR_BURST_LEN_SHIFT) | DMA_CTRL_DMAR_EN | 913 << DMA_CTRL_DMAW_BURST_LEN_SHIFT) | DMA_CTRL_DMAR_EN |
913 DMA_CTRL_DMAW_EN; 914 DMA_CTRL_DMAW_EN;
914 value |= (u32) hw->dma_ord; 915 value |= (u32) hw->dma_ord;
915 if (atl1_rcb_128 == hw->rcb_value) 916 if (atl1_rcb_128 == hw->rcb_value)
@@ -917,7 +918,10 @@ static u32 atl1_configure(struct atl1_adapter *adapter)
917 iowrite32(value, hw->hw_addr + REG_DMA_CTRL); 918 iowrite32(value, hw->hw_addr + REG_DMA_CTRL);
918 919
919 /* config CMB / SMB */ 920 /* config CMB / SMB */
920 value = hw->cmb_rrd | ((u32) hw->cmb_tpd << 16); 921 value = (hw->cmb_tpd > adapter->tpd_ring.count) ?
922 hw->cmb_tpd : adapter->tpd_ring.count;
923 value <<= 16;
924 value |= hw->cmb_rrd;
921 iowrite32(value, hw->hw_addr + REG_CMB_WRITE_TH); 925 iowrite32(value, hw->hw_addr + REG_CMB_WRITE_TH);
922 value = hw->cmb_rx_timer | ((u32) hw->cmb_tx_timer << 16); 926 value = hw->cmb_rx_timer | ((u32) hw->cmb_tx_timer << 16);
923 iowrite32(value, hw->hw_addr + REG_CMB_WRITE_TIMER); 927 iowrite32(value, hw->hw_addr + REG_CMB_WRITE_TIMER);
@@ -1334,7 +1338,7 @@ rrd_ok:
1334 skb = buffer_info->skb; 1338 skb = buffer_info->skb;
1335 length = le16_to_cpu(rrd->xsz.xsum_sz.pkt_size); 1339 length = le16_to_cpu(rrd->xsz.xsum_sz.pkt_size);
1336 1340
1337 skb_put(skb, length - ETHERNET_FCS_SIZE); 1341 skb_put(skb, length - ETH_FCS_LEN);
1338 1342
1339 /* Receive Checksum Offload */ 1343 /* Receive Checksum Offload */
1340 atl1_rx_checksum(adapter, rrd, skb); 1344 atl1_rx_checksum(adapter, rrd, skb);
@@ -1422,7 +1426,7 @@ static void atl1_intr_tx(struct atl1_adapter *adapter)
1422 netif_wake_queue(adapter->netdev); 1426 netif_wake_queue(adapter->netdev);
1423} 1427}
1424 1428
1425static u16 tpd_avail(struct atl1_tpd_ring *tpd_ring) 1429static u16 atl1_tpd_avail(struct atl1_tpd_ring *tpd_ring)
1426{ 1430{
1427 u16 next_to_clean = atomic_read(&tpd_ring->next_to_clean); 1431 u16 next_to_clean = atomic_read(&tpd_ring->next_to_clean);
1428 u16 next_to_use = atomic_read(&tpd_ring->next_to_use); 1432 u16 next_to_use = atomic_read(&tpd_ring->next_to_use);
@@ -1453,7 +1457,7 @@ static int atl1_tso(struct atl1_adapter *adapter, struct sk_buff *skb,
1453 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, 1457 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
1454 iph->daddr, 0, IPPROTO_TCP, 0); 1458 iph->daddr, 0, IPPROTO_TCP, 0);
1455 ipofst = skb_network_offset(skb); 1459 ipofst = skb_network_offset(skb);
1456 if (ipofst != ENET_HEADER_SIZE) /* 802.3 frame */ 1460 if (ipofst != ETH_HLEN) /* 802.3 frame */
1457 tso->tsopl |= 1 << TSO_PARAM_ETHTYPE_SHIFT; 1461 tso->tsopl |= 1 << TSO_PARAM_ETHTYPE_SHIFT;
1458 1462
1459 tso->tsopl |= (iph->ihl & 1463 tso->tsopl |= (iph->ihl &
@@ -1708,7 +1712,7 @@ static int atl1_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1708 return NETDEV_TX_LOCKED; 1712 return NETDEV_TX_LOCKED;
1709 } 1713 }
1710 1714
1711 if (tpd_avail(&adapter->tpd_ring) < count) { 1715 if (atl1_tpd_avail(&adapter->tpd_ring) < count) {
1712 /* not enough descriptors */ 1716 /* not enough descriptors */
1713 netif_stop_queue(netdev); 1717 netif_stop_queue(netdev);
1714 spin_unlock_irqrestore(&adapter->lock, flags); 1718 spin_unlock_irqrestore(&adapter->lock, flags);
diff --git a/drivers/net/ax88796.c b/drivers/net/ax88796.c
index 1d882360b34d..e43e8047b90e 100644
--- a/drivers/net/ax88796.c
+++ b/drivers/net/ax88796.c
@@ -819,7 +819,7 @@ static int ax_probe(struct platform_device *pdev)
819 } 819 }
820 820
821 ei_status.mem = ioremap(res->start, size); 821 ei_status.mem = ioremap(res->start, size);
822 dev->base_addr = (long)ei_status.mem; 822 dev->base_addr = (unsigned long)ei_status.mem;
823 823
824 if (ei_status.mem == NULL) { 824 if (ei_status.mem == NULL) {
825 dev_err(&pdev->dev, "Cannot ioremap area (%08zx,%08zx)\n", 825 dev_err(&pdev->dev, "Cannot ioremap area (%08zx,%08zx)\n",
diff --git a/drivers/net/bfin_mac.c b/drivers/net/bfin_mac.c
index 9a08d656f1ce..2bb97d464689 100644
--- a/drivers/net/bfin_mac.c
+++ b/drivers/net/bfin_mac.c
@@ -798,6 +798,7 @@ static void bf537mac_shutdown(struct net_device *dev)
798 */ 798 */
799static int bf537mac_open(struct net_device *dev) 799static int bf537mac_open(struct net_device *dev)
800{ 800{
801 int retval;
801 pr_debug("%s: %s\n", dev->name, __FUNCTION__); 802 pr_debug("%s: %s\n", dev->name, __FUNCTION__);
802 803
803 /* 804 /*
@@ -811,7 +812,10 @@ static int bf537mac_open(struct net_device *dev)
811 } 812 }
812 813
813 /* initial rx and tx list */ 814 /* initial rx and tx list */
814 desc_list_init(); 815 retval = desc_list_init();
816
817 if (retval)
818 return retval;
815 819
816 bf537mac_setphy(dev); 820 bf537mac_setphy(dev);
817 setup_system_regs(dev); 821 setup_system_regs(dev);
diff --git a/drivers/net/cxgb3/cxgb3_offload.c b/drivers/net/cxgb3/cxgb3_offload.c
index ebcf35e4cf5b..e620ed4c3ff0 100644
--- a/drivers/net/cxgb3/cxgb3_offload.c
+++ b/drivers/net/cxgb3/cxgb3_offload.c
@@ -699,7 +699,7 @@ static int do_cr(struct t3cdev *dev, struct sk_buff *skb)
699 * the buffer. 699 * the buffer.
700 */ 700 */
701static struct sk_buff *cxgb3_get_cpl_reply_skb(struct sk_buff *skb, size_t len, 701static struct sk_buff *cxgb3_get_cpl_reply_skb(struct sk_buff *skb, size_t len,
702 int gfp) 702 gfp_t gfp)
703{ 703{
704 if (likely(!skb_cloned(skb))) { 704 if (likely(!skb_cloned(skb))) {
705 BUG_ON(skb->len < len); 705 BUG_ON(skb->len < len);
diff --git a/drivers/net/defxx.c b/drivers/net/defxx.c
index 7df23dc28190..9c8e3f9f5e58 100644
--- a/drivers/net/defxx.c
+++ b/drivers/net/defxx.c
@@ -200,6 +200,7 @@
200 200
201/* Include files */ 201/* Include files */
202#include <linux/bitops.h> 202#include <linux/bitops.h>
203#include <linux/compiler.h>
203#include <linux/delay.h> 204#include <linux/delay.h>
204#include <linux/dma-mapping.h> 205#include <linux/dma-mapping.h>
205#include <linux/eisa.h> 206#include <linux/eisa.h>
@@ -240,8 +241,6 @@ static char version[] __devinitdata =
240 */ 241 */
241#define NEW_SKB_SIZE (PI_RCV_DATA_K_SIZE_MAX+128) 242#define NEW_SKB_SIZE (PI_RCV_DATA_K_SIZE_MAX+128)
242 243
243#define __unused __attribute__ ((unused))
244
245#ifdef CONFIG_PCI 244#ifdef CONFIG_PCI
246#define DFX_BUS_PCI(dev) (dev->bus == &pci_bus_type) 245#define DFX_BUS_PCI(dev) (dev->bus == &pci_bus_type)
247#else 246#else
@@ -375,7 +374,7 @@ static inline void dfx_outl(DFX_board_t *bp, int offset, u32 data)
375 374
376static void dfx_port_write_long(DFX_board_t *bp, int offset, u32 data) 375static void dfx_port_write_long(DFX_board_t *bp, int offset, u32 data)
377{ 376{
378 struct device __unused *bdev = bp->bus_dev; 377 struct device __maybe_unused *bdev = bp->bus_dev;
379 int dfx_bus_tc = DFX_BUS_TC(bdev); 378 int dfx_bus_tc = DFX_BUS_TC(bdev);
380 int dfx_use_mmio = DFX_MMIO || dfx_bus_tc; 379 int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
381 380
@@ -399,7 +398,7 @@ static inline void dfx_inl(DFX_board_t *bp, int offset, u32 *data)
399 398
400static void dfx_port_read_long(DFX_board_t *bp, int offset, u32 *data) 399static void dfx_port_read_long(DFX_board_t *bp, int offset, u32 *data)
401{ 400{
402 struct device __unused *bdev = bp->bus_dev; 401 struct device __maybe_unused *bdev = bp->bus_dev;
403 int dfx_bus_tc = DFX_BUS_TC(bdev); 402 int dfx_bus_tc = DFX_BUS_TC(bdev);
404 int dfx_use_mmio = DFX_MMIO || dfx_bus_tc; 403 int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
405 404
@@ -866,7 +865,7 @@ static void __devinit dfx_bus_uninit(struct net_device *dev)
866 865
867static void __devinit dfx_bus_config_check(DFX_board_t *bp) 866static void __devinit dfx_bus_config_check(DFX_board_t *bp)
868{ 867{
869 struct device __unused *bdev = bp->bus_dev; 868 struct device __maybe_unused *bdev = bp->bus_dev;
870 int dfx_bus_eisa = DFX_BUS_EISA(bdev); 869 int dfx_bus_eisa = DFX_BUS_EISA(bdev);
871 int status; /* return code from adapter port control call */ 870 int status; /* return code from adapter port control call */
872 u32 host_data; /* LW data returned from port control call */ 871 u32 host_data; /* LW data returned from port control call */
@@ -3624,8 +3623,8 @@ static void __devexit dfx_unregister(struct device *bdev)
3624} 3623}
3625 3624
3626 3625
3627static int __devinit __unused dfx_dev_register(struct device *); 3626static int __devinit __maybe_unused dfx_dev_register(struct device *);
3628static int __devexit __unused dfx_dev_unregister(struct device *); 3627static int __devexit __maybe_unused dfx_dev_unregister(struct device *);
3629 3628
3630#ifdef CONFIG_PCI 3629#ifdef CONFIG_PCI
3631static int __devinit dfx_pci_register(struct pci_dev *, 3630static int __devinit dfx_pci_register(struct pci_dev *,
@@ -3699,7 +3698,7 @@ static struct tc_driver dfx_tc_driver = {
3699}; 3698};
3700#endif /* CONFIG_TC */ 3699#endif /* CONFIG_TC */
3701 3700
3702static int __devinit __unused dfx_dev_register(struct device *dev) 3701static int __devinit __maybe_unused dfx_dev_register(struct device *dev)
3703{ 3702{
3704 int status; 3703 int status;
3705 3704
@@ -3709,7 +3708,7 @@ static int __devinit __unused dfx_dev_register(struct device *dev)
3709 return status; 3708 return status;
3710} 3709}
3711 3710
3712static int __devexit __unused dfx_dev_unregister(struct device *dev) 3711static int __devexit __maybe_unused dfx_dev_unregister(struct device *dev)
3713{ 3712{
3714 put_device(dev); 3713 put_device(dev);
3715 dfx_unregister(dev); 3714 dfx_unregister(dev);
diff --git a/drivers/net/ehea/ehea.h b/drivers/net/ehea/ehea.h
index 489c8b260dd8..8ee2c2c86b42 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_0071" 42#define DRV_VERSION "EHEA_0072"
43 43
44/* eHEA capability flags */ 44/* eHEA capability flags */
45#define DLPAR_PORT_ADD_REM 1 45#define DLPAR_PORT_ADD_REM 1
diff --git a/drivers/net/ehea/ehea_main.c b/drivers/net/ehea/ehea_main.c
index 4c70a9301c1b..58702f54c3fb 100644
--- a/drivers/net/ehea/ehea_main.c
+++ b/drivers/net/ehea/ehea_main.c
@@ -589,6 +589,23 @@ static int ehea_poll(struct net_device *dev, int *budget)
589 return 1; 589 return 1;
590} 590}
591 591
592#ifdef CONFIG_NET_POLL_CONTROLLER
593static void ehea_netpoll(struct net_device *dev)
594{
595 struct ehea_port *port = netdev_priv(dev);
596
597 netif_rx_schedule(port->port_res[0].d_netdev);
598}
599#endif
600
601static int ehea_poll_firstqueue(struct net_device *dev, int *budget)
602{
603 struct ehea_port *port = netdev_priv(dev);
604 struct net_device *d_dev = port->port_res[0].d_netdev;
605
606 return ehea_poll(d_dev, budget);
607}
608
592static irqreturn_t ehea_recv_irq_handler(int irq, void *param) 609static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
593{ 610{
594 struct ehea_port_res *pr = param; 611 struct ehea_port_res *pr = param;
@@ -2626,7 +2643,10 @@ struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
2626 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN); 2643 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
2627 2644
2628 dev->open = ehea_open; 2645 dev->open = ehea_open;
2629 dev->poll = ehea_poll; 2646 dev->poll = ehea_poll_firstqueue;
2647#ifdef CONFIG_NET_POLL_CONTROLLER
2648 dev->poll_controller = ehea_netpoll;
2649#endif
2630 dev->weight = 64; 2650 dev->weight = 64;
2631 dev->stop = ehea_stop; 2651 dev->stop = ehea_stop;
2632 dev->hard_start_xmit = ehea_start_xmit; 2652 dev->hard_start_xmit = ehea_start_xmit;
diff --git a/drivers/net/forcedeth.c b/drivers/net/forcedeth.c
index 6d1d50a19783..661c747389e4 100644
--- a/drivers/net/forcedeth.c
+++ b/drivers/net/forcedeth.c
@@ -5546,6 +5546,22 @@ static struct pci_device_id pci_tbl[] = {
5546 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_27), 5546 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_27),
5547 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT, 5547 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
5548 }, 5548 },
5549 { /* MCP73 Ethernet Controller */
5550 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_28),
5551 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
5552 },
5553 { /* MCP73 Ethernet Controller */
5554 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_29),
5555 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
5556 },
5557 { /* MCP73 Ethernet Controller */
5558 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_30),
5559 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
5560 },
5561 { /* MCP73 Ethernet Controller */
5562 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_31),
5563 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
5564 },
5549 {0,}, 5565 {0,},
5550}; 5566};
5551 5567
diff --git a/drivers/net/lguest_net.c b/drivers/net/lguest_net.c
index 112778652f7d..cab57911a80e 100644
--- a/drivers/net/lguest_net.c
+++ b/drivers/net/lguest_net.c
@@ -1,6 +1,13 @@
1/* A simple network driver for lguest. 1/*D:500
2 * The Guest network driver.
2 * 3 *
3 * Copyright 2006 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation 4 * This is very simple a virtual network driver, and our last Guest driver.
5 * The only trick is that it can talk directly to multiple other recipients
6 * (ie. other Guests on the same network). It can also be used with only the
7 * Host on the network.
8 :*/
9
10/* Copyright 2006 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation
4 * 11 *
5 * This program is free software; you can redistribute it and/or modify 12 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 13 * it under the terms of the GNU General Public License as published by
@@ -28,23 +35,47 @@
28#define MAX_LANS 4 35#define MAX_LANS 4
29#define NUM_SKBS 8 36#define NUM_SKBS 8
30 37
38/*M:011 Network code master Jeff Garzik points out numerous shortcomings in
39 * this driver if it aspires to greatness.
40 *
41 * Firstly, it doesn't use "NAPI": the networking's New API, and is poorer for
42 * it. As he says "NAPI means system-wide load leveling, across multiple
43 * network interfaces. Lack of NAPI can mean competition at higher loads."
44 *
45 * He also points out that we don't implement set_mac_address, so users cannot
46 * change the devices hardware address. When I asked why one would want to:
47 * "Bonding, and situations where you /do/ want the MAC address to "leak" out
48 * of the host onto the wider net."
49 *
50 * Finally, he would like module unloading: "It is not unrealistic to think of
51 * [un|re|]loading the net support module in an lguest guest. And, adding
52 * module support makes the programmer more responsible, because they now have
53 * to learn to clean up after themselves. Any driver that cannot clean up
54 * after itself is an incomplete driver in my book."
55 :*/
56
57/*D:530 The "struct lguestnet_info" contains all the information we need to
58 * know about the network device. */
31struct lguestnet_info 59struct lguestnet_info
32{ 60{
33 /* The shared page(s). */ 61 /* The mapped device page(s) (an array of "struct lguest_net"). */
34 struct lguest_net *peer; 62 struct lguest_net *peer;
63 /* The physical address of the device page(s) */
35 unsigned long peer_phys; 64 unsigned long peer_phys;
65 /* The size of the device page(s). */
36 unsigned long mapsize; 66 unsigned long mapsize;
37 67
38 /* The lguest_device I come from */ 68 /* The lguest_device I come from */
39 struct lguest_device *lgdev; 69 struct lguest_device *lgdev;
40 70
41 /* My peerid. */ 71 /* My peerid (ie. my slot in the array). */
42 unsigned int me; 72 unsigned int me;
43 73
44 /* Receive queue. */ 74 /* Receive queue: the network packets waiting to be filled. */
45 struct sk_buff *skb[NUM_SKBS]; 75 struct sk_buff *skb[NUM_SKBS];
46 struct lguest_dma dma[NUM_SKBS]; 76 struct lguest_dma dma[NUM_SKBS];
47}; 77};
78/*:*/
48 79
49/* How many bytes left in this page. */ 80/* How many bytes left in this page. */
50static unsigned int rest_of_page(void *data) 81static unsigned int rest_of_page(void *data)
@@ -52,39 +83,82 @@ static unsigned int rest_of_page(void *data)
52 return PAGE_SIZE - ((unsigned long)data % PAGE_SIZE); 83 return PAGE_SIZE - ((unsigned long)data % PAGE_SIZE);
53} 84}
54 85
55/* Simple convention: offset 4 * peernum. */ 86/*D:570 Each peer (ie. Guest or Host) on the network binds their receive
87 * buffers to a different key: we simply use the physical address of the
88 * device's memory page plus the peer number. The Host insists that all keys
89 * be a multiple of 4, so we multiply the peer number by 4. */
56static unsigned long peer_key(struct lguestnet_info *info, unsigned peernum) 90static unsigned long peer_key(struct lguestnet_info *info, unsigned peernum)
57{ 91{
58 return info->peer_phys + 4 * peernum; 92 return info->peer_phys + 4 * peernum;
59} 93}
60 94
95/* This is the routine which sets up a "struct lguest_dma" to point to a
96 * network packet, similar to req_to_dma() in lguest_blk.c. The structure of a
97 * "struct sk_buff" has grown complex over the years: it consists of a "head"
98 * linear section pointed to by "skb->data", and possibly an array of
99 * "fragments" in the case of a non-linear packet.
100 *
101 * Our receive buffers don't use fragments at all but outgoing skbs might, so
102 * we handle it. */
61static void skb_to_dma(const struct sk_buff *skb, unsigned int headlen, 103static void skb_to_dma(const struct sk_buff *skb, unsigned int headlen,
62 struct lguest_dma *dma) 104 struct lguest_dma *dma)
63{ 105{
64 unsigned int i, seg; 106 unsigned int i, seg;
65 107
108 /* First, we put the linear region into the "struct lguest_dma". Each
109 * entry can't go over a page boundary, so even though all our packets
110 * are 1514 bytes or less, we might need to use two entries here: */
66 for (i = seg = 0; i < headlen; seg++, i += rest_of_page(skb->data+i)) { 111 for (i = seg = 0; i < headlen; seg++, i += rest_of_page(skb->data+i)) {
67 dma->addr[seg] = virt_to_phys(skb->data + i); 112 dma->addr[seg] = virt_to_phys(skb->data + i);
68 dma->len[seg] = min((unsigned)(headlen - i), 113 dma->len[seg] = min((unsigned)(headlen - i),
69 rest_of_page(skb->data + i)); 114 rest_of_page(skb->data + i));
70 } 115 }
116
117 /* Now we handle the fragments: at least they're guaranteed not to go
118 * over a page. skb_shinfo(skb) returns a pointer to the structure
119 * which tells us about the number of fragments and the fragment
120 * array. */
71 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++, seg++) { 121 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++, seg++) {
72 const skb_frag_t *f = &skb_shinfo(skb)->frags[i]; 122 const skb_frag_t *f = &skb_shinfo(skb)->frags[i];
73 /* Should not happen with MTU less than 64k - 2 * PAGE_SIZE. */ 123 /* Should not happen with MTU less than 64k - 2 * PAGE_SIZE. */
74 if (seg == LGUEST_MAX_DMA_SECTIONS) { 124 if (seg == LGUEST_MAX_DMA_SECTIONS) {
125 /* We will end up sending a truncated packet should
126 * this ever happen. Plus, a cool log message! */
75 printk("Woah dude! Megapacket!\n"); 127 printk("Woah dude! Megapacket!\n");
76 break; 128 break;
77 } 129 }
78 dma->addr[seg] = page_to_phys(f->page) + f->page_offset; 130 dma->addr[seg] = page_to_phys(f->page) + f->page_offset;
79 dma->len[seg] = f->size; 131 dma->len[seg] = f->size;
80 } 132 }
133
134 /* If after all that we didn't use the entire "struct lguest_dma"
135 * array, we terminate it with a 0 length. */
81 if (seg < LGUEST_MAX_DMA_SECTIONS) 136 if (seg < LGUEST_MAX_DMA_SECTIONS)
82 dma->len[seg] = 0; 137 dma->len[seg] = 0;
83} 138}
84 139
85/* We overload multicast bit to show promiscuous mode. */ 140/*
141 * Packet transmission.
142 *
143 * Our packet transmission is a little unusual. A real network card would just
144 * send out the packet and leave the receivers to decide if they're interested.
145 * Instead, we look through the network device memory page and see if any of
146 * the ethernet addresses match the packet destination, and if so we send it to
147 * that Guest.
148 *
149 * This is made a little more complicated in two cases. The first case is
150 * broadcast packets: for that we send the packet to all Guests on the network,
151 * one at a time. The second case is "promiscuous" mode, where a Guest wants
152 * to see all the packets on the network. We need a way for the Guest to tell
153 * us it wants to see all packets, so it sets the "multicast" bit on its
154 * published MAC address, which is never valid in a real ethernet address.
155 */
86#define PROMISC_BIT 0x01 156#define PROMISC_BIT 0x01
87 157
158/* This is the callback which is summoned whenever the network device's
159 * multicast or promiscuous state changes. If the card is in promiscuous mode,
160 * we advertise that in our ethernet address in the device's memory. We do the
161 * same if Linux wants any or all multicast traffic. */
88static void lguestnet_set_multicast(struct net_device *dev) 162static void lguestnet_set_multicast(struct net_device *dev)
89{ 163{
90 struct lguestnet_info *info = netdev_priv(dev); 164 struct lguestnet_info *info = netdev_priv(dev);
@@ -95,11 +169,14 @@ static void lguestnet_set_multicast(struct net_device *dev)
95 info->peer[info->me].mac[0] &= ~PROMISC_BIT; 169 info->peer[info->me].mac[0] &= ~PROMISC_BIT;
96} 170}
97 171
172/* A simple test function to see if a peer wants to see all packets.*/
98static int promisc(struct lguestnet_info *info, unsigned int peer) 173static int promisc(struct lguestnet_info *info, unsigned int peer)
99{ 174{
100 return info->peer[peer].mac[0] & PROMISC_BIT; 175 return info->peer[peer].mac[0] & PROMISC_BIT;
101} 176}
102 177
178/* Another simple function to see if a peer's advertised ethernet address
179 * matches a packet's destination ethernet address. */
103static int mac_eq(const unsigned char mac[ETH_ALEN], 180static int mac_eq(const unsigned char mac[ETH_ALEN],
104 struct lguestnet_info *info, unsigned int peer) 181 struct lguestnet_info *info, unsigned int peer)
105{ 182{
@@ -109,6 +186,8 @@ static int mac_eq(const unsigned char mac[ETH_ALEN],
109 return memcmp(mac+1, info->peer[peer].mac+1, ETH_ALEN-1) == 0; 186 return memcmp(mac+1, info->peer[peer].mac+1, ETH_ALEN-1) == 0;
110} 187}
111 188
189/* This is the function which actually sends a packet once we've decided a
190 * peer wants it: */
112static void transfer_packet(struct net_device *dev, 191static void transfer_packet(struct net_device *dev,
113 struct sk_buff *skb, 192 struct sk_buff *skb,
114 unsigned int peernum) 193 unsigned int peernum)
@@ -116,76 +195,134 @@ static void transfer_packet(struct net_device *dev,
116 struct lguestnet_info *info = netdev_priv(dev); 195 struct lguestnet_info *info = netdev_priv(dev);
117 struct lguest_dma dma; 196 struct lguest_dma dma;
118 197
198 /* We use our handy "struct lguest_dma" packing function to prepare
199 * the skb for sending. */
119 skb_to_dma(skb, skb_headlen(skb), &dma); 200 skb_to_dma(skb, skb_headlen(skb), &dma);
120 pr_debug("xfer length %04x (%u)\n", htons(skb->len), skb->len); 201 pr_debug("xfer length %04x (%u)\n", htons(skb->len), skb->len);
121 202
203 /* This is the actual send call which copies the packet. */
122 lguest_send_dma(peer_key(info, peernum), &dma); 204 lguest_send_dma(peer_key(info, peernum), &dma);
205
206 /* Check that the entire packet was transmitted. If not, it could mean
207 * that the other Guest registered a short receive buffer, but this
208 * driver should never do that. More likely, the peer is dead. */
123 if (dma.used_len != skb->len) { 209 if (dma.used_len != skb->len) {
124 dev->stats.tx_carrier_errors++; 210 dev->stats.tx_carrier_errors++;
125 pr_debug("Bad xfer to peer %i: %i of %i (dma %p/%i)\n", 211 pr_debug("Bad xfer to peer %i: %i of %i (dma %p/%i)\n",
126 peernum, dma.used_len, skb->len, 212 peernum, dma.used_len, skb->len,
127 (void *)dma.addr[0], dma.len[0]); 213 (void *)dma.addr[0], dma.len[0]);
128 } else { 214 } else {
215 /* On success we update the stats. */
129 dev->stats.tx_bytes += skb->len; 216 dev->stats.tx_bytes += skb->len;
130 dev->stats.tx_packets++; 217 dev->stats.tx_packets++;
131 } 218 }
132} 219}
133 220
221/* Another helper function to tell is if a slot in the device memory is unused.
222 * Since we always set the Local Assignment bit in the ethernet address, the
223 * first byte can never be 0. */
134static int unused_peer(const struct lguest_net peer[], unsigned int num) 224static int unused_peer(const struct lguest_net peer[], unsigned int num)
135{ 225{
136 return peer[num].mac[0] == 0; 226 return peer[num].mac[0] == 0;
137} 227}
138 228
229/* Finally, here is the routine which handles an outgoing packet. It's called
230 * "start_xmit" for traditional reasons. */
139static int lguestnet_start_xmit(struct sk_buff *skb, struct net_device *dev) 231static int lguestnet_start_xmit(struct sk_buff *skb, struct net_device *dev)
140{ 232{
141 unsigned int i; 233 unsigned int i;
142 int broadcast; 234 int broadcast;
143 struct lguestnet_info *info = netdev_priv(dev); 235 struct lguestnet_info *info = netdev_priv(dev);
236 /* Extract the destination ethernet address from the packet. */
144 const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest; 237 const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest;
145 238
146 pr_debug("%s: xmit %02x:%02x:%02x:%02x:%02x:%02x\n", 239 pr_debug("%s: xmit %02x:%02x:%02x:%02x:%02x:%02x\n",
147 dev->name, dest[0],dest[1],dest[2],dest[3],dest[4],dest[5]); 240 dev->name, dest[0],dest[1],dest[2],dest[3],dest[4],dest[5]);
148 241
242 /* If it's a multicast packet, we broadcast to everyone. That's not
243 * very efficient, but there are very few applications which actually
244 * use multicast, which is a shame really.
245 *
246 * As etherdevice.h points out: "By definition the broadcast address is
247 * also a multicast address." So we don't have to test for broadcast
248 * packets separately. */
149 broadcast = is_multicast_ether_addr(dest); 249 broadcast = is_multicast_ether_addr(dest);
250
251 /* Look through all the published ethernet addresses to see if we
252 * should send this packet. */
150 for (i = 0; i < info->mapsize/sizeof(struct lguest_net); i++) { 253 for (i = 0; i < info->mapsize/sizeof(struct lguest_net); i++) {
254 /* We don't send to ourselves (we actually can't SEND_DMA to
255 * ourselves anyway), and don't send to unused slots.*/
151 if (i == info->me || unused_peer(info->peer, i)) 256 if (i == info->me || unused_peer(info->peer, i))
152 continue; 257 continue;
153 258
259 /* If it's broadcast we send it. If they want every packet we
260 * send it. If the destination matches their address we send
261 * it. Otherwise we go to the next peer. */
154 if (!broadcast && !promisc(info, i) && !mac_eq(dest, info, i)) 262 if (!broadcast && !promisc(info, i) && !mac_eq(dest, info, i))
155 continue; 263 continue;
156 264
157 pr_debug("lguestnet %s: sending from %i to %i\n", 265 pr_debug("lguestnet %s: sending from %i to %i\n",
158 dev->name, info->me, i); 266 dev->name, info->me, i);
267 /* Our routine which actually does the transfer. */
159 transfer_packet(dev, skb, i); 268 transfer_packet(dev, skb, i);
160 } 269 }
270
271 /* An xmit routine is expected to dispose of the packet, so we do. */
161 dev_kfree_skb(skb); 272 dev_kfree_skb(skb);
273
274 /* As per kernel convention, 0 means success. This is why I love
275 * networking: even if we never sent to anyone, that's still
276 * success! */
162 return 0; 277 return 0;
163} 278}
164 279
165/* Find a new skb to put in this slot in shared mem. */ 280/*D:560
281 * Packet receiving.
282 *
283 * First, here's a helper routine which fills one of our array of receive
284 * buffers: */
166static int fill_slot(struct net_device *dev, unsigned int slot) 285static int fill_slot(struct net_device *dev, unsigned int slot)
167{ 286{
168 struct lguestnet_info *info = netdev_priv(dev); 287 struct lguestnet_info *info = netdev_priv(dev);
169 /* Try to create and register a new one. */ 288
289 /* We can receive ETH_DATA_LEN (1500) byte packets, plus a standard
290 * ethernet header of ETH_HLEN (14) bytes. */
170 info->skb[slot] = netdev_alloc_skb(dev, ETH_HLEN + ETH_DATA_LEN); 291 info->skb[slot] = netdev_alloc_skb(dev, ETH_HLEN + ETH_DATA_LEN);
171 if (!info->skb[slot]) { 292 if (!info->skb[slot]) {
172 printk("%s: could not fill slot %i\n", dev->name, slot); 293 printk("%s: could not fill slot %i\n", dev->name, slot);
173 return -ENOMEM; 294 return -ENOMEM;
174 } 295 }
175 296
297 /* skb_to_dma() is a helper which sets up the "struct lguest_dma" to
298 * point to the data in the skb: we also use it for sending out a
299 * packet. */
176 skb_to_dma(info->skb[slot], ETH_HLEN + ETH_DATA_LEN, &info->dma[slot]); 300 skb_to_dma(info->skb[slot], ETH_HLEN + ETH_DATA_LEN, &info->dma[slot]);
301
302 /* This is a Write Memory Barrier: it ensures that the entry in the
303 * receive buffer array is written *before* we set the "used_len" entry
304 * to 0. If the Host were looking at the receive buffer array from a
305 * different CPU, it could potentially see "used_len = 0" and not see
306 * the updated receive buffer information. This would be a horribly
307 * nasty bug, so make sure the compiler and CPU know this has to happen
308 * first. */
177 wmb(); 309 wmb();
178 /* Now we tell hypervisor it can use the slot. */ 310 /* Writing 0 to "used_len" tells the Host it can use this receive
311 * buffer now. */
179 info->dma[slot].used_len = 0; 312 info->dma[slot].used_len = 0;
180 return 0; 313 return 0;
181} 314}
182 315
316/* This is the actual receive routine. When we receive an interrupt from the
317 * Host to tell us a packet has been delivered, we arrive here: */
183static irqreturn_t lguestnet_rcv(int irq, void *dev_id) 318static irqreturn_t lguestnet_rcv(int irq, void *dev_id)
184{ 319{
185 struct net_device *dev = dev_id; 320 struct net_device *dev = dev_id;
186 struct lguestnet_info *info = netdev_priv(dev); 321 struct lguestnet_info *info = netdev_priv(dev);
187 unsigned int i, done = 0; 322 unsigned int i, done = 0;
188 323
324 /* Look through our entire receive array for an entry which has data
325 * in it. */
189 for (i = 0; i < ARRAY_SIZE(info->dma); i++) { 326 for (i = 0; i < ARRAY_SIZE(info->dma); i++) {
190 unsigned int length; 327 unsigned int length;
191 struct sk_buff *skb; 328 struct sk_buff *skb;
@@ -194,10 +331,16 @@ static irqreturn_t lguestnet_rcv(int irq, void *dev_id)
194 if (length == 0) 331 if (length == 0)
195 continue; 332 continue;
196 333
334 /* We've found one! Remember the skb (we grabbed the length
335 * above), and immediately refill the slot we've taken it
336 * from. */
197 done++; 337 done++;
198 skb = info->skb[i]; 338 skb = info->skb[i];
199 fill_slot(dev, i); 339 fill_slot(dev, i);
200 340
341 /* This shouldn't happen: micropackets could be sent by a
342 * badly-behaved Guest on the network, but the Host will never
343 * stuff more data in the buffer than the buffer length. */
201 if (length < ETH_HLEN || length > ETH_HLEN + ETH_DATA_LEN) { 344 if (length < ETH_HLEN || length > ETH_HLEN + ETH_DATA_LEN) {
202 pr_debug(KERN_WARNING "%s: unbelievable skb len: %i\n", 345 pr_debug(KERN_WARNING "%s: unbelievable skb len: %i\n",
203 dev->name, length); 346 dev->name, length);
@@ -205,36 +348,72 @@ static irqreturn_t lguestnet_rcv(int irq, void *dev_id)
205 continue; 348 continue;
206 } 349 }
207 350
351 /* skb_put(), what a great function! I've ranted about this
352 * function before (http://lkml.org/lkml/1999/9/26/24). You
353 * call it after you've added data to the end of an skb (in
354 * this case, it was the Host which wrote the data). */
208 skb_put(skb, length); 355 skb_put(skb, length);
356
357 /* The ethernet header contains a protocol field: we use the
358 * standard helper to extract it, and place the result in
359 * skb->protocol. The helper also sets up skb->pkt_type and
360 * eats up the ethernet header from the front of the packet. */
209 skb->protocol = eth_type_trans(skb, dev); 361 skb->protocol = eth_type_trans(skb, dev);
210 /* This is a reliable transport. */ 362
363 /* If this device doesn't need checksums for sending, we also
364 * don't need to check the packets when they come in. */
211 if (dev->features & NETIF_F_NO_CSUM) 365 if (dev->features & NETIF_F_NO_CSUM)
212 skb->ip_summed = CHECKSUM_UNNECESSARY; 366 skb->ip_summed = CHECKSUM_UNNECESSARY;
367
368 /* As a last resort for debugging the driver or the lguest I/O
369 * subsystem, you can uncomment the "#define DEBUG" at the top
370 * of this file, which turns all the pr_debug() into printk()
371 * and floods the logs. */
213 pr_debug("Receiving skb proto 0x%04x len %i type %i\n", 372 pr_debug("Receiving skb proto 0x%04x len %i type %i\n",
214 ntohs(skb->protocol), skb->len, skb->pkt_type); 373 ntohs(skb->protocol), skb->len, skb->pkt_type);
215 374
375 /* Update the packet and byte counts (visible from ifconfig,
376 * and good for debugging). */
216 dev->stats.rx_bytes += skb->len; 377 dev->stats.rx_bytes += skb->len;
217 dev->stats.rx_packets++; 378 dev->stats.rx_packets++;
379
380 /* Hand our fresh network packet into the stack's "network
381 * interface receive" routine. That will free the packet
382 * itself when it's finished. */
218 netif_rx(skb); 383 netif_rx(skb);
219 } 384 }
385
386 /* If we found any packets, we assume the interrupt was for us. */
220 return done ? IRQ_HANDLED : IRQ_NONE; 387 return done ? IRQ_HANDLED : IRQ_NONE;
221} 388}
222 389
390/*D:550 This is where we start: when the device is brought up by dhcpd or
391 * ifconfig. At this point we advertise our MAC address to the rest of the
392 * network, and register receive buffers ready for incoming packets. */
223static int lguestnet_open(struct net_device *dev) 393static int lguestnet_open(struct net_device *dev)
224{ 394{
225 int i; 395 int i;
226 struct lguestnet_info *info = netdev_priv(dev); 396 struct lguestnet_info *info = netdev_priv(dev);
227 397
228 /* Set up our MAC address */ 398 /* Copy our MAC address into the device page, so others on the network
399 * can find us. */
229 memcpy(info->peer[info->me].mac, dev->dev_addr, ETH_ALEN); 400 memcpy(info->peer[info->me].mac, dev->dev_addr, ETH_ALEN);
230 401
231 /* Turn on promisc mode if needed */ 402 /* We might already be in promisc mode (dev->flags & IFF_PROMISC). Our
403 * set_multicast callback handles this already, so we call it now. */
232 lguestnet_set_multicast(dev); 404 lguestnet_set_multicast(dev);
233 405
406 /* Allocate packets and put them into our "struct lguest_dma" array.
407 * If we fail to allocate all the packets we could still limp along,
408 * but it's a sign of real stress so we should probably give up now. */
234 for (i = 0; i < ARRAY_SIZE(info->dma); i++) { 409 for (i = 0; i < ARRAY_SIZE(info->dma); i++) {
235 if (fill_slot(dev, i) != 0) 410 if (fill_slot(dev, i) != 0)
236 goto cleanup; 411 goto cleanup;
237 } 412 }
413
414 /* Finally we tell the Host where our array of "struct lguest_dma"
415 * receive buffers is, binding it to the key corresponding to the
416 * device's physical memory plus our peerid. */
238 if (lguest_bind_dma(peer_key(info,info->me), info->dma, 417 if (lguest_bind_dma(peer_key(info,info->me), info->dma,
239 NUM_SKBS, lgdev_irq(info->lgdev)) != 0) 418 NUM_SKBS, lgdev_irq(info->lgdev)) != 0)
240 goto cleanup; 419 goto cleanup;
@@ -245,22 +424,29 @@ cleanup:
245 dev_kfree_skb(info->skb[i]); 424 dev_kfree_skb(info->skb[i]);
246 return -ENOMEM; 425 return -ENOMEM;
247} 426}
427/*:*/
248 428
429/* The close routine is called when the device is no longer in use: we clean up
430 * elegantly. */
249static int lguestnet_close(struct net_device *dev) 431static int lguestnet_close(struct net_device *dev)
250{ 432{
251 unsigned int i; 433 unsigned int i;
252 struct lguestnet_info *info = netdev_priv(dev); 434 struct lguestnet_info *info = netdev_priv(dev);
253 435
254 /* Clear all trace: others might deliver packets, we'll ignore it. */ 436 /* Clear all trace of our existence out of the device memory by setting
437 * the slot which held our MAC address to 0 (unused). */
255 memset(&info->peer[info->me], 0, sizeof(info->peer[info->me])); 438 memset(&info->peer[info->me], 0, sizeof(info->peer[info->me]));
256 439
257 /* Deregister sg lists. */ 440 /* Unregister our array of receive buffers */
258 lguest_unbind_dma(peer_key(info, info->me), info->dma); 441 lguest_unbind_dma(peer_key(info, info->me), info->dma);
259 for (i = 0; i < ARRAY_SIZE(info->dma); i++) 442 for (i = 0; i < ARRAY_SIZE(info->dma); i++)
260 dev_kfree_skb(info->skb[i]); 443 dev_kfree_skb(info->skb[i]);
261 return 0; 444 return 0;
262} 445}
263 446
447/*D:510 The network device probe function is basically a standard ethernet
448 * device setup. It reads the "struct lguest_device_desc" and sets the "struct
449 * net_device". Oh, the line-by-line excitement! Let's skip over it. :*/
264static int lguestnet_probe(struct lguest_device *lgdev) 450static int lguestnet_probe(struct lguest_device *lgdev)
265{ 451{
266 int err, irqf = IRQF_SHARED; 452 int err, irqf = IRQF_SHARED;
@@ -290,10 +476,16 @@ static int lguestnet_probe(struct lguest_device *lgdev)
290 dev->stop = lguestnet_close; 476 dev->stop = lguestnet_close;
291 dev->hard_start_xmit = lguestnet_start_xmit; 477 dev->hard_start_xmit = lguestnet_start_xmit;
292 478
293 /* Turning on/off promisc will call dev->set_multicast_list. 479 /* We don't actually support multicast yet, but turning on/off
294 * We don't actually support multicast yet */ 480 * promisc also calls dev->set_multicast_list. */
295 dev->set_multicast_list = lguestnet_set_multicast; 481 dev->set_multicast_list = lguestnet_set_multicast;
296 SET_NETDEV_DEV(dev, &lgdev->dev); 482 SET_NETDEV_DEV(dev, &lgdev->dev);
483
484 /* The network code complains if you have "scatter-gather" capability
485 * if you don't also handle checksums (it seem that would be
486 * "illogical"). So we use a lie of omission and don't tell it that we
487 * can handle scattered packets unless we also don't want checksums,
488 * even though to us they're completely independent. */
297 if (desc->features & LGUEST_NET_F_NOCSUM) 489 if (desc->features & LGUEST_NET_F_NOCSUM)
298 dev->features = NETIF_F_SG|NETIF_F_NO_CSUM; 490 dev->features = NETIF_F_SG|NETIF_F_NO_CSUM;
299 491
@@ -325,6 +517,9 @@ static int lguestnet_probe(struct lguest_device *lgdev)
325 } 517 }
326 518
327 pr_debug("lguestnet: registered device %s\n", dev->name); 519 pr_debug("lguestnet: registered device %s\n", dev->name);
520 /* Finally, we put the "struct net_device" in the generic "struct
521 * lguest_device"s private pointer. Again, it's not necessary, but
522 * makes sure the cool kernel kids don't tease us. */
328 lgdev->private = dev; 523 lgdev->private = dev;
329 return 0; 524 return 0;
330 525
@@ -352,3 +547,11 @@ module_init(lguestnet_init);
352 547
353MODULE_DESCRIPTION("Lguest network driver"); 548MODULE_DESCRIPTION("Lguest network driver");
354MODULE_LICENSE("GPL"); 549MODULE_LICENSE("GPL");
550
551/*D:580
552 * This is the last of the Drivers, and with this we have covered the many and
553 * wonderous and fine (and boring) details of the Guest.
554 *
555 * "make Launcher" beckons, where we answer questions like "Where do Guests
556 * come from?", and "What do you do when someone asks for optimization?"
557 */
diff --git a/drivers/net/lib8390.c b/drivers/net/lib8390.c
index 5c86e737f954..721ee38d2241 100644
--- a/drivers/net/lib8390.c
+++ b/drivers/net/lib8390.c
@@ -219,15 +219,6 @@ static void ei_tx_timeout(struct net_device *dev)
219 int txsr, isr, tickssofar = jiffies - dev->trans_start; 219 int txsr, isr, tickssofar = jiffies - dev->trans_start;
220 unsigned long flags; 220 unsigned long flags;
221 221
222#if defined(CONFIG_M32R) && defined(CONFIG_SMP)
223 unsigned long icucr;
224
225 local_irq_save(flags);
226 icucr = inl(M32R_ICU_CR1_PORTL);
227 icucr |= M32R_ICUCR_ISMOD11;
228 outl(icucr, M32R_ICU_CR1_PORTL);
229 local_irq_restore(flags);
230#endif
231 ei_local->stat.tx_errors++; 222 ei_local->stat.tx_errors++;
232 223
233 spin_lock_irqsave(&ei_local->page_lock, flags); 224 spin_lock_irqsave(&ei_local->page_lock, flags);
diff --git a/drivers/net/netxen/netxen_nic.h b/drivers/net/netxen/netxen_nic.h
index 325269d8ae38..d4c92cc879d4 100644
--- a/drivers/net/netxen/netxen_nic.h
+++ b/drivers/net/netxen/netxen_nic.h
@@ -1179,8 +1179,7 @@ dma_watchdog_shutdown_poll_result(struct netxen_adapter *adapter)
1179 NETXEN_CAM_RAM(NETXEN_CAM_RAM_DMA_WATCHDOG_CTRL), &ctrl, 4)) 1179 NETXEN_CAM_RAM(NETXEN_CAM_RAM_DMA_WATCHDOG_CTRL), &ctrl, 4))
1180 printk(KERN_ERR "failed to read dma watchdog status\n"); 1180 printk(KERN_ERR "failed to read dma watchdog status\n");
1181 1181
1182 return ((netxen_get_dma_watchdog_enabled(ctrl) == 0) && 1182 return (netxen_get_dma_watchdog_enabled(ctrl) == 0);
1183 (netxen_get_dma_watchdog_disabled(ctrl) == 0));
1184} 1183}
1185 1184
1186static inline int 1185static inline int
diff --git a/drivers/net/netxen/netxen_nic_main.c b/drivers/net/netxen/netxen_nic_main.c
index b703ccfe040b..19e2fa940ac0 100644
--- a/drivers/net/netxen/netxen_nic_main.c
+++ b/drivers/net/netxen/netxen_nic_main.c
@@ -46,7 +46,7 @@ MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver");
46MODULE_LICENSE("GPL"); 46MODULE_LICENSE("GPL");
47MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID); 47MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID);
48 48
49char netxen_nic_driver_name[] = "netxen-nic"; 49char netxen_nic_driver_name[] = "netxen_nic";
50static char netxen_nic_driver_string[] = "NetXen Network Driver version " 50static char netxen_nic_driver_string[] = "NetXen Network Driver version "
51 NETXEN_NIC_LINUX_VERSIONID; 51 NETXEN_NIC_LINUX_VERSIONID;
52 52
@@ -640,6 +640,10 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
640 NETXEN_CRB_NORMALIZE(adapter, 640 NETXEN_CRB_NORMALIZE(adapter,
641 NETXEN_ROMUSB_GLB_PEGTUNE_DONE)); 641 NETXEN_ROMUSB_GLB_PEGTUNE_DONE));
642 /* Handshake with the card before we register the devices. */ 642 /* Handshake with the card before we register the devices. */
643 writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE));
644 netxen_pinit_from_rom(adapter, 0);
645 msleep(1);
646 netxen_load_firmware(adapter);
643 netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); 647 netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
644 } 648 }
645 649
@@ -782,19 +786,18 @@ static void __devexit netxen_nic_remove(struct pci_dev *pdev)
782 786
783 if (adapter->portnum == 0) { 787 if (adapter->portnum == 0) {
784 if (init_firmware_done) { 788 if (init_firmware_done) {
785 dma_watchdog_shutdown_request(adapter);
786 msleep(100);
787 i = 100; 789 i = 100;
788 while ((dma_watchdog_shutdown_poll_result(adapter) != 1) && i) { 790 do {
789 printk(KERN_INFO "dma_watchdog_shutdown_poll still in progress\n"); 791 if (dma_watchdog_shutdown_request(adapter) == 1)
792 break;
790 msleep(100); 793 msleep(100);
791 i--; 794 if (dma_watchdog_shutdown_poll_result(adapter) == 1)
792 } 795 break;
796 } while (--i);
793 797
794 if (i == 0) { 798 if (i == 0)
795 printk(KERN_ERR "dma_watchdog_shutdown_request failed\n"); 799 printk(KERN_ERR "%s: dma_watchdog_shutdown failed\n",
796 return; 800 netdev->name);
797 }
798 801
799 /* clear the register for future unloads/loads */ 802 /* clear the register for future unloads/loads */
800 writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_CAM_RAM(0x1fc))); 803 writel(0, NETXEN_CRB_NORMALIZE(adapter, NETXEN_CAM_RAM(0x1fc)));
@@ -803,11 +806,9 @@ static void __devexit netxen_nic_remove(struct pci_dev *pdev)
803 806
804 /* leave the hw in the same state as reboot */ 807 /* leave the hw in the same state as reboot */
805 writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)); 808 writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE));
806 if (netxen_pinit_from_rom(adapter, 0)) 809 netxen_pinit_from_rom(adapter, 0);
807 return;
808 msleep(1); 810 msleep(1);
809 if (netxen_load_firmware(adapter)) 811 netxen_load_firmware(adapter);
810 return;
811 netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); 812 netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
812 } 813 }
813 814
@@ -816,22 +817,21 @@ static void __devexit netxen_nic_remove(struct pci_dev *pdev)
816 printk(KERN_INFO "State: 0x%0x\n", 817 printk(KERN_INFO "State: 0x%0x\n",
817 readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE))); 818 readl(NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)));
818 819
819 dma_watchdog_shutdown_request(adapter);
820 msleep(100);
821 i = 100; 820 i = 100;
822 while ((dma_watchdog_shutdown_poll_result(adapter) != 1) && i) { 821 do {
823 printk(KERN_INFO "dma_watchdog_shutdown_poll still in progress\n"); 822 if (dma_watchdog_shutdown_request(adapter) == 1)
823 break;
824 msleep(100); 824 msleep(100);
825 i--; 825 if (dma_watchdog_shutdown_poll_result(adapter) == 1)
826 } 826 break;
827 } while (--i);
827 828
828 if (i) { 829 if (i) {
829 netxen_free_adapter_offload(adapter); 830 netxen_free_adapter_offload(adapter);
830 } else { 831 } else {
831 printk(KERN_ERR "failed to dma shutdown\n"); 832 printk(KERN_ERR "%s: dma_watchdog_shutdown failed\n",
832 return; 833 netdev->name);
833 } 834 }
834
835 } 835 }
836 836
837 iounmap(adapter->ahw.db_base); 837 iounmap(adapter->ahw.db_base);
diff --git a/drivers/net/phy/vitesse.c b/drivers/net/phy/vitesse.c
index 6a5385647911..8874497b6bbf 100644
--- a/drivers/net/phy/vitesse.c
+++ b/drivers/net/phy/vitesse.c
@@ -109,7 +109,7 @@ static int vsc824x_config_intr(struct phy_device *phydev)
109 */ 109 */
110 err = phy_read(phydev, MII_VSC8244_ISTAT); 110 err = phy_read(phydev, MII_VSC8244_ISTAT);
111 111
112 if (err) 112 if (err < 0)
113 return err; 113 return err;
114 114
115 err = phy_write(phydev, MII_VSC8244_IMASK, 0); 115 err = phy_write(phydev, MII_VSC8244_IMASK, 0);
diff --git a/drivers/net/pppol2tp.c b/drivers/net/pppol2tp.c
index f87176055d0e..266e8b38fe10 100644
--- a/drivers/net/pppol2tp.c
+++ b/drivers/net/pppol2tp.c
@@ -2054,7 +2054,7 @@ end:
2054 */ 2054 */
2055static int pppol2tp_tunnel_getsockopt(struct sock *sk, 2055static int pppol2tp_tunnel_getsockopt(struct sock *sk,
2056 struct pppol2tp_tunnel *tunnel, 2056 struct pppol2tp_tunnel *tunnel,
2057 int optname, int __user *val) 2057 int optname, int *val)
2058{ 2058{
2059 int err = 0; 2059 int err = 0;
2060 2060
@@ -2077,7 +2077,7 @@ static int pppol2tp_tunnel_getsockopt(struct sock *sk,
2077 */ 2077 */
2078static int pppol2tp_session_getsockopt(struct sock *sk, 2078static int pppol2tp_session_getsockopt(struct sock *sk,
2079 struct pppol2tp_session *session, 2079 struct pppol2tp_session *session,
2080 int optname, int __user *val) 2080 int optname, int *val)
2081{ 2081{
2082 int err = 0; 2082 int err = 0;
2083 2083
diff --git a/drivers/net/ps3_gelic_net.c b/drivers/net/ps3_gelic_net.c
index 08d25066f051..13d1c0a2a25f 100644
--- a/drivers/net/ps3_gelic_net.c
+++ b/drivers/net/ps3_gelic_net.c
@@ -290,7 +290,8 @@ static void gelic_net_release_rx_chain(struct gelic_net_card *card)
290 descr->buf_addr = 0; 290 descr->buf_addr = 0;
291 dev_kfree_skb_any(descr->skb); 291 dev_kfree_skb_any(descr->skb);
292 descr->skb = NULL; 292 descr->skb = NULL;
293 descr->dmac_cmd_status = GELIC_NET_DESCR_NOT_IN_USE; 293 gelic_net_set_descr_status(descr,
294 GELIC_NET_DESCR_NOT_IN_USE);
294 } 295 }
295 descr = descr->next; 296 descr = descr->next;
296 } while (descr != card->rx_chain.head); 297 } while (descr != card->rx_chain.head);
@@ -374,7 +375,7 @@ static void gelic_net_release_tx_descr(struct gelic_net_card *card,
374 descr->skb = NULL; 375 descr->skb = NULL;
375 376
376 /* set descr status */ 377 /* set descr status */
377 descr->dmac_cmd_status = GELIC_NET_DMAC_CMDSTAT_NOT_IN_USE; 378 gelic_net_set_descr_status(descr, GELIC_NET_DESCR_NOT_IN_USE);
378} 379}
379 380
380/** 381/**
@@ -403,26 +404,29 @@ static void gelic_net_release_tx_chain(struct gelic_net_card *card, int stop)
403 "%s: forcing end of tx descriptor " \ 404 "%s: forcing end of tx descriptor " \
404 "with status %x\n", 405 "with status %x\n",
405 __func__, status); 406 __func__, status);
406 card->netdev_stats.tx_dropped++; 407 card->netdev->stats.tx_dropped++;
407 break; 408 break;
408 409
409 case GELIC_NET_DESCR_COMPLETE: 410 case GELIC_NET_DESCR_COMPLETE:
410 card->netdev_stats.tx_packets++; 411 if (tx_chain->tail->skb) {
411 card->netdev_stats.tx_bytes += 412 card->netdev->stats.tx_packets++;
412 tx_chain->tail->skb->len; 413 card->netdev->stats.tx_bytes +=
414 tx_chain->tail->skb->len;
415 }
413 break; 416 break;
414 417
415 case GELIC_NET_DESCR_CARDOWNED: 418 case GELIC_NET_DESCR_CARDOWNED:
416 /* pending tx request */ 419 /* pending tx request */
417 default: 420 default:
418 /* any other value (== GELIC_NET_DESCR_NOT_IN_USE) */ 421 /* any other value (== GELIC_NET_DESCR_NOT_IN_USE) */
419 goto out; 422 if (!stop)
423 goto out;
420 } 424 }
421 gelic_net_release_tx_descr(card, tx_chain->tail); 425 gelic_net_release_tx_descr(card, tx_chain->tail);
422 release = 1; 426 release ++;
423 } 427 }
424out: 428out:
425 if (!stop && release) 429 if (!stop && (2 < release))
426 netif_wake_queue(card->netdev); 430 netif_wake_queue(card->netdev);
427} 431}
428 432
@@ -659,19 +663,21 @@ static int gelic_net_prepare_tx_descr_v(struct gelic_net_card *card,
659{ 663{
660 dma_addr_t buf[2]; 664 dma_addr_t buf[2];
661 unsigned int vlan_len; 665 unsigned int vlan_len;
666 struct gelic_net_descr *sec_descr = descr->next;
662 667
663 if (skb->len < GELIC_NET_VLAN_POS) 668 if (skb->len < GELIC_NET_VLAN_POS)
664 return -EINVAL; 669 return -EINVAL;
665 670
666 memcpy(&descr->vlan, skb->data, GELIC_NET_VLAN_POS); 671 vlan_len = GELIC_NET_VLAN_POS;
672 memcpy(&descr->vlan, skb->data, vlan_len);
667 if (card->vlan_index != -1) { 673 if (card->vlan_index != -1) {
674 /* internal vlan tag used */
668 descr->vlan.h_vlan_proto = htons(ETH_P_8021Q); /* vlan 0x8100*/ 675 descr->vlan.h_vlan_proto = htons(ETH_P_8021Q); /* vlan 0x8100*/
669 descr->vlan.h_vlan_TCI = htons(card->vlan_id[card->vlan_index]); 676 descr->vlan.h_vlan_TCI = htons(card->vlan_id[card->vlan_index]);
670 vlan_len = GELIC_NET_VLAN_POS + VLAN_HLEN; /* VLAN_HLEN=4 */ 677 vlan_len += VLAN_HLEN; /* added for above two lines */
671 } else 678 }
672 vlan_len = GELIC_NET_VLAN_POS; /* no vlan tag */
673 679
674 /* first descr */ 680 /* map data area */
675 buf[0] = dma_map_single(ctodev(card), &descr->vlan, 681 buf[0] = dma_map_single(ctodev(card), &descr->vlan,
676 vlan_len, DMA_TO_DEVICE); 682 vlan_len, DMA_TO_DEVICE);
677 683
@@ -682,20 +688,6 @@ static int gelic_net_prepare_tx_descr_v(struct gelic_net_card *card,
682 return -ENOMEM; 688 return -ENOMEM;
683 } 689 }
684 690
685 descr->buf_addr = buf[0];
686 descr->buf_size = vlan_len;
687 descr->skb = skb; /* not used */
688 descr->data_status = 0;
689 gelic_net_set_txdescr_cmdstat(descr, skb, 1); /* not the frame end */
690
691 /* second descr */
692 card->tx_chain.head = card->tx_chain.head->next;
693 descr->next_descr_addr = descr->next->bus_addr;
694 descr = descr->next;
695 if (gelic_net_get_descr_status(descr) != GELIC_NET_DESCR_NOT_IN_USE)
696 /* XXX will be removed */
697 dev_err(ctodev(card), "descr is not free!\n");
698
699 buf[1] = dma_map_single(ctodev(card), skb->data + GELIC_NET_VLAN_POS, 691 buf[1] = dma_map_single(ctodev(card), skb->data + GELIC_NET_VLAN_POS,
700 skb->len - GELIC_NET_VLAN_POS, 692 skb->len - GELIC_NET_VLAN_POS,
701 DMA_TO_DEVICE); 693 DMA_TO_DEVICE);
@@ -710,13 +702,24 @@ static int gelic_net_prepare_tx_descr_v(struct gelic_net_card *card,
710 return -ENOMEM; 702 return -ENOMEM;
711 } 703 }
712 704
713 descr->buf_addr = buf[1]; 705 /* first descr */
714 descr->buf_size = skb->len - GELIC_NET_VLAN_POS; 706 descr->buf_addr = buf[0];
715 descr->skb = skb; 707 descr->buf_size = vlan_len;
708 descr->skb = NULL; /* not used */
716 descr->data_status = 0; 709 descr->data_status = 0;
717 descr->next_descr_addr = 0; /* terminate hw descr */ 710 descr->next_descr_addr = descr->next->bus_addr;
718 gelic_net_set_txdescr_cmdstat(descr, skb, 0); 711 gelic_net_set_txdescr_cmdstat(descr, skb, 1); /* not the frame end */
719 712
713 /* second descr */
714 sec_descr->buf_addr = buf[1];
715 sec_descr->buf_size = skb->len - GELIC_NET_VLAN_POS;
716 sec_descr->skb = skb;
717 sec_descr->data_status = 0;
718 sec_descr->next_descr_addr = 0; /* terminate hw descr */
719 gelic_net_set_txdescr_cmdstat(sec_descr, skb, 0);
720
721 /* bump free descriptor pointer */
722 card->tx_chain.head = sec_descr->next;
720 return 0; 723 return 0;
721} 724}
722 725
@@ -729,7 +732,7 @@ static int gelic_net_prepare_tx_descr_v(struct gelic_net_card *card,
729static int gelic_net_kick_txdma(struct gelic_net_card *card, 732static int gelic_net_kick_txdma(struct gelic_net_card *card,
730 struct gelic_net_descr *descr) 733 struct gelic_net_descr *descr)
731{ 734{
732 int status = -ENXIO; 735 int status = 0;
733 int count = 10; 736 int count = 10;
734 737
735 if (card->tx_dma_progress) 738 if (card->tx_dma_progress)
@@ -763,47 +766,62 @@ static int gelic_net_kick_txdma(struct gelic_net_card *card,
763static int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev) 766static int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
764{ 767{
765 struct gelic_net_card *card = netdev_priv(netdev); 768 struct gelic_net_card *card = netdev_priv(netdev);
766 struct gelic_net_descr *descr = NULL; 769 struct gelic_net_descr *descr;
767 int result; 770 int result;
768 unsigned long flags; 771 unsigned long flags;
769 772
770 spin_lock_irqsave(&card->tx_dma_lock, flags); 773 spin_lock_irqsave(&card->tx_dma_lock, flags);
771 774
772 gelic_net_release_tx_chain(card, 0); 775 gelic_net_release_tx_chain(card, 0);
773 if (!skb) 776
774 goto kick;
775 descr = gelic_net_get_next_tx_descr(card); 777 descr = gelic_net_get_next_tx_descr(card);
776 if (!descr) { 778 if (!descr) {
779 /*
780 * no more descriptors free
781 */
777 netif_stop_queue(netdev); 782 netif_stop_queue(netdev);
778 spin_unlock_irqrestore(&card->tx_dma_lock, flags); 783 spin_unlock_irqrestore(&card->tx_dma_lock, flags);
779 return NETDEV_TX_BUSY; 784 return NETDEV_TX_BUSY;
780 } 785 }
781 result = gelic_net_prepare_tx_descr_v(card, descr, skb);
782
783 if (result)
784 goto error;
785 786
786 card->tx_chain.head = card->tx_chain.head->next; 787 result = gelic_net_prepare_tx_descr_v(card, descr, skb);
787 788 if (result) {
788 if (descr->prev) 789 /*
789 descr->prev->next_descr_addr = descr->bus_addr; 790 * DMA map failed. As chanses are that failure
790kick: 791 * would continue, just release skb and return
792 */
793 card->netdev->stats.tx_dropped++;
794 dev_kfree_skb_any(skb);
795 spin_unlock_irqrestore(&card->tx_dma_lock, flags);
796 return NETDEV_TX_OK;
797 }
798 /*
799 * link this prepared descriptor to previous one
800 * to achieve high performance
801 */
802 descr->prev->next_descr_addr = descr->bus_addr;
791 /* 803 /*
792 * as hardware descriptor is modified in the above lines, 804 * as hardware descriptor is modified in the above lines,
793 * ensure that the hardware sees it 805 * ensure that the hardware sees it
794 */ 806 */
795 wmb(); 807 wmb();
796 if (gelic_net_kick_txdma(card, card->tx_chain.tail)) 808 if (gelic_net_kick_txdma(card, descr)) {
797 goto error; 809 /*
810 * kick failed.
811 * release descriptors which were just prepared
812 */
813 card->netdev->stats.tx_dropped++;
814 gelic_net_release_tx_descr(card, descr);
815 gelic_net_release_tx_descr(card, descr->next);
816 card->tx_chain.tail = descr->next->next;
817 dev_info(ctodev(card), "%s: kick failure\n", __func__);
818 } else {
819 /* OK, DMA started/reserved */
820 netdev->trans_start = jiffies;
821 }
798 822
799 netdev->trans_start = jiffies;
800 spin_unlock_irqrestore(&card->tx_dma_lock, flags); 823 spin_unlock_irqrestore(&card->tx_dma_lock, flags);
801 return NETDEV_TX_OK; 824 return NETDEV_TX_OK;
802
803error:
804 card->netdev_stats.tx_dropped++;
805 spin_unlock_irqrestore(&card->tx_dma_lock, flags);
806 return NETDEV_TX_LOCKED;
807} 825}
808 826
809/** 827/**
@@ -854,8 +872,8 @@ static void gelic_net_pass_skb_up(struct gelic_net_descr *descr,
854 skb->ip_summed = CHECKSUM_NONE; 872 skb->ip_summed = CHECKSUM_NONE;
855 873
856 /* update netdevice statistics */ 874 /* update netdevice statistics */
857 card->netdev_stats.rx_packets++; 875 card->netdev->stats.rx_packets++;
858 card->netdev_stats.rx_bytes += skb->len; 876 card->netdev->stats.rx_bytes += skb->len;
859 877
860 /* pass skb up to stack */ 878 /* pass skb up to stack */
861 netif_receive_skb(skb); 879 netif_receive_skb(skb);
@@ -895,38 +913,67 @@ static int gelic_net_decode_one_descr(struct gelic_net_card *card)
895 (status == GELIC_NET_DESCR_FORCE_END)) { 913 (status == GELIC_NET_DESCR_FORCE_END)) {
896 dev_info(ctodev(card), "dropping RX descriptor with state %x\n", 914 dev_info(ctodev(card), "dropping RX descriptor with state %x\n",
897 status); 915 status);
898 card->netdev_stats.rx_dropped++; 916 card->netdev->stats.rx_dropped++;
899 goto refill; 917 goto refill;
900 } 918 }
901 919
902 if ((status != GELIC_NET_DESCR_COMPLETE) && 920 if (status == GELIC_NET_DESCR_BUFFER_FULL) {
903 (status != GELIC_NET_DESCR_FRAME_END)) { 921 /*
922 * Buffer full would occur if and only if
923 * the frame length was longer than the size of this
924 * descriptor's buffer. If the frame length was equal
925 * to or shorter than buffer'size, FRAME_END condition
926 * would occur.
927 * Anyway this frame was longer than the MTU,
928 * just drop it.
929 */
930 dev_info(ctodev(card), "overlength frame\n");
931 goto refill;
932 }
933 /*
934 * descriptoers any other than FRAME_END here should
935 * be treated as error.
936 */
937 if (status != GELIC_NET_DESCR_FRAME_END) {
904 dev_dbg(ctodev(card), "RX descriptor with state %x\n", 938 dev_dbg(ctodev(card), "RX descriptor with state %x\n",
905 status); 939 status);
906 goto refill; 940 goto refill;
907 } 941 }
908 942
909 /* ok, we've got a packet in descr */ 943 /* ok, we've got a packet in descr */
910 gelic_net_pass_skb_up(descr, card); /* 1: skb_up sccess */ 944 gelic_net_pass_skb_up(descr, card);
911
912refill: 945refill:
913 descr->next_descr_addr = 0; /* unlink the descr */ 946 /*
947 * So that always DMAC can see the end
948 * of the descriptor chain to avoid
949 * from unwanted DMAC overrun.
950 */
951 descr->next_descr_addr = 0;
914 952
915 /* change the descriptor state: */ 953 /* change the descriptor state: */
916 gelic_net_set_descr_status(descr, GELIC_NET_DESCR_NOT_IN_USE); 954 gelic_net_set_descr_status(descr, GELIC_NET_DESCR_NOT_IN_USE);
917 955
918 /* refill one desc 956 /*
919 * FIXME: this can fail, but for now, just leave this 957 * this call can fail, but for now, just leave this
920 * descriptor without skb 958 * decriptor without skb
921 */ 959 */
922 gelic_net_prepare_rx_descr(card, descr); 960 gelic_net_prepare_rx_descr(card, descr);
961
923 chain->head = descr; 962 chain->head = descr;
924 chain->tail = descr->next; 963 chain->tail = descr->next;
964
965 /*
966 * Set this descriptor the end of the chain.
967 */
925 descr->prev->next_descr_addr = descr->bus_addr; 968 descr->prev->next_descr_addr = descr->bus_addr;
926 969
970 /*
971 * If dmac chain was met, DMAC stopped.
972 * thus re-enable it
973 */
927 if (dmac_chain_ended) { 974 if (dmac_chain_ended) {
928 gelic_net_enable_rxdmac(card); 975 card->rx_dma_restart_required = 1;
929 dev_dbg(ctodev(card), "reenable rx dma\n"); 976 dev_dbg(ctodev(card), "reenable rx dma scheduled\n");
930 } 977 }
931 978
932 return 1; 979 return 1;
@@ -968,20 +1015,6 @@ static int gelic_net_poll(struct net_device *netdev, int *budget)
968 } else 1015 } else
969 return 1; 1016 return 1;
970} 1017}
971
972/**
973 * gelic_net_get_stats - get interface statistics
974 * @netdev: interface device structure
975 *
976 * returns the interface statistics residing in the gelic_net_card struct
977 */
978static struct net_device_stats *gelic_net_get_stats(struct net_device *netdev)
979{
980 struct gelic_net_card *card = netdev_priv(netdev);
981
982 return &card->netdev_stats;
983}
984
985/** 1018/**
986 * gelic_net_change_mtu - changes the MTU of an interface 1019 * gelic_net_change_mtu - changes the MTU of an interface
987 * @netdev: interface device structure 1020 * @netdev: interface device structure
@@ -1016,6 +1049,11 @@ static irqreturn_t gelic_net_interrupt(int irq, void *ptr)
1016 if (!status) 1049 if (!status)
1017 return IRQ_NONE; 1050 return IRQ_NONE;
1018 1051
1052 if (card->rx_dma_restart_required) {
1053 card->rx_dma_restart_required = 0;
1054 gelic_net_enable_rxdmac(card);
1055 }
1056
1019 if (status & GELIC_NET_RXINT) { 1057 if (status & GELIC_NET_RXINT) {
1020 gelic_net_rx_irq_off(card); 1058 gelic_net_rx_irq_off(card);
1021 netif_rx_schedule(netdev); 1059 netif_rx_schedule(netdev);
@@ -1024,9 +1062,10 @@ static irqreturn_t gelic_net_interrupt(int irq, void *ptr)
1024 if (status & GELIC_NET_TXINT) { 1062 if (status & GELIC_NET_TXINT) {
1025 spin_lock_irqsave(&card->tx_dma_lock, flags); 1063 spin_lock_irqsave(&card->tx_dma_lock, flags);
1026 card->tx_dma_progress = 0; 1064 card->tx_dma_progress = 0;
1065 gelic_net_release_tx_chain(card, 0);
1066 /* kick outstanding tx descriptor if any */
1067 gelic_net_kick_txdma(card, card->tx_chain.tail);
1027 spin_unlock_irqrestore(&card->tx_dma_lock, flags); 1068 spin_unlock_irqrestore(&card->tx_dma_lock, flags);
1028 /* start pending DMA */
1029 gelic_net_xmit(NULL, netdev);
1030 } 1069 }
1031 return IRQ_HANDLED; 1070 return IRQ_HANDLED;
1032} 1071}
@@ -1068,7 +1107,7 @@ static int gelic_net_open_device(struct gelic_net_card *card)
1068 } 1107 }
1069 1108
1070 result = request_irq(card->netdev->irq, gelic_net_interrupt, 1109 result = request_irq(card->netdev->irq, gelic_net_interrupt,
1071 IRQF_DISABLED, "gelic network", card->netdev); 1110 IRQF_DISABLED, card->netdev->name, card->netdev);
1072 1111
1073 if (result) { 1112 if (result) {
1074 dev_info(ctodev(card), "%s:%d: request_irq failed (%d)\n", 1113 dev_info(ctodev(card), "%s:%d: request_irq failed (%d)\n",
@@ -1107,7 +1146,7 @@ static int gelic_net_open(struct net_device *netdev)
1107 card->descr, GELIC_NET_TX_DESCRIPTORS)) 1146 card->descr, GELIC_NET_TX_DESCRIPTORS))
1108 goto alloc_tx_failed; 1147 goto alloc_tx_failed;
1109 if (gelic_net_init_chain(card, &card->rx_chain, 1148 if (gelic_net_init_chain(card, &card->rx_chain,
1110 card->descr + GELIC_NET_RX_DESCRIPTORS, 1149 card->descr + GELIC_NET_TX_DESCRIPTORS,
1111 GELIC_NET_RX_DESCRIPTORS)) 1150 GELIC_NET_RX_DESCRIPTORS))
1112 goto alloc_rx_failed; 1151 goto alloc_rx_failed;
1113 1152
@@ -1129,7 +1168,6 @@ static int gelic_net_open(struct net_device *netdev)
1129 1168
1130 netif_start_queue(netdev); 1169 netif_start_queue(netdev);
1131 netif_carrier_on(netdev); 1170 netif_carrier_on(netdev);
1132 netif_poll_enable(netdev);
1133 1171
1134 return 0; 1172 return 0;
1135 1173
@@ -1141,7 +1179,6 @@ alloc_tx_failed:
1141 return -ENOMEM; 1179 return -ENOMEM;
1142} 1180}
1143 1181
1144#ifdef GELIC_NET_ETHTOOL
1145static void gelic_net_get_drvinfo (struct net_device *netdev, 1182static void gelic_net_get_drvinfo (struct net_device *netdev,
1146 struct ethtool_drvinfo *info) 1183 struct ethtool_drvinfo *info)
1147{ 1184{
@@ -1261,7 +1298,6 @@ static struct ethtool_ops gelic_net_ethtool_ops = {
1261 .get_rx_csum = gelic_net_get_rx_csum, 1298 .get_rx_csum = gelic_net_get_rx_csum,
1262 .set_rx_csum = gelic_net_set_rx_csum, 1299 .set_rx_csum = gelic_net_set_rx_csum,
1263}; 1300};
1264#endif
1265 1301
1266/** 1302/**
1267 * gelic_net_tx_timeout_task - task scheduled by the watchdog timeout 1303 * gelic_net_tx_timeout_task - task scheduled by the watchdog timeout
@@ -1320,7 +1356,6 @@ static void gelic_net_setup_netdev_ops(struct net_device *netdev)
1320 netdev->open = &gelic_net_open; 1356 netdev->open = &gelic_net_open;
1321 netdev->stop = &gelic_net_stop; 1357 netdev->stop = &gelic_net_stop;
1322 netdev->hard_start_xmit = &gelic_net_xmit; 1358 netdev->hard_start_xmit = &gelic_net_xmit;
1323 netdev->get_stats = &gelic_net_get_stats;
1324 netdev->set_multicast_list = &gelic_net_set_multi; 1359 netdev->set_multicast_list = &gelic_net_set_multi;
1325 netdev->change_mtu = &gelic_net_change_mtu; 1360 netdev->change_mtu = &gelic_net_change_mtu;
1326 /* tx watchdog */ 1361 /* tx watchdog */
@@ -1329,9 +1364,7 @@ static void gelic_net_setup_netdev_ops(struct net_device *netdev)
1329 /* NAPI */ 1364 /* NAPI */
1330 netdev->poll = &gelic_net_poll; 1365 netdev->poll = &gelic_net_poll;
1331 netdev->weight = GELIC_NET_NAPI_WEIGHT; 1366 netdev->weight = GELIC_NET_NAPI_WEIGHT;
1332#ifdef GELIC_NET_ETHTOOL
1333 netdev->ethtool_ops = &gelic_net_ethtool_ops; 1367 netdev->ethtool_ops = &gelic_net_ethtool_ops;
1334#endif
1335} 1368}
1336 1369
1337/** 1370/**
diff --git a/drivers/net/ps3_gelic_net.h b/drivers/net/ps3_gelic_net.h
index 5e1c28654e16..a9c4c4fc2547 100644
--- a/drivers/net/ps3_gelic_net.h
+++ b/drivers/net/ps3_gelic_net.h
@@ -28,21 +28,12 @@
28#ifndef _GELIC_NET_H 28#ifndef _GELIC_NET_H
29#define _GELIC_NET_H 29#define _GELIC_NET_H
30 30
31#define GELIC_NET_DRV_NAME "Gelic Network Driver"
32#define GELIC_NET_DRV_VERSION "1.0"
33
34#define GELIC_NET_ETHTOOL /* use ethtool */
35
36/* ioctl */
37#define GELIC_NET_GET_MODE (SIOCDEVPRIVATE + 0)
38#define GELIC_NET_SET_MODE (SIOCDEVPRIVATE + 1)
39
40/* descriptors */ 31/* descriptors */
41#define GELIC_NET_RX_DESCRIPTORS 128 /* num of descriptors */ 32#define GELIC_NET_RX_DESCRIPTORS 128 /* num of descriptors */
42#define GELIC_NET_TX_DESCRIPTORS 128 /* num of descriptors */ 33#define GELIC_NET_TX_DESCRIPTORS 128 /* num of descriptors */
43 34
44#define GELIC_NET_MAX_MTU 2308 35#define GELIC_NET_MAX_MTU VLAN_ETH_FRAME_LEN
45#define GELIC_NET_MIN_MTU 64 36#define GELIC_NET_MIN_MTU VLAN_ETH_ZLEN
46#define GELIC_NET_RXBUF_ALIGN 128 37#define GELIC_NET_RXBUF_ALIGN 128
47#define GELIC_NET_RX_CSUM_DEFAULT 1 /* hw chksum */ 38#define GELIC_NET_RX_CSUM_DEFAULT 1 /* hw chksum */
48#define GELIC_NET_WATCHDOG_TIMEOUT 5*HZ 39#define GELIC_NET_WATCHDOG_TIMEOUT 5*HZ
@@ -90,7 +81,8 @@ enum gelic_net_int1_status {
90 */ 81 */
91#define GELIC_NET_RXVLNPKT 0x00200000 /* VLAN packet */ 82#define GELIC_NET_RXVLNPKT 0x00200000 /* VLAN packet */
92/* bit 20..16 reserved */ 83/* bit 20..16 reserved */
93#define GELIC_NET_RXRECNUM 0x0000ff00 /* reception receipt number */ 84#define GELIC_NET_RXRRECNUM 0x0000ff00 /* reception receipt number */
85#define GELIC_NET_RXRRECNUM_SHIFT 8
94/* bit 7..0 reserved */ 86/* bit 7..0 reserved */
95 87
96#define GELIC_NET_TXDESC_TAIL 0 88#define GELIC_NET_TXDESC_TAIL 0
@@ -133,19 +125,19 @@ enum gelic_net_int1_status {
133 * interrupt status */ 125 * interrupt status */
134 126
135#define GELIC_NET_DMAC_CMDSTAT_CHAIN_END 0x00000002 /* RXDCEIS:DMA stopped */ 127#define GELIC_NET_DMAC_CMDSTAT_CHAIN_END 0x00000002 /* RXDCEIS:DMA stopped */
136#define GELIC_NET_DMAC_CMDSTAT_NOT_IN_USE 0xb0000000
137#define GELIC_NET_DESCR_IND_PROC_SHIFT 28 128#define GELIC_NET_DESCR_IND_PROC_SHIFT 28
138#define GELIC_NET_DESCR_IND_PROC_MASKO 0x0fffffff 129#define GELIC_NET_DESCR_IND_PROC_MASKO 0x0fffffff
139 130
140 131
141enum gelic_net_descr_status { 132enum gelic_net_descr_status {
142 GELIC_NET_DESCR_COMPLETE = 0x00, /* used in rx and tx */ 133 GELIC_NET_DESCR_COMPLETE = 0x00, /* used in tx */
134 GELIC_NET_DESCR_BUFFER_FULL = 0x00, /* used in rx */
143 GELIC_NET_DESCR_RESPONSE_ERROR = 0x01, /* used in rx and tx */ 135 GELIC_NET_DESCR_RESPONSE_ERROR = 0x01, /* used in rx and tx */
144 GELIC_NET_DESCR_PROTECTION_ERROR = 0x02, /* used in rx and tx */ 136 GELIC_NET_DESCR_PROTECTION_ERROR = 0x02, /* used in rx and tx */
145 GELIC_NET_DESCR_FRAME_END = 0x04, /* used in rx */ 137 GELIC_NET_DESCR_FRAME_END = 0x04, /* used in rx */
146 GELIC_NET_DESCR_FORCE_END = 0x05, /* used in rx and tx */ 138 GELIC_NET_DESCR_FORCE_END = 0x05, /* used in rx and tx */
147 GELIC_NET_DESCR_CARDOWNED = 0x0a, /* used in rx and tx */ 139 GELIC_NET_DESCR_CARDOWNED = 0x0a, /* used in rx and tx */
148 GELIC_NET_DESCR_NOT_IN_USE /* any other value */ 140 GELIC_NET_DESCR_NOT_IN_USE = 0x0b /* any other value */
149}; 141};
150/* for lv1_net_control */ 142/* for lv1_net_control */
151#define GELIC_NET_GET_MAC_ADDRESS 0x0000000000000001 143#define GELIC_NET_GET_MAC_ADDRESS 0x0000000000000001
@@ -216,10 +208,10 @@ struct gelic_net_card {
216 208
217 struct gelic_net_descr_chain tx_chain; 209 struct gelic_net_descr_chain tx_chain;
218 struct gelic_net_descr_chain rx_chain; 210 struct gelic_net_descr_chain rx_chain;
211 int rx_dma_restart_required;
219 /* gurad dmac descriptor chain*/ 212 /* gurad dmac descriptor chain*/
220 spinlock_t chain_lock; 213 spinlock_t chain_lock;
221 214
222 struct net_device_stats netdev_stats;
223 int rx_csum; 215 int rx_csum;
224 /* guard tx_dma_progress */ 216 /* guard tx_dma_progress */
225 spinlock_t tx_dma_lock; 217 spinlock_t tx_dma_lock;
diff --git a/drivers/net/ucc_geth.c b/drivers/net/ucc_geth.c
index e4736a3b1b7a..12e01b24105a 100644
--- a/drivers/net/ucc_geth.c
+++ b/drivers/net/ucc_geth.c
@@ -43,10 +43,6 @@
43 43
44#undef DEBUG 44#undef DEBUG
45 45
46#define DRV_DESC "QE UCC Gigabit Ethernet Controller"
47#define DRV_NAME "ucc_geth"
48#define DRV_VERSION "1.1"
49
50#define ugeth_printk(level, format, arg...) \ 46#define ugeth_printk(level, format, arg...) \
51 printk(level format "\n", ## arg) 47 printk(level format "\n", ## arg)
52 48
@@ -64,9 +60,19 @@
64#else 60#else
65#define ugeth_vdbg(fmt, args...) do { } while (0) 61#define ugeth_vdbg(fmt, args...) do { } while (0)
66#endif /* UGETH_VERBOSE_DEBUG */ 62#endif /* UGETH_VERBOSE_DEBUG */
63#define UGETH_MSG_DEFAULT (NETIF_MSG_IFUP << 1 ) - 1
67 64
65void uec_set_ethtool_ops(struct net_device *netdev);
66
68static DEFINE_SPINLOCK(ugeth_lock); 67static DEFINE_SPINLOCK(ugeth_lock);
69 68
69static struct {
70 u32 msg_enable;
71} debug = { -1 };
72
73module_param_named(debug, debug.msg_enable, int, 0);
74MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 0xffff=all)");
75
70static struct ucc_geth_info ugeth_primary_info = { 76static struct ucc_geth_info ugeth_primary_info = {
71 .uf_info = { 77 .uf_info = {
72 .bd_mem_part = MEM_PART_SYSTEM, 78 .bd_mem_part = MEM_PART_SYSTEM,
@@ -104,6 +110,7 @@ static struct ucc_geth_info ugeth_primary_info = {
104 .maxRetransmission = 0xf, 110 .maxRetransmission = 0xf,
105 .collisionWindow = 0x37, 111 .collisionWindow = 0x37,
106 .receiveFlowControl = 1, 112 .receiveFlowControl = 1,
113 .transmitFlowControl = 1,
107 .maxGroupAddrInHash = 4, 114 .maxGroupAddrInHash = 4,
108 .maxIndAddrInHash = 4, 115 .maxIndAddrInHash = 4,
109 .prel = 7, 116 .prel = 7,
@@ -139,7 +146,9 @@ static struct ucc_geth_info ugeth_primary_info = {
139 .numStationAddresses = UCC_GETH_NUM_OF_STATION_ADDRESSES_1, 146 .numStationAddresses = UCC_GETH_NUM_OF_STATION_ADDRESSES_1,
140 .largestexternallookupkeysize = 147 .largestexternallookupkeysize =
141 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_NONE, 148 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_NONE,
142 .statisticsMode = UCC_GETH_STATISTICS_GATHERING_MODE_NONE, 149 .statisticsMode = UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE |
150 UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX |
151 UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX,
143 .vlanOperationTagged = UCC_GETH_VLAN_OPERATION_TAGGED_NOP, 152 .vlanOperationTagged = UCC_GETH_VLAN_OPERATION_TAGGED_NOP,
144 .vlanOperationNonTagged = UCC_GETH_VLAN_OPERATION_NON_TAGGED_NOP, 153 .vlanOperationNonTagged = UCC_GETH_VLAN_OPERATION_NON_TAGGED_NOP,
145 .rxQoSMode = UCC_GETH_QOS_MODE_DEFAULT, 154 .rxQoSMode = UCC_GETH_QOS_MODE_DEFAULT,
@@ -281,7 +290,8 @@ static int fill_init_enet_entries(struct ucc_geth_private *ugeth,
281 290
282 for (i = 0; i < num_entries; i++) { 291 for (i = 0; i < num_entries; i++) {
283 if ((snum = qe_get_snum()) < 0) { 292 if ((snum = qe_get_snum()) < 0) {
284 ugeth_err("fill_init_enet_entries: Can not get SNUM."); 293 if (netif_msg_ifup(ugeth))
294 ugeth_err("fill_init_enet_entries: Can not get SNUM.");
285 return snum; 295 return snum;
286 } 296 }
287 if ((i == 0) && skip_page_for_first_entry) 297 if ((i == 0) && skip_page_for_first_entry)
@@ -291,8 +301,8 @@ static int fill_init_enet_entries(struct ucc_geth_private *ugeth,
291 init_enet_offset = 301 init_enet_offset =
292 qe_muram_alloc(thread_size, thread_alignment); 302 qe_muram_alloc(thread_size, thread_alignment);
293 if (IS_ERR_VALUE(init_enet_offset)) { 303 if (IS_ERR_VALUE(init_enet_offset)) {
294 ugeth_err 304 if (netif_msg_ifup(ugeth))
295 ("fill_init_enet_entries: Can not allocate DPRAM memory."); 305 ugeth_err("fill_init_enet_entries: Can not allocate DPRAM memory.");
296 qe_put_snum((u8) snum); 306 qe_put_snum((u8) snum);
297 return -ENOMEM; 307 return -ENOMEM;
298 } 308 }
@@ -1200,7 +1210,7 @@ static int init_inter_frame_gap_params(u8 non_btb_cs_ipg,
1200 return 0; 1210 return 0;
1201} 1211}
1202 1212
1203static int init_flow_control_params(u32 automatic_flow_control_mode, 1213int init_flow_control_params(u32 automatic_flow_control_mode,
1204 int rx_flow_control_enable, 1214 int rx_flow_control_enable,
1205 int tx_flow_control_enable, 1215 int tx_flow_control_enable,
1206 u16 pause_period, 1216 u16 pause_period,
@@ -1486,9 +1496,9 @@ static int adjust_enet_interface(struct ucc_geth_private *ugeth)
1486 1496
1487 ret_val = init_preamble_length(ug_info->prel, &ug_regs->maccfg2); 1497 ret_val = init_preamble_length(ug_info->prel, &ug_regs->maccfg2);
1488 if (ret_val != 0) { 1498 if (ret_val != 0) {
1489 ugeth_err 1499 if (netif_msg_probe(ugeth))
1490 ("%s: Preamble length must be between 3 and 7 inclusive.", 1500 ugeth_err("%s: Preamble length must be between 3 and 7 inclusive.",
1491 __FUNCTION__); 1501 __FUNCTION__);
1492 return ret_val; 1502 return ret_val;
1493 } 1503 }
1494 1504
@@ -1726,7 +1736,8 @@ static int ugeth_enable(struct ucc_geth_private *ugeth, enum comm_dir mode)
1726 1736
1727 /* check if the UCC number is in range. */ 1737 /* check if the UCC number is in range. */
1728 if (ugeth->ug_info->uf_info.ucc_num >= UCC_MAX_NUM) { 1738 if (ugeth->ug_info->uf_info.ucc_num >= UCC_MAX_NUM) {
1729 ugeth_err("%s: ucc_num out of range.", __FUNCTION__); 1739 if (netif_msg_probe(ugeth))
1740 ugeth_err("%s: ucc_num out of range.", __FUNCTION__);
1730 return -EINVAL; 1741 return -EINVAL;
1731 } 1742 }
1732 1743
@@ -1754,7 +1765,8 @@ static int ugeth_disable(struct ucc_geth_private * ugeth, enum comm_dir mode)
1754 1765
1755 /* check if the UCC number is in range. */ 1766 /* check if the UCC number is in range. */
1756 if (ugeth->ug_info->uf_info.ucc_num >= UCC_MAX_NUM) { 1767 if (ugeth->ug_info->uf_info.ucc_num >= UCC_MAX_NUM) {
1757 ugeth_err("%s: ucc_num out of range.", __FUNCTION__); 1768 if (netif_msg_probe(ugeth))
1769 ugeth_err("%s: ucc_num out of range.", __FUNCTION__);
1758 return -EINVAL; 1770 return -EINVAL;
1759 } 1771 }
1760 1772
@@ -2306,7 +2318,9 @@ static int ucc_struct_init(struct ucc_geth_private *ugeth)
2306 2318
2307 if (!((uf_info->bd_mem_part == MEM_PART_SYSTEM) || 2319 if (!((uf_info->bd_mem_part == MEM_PART_SYSTEM) ||
2308 (uf_info->bd_mem_part == MEM_PART_MURAM))) { 2320 (uf_info->bd_mem_part == MEM_PART_MURAM))) {
2309 ugeth_err("%s: Bad memory partition value.", __FUNCTION__); 2321 if (netif_msg_probe(ugeth))
2322 ugeth_err("%s: Bad memory partition value.",
2323 __FUNCTION__);
2310 return -EINVAL; 2324 return -EINVAL;
2311 } 2325 }
2312 2326
@@ -2315,9 +2329,10 @@ static int ucc_struct_init(struct ucc_geth_private *ugeth)
2315 if ((ug_info->bdRingLenRx[i] < UCC_GETH_RX_BD_RING_SIZE_MIN) || 2329 if ((ug_info->bdRingLenRx[i] < UCC_GETH_RX_BD_RING_SIZE_MIN) ||
2316 (ug_info->bdRingLenRx[i] % 2330 (ug_info->bdRingLenRx[i] %
2317 UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT)) { 2331 UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT)) {
2318 ugeth_err 2332 if (netif_msg_probe(ugeth))
2319 ("%s: Rx BD ring length must be multiple of 4," 2333 ugeth_err
2320 " no smaller than 8.", __FUNCTION__); 2334 ("%s: Rx BD ring length must be multiple of 4, no smaller than 8.",
2335 __FUNCTION__);
2321 return -EINVAL; 2336 return -EINVAL;
2322 } 2337 }
2323 } 2338 }
@@ -2325,9 +2340,10 @@ static int ucc_struct_init(struct ucc_geth_private *ugeth)
2325 /* Tx BD lengths */ 2340 /* Tx BD lengths */
2326 for (i = 0; i < ug_info->numQueuesTx; i++) { 2341 for (i = 0; i < ug_info->numQueuesTx; i++) {
2327 if (ug_info->bdRingLenTx[i] < UCC_GETH_TX_BD_RING_SIZE_MIN) { 2342 if (ug_info->bdRingLenTx[i] < UCC_GETH_TX_BD_RING_SIZE_MIN) {
2328 ugeth_err 2343 if (netif_msg_probe(ugeth))
2329 ("%s: Tx BD ring length must be no smaller than 2.", 2344 ugeth_err
2330 __FUNCTION__); 2345 ("%s: Tx BD ring length must be no smaller than 2.",
2346 __FUNCTION__);
2331 return -EINVAL; 2347 return -EINVAL;
2332 } 2348 }
2333 } 2349 }
@@ -2335,31 +2351,35 @@ static int ucc_struct_init(struct ucc_geth_private *ugeth)
2335 /* mrblr */ 2351 /* mrblr */
2336 if ((uf_info->max_rx_buf_length == 0) || 2352 if ((uf_info->max_rx_buf_length == 0) ||
2337 (uf_info->max_rx_buf_length % UCC_GETH_MRBLR_ALIGNMENT)) { 2353 (uf_info->max_rx_buf_length % UCC_GETH_MRBLR_ALIGNMENT)) {
2338 ugeth_err 2354 if (netif_msg_probe(ugeth))
2339 ("%s: max_rx_buf_length must be non-zero multiple of 128.", 2355 ugeth_err
2340 __FUNCTION__); 2356 ("%s: max_rx_buf_length must be non-zero multiple of 128.",
2357 __FUNCTION__);
2341 return -EINVAL; 2358 return -EINVAL;
2342 } 2359 }
2343 2360
2344 /* num Tx queues */ 2361 /* num Tx queues */
2345 if (ug_info->numQueuesTx > NUM_TX_QUEUES) { 2362 if (ug_info->numQueuesTx > NUM_TX_QUEUES) {
2346 ugeth_err("%s: number of tx queues too large.", __FUNCTION__); 2363 if (netif_msg_probe(ugeth))
2364 ugeth_err("%s: number of tx queues too large.", __FUNCTION__);
2347 return -EINVAL; 2365 return -EINVAL;
2348 } 2366 }
2349 2367
2350 /* num Rx queues */ 2368 /* num Rx queues */
2351 if (ug_info->numQueuesRx > NUM_RX_QUEUES) { 2369 if (ug_info->numQueuesRx > NUM_RX_QUEUES) {
2352 ugeth_err("%s: number of rx queues too large.", __FUNCTION__); 2370 if (netif_msg_probe(ugeth))
2371 ugeth_err("%s: number of rx queues too large.", __FUNCTION__);
2353 return -EINVAL; 2372 return -EINVAL;
2354 } 2373 }
2355 2374
2356 /* l2qt */ 2375 /* l2qt */
2357 for (i = 0; i < UCC_GETH_VLAN_PRIORITY_MAX; i++) { 2376 for (i = 0; i < UCC_GETH_VLAN_PRIORITY_MAX; i++) {
2358 if (ug_info->l2qt[i] >= ug_info->numQueuesRx) { 2377 if (ug_info->l2qt[i] >= ug_info->numQueuesRx) {
2359 ugeth_err 2378 if (netif_msg_probe(ugeth))
2360 ("%s: VLAN priority table entry must not be" 2379 ugeth_err
2361 " larger than number of Rx queues.", 2380 ("%s: VLAN priority table entry must not be"
2362 __FUNCTION__); 2381 " larger than number of Rx queues.",
2382 __FUNCTION__);
2363 return -EINVAL; 2383 return -EINVAL;
2364 } 2384 }
2365 } 2385 }
@@ -2367,26 +2387,29 @@ static int ucc_struct_init(struct ucc_geth_private *ugeth)
2367 /* l3qt */ 2387 /* l3qt */
2368 for (i = 0; i < UCC_GETH_IP_PRIORITY_MAX; i++) { 2388 for (i = 0; i < UCC_GETH_IP_PRIORITY_MAX; i++) {
2369 if (ug_info->l3qt[i] >= ug_info->numQueuesRx) { 2389 if (ug_info->l3qt[i] >= ug_info->numQueuesRx) {
2370 ugeth_err 2390 if (netif_msg_probe(ugeth))
2371 ("%s: IP priority table entry must not be" 2391 ugeth_err
2372 " larger than number of Rx queues.", 2392 ("%s: IP priority table entry must not be"
2373 __FUNCTION__); 2393 " larger than number of Rx queues.",
2394 __FUNCTION__);
2374 return -EINVAL; 2395 return -EINVAL;
2375 } 2396 }
2376 } 2397 }
2377 2398
2378 if (ug_info->cam && !ug_info->ecamptr) { 2399 if (ug_info->cam && !ug_info->ecamptr) {
2379 ugeth_err("%s: If cam mode is chosen, must supply cam ptr.", 2400 if (netif_msg_probe(ugeth))
2380 __FUNCTION__); 2401 ugeth_err("%s: If cam mode is chosen, must supply cam ptr.",
2402 __FUNCTION__);
2381 return -EINVAL; 2403 return -EINVAL;
2382 } 2404 }
2383 2405
2384 if ((ug_info->numStationAddresses != 2406 if ((ug_info->numStationAddresses !=
2385 UCC_GETH_NUM_OF_STATION_ADDRESSES_1) 2407 UCC_GETH_NUM_OF_STATION_ADDRESSES_1)
2386 && ug_info->rxExtendedFiltering) { 2408 && ug_info->rxExtendedFiltering) {
2387 ugeth_err("%s: Number of station addresses greater than 1 " 2409 if (netif_msg_probe(ugeth))
2388 "not allowed in extended parsing mode.", 2410 ugeth_err("%s: Number of station addresses greater than 1 "
2389 __FUNCTION__); 2411 "not allowed in extended parsing mode.",
2412 __FUNCTION__);
2390 return -EINVAL; 2413 return -EINVAL;
2391 } 2414 }
2392 2415
@@ -2399,7 +2422,8 @@ static int ucc_struct_init(struct ucc_geth_private *ugeth)
2399 uf_info->uccm_mask |= (UCCE_TXBF_SINGLE_MASK << i); 2422 uf_info->uccm_mask |= (UCCE_TXBF_SINGLE_MASK << i);
2400 /* Initialize the general fast UCC block. */ 2423 /* Initialize the general fast UCC block. */
2401 if (ucc_fast_init(uf_info, &ugeth->uccf)) { 2424 if (ucc_fast_init(uf_info, &ugeth->uccf)) {
2402 ugeth_err("%s: Failed to init uccf.", __FUNCTION__); 2425 if (netif_msg_probe(ugeth))
2426 ugeth_err("%s: Failed to init uccf.", __FUNCTION__);
2403 ucc_geth_memclean(ugeth); 2427 ucc_geth_memclean(ugeth);
2404 return -ENOMEM; 2428 return -ENOMEM;
2405 } 2429 }
@@ -2452,7 +2476,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2452 numThreadsRxNumerical = 8; 2476 numThreadsRxNumerical = 8;
2453 break; 2477 break;
2454 default: 2478 default:
2455 ugeth_err("%s: Bad number of Rx threads value.", __FUNCTION__); 2479 if (netif_msg_ifup(ugeth))
2480 ugeth_err("%s: Bad number of Rx threads value.",
2481 __FUNCTION__);
2456 ucc_geth_memclean(ugeth); 2482 ucc_geth_memclean(ugeth);
2457 return -EINVAL; 2483 return -EINVAL;
2458 break; 2484 break;
@@ -2475,7 +2501,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2475 numThreadsTxNumerical = 8; 2501 numThreadsTxNumerical = 8;
2476 break; 2502 break;
2477 default: 2503 default:
2478 ugeth_err("%s: Bad number of Tx threads value.", __FUNCTION__); 2504 if (netif_msg_ifup(ugeth))
2505 ugeth_err("%s: Bad number of Tx threads value.",
2506 __FUNCTION__);
2479 ucc_geth_memclean(ugeth); 2507 ucc_geth_memclean(ugeth);
2480 return -EINVAL; 2508 return -EINVAL;
2481 break; 2509 break;
@@ -2507,7 +2535,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2507 /* For more details see the hardware spec. */ 2535 /* For more details see the hardware spec. */
2508 init_flow_control_params(ug_info->aufc, 2536 init_flow_control_params(ug_info->aufc,
2509 ug_info->receiveFlowControl, 2537 ug_info->receiveFlowControl,
2510 1, 2538 ug_info->transmitFlowControl,
2511 ug_info->pausePeriod, 2539 ug_info->pausePeriod,
2512 ug_info->extensionField, 2540 ug_info->extensionField,
2513 &uf_regs->upsmr, 2541 &uf_regs->upsmr,
@@ -2527,8 +2555,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2527 ug_info->backToBackInterFrameGap, 2555 ug_info->backToBackInterFrameGap,
2528 &ug_regs->ipgifg); 2556 &ug_regs->ipgifg);
2529 if (ret_val != 0) { 2557 if (ret_val != 0) {
2530 ugeth_err("%s: IPGIFG initialization parameter too large.", 2558 if (netif_msg_ifup(ugeth))
2531 __FUNCTION__); 2559 ugeth_err("%s: IPGIFG initialization parameter too large.",
2560 __FUNCTION__);
2532 ucc_geth_memclean(ugeth); 2561 ucc_geth_memclean(ugeth);
2533 return ret_val; 2562 return ret_val;
2534 } 2563 }
@@ -2544,7 +2573,8 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2544 ug_info->collisionWindow, 2573 ug_info->collisionWindow,
2545 &ug_regs->hafdup); 2574 &ug_regs->hafdup);
2546 if (ret_val != 0) { 2575 if (ret_val != 0) {
2547 ugeth_err("%s: Half Duplex initialization parameter too large.", 2576 if (netif_msg_ifup(ugeth))
2577 ugeth_err("%s: Half Duplex initialization parameter too large.",
2548 __FUNCTION__); 2578 __FUNCTION__);
2549 ucc_geth_memclean(ugeth); 2579 ucc_geth_memclean(ugeth);
2550 return ret_val; 2580 return ret_val;
@@ -2597,9 +2627,10 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2597 tx_bd_ring_offset[j]); 2627 tx_bd_ring_offset[j]);
2598 } 2628 }
2599 if (!ugeth->p_tx_bd_ring[j]) { 2629 if (!ugeth->p_tx_bd_ring[j]) {
2600 ugeth_err 2630 if (netif_msg_ifup(ugeth))
2601 ("%s: Can not allocate memory for Tx bd rings.", 2631 ugeth_err
2602 __FUNCTION__); 2632 ("%s: Can not allocate memory for Tx bd rings.",
2633 __FUNCTION__);
2603 ucc_geth_memclean(ugeth); 2634 ucc_geth_memclean(ugeth);
2604 return -ENOMEM; 2635 return -ENOMEM;
2605 } 2636 }
@@ -2632,9 +2663,10 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2632 rx_bd_ring_offset[j]); 2663 rx_bd_ring_offset[j]);
2633 } 2664 }
2634 if (!ugeth->p_rx_bd_ring[j]) { 2665 if (!ugeth->p_rx_bd_ring[j]) {
2635 ugeth_err 2666 if (netif_msg_ifup(ugeth))
2636 ("%s: Can not allocate memory for Rx bd rings.", 2667 ugeth_err
2637 __FUNCTION__); 2668 ("%s: Can not allocate memory for Rx bd rings.",
2669 __FUNCTION__);
2638 ucc_geth_memclean(ugeth); 2670 ucc_geth_memclean(ugeth);
2639 return -ENOMEM; 2671 return -ENOMEM;
2640 } 2672 }
@@ -2648,8 +2680,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2648 GFP_KERNEL); 2680 GFP_KERNEL);
2649 2681
2650 if (ugeth->tx_skbuff[j] == NULL) { 2682 if (ugeth->tx_skbuff[j] == NULL) {
2651 ugeth_err("%s: Could not allocate tx_skbuff", 2683 if (netif_msg_ifup(ugeth))
2652 __FUNCTION__); 2684 ugeth_err("%s: Could not allocate tx_skbuff",
2685 __FUNCTION__);
2653 ucc_geth_memclean(ugeth); 2686 ucc_geth_memclean(ugeth);
2654 return -ENOMEM; 2687 return -ENOMEM;
2655 } 2688 }
@@ -2679,8 +2712,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2679 GFP_KERNEL); 2712 GFP_KERNEL);
2680 2713
2681 if (ugeth->rx_skbuff[j] == NULL) { 2714 if (ugeth->rx_skbuff[j] == NULL) {
2682 ugeth_err("%s: Could not allocate rx_skbuff", 2715 if (netif_msg_ifup(ugeth))
2683 __FUNCTION__); 2716 ugeth_err("%s: Could not allocate rx_skbuff",
2717 __FUNCTION__);
2684 ucc_geth_memclean(ugeth); 2718 ucc_geth_memclean(ugeth);
2685 return -ENOMEM; 2719 return -ENOMEM;
2686 } 2720 }
@@ -2711,9 +2745,10 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2711 qe_muram_alloc(sizeof(struct ucc_geth_tx_global_pram), 2745 qe_muram_alloc(sizeof(struct ucc_geth_tx_global_pram),
2712 UCC_GETH_TX_GLOBAL_PRAM_ALIGNMENT); 2746 UCC_GETH_TX_GLOBAL_PRAM_ALIGNMENT);
2713 if (IS_ERR_VALUE(ugeth->tx_glbl_pram_offset)) { 2747 if (IS_ERR_VALUE(ugeth->tx_glbl_pram_offset)) {
2714 ugeth_err 2748 if (netif_msg_ifup(ugeth))
2715 ("%s: Can not allocate DPRAM memory for p_tx_glbl_pram.", 2749 ugeth_err
2716 __FUNCTION__); 2750 ("%s: Can not allocate DPRAM memory for p_tx_glbl_pram.",
2751 __FUNCTION__);
2717 ucc_geth_memclean(ugeth); 2752 ucc_geth_memclean(ugeth);
2718 return -ENOMEM; 2753 return -ENOMEM;
2719 } 2754 }
@@ -2733,9 +2768,10 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2733 32 * (numThreadsTxNumerical == 1), 2768 32 * (numThreadsTxNumerical == 1),
2734 UCC_GETH_THREAD_DATA_ALIGNMENT); 2769 UCC_GETH_THREAD_DATA_ALIGNMENT);
2735 if (IS_ERR_VALUE(ugeth->thread_dat_tx_offset)) { 2770 if (IS_ERR_VALUE(ugeth->thread_dat_tx_offset)) {
2736 ugeth_err 2771 if (netif_msg_ifup(ugeth))
2737 ("%s: Can not allocate DPRAM memory for p_thread_data_tx.", 2772 ugeth_err
2738 __FUNCTION__); 2773 ("%s: Can not allocate DPRAM memory for p_thread_data_tx.",
2774 __FUNCTION__);
2739 ucc_geth_memclean(ugeth); 2775 ucc_geth_memclean(ugeth);
2740 return -ENOMEM; 2776 return -ENOMEM;
2741 } 2777 }
@@ -2761,9 +2797,10 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2761 sizeof(struct ucc_geth_send_queue_qd), 2797 sizeof(struct ucc_geth_send_queue_qd),
2762 UCC_GETH_SEND_QUEUE_QUEUE_DESCRIPTOR_ALIGNMENT); 2798 UCC_GETH_SEND_QUEUE_QUEUE_DESCRIPTOR_ALIGNMENT);
2763 if (IS_ERR_VALUE(ugeth->send_q_mem_reg_offset)) { 2799 if (IS_ERR_VALUE(ugeth->send_q_mem_reg_offset)) {
2764 ugeth_err 2800 if (netif_msg_ifup(ugeth))
2765 ("%s: Can not allocate DPRAM memory for p_send_q_mem_reg.", 2801 ugeth_err
2766 __FUNCTION__); 2802 ("%s: Can not allocate DPRAM memory for p_send_q_mem_reg.",
2803 __FUNCTION__);
2767 ucc_geth_memclean(ugeth); 2804 ucc_geth_memclean(ugeth);
2768 return -ENOMEM; 2805 return -ENOMEM;
2769 } 2806 }
@@ -2804,9 +2841,10 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2804 qe_muram_alloc(sizeof(struct ucc_geth_scheduler), 2841 qe_muram_alloc(sizeof(struct ucc_geth_scheduler),
2805 UCC_GETH_SCHEDULER_ALIGNMENT); 2842 UCC_GETH_SCHEDULER_ALIGNMENT);
2806 if (IS_ERR_VALUE(ugeth->scheduler_offset)) { 2843 if (IS_ERR_VALUE(ugeth->scheduler_offset)) {
2807 ugeth_err 2844 if (netif_msg_ifup(ugeth))
2808 ("%s: Can not allocate DPRAM memory for p_scheduler.", 2845 ugeth_err
2809 __FUNCTION__); 2846 ("%s: Can not allocate DPRAM memory for p_scheduler.",
2847 __FUNCTION__);
2810 ucc_geth_memclean(ugeth); 2848 ucc_geth_memclean(ugeth);
2811 return -ENOMEM; 2849 return -ENOMEM;
2812 } 2850 }
@@ -2852,9 +2890,11 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2852 (struct ucc_geth_tx_firmware_statistics_pram), 2890 (struct ucc_geth_tx_firmware_statistics_pram),
2853 UCC_GETH_TX_STATISTICS_ALIGNMENT); 2891 UCC_GETH_TX_STATISTICS_ALIGNMENT);
2854 if (IS_ERR_VALUE(ugeth->tx_fw_statistics_pram_offset)) { 2892 if (IS_ERR_VALUE(ugeth->tx_fw_statistics_pram_offset)) {
2855 ugeth_err 2893 if (netif_msg_ifup(ugeth))
2856 ("%s: Can not allocate DPRAM memory for" 2894 ugeth_err
2857 " p_tx_fw_statistics_pram.", __FUNCTION__); 2895 ("%s: Can not allocate DPRAM memory for"
2896 " p_tx_fw_statistics_pram.",
2897 __FUNCTION__);
2858 ucc_geth_memclean(ugeth); 2898 ucc_geth_memclean(ugeth);
2859 return -ENOMEM; 2899 return -ENOMEM;
2860 } 2900 }
@@ -2891,9 +2931,10 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2891 qe_muram_alloc(sizeof(struct ucc_geth_rx_global_pram), 2931 qe_muram_alloc(sizeof(struct ucc_geth_rx_global_pram),
2892 UCC_GETH_RX_GLOBAL_PRAM_ALIGNMENT); 2932 UCC_GETH_RX_GLOBAL_PRAM_ALIGNMENT);
2893 if (IS_ERR_VALUE(ugeth->rx_glbl_pram_offset)) { 2933 if (IS_ERR_VALUE(ugeth->rx_glbl_pram_offset)) {
2894 ugeth_err 2934 if (netif_msg_ifup(ugeth))
2895 ("%s: Can not allocate DPRAM memory for p_rx_glbl_pram.", 2935 ugeth_err
2896 __FUNCTION__); 2936 ("%s: Can not allocate DPRAM memory for p_rx_glbl_pram.",
2937 __FUNCTION__);
2897 ucc_geth_memclean(ugeth); 2938 ucc_geth_memclean(ugeth);
2898 return -ENOMEM; 2939 return -ENOMEM;
2899 } 2940 }
@@ -2912,9 +2953,10 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2912 sizeof(struct ucc_geth_thread_data_rx), 2953 sizeof(struct ucc_geth_thread_data_rx),
2913 UCC_GETH_THREAD_DATA_ALIGNMENT); 2954 UCC_GETH_THREAD_DATA_ALIGNMENT);
2914 if (IS_ERR_VALUE(ugeth->thread_dat_rx_offset)) { 2955 if (IS_ERR_VALUE(ugeth->thread_dat_rx_offset)) {
2915 ugeth_err 2956 if (netif_msg_ifup(ugeth))
2916 ("%s: Can not allocate DPRAM memory for p_thread_data_rx.", 2957 ugeth_err
2917 __FUNCTION__); 2958 ("%s: Can not allocate DPRAM memory for p_thread_data_rx.",
2959 __FUNCTION__);
2918 ucc_geth_memclean(ugeth); 2960 ucc_geth_memclean(ugeth);
2919 return -ENOMEM; 2961 return -ENOMEM;
2920 } 2962 }
@@ -2935,9 +2977,10 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2935 (struct ucc_geth_rx_firmware_statistics_pram), 2977 (struct ucc_geth_rx_firmware_statistics_pram),
2936 UCC_GETH_RX_STATISTICS_ALIGNMENT); 2978 UCC_GETH_RX_STATISTICS_ALIGNMENT);
2937 if (IS_ERR_VALUE(ugeth->rx_fw_statistics_pram_offset)) { 2979 if (IS_ERR_VALUE(ugeth->rx_fw_statistics_pram_offset)) {
2938 ugeth_err 2980 if (netif_msg_ifup(ugeth))
2939 ("%s: Can not allocate DPRAM memory for" 2981 ugeth_err
2940 " p_rx_fw_statistics_pram.", __FUNCTION__); 2982 ("%s: Can not allocate DPRAM memory for"
2983 " p_rx_fw_statistics_pram.", __FUNCTION__);
2941 ucc_geth_memclean(ugeth); 2984 ucc_geth_memclean(ugeth);
2942 return -ENOMEM; 2985 return -ENOMEM;
2943 } 2986 }
@@ -2957,9 +3000,10 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2957 sizeof(struct ucc_geth_rx_interrupt_coalescing_entry) 3000 sizeof(struct ucc_geth_rx_interrupt_coalescing_entry)
2958 + 4, UCC_GETH_RX_INTERRUPT_COALESCING_ALIGNMENT); 3001 + 4, UCC_GETH_RX_INTERRUPT_COALESCING_ALIGNMENT);
2959 if (IS_ERR_VALUE(ugeth->rx_irq_coalescing_tbl_offset)) { 3002 if (IS_ERR_VALUE(ugeth->rx_irq_coalescing_tbl_offset)) {
2960 ugeth_err 3003 if (netif_msg_ifup(ugeth))
2961 ("%s: Can not allocate DPRAM memory for" 3004 ugeth_err
2962 " p_rx_irq_coalescing_tbl.", __FUNCTION__); 3005 ("%s: Can not allocate DPRAM memory for"
3006 " p_rx_irq_coalescing_tbl.", __FUNCTION__);
2963 ucc_geth_memclean(ugeth); 3007 ucc_geth_memclean(ugeth);
2964 return -ENOMEM; 3008 return -ENOMEM;
2965 } 3009 }
@@ -3025,9 +3069,10 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
3025 sizeof(struct ucc_geth_rx_prefetched_bds)), 3069 sizeof(struct ucc_geth_rx_prefetched_bds)),
3026 UCC_GETH_RX_BD_QUEUES_ALIGNMENT); 3070 UCC_GETH_RX_BD_QUEUES_ALIGNMENT);
3027 if (IS_ERR_VALUE(ugeth->rx_bd_qs_tbl_offset)) { 3071 if (IS_ERR_VALUE(ugeth->rx_bd_qs_tbl_offset)) {
3028 ugeth_err 3072 if (netif_msg_ifup(ugeth))
3029 ("%s: Can not allocate DPRAM memory for p_rx_bd_qs_tbl.", 3073 ugeth_err
3030 __FUNCTION__); 3074 ("%s: Can not allocate DPRAM memory for p_rx_bd_qs_tbl.",
3075 __FUNCTION__);
3031 ucc_geth_memclean(ugeth); 3076 ucc_geth_memclean(ugeth);
3032 return -ENOMEM; 3077 return -ENOMEM;
3033 } 3078 }
@@ -3102,8 +3147,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
3102 /* initialize extended filtering */ 3147 /* initialize extended filtering */
3103 if (ug_info->rxExtendedFiltering) { 3148 if (ug_info->rxExtendedFiltering) {
3104 if (!ug_info->extendedFilteringChainPointer) { 3149 if (!ug_info->extendedFilteringChainPointer) {
3105 ugeth_err("%s: Null Extended Filtering Chain Pointer.", 3150 if (netif_msg_ifup(ugeth))
3106 __FUNCTION__); 3151 ugeth_err("%s: Null Extended Filtering Chain Pointer.",
3152 __FUNCTION__);
3107 ucc_geth_memclean(ugeth); 3153 ucc_geth_memclean(ugeth);
3108 return -EINVAL; 3154 return -EINVAL;
3109 } 3155 }
@@ -3114,9 +3160,10 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
3114 qe_muram_alloc(sizeof(struct ucc_geth_exf_global_pram), 3160 qe_muram_alloc(sizeof(struct ucc_geth_exf_global_pram),
3115 UCC_GETH_RX_EXTENDED_FILTERING_GLOBAL_PARAMETERS_ALIGNMENT); 3161 UCC_GETH_RX_EXTENDED_FILTERING_GLOBAL_PARAMETERS_ALIGNMENT);
3116 if (IS_ERR_VALUE(ugeth->exf_glbl_param_offset)) { 3162 if (IS_ERR_VALUE(ugeth->exf_glbl_param_offset)) {
3117 ugeth_err 3163 if (netif_msg_ifup(ugeth))
3118 ("%s: Can not allocate DPRAM memory for" 3164 ugeth_err
3119 " p_exf_glbl_param.", __FUNCTION__); 3165 ("%s: Can not allocate DPRAM memory for"
3166 " p_exf_glbl_param.", __FUNCTION__);
3120 ucc_geth_memclean(ugeth); 3167 ucc_geth_memclean(ugeth);
3121 return -ENOMEM; 3168 return -ENOMEM;
3122 } 3169 }
@@ -3161,9 +3208,10 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
3161 */ 3208 */
3162 if (!(ugeth->p_init_enet_param_shadow = 3209 if (!(ugeth->p_init_enet_param_shadow =
3163 kmalloc(sizeof(struct ucc_geth_init_pram), GFP_KERNEL))) { 3210 kmalloc(sizeof(struct ucc_geth_init_pram), GFP_KERNEL))) {
3164 ugeth_err 3211 if (netif_msg_ifup(ugeth))
3165 ("%s: Can not allocate memory for" 3212 ugeth_err
3166 " p_UccInitEnetParamShadows.", __FUNCTION__); 3213 ("%s: Can not allocate memory for"
3214 " p_UccInitEnetParamShadows.", __FUNCTION__);
3167 ucc_geth_memclean(ugeth); 3215 ucc_geth_memclean(ugeth);
3168 return -ENOMEM; 3216 return -ENOMEM;
3169 } 3217 }
@@ -3196,8 +3244,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
3196 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_8_BYTES) 3244 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_8_BYTES)
3197 && (ug_info->largestexternallookupkeysize != 3245 && (ug_info->largestexternallookupkeysize !=
3198 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_16_BYTES)) { 3246 QE_FLTR_LARGEST_EXTERNAL_TABLE_LOOKUP_KEY_SIZE_16_BYTES)) {
3199 ugeth_err("%s: Invalid largest External Lookup Key Size.", 3247 if (netif_msg_ifup(ugeth))
3200 __FUNCTION__); 3248 ugeth_err("%s: Invalid largest External Lookup Key Size.",
3249 __FUNCTION__);
3201 ucc_geth_memclean(ugeth); 3250 ucc_geth_memclean(ugeth);
3202 return -EINVAL; 3251 return -EINVAL;
3203 } 3252 }
@@ -3222,8 +3271,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
3222 /* Rx needs one extra for terminator */ 3271 /* Rx needs one extra for terminator */
3223 , size, UCC_GETH_THREAD_RX_PRAM_ALIGNMENT, 3272 , size, UCC_GETH_THREAD_RX_PRAM_ALIGNMENT,
3224 ug_info->riscRx, 1)) != 0) { 3273 ug_info->riscRx, 1)) != 0) {
3225 ugeth_err("%s: Can not fill p_init_enet_param_shadow.", 3274 if (netif_msg_ifup(ugeth))
3226 __FUNCTION__); 3275 ugeth_err("%s: Can not fill p_init_enet_param_shadow.",
3276 __FUNCTION__);
3227 ucc_geth_memclean(ugeth); 3277 ucc_geth_memclean(ugeth);
3228 return ret_val; 3278 return ret_val;
3229 } 3279 }
@@ -3237,8 +3287,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
3237 sizeof(struct ucc_geth_thread_tx_pram), 3287 sizeof(struct ucc_geth_thread_tx_pram),
3238 UCC_GETH_THREAD_TX_PRAM_ALIGNMENT, 3288 UCC_GETH_THREAD_TX_PRAM_ALIGNMENT,
3239 ug_info->riscTx, 0)) != 0) { 3289 ug_info->riscTx, 0)) != 0) {
3240 ugeth_err("%s: Can not fill p_init_enet_param_shadow.", 3290 if (netif_msg_ifup(ugeth))
3241 __FUNCTION__); 3291 ugeth_err("%s: Can not fill p_init_enet_param_shadow.",
3292 __FUNCTION__);
3242 ucc_geth_memclean(ugeth); 3293 ucc_geth_memclean(ugeth);
3243 return ret_val; 3294 return ret_val;
3244 } 3295 }
@@ -3246,8 +3297,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
3246 /* Load Rx bds with buffers */ 3297 /* Load Rx bds with buffers */
3247 for (i = 0; i < ug_info->numQueuesRx; i++) { 3298 for (i = 0; i < ug_info->numQueuesRx; i++) {
3248 if ((ret_val = rx_bd_buffer_set(ugeth, (u8) i)) != 0) { 3299 if ((ret_val = rx_bd_buffer_set(ugeth, (u8) i)) != 0) {
3249 ugeth_err("%s: Can not fill Rx bds with buffers.", 3300 if (netif_msg_ifup(ugeth))
3250 __FUNCTION__); 3301 ugeth_err("%s: Can not fill Rx bds with buffers.",
3302 __FUNCTION__);
3251 ucc_geth_memclean(ugeth); 3303 ucc_geth_memclean(ugeth);
3252 return ret_val; 3304 return ret_val;
3253 } 3305 }
@@ -3256,9 +3308,10 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
3256 /* Allocate InitEnet command parameter structure */ 3308 /* Allocate InitEnet command parameter structure */
3257 init_enet_pram_offset = qe_muram_alloc(sizeof(struct ucc_geth_init_pram), 4); 3309 init_enet_pram_offset = qe_muram_alloc(sizeof(struct ucc_geth_init_pram), 4);
3258 if (IS_ERR_VALUE(init_enet_pram_offset)) { 3310 if (IS_ERR_VALUE(init_enet_pram_offset)) {
3259 ugeth_err 3311 if (netif_msg_ifup(ugeth))
3260 ("%s: Can not allocate DPRAM memory for p_init_enet_pram.", 3312 ugeth_err
3261 __FUNCTION__); 3313 ("%s: Can not allocate DPRAM memory for p_init_enet_pram.",
3314 __FUNCTION__);
3262 ucc_geth_memclean(ugeth); 3315 ucc_geth_memclean(ugeth);
3263 return -ENOMEM; 3316 return -ENOMEM;
3264 } 3317 }
@@ -3428,8 +3481,9 @@ static int ucc_geth_rx(struct ucc_geth_private *ugeth, u8 rxQ, int rx_work_limit
3428 if (!skb || 3481 if (!skb ||
3429 (!(bd_status & (R_F | R_L))) || 3482 (!(bd_status & (R_F | R_L))) ||
3430 (bd_status & R_ERRORS_FATAL)) { 3483 (bd_status & R_ERRORS_FATAL)) {
3431 ugeth_vdbg("%s, %d: ERROR!!! skb - 0x%08x", 3484 if (netif_msg_rx_err(ugeth))
3432 __FUNCTION__, __LINE__, (u32) skb); 3485 ugeth_err("%s, %d: ERROR!!! skb - 0x%08x",
3486 __FUNCTION__, __LINE__, (u32) skb);
3433 if (skb) 3487 if (skb)
3434 dev_kfree_skb_any(skb); 3488 dev_kfree_skb_any(skb);
3435 3489
@@ -3458,7 +3512,8 @@ static int ucc_geth_rx(struct ucc_geth_private *ugeth, u8 rxQ, int rx_work_limit
3458 3512
3459 skb = get_new_skb(ugeth, bd); 3513 skb = get_new_skb(ugeth, bd);
3460 if (!skb) { 3514 if (!skb) {
3461 ugeth_warn("%s: No Rx Data Buffer", __FUNCTION__); 3515 if (netif_msg_rx_err(ugeth))
3516 ugeth_warn("%s: No Rx Data Buffer", __FUNCTION__);
3462 ugeth->stats.rx_dropped++; 3517 ugeth->stats.rx_dropped++;
3463 break; 3518 break;
3464 } 3519 }
@@ -3649,28 +3704,32 @@ static int ucc_geth_open(struct net_device *dev)
3649 3704
3650 /* Test station address */ 3705 /* Test station address */
3651 if (dev->dev_addr[0] & ENET_GROUP_ADDR) { 3706 if (dev->dev_addr[0] & ENET_GROUP_ADDR) {
3652 ugeth_err("%s: Multicast address used for station address" 3707 if (netif_msg_ifup(ugeth))
3653 " - is this what you wanted?", __FUNCTION__); 3708 ugeth_err("%s: Multicast address used for station address"
3709 " - is this what you wanted?", __FUNCTION__);
3654 return -EINVAL; 3710 return -EINVAL;
3655 } 3711 }
3656 3712
3657 err = ucc_struct_init(ugeth); 3713 err = ucc_struct_init(ugeth);
3658 if (err) { 3714 if (err) {
3659 ugeth_err("%s: Cannot configure internal struct, aborting.", dev->name); 3715 if (netif_msg_ifup(ugeth))
3716 ugeth_err("%s: Cannot configure internal struct, aborting.", dev->name);
3660 return err; 3717 return err;
3661 } 3718 }
3662 3719
3663 err = ucc_geth_startup(ugeth); 3720 err = ucc_geth_startup(ugeth);
3664 if (err) { 3721 if (err) {
3665 ugeth_err("%s: Cannot configure net device, aborting.", 3722 if (netif_msg_ifup(ugeth))
3666 dev->name); 3723 ugeth_err("%s: Cannot configure net device, aborting.",
3724 dev->name);
3667 return err; 3725 return err;
3668 } 3726 }
3669 3727
3670 err = adjust_enet_interface(ugeth); 3728 err = adjust_enet_interface(ugeth);
3671 if (err) { 3729 if (err) {
3672 ugeth_err("%s: Cannot configure net device, aborting.", 3730 if (netif_msg_ifup(ugeth))
3673 dev->name); 3731 ugeth_err("%s: Cannot configure net device, aborting.",
3732 dev->name);
3674 return err; 3733 return err;
3675 } 3734 }
3676 3735
@@ -3687,7 +3746,8 @@ static int ucc_geth_open(struct net_device *dev)
3687 3746
3688 err = init_phy(dev); 3747 err = init_phy(dev);
3689 if (err) { 3748 if (err) {
3690 ugeth_err("%s: Cannot initialize PHY, aborting.", dev->name); 3749 if (netif_msg_ifup(ugeth))
3750 ugeth_err("%s: Cannot initialize PHY, aborting.", dev->name);
3691 return err; 3751 return err;
3692 } 3752 }
3693 3753
@@ -3697,15 +3757,17 @@ static int ucc_geth_open(struct net_device *dev)
3697 request_irq(ugeth->ug_info->uf_info.irq, ucc_geth_irq_handler, 0, 3757 request_irq(ugeth->ug_info->uf_info.irq, ucc_geth_irq_handler, 0,
3698 "UCC Geth", dev); 3758 "UCC Geth", dev);
3699 if (err) { 3759 if (err) {
3700 ugeth_err("%s: Cannot get IRQ for net device, aborting.", 3760 if (netif_msg_ifup(ugeth))
3701 dev->name); 3761 ugeth_err("%s: Cannot get IRQ for net device, aborting.",
3762 dev->name);
3702 ucc_geth_stop(ugeth); 3763 ucc_geth_stop(ugeth);
3703 return err; 3764 return err;
3704 } 3765 }
3705 3766
3706 err = ugeth_enable(ugeth, COMM_DIR_RX_AND_TX); 3767 err = ugeth_enable(ugeth, COMM_DIR_RX_AND_TX);
3707 if (err) { 3768 if (err) {
3708 ugeth_err("%s: Cannot enable net device, aborting.", dev->name); 3769 if (netif_msg_ifup(ugeth))
3770 ugeth_err("%s: Cannot enable net device, aborting.", dev->name);
3709 ucc_geth_stop(ugeth); 3771 ucc_geth_stop(ugeth);
3710 return err; 3772 return err;
3711 } 3773 }
@@ -3732,8 +3794,6 @@ static int ucc_geth_close(struct net_device *dev)
3732 return 0; 3794 return 0;
3733} 3795}
3734 3796
3735const struct ethtool_ops ucc_geth_ethtool_ops = { };
3736
3737static phy_interface_t to_phy_interface(const char *phy_connection_type) 3797static phy_interface_t to_phy_interface(const char *phy_connection_type)
3738{ 3798{
3739 if (strcasecmp(phy_connection_type, "mii") == 0) 3799 if (strcasecmp(phy_connection_type, "mii") == 0)
@@ -3790,6 +3850,13 @@ static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *ma
3790 return -ENODEV; 3850 return -ENODEV;
3791 3851
3792 ug_info = &ugeth_info[ucc_num]; 3852 ug_info = &ugeth_info[ucc_num];
3853 if (ug_info == NULL) {
3854 if (netif_msg_probe(&debug))
3855 ugeth_err("%s: [%d] Missing additional data!",
3856 __FUNCTION__, ucc_num);
3857 return -ENODEV;
3858 }
3859
3793 ug_info->uf_info.ucc_num = ucc_num; 3860 ug_info->uf_info.ucc_num = ucc_num;
3794 3861
3795 prop = of_get_property(np, "rx-clock", NULL); 3862 prop = of_get_property(np, "rx-clock", NULL);
@@ -3868,15 +3935,10 @@ static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *ma
3868 3935
3869 ug_info->mdio_bus = res.start; 3936 ug_info->mdio_bus = res.start;
3870 3937
3871 printk(KERN_INFO "ucc_geth: UCC%1d at 0x%8x (irq = %d) \n", 3938 if (netif_msg_probe(&debug))
3872 ug_info->uf_info.ucc_num + 1, ug_info->uf_info.regs, 3939 printk(KERN_INFO "ucc_geth: UCC%1d at 0x%8x (irq = %d) \n",
3873 ug_info->uf_info.irq); 3940 ug_info->uf_info.ucc_num + 1, ug_info->uf_info.regs,
3874 3941 ug_info->uf_info.irq);
3875 if (ug_info == NULL) {
3876 ugeth_err("%s: [%d] Missing additional data!", __FUNCTION__,
3877 ucc_num);
3878 return -ENODEV;
3879 }
3880 3942
3881 /* Create an ethernet device instance */ 3943 /* Create an ethernet device instance */
3882 dev = alloc_etherdev(sizeof(*ugeth)); 3944 dev = alloc_etherdev(sizeof(*ugeth));
@@ -3896,6 +3958,7 @@ static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *ma
3896 SET_NETDEV_DEV(dev, device); 3958 SET_NETDEV_DEV(dev, device);
3897 3959
3898 /* Fill in the dev structure */ 3960 /* Fill in the dev structure */
3961 uec_set_ethtool_ops(dev);
3899 dev->open = ucc_geth_open; 3962 dev->open = ucc_geth_open;
3900 dev->hard_start_xmit = ucc_geth_start_xmit; 3963 dev->hard_start_xmit = ucc_geth_start_xmit;
3901 dev->tx_timeout = ucc_geth_timeout; 3964 dev->tx_timeout = ucc_geth_timeout;
@@ -3909,16 +3972,16 @@ static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *ma
3909// dev->change_mtu = ucc_geth_change_mtu; 3972// dev->change_mtu = ucc_geth_change_mtu;
3910 dev->mtu = 1500; 3973 dev->mtu = 1500;
3911 dev->set_multicast_list = ucc_geth_set_multi; 3974 dev->set_multicast_list = ucc_geth_set_multi;
3912 dev->ethtool_ops = &ucc_geth_ethtool_ops;
3913 3975
3914 ugeth->msg_enable = (NETIF_MSG_IFUP << 1 ) - 1; 3976 ugeth->msg_enable = netif_msg_init(debug.msg_enable, UGETH_MSG_DEFAULT);
3915 ugeth->phy_interface = phy_interface; 3977 ugeth->phy_interface = phy_interface;
3916 ugeth->max_speed = max_speed; 3978 ugeth->max_speed = max_speed;
3917 3979
3918 err = register_netdev(dev); 3980 err = register_netdev(dev);
3919 if (err) { 3981 if (err) {
3920 ugeth_err("%s: Cannot register net device, aborting.", 3982 if (netif_msg_probe(ugeth))
3921 dev->name); 3983 ugeth_err("%s: Cannot register net device, aborting.",
3984 dev->name);
3922 free_netdev(dev); 3985 free_netdev(dev);
3923 return err; 3986 return err;
3924 } 3987 }
@@ -3972,7 +4035,8 @@ static int __init ucc_geth_init(void)
3972 if (ret) 4035 if (ret)
3973 return ret; 4036 return ret;
3974 4037
3975 printk(KERN_INFO "ucc_geth: " DRV_DESC "\n"); 4038 if (netif_msg_drv(&debug))
4039 printk(KERN_INFO "ucc_geth: " DRV_DESC "\n");
3976 for (i = 0; i < 8; i++) 4040 for (i = 0; i < 8; i++)
3977 memcpy(&(ugeth_info[i]), &ugeth_primary_info, 4041 memcpy(&(ugeth_info[i]), &ugeth_primary_info,
3978 sizeof(ugeth_primary_info)); 4042 sizeof(ugeth_primary_info));
diff --git a/drivers/net/ucc_geth.h b/drivers/net/ucc_geth.h
index a29e1c3ca4b7..bb4dac8c0c65 100644
--- a/drivers/net/ucc_geth.h
+++ b/drivers/net/ucc_geth.h
@@ -30,6 +30,10 @@
30 30
31#include "ucc_geth_mii.h" 31#include "ucc_geth_mii.h"
32 32
33#define DRV_DESC "QE UCC Gigabit Ethernet Controller"
34#define DRV_NAME "ucc_geth"
35#define DRV_VERSION "1.1"
36
33#define NUM_TX_QUEUES 8 37#define NUM_TX_QUEUES 8
34#define NUM_RX_QUEUES 8 38#define NUM_RX_QUEUES 8
35#define NUM_BDS_IN_PREFETCHED_BDS 4 39#define NUM_BDS_IN_PREFETCHED_BDS 4
@@ -896,6 +900,7 @@ struct ucc_geth_hardware_statistics {
896#define UCC_GETH_TX_VTAG_TABLE_ENTRY_MAX 8 900#define UCC_GETH_TX_VTAG_TABLE_ENTRY_MAX 8
897#define UCC_GETH_RX_BD_RING_SIZE_MIN 8 901#define UCC_GETH_RX_BD_RING_SIZE_MIN 8
898#define UCC_GETH_TX_BD_RING_SIZE_MIN 2 902#define UCC_GETH_TX_BD_RING_SIZE_MIN 2
903#define UCC_GETH_BD_RING_SIZE_MAX 0xffff
899 904
900#define UCC_GETH_SIZE_OF_BD QE_SIZEOF_BD 905#define UCC_GETH_SIZE_OF_BD QE_SIZEOF_BD
901 906
@@ -1135,6 +1140,7 @@ struct ucc_geth_info {
1135 int bro; 1140 int bro;
1136 int ecm; 1141 int ecm;
1137 int receiveFlowControl; 1142 int receiveFlowControl;
1143 int transmitFlowControl;
1138 u8 maxGroupAddrInHash; 1144 u8 maxGroupAddrInHash;
1139 u8 maxIndAddrInHash; 1145 u8 maxIndAddrInHash;
1140 u8 prel; 1146 u8 prel;
diff --git a/drivers/net/ucc_geth_ethtool.c b/drivers/net/ucc_geth_ethtool.c
new file mode 100644
index 000000000000..a8994c7b8583
--- /dev/null
+++ b/drivers/net/ucc_geth_ethtool.c
@@ -0,0 +1,388 @@
1/*
2 * Copyright (c) 2007 Freescale Semiconductor, Inc. All rights reserved.
3 *
4 * Description: QE UCC Gigabit Ethernet Ethtool API Set
5 *
6 * Author: Li Yang <leoli@freescale.com>
7 *
8 * Limitation:
9 * Can only get/set setttings of the first queue.
10 * Need to re-open the interface manually after changing some paramters.
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
18#include <linux/kernel.h>
19#include <linux/init.h>
20#include <linux/errno.h>
21#include <linux/slab.h>
22#include <linux/stddef.h>
23#include <linux/interrupt.h>
24#include <linux/netdevice.h>
25#include <linux/etherdevice.h>
26#include <linux/skbuff.h>
27#include <linux/spinlock.h>
28#include <linux/mm.h>
29#include <linux/delay.h>
30#include <linux/dma-mapping.h>
31#include <linux/fsl_devices.h>
32#include <linux/ethtool.h>
33#include <linux/mii.h>
34#include <linux/phy.h>
35
36#include <asm/io.h>
37#include <asm/irq.h>
38#include <asm/uaccess.h>
39#include <asm/types.h>
40#include <asm/uaccess.h>
41
42#include "ucc_geth.h"
43#include "ucc_geth_mii.h"
44
45static char hw_stat_gstrings[][ETH_GSTRING_LEN] = {
46 "tx-64-frames",
47 "tx-65-127-frames",
48 "tx-128-255-frames",
49 "rx-64-frames",
50 "rx-65-127-frames",
51 "rx-128-255-frames",
52 "tx-bytes-ok",
53 "tx-pause-frames",
54 "tx-multicast-frames",
55 "tx-broadcast-frames",
56 "rx-frames",
57 "rx-bytes-ok",
58 "rx-bytes-all",
59 "rx-multicast-frames",
60 "rx-broadcast-frames",
61 "stats-counter-carry",
62 "stats-counter-mask",
63 "rx-dropped-frames",
64};
65
66static char tx_fw_stat_gstrings[][ETH_GSTRING_LEN] = {
67 "tx-single-collision",
68 "tx-multiple-collision",
69 "tx-late-collsion",
70 "tx-aborted-frames",
71 "tx-lost-frames",
72 "tx-carrier-sense-errors",
73 "tx-frames-ok",
74 "tx-excessive-differ-frames",
75 "tx-256-511-frames",
76 "tx-1024-1518-frames",
77 "tx-jumbo-frames",
78};
79
80static char rx_fw_stat_gstrings[][ETH_GSTRING_LEN] = {
81 "rx-crc-errors",
82 "rx-alignment-errors",
83 "rx-in-range-length-errors",
84 "rx-out-of-range-length-errors",
85 "rx-too-long-frames",
86 "rx-runt",
87 "rx-very-long-event",
88 "rx-symbol-errors",
89 "rx-busy-drop-frames",
90 "reserved",
91 "reserved",
92 "rx-mismatch-drop-frames",
93 "rx-small-than-64",
94 "rx-256-511-frames",
95 "rx-512-1023-frames",
96 "rx-1024-1518-frames",
97 "rx-jumbo-frames",
98 "rx-mac-error-loss",
99 "rx-pause-frames",
100 "reserved",
101 "rx-vlan-removed",
102 "rx-vlan-replaced",
103 "rx-vlan-inserted",
104 "rx-ip-checksum-errors",
105};
106
107#define UEC_HW_STATS_LEN ARRAY_SIZE(hw_stat_gstrings)
108#define UEC_TX_FW_STATS_LEN ARRAY_SIZE(tx_fw_stat_gstrings)
109#define UEC_RX_FW_STATS_LEN ARRAY_SIZE(rx_fw_stat_gstrings)
110
111extern int init_flow_control_params(u32 automatic_flow_control_mode,
112 int rx_flow_control_enable,
113 int tx_flow_control_enable, u16 pause_period,
114 u16 extension_field, volatile u32 *upsmr_register,
115 volatile u32 *uempr_register, volatile u32 *maccfg1_register);
116
117static int
118uec_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
119{
120 struct ucc_geth_private *ugeth = netdev_priv(netdev);
121 struct phy_device *phydev = ugeth->phydev;
122 struct ucc_geth_info *ug_info = ugeth->ug_info;
123
124 if (!phydev)
125 return -ENODEV;
126
127 ecmd->maxtxpkt = 1;
128 ecmd->maxrxpkt = ug_info->interruptcoalescingmaxvalue[0];
129
130 return phy_ethtool_gset(phydev, ecmd);
131}
132
133static int
134uec_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
135{
136 struct ucc_geth_private *ugeth = netdev_priv(netdev);
137 struct phy_device *phydev = ugeth->phydev;
138
139 if (!phydev)
140 return -ENODEV;
141
142 return phy_ethtool_sset(phydev, ecmd);
143}
144
145static void
146uec_get_pauseparam(struct net_device *netdev,
147 struct ethtool_pauseparam *pause)
148{
149 struct ucc_geth_private *ugeth = netdev_priv(netdev);
150
151 pause->autoneg = ugeth->phydev->autoneg;
152
153 if (ugeth->ug_info->receiveFlowControl)
154 pause->rx_pause = 1;
155 if (ugeth->ug_info->transmitFlowControl)
156 pause->tx_pause = 1;
157}
158
159static int
160uec_set_pauseparam(struct net_device *netdev,
161 struct ethtool_pauseparam *pause)
162{
163 struct ucc_geth_private *ugeth = netdev_priv(netdev);
164 int ret = 0;
165
166 ugeth->ug_info->receiveFlowControl = pause->rx_pause;
167 ugeth->ug_info->transmitFlowControl = pause->tx_pause;
168
169 if (ugeth->phydev->autoneg) {
170 if (netif_running(netdev)) {
171 /* FIXME: automatically restart */
172 printk(KERN_INFO
173 "Please re-open the interface.\n");
174 }
175 } else {
176 struct ucc_geth_info *ug_info = ugeth->ug_info;
177
178 ret = init_flow_control_params(ug_info->aufc,
179 ug_info->receiveFlowControl,
180 ug_info->transmitFlowControl,
181 ug_info->pausePeriod,
182 ug_info->extensionField,
183 &ugeth->uccf->uf_regs->upsmr,
184 &ugeth->ug_regs->uempr,
185 &ugeth->ug_regs->maccfg1);
186 }
187
188 return ret;
189}
190
191static uint32_t
192uec_get_msglevel(struct net_device *netdev)
193{
194 struct ucc_geth_private *ugeth = netdev_priv(netdev);
195 return ugeth->msg_enable;
196}
197
198static void
199uec_set_msglevel(struct net_device *netdev, uint32_t data)
200{
201 struct ucc_geth_private *ugeth = netdev_priv(netdev);
202 ugeth->msg_enable = data;
203}
204
205static int
206uec_get_regs_len(struct net_device *netdev)
207{
208 return sizeof(struct ucc_geth);
209}
210
211static void
212uec_get_regs(struct net_device *netdev,
213 struct ethtool_regs *regs, void *p)
214{
215 int i;
216 struct ucc_geth_private *ugeth = netdev_priv(netdev);
217 u32 __iomem *ug_regs = (u32 __iomem *)ugeth->ug_regs;
218 u32 *buff = p;
219
220 for (i = 0; i < sizeof(struct ucc_geth) / sizeof(u32); i++)
221 buff[i] = in_be32(&ug_regs[i]);
222}
223
224static void
225uec_get_ringparam(struct net_device *netdev,
226 struct ethtool_ringparam *ring)
227{
228 struct ucc_geth_private *ugeth = netdev_priv(netdev);
229 struct ucc_geth_info *ug_info = ugeth->ug_info;
230 int queue = 0;
231
232 ring->rx_max_pending = UCC_GETH_BD_RING_SIZE_MAX;
233 ring->rx_mini_max_pending = UCC_GETH_BD_RING_SIZE_MAX;
234 ring->rx_jumbo_max_pending = UCC_GETH_BD_RING_SIZE_MAX;
235 ring->tx_max_pending = UCC_GETH_BD_RING_SIZE_MAX;
236
237 ring->rx_pending = ug_info->bdRingLenRx[queue];
238 ring->rx_mini_pending = ug_info->bdRingLenRx[queue];
239 ring->rx_jumbo_pending = ug_info->bdRingLenRx[queue];
240 ring->tx_pending = ug_info->bdRingLenTx[queue];
241}
242
243static int
244uec_set_ringparam(struct net_device *netdev,
245 struct ethtool_ringparam *ring)
246{
247 struct ucc_geth_private *ugeth = netdev_priv(netdev);
248 struct ucc_geth_info *ug_info = ugeth->ug_info;
249 int queue = 0, ret = 0;
250
251 if (ring->rx_pending < UCC_GETH_RX_BD_RING_SIZE_MIN) {
252 printk("%s: RxBD ring size must be no smaller than %d.\n",
253 netdev->name, UCC_GETH_RX_BD_RING_SIZE_MIN);
254 return -EINVAL;
255 }
256 if (ring->rx_pending % UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT) {
257 printk("%s: RxBD ring size must be multiple of %d.\n",
258 netdev->name, UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT);
259 return -EINVAL;
260 }
261 if (ring->tx_pending < UCC_GETH_TX_BD_RING_SIZE_MIN) {
262 printk("%s: TxBD ring size must be no smaller than %d.\n",
263 netdev->name, UCC_GETH_TX_BD_RING_SIZE_MIN);
264 return -EINVAL;
265 }
266
267 ug_info->bdRingLenRx[queue] = ring->rx_pending;
268 ug_info->bdRingLenTx[queue] = ring->tx_pending;
269
270 if (netif_running(netdev)) {
271 /* FIXME: restart automatically */
272 printk(KERN_INFO
273 "Please re-open the interface.\n");
274 }
275
276 return ret;
277}
278
279static int uec_get_stats_count(struct net_device *netdev)
280{
281 struct ucc_geth_private *ugeth = netdev_priv(netdev);
282 u32 stats_mode = ugeth->ug_info->statisticsMode;
283 int len = 0;
284
285 if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE)
286 len += UEC_HW_STATS_LEN;
287 if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX)
288 len += UEC_TX_FW_STATS_LEN;
289 if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX)
290 len += UEC_RX_FW_STATS_LEN;
291
292 return len;
293}
294
295static void uec_get_strings(struct net_device *netdev, u32 stringset, u8 *buf)
296{
297 struct ucc_geth_private *ugeth = netdev_priv(netdev);
298 u32 stats_mode = ugeth->ug_info->statisticsMode;
299
300 if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE) {
301 memcpy(buf, hw_stat_gstrings, UEC_HW_STATS_LEN *
302 ETH_GSTRING_LEN);
303 buf += UEC_HW_STATS_LEN * ETH_GSTRING_LEN;
304 }
305 if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) {
306 memcpy(buf, tx_fw_stat_gstrings, UEC_TX_FW_STATS_LEN *
307 ETH_GSTRING_LEN);
308 buf += UEC_TX_FW_STATS_LEN * ETH_GSTRING_LEN;
309 }
310 if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX)
311 memcpy(buf, tx_fw_stat_gstrings, UEC_RX_FW_STATS_LEN *
312 ETH_GSTRING_LEN);
313}
314
315static void uec_get_ethtool_stats(struct net_device *netdev,
316 struct ethtool_stats *stats, uint64_t *data)
317{
318 struct ucc_geth_private *ugeth = netdev_priv(netdev);
319 u32 stats_mode = ugeth->ug_info->statisticsMode;
320 u32 __iomem *base;
321 int i, j = 0;
322
323 if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE) {
324 base = (u32 __iomem *)&ugeth->ug_regs->tx64;
325 for (i = 0; i < UEC_HW_STATS_LEN; i++)
326 data[j++] = (u64)in_be32(&base[i]);
327 }
328 if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) {
329 base = (u32 __iomem *)ugeth->p_tx_fw_statistics_pram;
330 for (i = 0; i < UEC_TX_FW_STATS_LEN; i++)
331 data[j++] = (u64)in_be32(&base[i]);
332 }
333 if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX) {
334 base = (u32 __iomem *)ugeth->p_rx_fw_statistics_pram;
335 for (i = 0; i < UEC_RX_FW_STATS_LEN; i++)
336 data[j++] = (u64)in_be32(&base[i]);
337 }
338}
339
340static int uec_nway_reset(struct net_device *netdev)
341{
342 struct ucc_geth_private *ugeth = netdev_priv(netdev);
343
344 return phy_start_aneg(ugeth->phydev);
345}
346
347/* Report driver information */
348static void
349uec_get_drvinfo(struct net_device *netdev,
350 struct ethtool_drvinfo *drvinfo)
351{
352 strncpy(drvinfo->driver, DRV_NAME, 32);
353 strncpy(drvinfo->version, DRV_VERSION, 32);
354 strncpy(drvinfo->fw_version, "N/A", 32);
355 strncpy(drvinfo->bus_info, "QUICC ENGINE", 32);
356 drvinfo->n_stats = uec_get_stats_count(netdev);
357 drvinfo->testinfo_len = 0;
358 drvinfo->eedump_len = 0;
359 drvinfo->regdump_len = uec_get_regs_len(netdev);
360}
361
362static const struct ethtool_ops uec_ethtool_ops = {
363 .get_settings = uec_get_settings,
364 .set_settings = uec_set_settings,
365 .get_drvinfo = uec_get_drvinfo,
366 .get_regs_len = uec_get_regs_len,
367 .get_regs = uec_get_regs,
368 .get_msglevel = uec_get_msglevel,
369 .set_msglevel = uec_set_msglevel,
370 .nway_reset = uec_nway_reset,
371 .get_link = ethtool_op_get_link,
372 .get_ringparam = uec_get_ringparam,
373 .set_ringparam = uec_set_ringparam,
374 .get_pauseparam = uec_get_pauseparam,
375 .set_pauseparam = uec_set_pauseparam,
376 .get_sg = ethtool_op_get_sg,
377 .set_sg = ethtool_op_set_sg,
378 .get_tso = ethtool_op_get_tso,
379 .get_stats_count = uec_get_stats_count,
380 .get_strings = uec_get_strings,
381 .get_ethtool_stats = uec_get_ethtool_stats,
382 .get_perm_addr = ethtool_op_get_perm_addr,
383};
384
385void uec_set_ethtool_ops(struct net_device *netdev)
386{
387 SET_ETHTOOL_OPS(netdev, &uec_ethtool_ops);
388}
diff --git a/drivers/net/ucc_geth_mii.c b/drivers/net/ucc_geth_mii.c
index 7bcb82f50cf7..5f8c2d30a328 100644
--- a/drivers/net/ucc_geth_mii.c
+++ b/drivers/net/ucc_geth_mii.c
@@ -54,8 +54,8 @@
54#define vdbg(format, arg...) do {} while(0) 54#define vdbg(format, arg...) do {} while(0)
55#endif 55#endif
56 56
57#define DRV_DESC "QE UCC Ethernet Controller MII Bus" 57#define MII_DRV_DESC "QE UCC Ethernet Controller MII Bus"
58#define DRV_NAME "fsl-uec_mdio" 58#define MII_DRV_NAME "fsl-uec_mdio"
59 59
60/* Write value to the PHY for this device to the register at regnum, */ 60/* Write value to the PHY for this device to the register at regnum, */
61/* waiting until the write is done before it returns. All PHY */ 61/* waiting until the write is done before it returns. All PHY */
@@ -261,7 +261,7 @@ static struct of_device_id uec_mdio_match[] = {
261}; 261};
262 262
263static struct of_platform_driver uec_mdio_driver = { 263static struct of_platform_driver uec_mdio_driver = {
264 .name = DRV_NAME, 264 .name = MII_DRV_NAME,
265 .probe = uec_mdio_probe, 265 .probe = uec_mdio_probe,
266 .remove = uec_mdio_remove, 266 .remove = uec_mdio_remove,
267 .match_table = uec_mdio_match, 267 .match_table = uec_mdio_match,
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index c8062494009f..5c6a5d043007 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -220,6 +220,7 @@ acpi_status pci_osc_control_set(acpi_handle handle, u32 flags)
220} 220}
221EXPORT_SYMBOL(pci_osc_control_set); 221EXPORT_SYMBOL(pci_osc_control_set);
222 222
223#ifdef CONFIG_ACPI_SLEEP
223/* 224/*
224 * _SxD returns the D-state with the highest power 225 * _SxD returns the D-state with the highest power
225 * (lowest D-state number) supported in the S-state "x". 226 * (lowest D-state number) supported in the S-state "x".
@@ -245,16 +246,34 @@ EXPORT_SYMBOL(pci_osc_control_set);
245 * currently we simply return _SxD, if present. 246 * currently we simply return _SxD, if present.
246 */ 247 */
247 248
248static int acpi_pci_choose_state(struct pci_dev *pdev, pm_message_t state) 249static pci_power_t acpi_pci_choose_state(struct pci_dev *pdev,
250 pm_message_t state)
249{ 251{
250 /* TBD */ 252 int acpi_state;
251 253
252 return -ENODEV; 254 acpi_state = acpi_pm_device_sleep_state(&pdev->dev,
255 device_may_wakeup(&pdev->dev), NULL);
256 if (acpi_state < 0)
257 return PCI_POWER_ERROR;
258
259 switch (acpi_state) {
260 case ACPI_STATE_D0:
261 return PCI_D0;
262 case ACPI_STATE_D1:
263 return PCI_D1;
264 case ACPI_STATE_D2:
265 return PCI_D2;
266 case ACPI_STATE_D3:
267 return PCI_D3hot;
268 }
269 return PCI_POWER_ERROR;
253} 270}
271#endif
254 272
255static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state) 273static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
256{ 274{
257 acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev); 275 acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev);
276 acpi_handle tmp;
258 static int state_conv[] = { 277 static int state_conv[] = {
259 [0] = 0, 278 [0] = 0,
260 [1] = 1, 279 [1] = 1,
@@ -266,6 +285,9 @@ static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
266 285
267 if (!handle) 286 if (!handle)
268 return -ENODEV; 287 return -ENODEV;
288 /* If the ACPI device has _EJ0, ignore the device */
289 if (ACPI_SUCCESS(acpi_get_handle(handle, "_EJ0", &tmp)))
290 return 0;
269 return acpi_bus_set_power(handle, acpi_state); 291 return acpi_bus_set_power(handle, acpi_state);
270} 292}
271 293
@@ -320,7 +342,9 @@ static int __init acpi_pci_init(void)
320 ret = register_acpi_bus_type(&acpi_pci_bus); 342 ret = register_acpi_bus_type(&acpi_pci_bus);
321 if (ret) 343 if (ret)
322 return 0; 344 return 0;
345#ifdef CONFIG_ACPI_SLEEP
323 platform_pci_choose_state = acpi_pci_choose_state; 346 platform_pci_choose_state = acpi_pci_choose_state;
347#endif
324 platform_pci_set_power_state = acpi_pci_set_power_state; 348 platform_pci_set_power_state = acpi_pci_set_power_state;
325 return 0; 349 return 0;
326} 350}
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 03fd59e80fef..fba319d6fcc8 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -499,7 +499,7 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state)
499 return 0; 499 return 0;
500} 500}
501 501
502int (*platform_pci_choose_state)(struct pci_dev *dev, pm_message_t state); 502pci_power_t (*platform_pci_choose_state)(struct pci_dev *dev, pm_message_t state);
503 503
504/** 504/**
505 * pci_choose_state - Choose the power state of a PCI device 505 * pci_choose_state - Choose the power state of a PCI device
@@ -513,15 +513,15 @@ int (*platform_pci_choose_state)(struct pci_dev *dev, pm_message_t state);
513 513
514pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state) 514pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state)
515{ 515{
516 int ret; 516 pci_power_t ret;
517 517
518 if (!pci_find_capability(dev, PCI_CAP_ID_PM)) 518 if (!pci_find_capability(dev, PCI_CAP_ID_PM))
519 return PCI_D0; 519 return PCI_D0;
520 520
521 if (platform_pci_choose_state) { 521 if (platform_pci_choose_state) {
522 ret = platform_pci_choose_state(dev, state); 522 ret = platform_pci_choose_state(dev, state);
523 if (ret >= 0) 523 if (ret != PCI_POWER_ERROR)
524 state.event = ret; 524 return ret;
525 } 525 }
526 526
527 switch (state.event) { 527 switch (state.event) {
@@ -1604,6 +1604,7 @@ early_param("pci", pci_setup);
1604device_initcall(pci_init); 1604device_initcall(pci_init);
1605 1605
1606EXPORT_SYMBOL_GPL(pci_restore_bars); 1606EXPORT_SYMBOL_GPL(pci_restore_bars);
1607EXPORT_SYMBOL(__pci_reenable_device);
1607EXPORT_SYMBOL(pci_enable_device_bars); 1608EXPORT_SYMBOL(pci_enable_device_bars);
1608EXPORT_SYMBOL(pci_enable_device); 1609EXPORT_SYMBOL(pci_enable_device);
1609EXPORT_SYMBOL(pcim_enable_device); 1610EXPORT_SYMBOL(pcim_enable_device);
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 3fec13d3add7..c6e132d7c0f7 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -1,6 +1,5 @@
1/* Functions internal to the PCI core code */ 1/* Functions internal to the PCI core code */
2 2
3extern int __must_check __pci_reenable_device(struct pci_dev *);
4extern int pci_uevent(struct device *dev, char **envp, int num_envp, 3extern int pci_uevent(struct device *dev, char **envp, int num_envp,
5 char *buffer, int buffer_size); 4 char *buffer, int buffer_size);
6extern int pci_create_sysfs_dev_files(struct pci_dev *pdev); 5extern int pci_create_sysfs_dev_files(struct pci_dev *pdev);
@@ -13,7 +12,7 @@ extern int pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
13 resource_size_t, resource_size_t), 12 resource_size_t, resource_size_t),
14 void *alignf_data); 13 void *alignf_data);
15/* Firmware callbacks */ 14/* Firmware callbacks */
16extern int (*platform_pci_choose_state)(struct pci_dev *dev, pm_message_t state); 15extern pci_power_t (*platform_pci_choose_state)(struct pci_dev *dev, pm_message_t state);
17extern int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t state); 16extern int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t state);
18 17
19extern int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val); 18extern int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val);
diff --git a/drivers/pnp/card.c b/drivers/pnp/card.c
index dd6384b1efce..b6a4f02b01d1 100644
--- a/drivers/pnp/card.c
+++ b/drivers/pnp/card.c
@@ -2,7 +2,6 @@
2 * card.c - contains functions for managing groups of PnP devices 2 * card.c - contains functions for managing groups of PnP devices
3 * 3 *
4 * Copyright 2002 Adam Belay <ambx1@neo.rr.com> 4 * Copyright 2002 Adam Belay <ambx1@neo.rr.com>
5 *
6 */ 5 */
7 6
8#include <linux/module.h> 7#include <linux/module.h>
@@ -13,26 +12,31 @@
13LIST_HEAD(pnp_cards); 12LIST_HEAD(pnp_cards);
14static LIST_HEAD(pnp_card_drivers); 13static LIST_HEAD(pnp_card_drivers);
15 14
16 15static const struct pnp_card_device_id *match_card(struct pnp_card_driver *drv,
17static const struct pnp_card_device_id * match_card(struct pnp_card_driver * drv, struct pnp_card * card) 16 struct pnp_card *card)
18{ 17{
19 const struct pnp_card_device_id * drv_id = drv->id_table; 18 const struct pnp_card_device_id *drv_id = drv->id_table;
20 while (*drv_id->id){ 19
21 if (compare_pnp_id(card->id,drv_id->id)) { 20 while (*drv_id->id) {
21 if (compare_pnp_id(card->id, drv_id->id)) {
22 int i = 0; 22 int i = 0;
23
23 for (;;) { 24 for (;;) {
24 int found; 25 int found;
25 struct pnp_dev *dev; 26 struct pnp_dev *dev;
26 if (i == PNP_MAX_DEVICES || ! *drv_id->devs[i].id) 27
28 if (i == PNP_MAX_DEVICES
29 || !*drv_id->devs[i].id)
27 return drv_id; 30 return drv_id;
28 found = 0; 31 found = 0;
29 card_for_each_dev(card, dev) { 32 card_for_each_dev(card, dev) {
30 if (compare_pnp_id(dev->id, drv_id->devs[i].id)) { 33 if (compare_pnp_id
34 (dev->id, drv_id->devs[i].id)) {
31 found = 1; 35 found = 1;
32 break; 36 break;
33 } 37 }
34 } 38 }
35 if (! found) 39 if (!found)
36 break; 40 break;
37 i++; 41 i++;
38 } 42 }
@@ -42,14 +46,15 @@ static const struct pnp_card_device_id * match_card(struct pnp_card_driver * drv
42 return NULL; 46 return NULL;
43} 47}
44 48
45static void card_remove(struct pnp_dev * dev) 49static void card_remove(struct pnp_dev *dev)
46{ 50{
47 dev->card_link = NULL; 51 dev->card_link = NULL;
48} 52}
49 53
50static void card_remove_first(struct pnp_dev * dev) 54static void card_remove_first(struct pnp_dev *dev)
51{ 55{
52 struct pnp_card_driver * drv = to_pnp_card_driver(dev->driver); 56 struct pnp_card_driver *drv = to_pnp_card_driver(dev->driver);
57
53 if (!dev->card || !drv) 58 if (!dev->card || !drv)
54 return; 59 return;
55 if (drv->remove) 60 if (drv->remove)
@@ -67,7 +72,7 @@ static int card_probe(struct pnp_card *card, struct pnp_card_driver *drv)
67 72
68 if (!drv->probe) 73 if (!drv->probe)
69 return 0; 74 return 0;
70 id = match_card(drv,card); 75 id = match_card(drv, card);
71 if (!id) 76 if (!id)
72 return 0; 77 return 0;
73 78
@@ -94,12 +99,11 @@ static int card_probe(struct pnp_card *card, struct pnp_card_driver *drv)
94 * pnp_add_card_id - adds an EISA id to the specified card 99 * pnp_add_card_id - adds an EISA id to the specified card
95 * @id: pointer to a pnp_id structure 100 * @id: pointer to a pnp_id structure
96 * @card: pointer to the desired card 101 * @card: pointer to the desired card
97 *
98 */ 102 */
99 103int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card)
100int pnp_add_card_id(struct pnp_id *id, struct pnp_card * card)
101{ 104{
102 struct pnp_id * ptr; 105 struct pnp_id *ptr;
106
103 if (!id) 107 if (!id)
104 return -EINVAL; 108 return -EINVAL;
105 if (!card) 109 if (!card)
@@ -115,10 +119,11 @@ int pnp_add_card_id(struct pnp_id *id, struct pnp_card * card)
115 return 0; 119 return 0;
116} 120}
117 121
118static void pnp_free_card_ids(struct pnp_card * card) 122static void pnp_free_card_ids(struct pnp_card *card)
119{ 123{
120 struct pnp_id * id; 124 struct pnp_id *id;
121 struct pnp_id *next; 125 struct pnp_id *next;
126
122 if (!card) 127 if (!card)
123 return; 128 return;
124 id = card->id; 129 id = card->id;
@@ -131,49 +136,55 @@ static void pnp_free_card_ids(struct pnp_card * card)
131 136
132static void pnp_release_card(struct device *dmdev) 137static void pnp_release_card(struct device *dmdev)
133{ 138{
134 struct pnp_card * card = to_pnp_card(dmdev); 139 struct pnp_card *card = to_pnp_card(dmdev);
140
135 pnp_free_card_ids(card); 141 pnp_free_card_ids(card);
136 kfree(card); 142 kfree(card);
137} 143}
138 144
139 145static ssize_t pnp_show_card_name(struct device *dmdev,
140static ssize_t pnp_show_card_name(struct device *dmdev, struct device_attribute *attr, char *buf) 146 struct device_attribute *attr, char *buf)
141{ 147{
142 char *str = buf; 148 char *str = buf;
143 struct pnp_card *card = to_pnp_card(dmdev); 149 struct pnp_card *card = to_pnp_card(dmdev);
144 str += sprintf(str,"%s\n", card->name); 150
151 str += sprintf(str, "%s\n", card->name);
145 return (str - buf); 152 return (str - buf);
146} 153}
147 154
148static DEVICE_ATTR(name,S_IRUGO,pnp_show_card_name,NULL); 155static DEVICE_ATTR(name, S_IRUGO, pnp_show_card_name, NULL);
149 156
150static ssize_t pnp_show_card_ids(struct device *dmdev, struct device_attribute *attr, char *buf) 157static ssize_t pnp_show_card_ids(struct device *dmdev,
158 struct device_attribute *attr, char *buf)
151{ 159{
152 char *str = buf; 160 char *str = buf;
153 struct pnp_card *card = to_pnp_card(dmdev); 161 struct pnp_card *card = to_pnp_card(dmdev);
154 struct pnp_id * pos = card->id; 162 struct pnp_id *pos = card->id;
155 163
156 while (pos) { 164 while (pos) {
157 str += sprintf(str,"%s\n", pos->id); 165 str += sprintf(str, "%s\n", pos->id);
158 pos = pos->next; 166 pos = pos->next;
159 } 167 }
160 return (str - buf); 168 return (str - buf);
161} 169}
162 170
163static DEVICE_ATTR(card_id,S_IRUGO,pnp_show_card_ids,NULL); 171static DEVICE_ATTR(card_id, S_IRUGO, pnp_show_card_ids, NULL);
164 172
165static int pnp_interface_attach_card(struct pnp_card *card) 173static int pnp_interface_attach_card(struct pnp_card *card)
166{ 174{
167 int rc = device_create_file(&card->dev,&dev_attr_name); 175 int rc = device_create_file(&card->dev, &dev_attr_name);
168 if (rc) return rc;
169 176
170 rc = device_create_file(&card->dev,&dev_attr_card_id); 177 if (rc)
171 if (rc) goto err_name; 178 return rc;
179
180 rc = device_create_file(&card->dev, &dev_attr_card_id);
181 if (rc)
182 goto err_name;
172 183
173 return 0; 184 return 0;
174 185
175err_name: 186 err_name:
176 device_remove_file(&card->dev,&dev_attr_name); 187 device_remove_file(&card->dev, &dev_attr_name);
177 return rc; 188 return rc;
178} 189}
179 190
@@ -181,15 +192,16 @@ err_name:
181 * pnp_add_card - adds a PnP card to the PnP Layer 192 * pnp_add_card - adds a PnP card to the PnP Layer
182 * @card: pointer to the card to add 193 * @card: pointer to the card to add
183 */ 194 */
184 195int pnp_add_card(struct pnp_card *card)
185int pnp_add_card(struct pnp_card * card)
186{ 196{
187 int error; 197 int error;
188 struct list_head * pos, * temp; 198 struct list_head *pos, *temp;
199
189 if (!card || !card->protocol) 200 if (!card || !card->protocol)
190 return -EINVAL; 201 return -EINVAL;
191 202
192 sprintf(card->dev.bus_id, "%02x:%02x", card->protocol->number, card->number); 203 sprintf(card->dev.bus_id, "%02x:%02x", card->protocol->number,
204 card->number);
193 card->dev.parent = &card->protocol->dev; 205 card->dev.parent = &card->protocol->dev;
194 card->dev.bus = NULL; 206 card->dev.bus = NULL;
195 card->dev.release = &pnp_release_card; 207 card->dev.release = &pnp_release_card;
@@ -205,18 +217,21 @@ int pnp_add_card(struct pnp_card * card)
205 /* we wait until now to add devices in order to ensure the drivers 217 /* we wait until now to add devices in order to ensure the drivers
206 * will be able to use all of the related devices on the card 218 * will be able to use all of the related devices on the card
207 * without waiting any unresonable length of time */ 219 * without waiting any unresonable length of time */
208 list_for_each(pos,&card->devices){ 220 list_for_each(pos, &card->devices) {
209 struct pnp_dev *dev = card_to_pnp_dev(pos); 221 struct pnp_dev *dev = card_to_pnp_dev(pos);
210 __pnp_add_device(dev); 222 __pnp_add_device(dev);
211 } 223 }
212 224
213 /* match with card drivers */ 225 /* match with card drivers */
214 list_for_each_safe(pos,temp,&pnp_card_drivers){ 226 list_for_each_safe(pos, temp, &pnp_card_drivers) {
215 struct pnp_card_driver * drv = list_entry(pos, struct pnp_card_driver, global_list); 227 struct pnp_card_driver *drv =
216 card_probe(card,drv); 228 list_entry(pos, struct pnp_card_driver,
229 global_list);
230 card_probe(card, drv);
217 } 231 }
218 } else 232 } else
219 pnp_err("sysfs failure, card '%s' will be unavailable", card->dev.bus_id); 233 pnp_err("sysfs failure, card '%s' will be unavailable",
234 card->dev.bus_id);
220 return error; 235 return error;
221} 236}
222 237
@@ -224,10 +239,10 @@ int pnp_add_card(struct pnp_card * card)
224 * pnp_remove_card - removes a PnP card from the PnP Layer 239 * pnp_remove_card - removes a PnP card from the PnP Layer
225 * @card: pointer to the card to remove 240 * @card: pointer to the card to remove
226 */ 241 */
227 242void pnp_remove_card(struct pnp_card *card)
228void pnp_remove_card(struct pnp_card * card)
229{ 243{
230 struct list_head *pos, *temp; 244 struct list_head *pos, *temp;
245
231 if (!card) 246 if (!card)
232 return; 247 return;
233 device_unregister(&card->dev); 248 device_unregister(&card->dev);
@@ -235,7 +250,7 @@ void pnp_remove_card(struct pnp_card * card)
235 list_del(&card->global_list); 250 list_del(&card->global_list);
236 list_del(&card->protocol_list); 251 list_del(&card->protocol_list);
237 spin_unlock(&pnp_lock); 252 spin_unlock(&pnp_lock);
238 list_for_each_safe(pos,temp,&card->devices){ 253 list_for_each_safe(pos, temp, &card->devices) {
239 struct pnp_dev *dev = card_to_pnp_dev(pos); 254 struct pnp_dev *dev = card_to_pnp_dev(pos);
240 pnp_remove_card_device(dev); 255 pnp_remove_card_device(dev);
241 } 256 }
@@ -246,15 +261,14 @@ void pnp_remove_card(struct pnp_card * card)
246 * @card: pointer to the card to add to 261 * @card: pointer to the card to add to
247 * @dev: pointer to the device to add 262 * @dev: pointer to the device to add
248 */ 263 */
249 264int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev)
250int pnp_add_card_device(struct pnp_card * card, struct pnp_dev * dev)
251{ 265{
252 if (!card || !dev || !dev->protocol) 266 if (!card || !dev || !dev->protocol)
253 return -EINVAL; 267 return -EINVAL;
254 dev->dev.parent = &card->dev; 268 dev->dev.parent = &card->dev;
255 dev->card_link = NULL; 269 dev->card_link = NULL;
256 snprintf(dev->dev.bus_id, BUS_ID_SIZE, "%02x:%02x.%02x", dev->protocol->number, 270 snprintf(dev->dev.bus_id, BUS_ID_SIZE, "%02x:%02x.%02x",
257 card->number,dev->number); 271 dev->protocol->number, card->number, dev->number);
258 spin_lock(&pnp_lock); 272 spin_lock(&pnp_lock);
259 dev->card = card; 273 dev->card = card;
260 list_add_tail(&dev->card_list, &card->devices); 274 list_add_tail(&dev->card_list, &card->devices);
@@ -266,8 +280,7 @@ int pnp_add_card_device(struct pnp_card * card, struct pnp_dev * dev)
266 * pnp_remove_card_device- removes a device from the specified card 280 * pnp_remove_card_device- removes a device from the specified card
267 * @dev: pointer to the device to remove 281 * @dev: pointer to the device to remove
268 */ 282 */
269 283void pnp_remove_card_device(struct pnp_dev *dev)
270void pnp_remove_card_device(struct pnp_dev * dev)
271{ 284{
272 spin_lock(&pnp_lock); 285 spin_lock(&pnp_lock);
273 dev->card = NULL; 286 dev->card = NULL;
@@ -282,13 +295,14 @@ void pnp_remove_card_device(struct pnp_dev * dev)
282 * @id: pointer to a PnP ID structure that explains the rules for finding the device 295 * @id: pointer to a PnP ID structure that explains the rules for finding the device
283 * @from: Starting place to search from. If NULL it will start from the begining. 296 * @from: Starting place to search from. If NULL it will start from the begining.
284 */ 297 */
285 298struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink,
286struct pnp_dev * pnp_request_card_device(struct pnp_card_link *clink, const char * id, struct pnp_dev * from) 299 const char *id, struct pnp_dev *from)
287{ 300{
288 struct list_head * pos; 301 struct list_head *pos;
289 struct pnp_dev * dev; 302 struct pnp_dev *dev;
290 struct pnp_card_driver * drv; 303 struct pnp_card_driver *drv;
291 struct pnp_card * card; 304 struct pnp_card *card;
305
292 if (!clink || !id) 306 if (!clink || !id)
293 goto done; 307 goto done;
294 card = clink->card; 308 card = clink->card;
@@ -302,15 +316,15 @@ struct pnp_dev * pnp_request_card_device(struct pnp_card_link *clink, const char
302 } 316 }
303 while (pos != &card->devices) { 317 while (pos != &card->devices) {
304 dev = card_to_pnp_dev(pos); 318 dev = card_to_pnp_dev(pos);
305 if ((!dev->card_link) && compare_pnp_id(dev->id,id)) 319 if ((!dev->card_link) && compare_pnp_id(dev->id, id))
306 goto found; 320 goto found;
307 pos = pos->next; 321 pos = pos->next;
308 } 322 }
309 323
310done: 324 done:
311 return NULL; 325 return NULL;
312 326
313found: 327 found:
314 dev->card_link = clink; 328 dev->card_link = clink;
315 dev->dev.driver = &drv->link.driver; 329 dev->dev.driver = &drv->link.driver;
316 if (pnp_bus_type.probe(&dev->dev)) 330 if (pnp_bus_type.probe(&dev->dev))
@@ -320,7 +334,7 @@ found:
320 334
321 return dev; 335 return dev;
322 336
323err_out: 337 err_out:
324 dev->dev.driver = NULL; 338 dev->dev.driver = NULL;
325 dev->card_link = NULL; 339 dev->card_link = NULL;
326 return NULL; 340 return NULL;
@@ -330,10 +344,10 @@ err_out:
330 * pnp_release_card_device - call this when the driver no longer needs the device 344 * pnp_release_card_device - call this when the driver no longer needs the device
331 * @dev: pointer to the PnP device stucture 345 * @dev: pointer to the PnP device stucture
332 */ 346 */
333 347void pnp_release_card_device(struct pnp_dev *dev)
334void pnp_release_card_device(struct pnp_dev * dev)
335{ 348{
336 struct pnp_card_driver * drv = dev->card_link->driver; 349 struct pnp_card_driver *drv = dev->card_link->driver;
350
337 if (!drv) 351 if (!drv)
338 return; 352 return;
339 drv->link.remove = &card_remove; 353 drv->link.remove = &card_remove;
@@ -347,6 +361,7 @@ void pnp_release_card_device(struct pnp_dev * dev)
347static int card_suspend(struct pnp_dev *dev, pm_message_t state) 361static int card_suspend(struct pnp_dev *dev, pm_message_t state)
348{ 362{
349 struct pnp_card_link *link = dev->card_link; 363 struct pnp_card_link *link = dev->card_link;
364
350 if (link->pm_state.event == state.event) 365 if (link->pm_state.event == state.event)
351 return 0; 366 return 0;
352 link->pm_state = state; 367 link->pm_state = state;
@@ -356,6 +371,7 @@ static int card_suspend(struct pnp_dev *dev, pm_message_t state)
356static int card_resume(struct pnp_dev *dev) 371static int card_resume(struct pnp_dev *dev)
357{ 372{
358 struct pnp_card_link *link = dev->card_link; 373 struct pnp_card_link *link = dev->card_link;
374
359 if (link->pm_state.event == PM_EVENT_ON) 375 if (link->pm_state.event == PM_EVENT_ON)
360 return 0; 376 return 0;
361 link->pm_state = PMSG_ON; 377 link->pm_state = PMSG_ON;
@@ -367,8 +383,7 @@ static int card_resume(struct pnp_dev *dev)
367 * pnp_register_card_driver - registers a PnP card driver with the PnP Layer 383 * pnp_register_card_driver - registers a PnP card driver with the PnP Layer
368 * @drv: pointer to the driver to register 384 * @drv: pointer to the driver to register
369 */ 385 */
370 386int pnp_register_card_driver(struct pnp_card_driver *drv)
371int pnp_register_card_driver(struct pnp_card_driver * drv)
372{ 387{
373 int error; 388 int error;
374 struct list_head *pos, *temp; 389 struct list_head *pos, *temp;
@@ -389,9 +404,10 @@ int pnp_register_card_driver(struct pnp_card_driver * drv)
389 list_add_tail(&drv->global_list, &pnp_card_drivers); 404 list_add_tail(&drv->global_list, &pnp_card_drivers);
390 spin_unlock(&pnp_lock); 405 spin_unlock(&pnp_lock);
391 406
392 list_for_each_safe(pos,temp,&pnp_cards){ 407 list_for_each_safe(pos, temp, &pnp_cards) {
393 struct pnp_card *card = list_entry(pos, struct pnp_card, global_list); 408 struct pnp_card *card =
394 card_probe(card,drv); 409 list_entry(pos, struct pnp_card, global_list);
410 card_probe(card, drv);
395 } 411 }
396 return 0; 412 return 0;
397} 413}
@@ -400,8 +416,7 @@ int pnp_register_card_driver(struct pnp_card_driver * drv)
400 * pnp_unregister_card_driver - unregisters a PnP card driver from the PnP Layer 416 * pnp_unregister_card_driver - unregisters a PnP card driver from the PnP Layer
401 * @drv: pointer to the driver to unregister 417 * @drv: pointer to the driver to unregister
402 */ 418 */
403 419void pnp_unregister_card_driver(struct pnp_card_driver *drv)
404void pnp_unregister_card_driver(struct pnp_card_driver * drv)
405{ 420{
406 spin_lock(&pnp_lock); 421 spin_lock(&pnp_lock);
407 list_del(&drv->global_list); 422 list_del(&drv->global_list);
@@ -409,13 +424,6 @@ void pnp_unregister_card_driver(struct pnp_card_driver * drv)
409 pnp_unregister_driver(&drv->link); 424 pnp_unregister_driver(&drv->link);
410} 425}
411 426
412#if 0
413EXPORT_SYMBOL(pnp_add_card);
414EXPORT_SYMBOL(pnp_remove_card);
415EXPORT_SYMBOL(pnp_add_card_device);
416EXPORT_SYMBOL(pnp_remove_card_device);
417EXPORT_SYMBOL(pnp_add_card_id);
418#endif /* 0 */
419EXPORT_SYMBOL(pnp_request_card_device); 427EXPORT_SYMBOL(pnp_request_card_device);
420EXPORT_SYMBOL(pnp_release_card_device); 428EXPORT_SYMBOL(pnp_release_card_device);
421EXPORT_SYMBOL(pnp_register_card_driver); 429EXPORT_SYMBOL(pnp_register_card_driver);
diff --git a/drivers/pnp/core.c b/drivers/pnp/core.c
index 8e7b2dd38810..61066fdb9e6d 100644
--- a/drivers/pnp/core.c
+++ b/drivers/pnp/core.c
@@ -2,7 +2,6 @@
2 * core.c - contains all core device and protocol registration functions 2 * core.c - contains all core device and protocol registration functions
3 * 3 *
4 * Copyright 2002 Adam Belay <ambx1@neo.rr.com> 4 * Copyright 2002 Adam Belay <ambx1@neo.rr.com>
5 *
6 */ 5 */
7 6
8#include <linux/pnp.h> 7#include <linux/pnp.h>
@@ -18,7 +17,6 @@
18 17
19#include "base.h" 18#include "base.h"
20 19
21
22static LIST_HEAD(pnp_protocols); 20static LIST_HEAD(pnp_protocols);
23LIST_HEAD(pnp_global); 21LIST_HEAD(pnp_global);
24DEFINE_SPINLOCK(pnp_lock); 22DEFINE_SPINLOCK(pnp_lock);
@@ -36,7 +34,7 @@ void *pnp_alloc(long size)
36 void *result; 34 void *result;
37 35
38 result = kzalloc(size, GFP_KERNEL); 36 result = kzalloc(size, GFP_KERNEL);
39 if (!result){ 37 if (!result) {
40 printk(KERN_ERR "pnp: Out of Memory\n"); 38 printk(KERN_ERR "pnp: Out of Memory\n");
41 return NULL; 39 return NULL;
42 } 40 }
@@ -49,11 +47,10 @@ void *pnp_alloc(long size)
49 * 47 *
50 * Ex protocols: ISAPNP, PNPBIOS, etc 48 * Ex protocols: ISAPNP, PNPBIOS, etc
51 */ 49 */
52
53int pnp_register_protocol(struct pnp_protocol *protocol) 50int pnp_register_protocol(struct pnp_protocol *protocol)
54{ 51{
55 int nodenum; 52 int nodenum;
56 struct list_head * pos; 53 struct list_head *pos;
57 54
58 if (!protocol) 55 if (!protocol)
59 return -EINVAL; 56 return -EINVAL;
@@ -64,9 +61,9 @@ int pnp_register_protocol(struct pnp_protocol *protocol)
64 spin_lock(&pnp_lock); 61 spin_lock(&pnp_lock);
65 62
66 /* assign the lowest unused number */ 63 /* assign the lowest unused number */
67 list_for_each(pos,&pnp_protocols) { 64 list_for_each(pos, &pnp_protocols) {
68 struct pnp_protocol * cur = to_pnp_protocol(pos); 65 struct pnp_protocol *cur = to_pnp_protocol(pos);
69 if (cur->number == nodenum){ 66 if (cur->number == nodenum) {
70 pos = &pnp_protocols; 67 pos = &pnp_protocols;
71 nodenum++; 68 nodenum++;
72 } 69 }
@@ -83,7 +80,6 @@ int pnp_register_protocol(struct pnp_protocol *protocol)
83/** 80/**
84 * pnp_protocol_unregister - removes a pnp protocol from the pnp layer 81 * pnp_protocol_unregister - removes a pnp protocol from the pnp layer
85 * @protocol: pointer to the corresponding pnp_protocol structure 82 * @protocol: pointer to the corresponding pnp_protocol structure
86 *
87 */ 83 */
88void pnp_unregister_protocol(struct pnp_protocol *protocol) 84void pnp_unregister_protocol(struct pnp_protocol *protocol)
89{ 85{
@@ -93,11 +89,11 @@ void pnp_unregister_protocol(struct pnp_protocol *protocol)
93 device_unregister(&protocol->dev); 89 device_unregister(&protocol->dev);
94} 90}
95 91
96
97static void pnp_free_ids(struct pnp_dev *dev) 92static void pnp_free_ids(struct pnp_dev *dev)
98{ 93{
99 struct pnp_id * id; 94 struct pnp_id *id;
100 struct pnp_id * next; 95 struct pnp_id *next;
96
101 if (!dev) 97 if (!dev)
102 return; 98 return;
103 id = dev->id; 99 id = dev->id;
@@ -110,7 +106,8 @@ static void pnp_free_ids(struct pnp_dev *dev)
110 106
111static void pnp_release_device(struct device *dmdev) 107static void pnp_release_device(struct device *dmdev)
112{ 108{
113 struct pnp_dev * dev = to_pnp_dev(dmdev); 109 struct pnp_dev *dev = to_pnp_dev(dmdev);
110
114 pnp_free_option(dev->independent); 111 pnp_free_option(dev->independent);
115 pnp_free_option(dev->dependent); 112 pnp_free_option(dev->dependent);
116 pnp_free_ids(dev); 113 pnp_free_ids(dev);
@@ -120,6 +117,7 @@ static void pnp_release_device(struct device *dmdev)
120int __pnp_add_device(struct pnp_dev *dev) 117int __pnp_add_device(struct pnp_dev *dev)
121{ 118{
122 int ret; 119 int ret;
120
123 pnp_fixup_device(dev); 121 pnp_fixup_device(dev);
124 dev->dev.bus = &pnp_bus_type; 122 dev->dev.bus = &pnp_bus_type;
125 dev->dev.dma_mask = &dev->dma_mask; 123 dev->dev.dma_mask = &dev->dma_mask;
@@ -143,13 +141,13 @@ int __pnp_add_device(struct pnp_dev *dev)
143 * 141 *
144 * adds to driver model, name database, fixups, interface, etc. 142 * adds to driver model, name database, fixups, interface, etc.
145 */ 143 */
146
147int pnp_add_device(struct pnp_dev *dev) 144int pnp_add_device(struct pnp_dev *dev)
148{ 145{
149 if (!dev || !dev->protocol || dev->card) 146 if (!dev || !dev->protocol || dev->card)
150 return -EINVAL; 147 return -EINVAL;
151 dev->dev.parent = &dev->protocol->dev; 148 dev->dev.parent = &dev->protocol->dev;
152 sprintf(dev->dev.bus_id, "%02x:%02x", dev->protocol->number, dev->number); 149 sprintf(dev->dev.bus_id, "%02x:%02x", dev->protocol->number,
150 dev->number);
153 return __pnp_add_device(dev); 151 return __pnp_add_device(dev);
154} 152}
155 153
@@ -162,21 +160,6 @@ void __pnp_remove_device(struct pnp_dev *dev)
162 device_unregister(&dev->dev); 160 device_unregister(&dev->dev);
163} 161}
164 162
165/**
166 * pnp_remove_device - removes a pnp device from the pnp layer
167 * @dev: pointer to dev to add
168 *
169 * this function will free all mem used by dev
170 */
171#if 0
172void pnp_remove_device(struct pnp_dev *dev)
173{
174 if (!dev || dev->card)
175 return;
176 __pnp_remove_device(dev);
177}
178#endif /* 0 */
179
180static int __init pnp_init(void) 163static int __init pnp_init(void)
181{ 164{
182 printk(KERN_INFO "Linux Plug and Play Support v0.97 (c) Adam Belay\n"); 165 printk(KERN_INFO "Linux Plug and Play Support v0.97 (c) Adam Belay\n");
@@ -184,10 +167,3 @@ static int __init pnp_init(void)
184} 167}
185 168
186subsys_initcall(pnp_init); 169subsys_initcall(pnp_init);
187
188#if 0
189EXPORT_SYMBOL(pnp_register_protocol);
190EXPORT_SYMBOL(pnp_unregister_protocol);
191EXPORT_SYMBOL(pnp_add_device);
192EXPORT_SYMBOL(pnp_remove_device);
193#endif /* 0 */
diff --git a/drivers/pnp/driver.c b/drivers/pnp/driver.c
index e161423b4300..30b8f6f3258a 100644
--- a/drivers/pnp/driver.c
+++ b/drivers/pnp/driver.c
@@ -2,7 +2,6 @@
2 * driver.c - device id matching, driver model, etc. 2 * driver.c - device id matching, driver model, etc.
3 * 3 *
4 * Copyright 2002 Adam Belay <ambx1@neo.rr.com> 4 * Copyright 2002 Adam Belay <ambx1@neo.rr.com>
5 *
6 */ 5 */
7 6
8#include <linux/string.h> 7#include <linux/string.h>
@@ -16,12 +15,11 @@
16static int compare_func(const char *ida, const char *idb) 15static int compare_func(const char *ida, const char *idb)
17{ 16{
18 int i; 17 int i;
18
19 /* we only need to compare the last 4 chars */ 19 /* we only need to compare the last 4 chars */
20 for (i=3; i<7; i++) 20 for (i = 3; i < 7; i++) {
21 {
22 if (ida[i] != 'X' && 21 if (ida[i] != 'X' &&
23 idb[i] != 'X' && 22 idb[i] != 'X' && toupper(ida[i]) != toupper(idb[i]))
24 toupper(ida[i]) != toupper(idb[i]))
25 return 0; 23 return 0;
26 } 24 }
27 return 1; 25 return 1;
@@ -31,20 +29,22 @@ int compare_pnp_id(struct pnp_id *pos, const char *id)
31{ 29{
32 if (!pos || !id || (strlen(id) != 7)) 30 if (!pos || !id || (strlen(id) != 7))
33 return 0; 31 return 0;
34 if (memcmp(id,"ANYDEVS",7)==0) 32 if (memcmp(id, "ANYDEVS", 7) == 0)
35 return 1; 33 return 1;
36 while (pos){ 34 while (pos) {
37 if (memcmp(pos->id,id,3)==0) 35 if (memcmp(pos->id, id, 3) == 0)
38 if (compare_func(pos->id,id)==1) 36 if (compare_func(pos->id, id) == 1)
39 return 1; 37 return 1;
40 pos = pos->next; 38 pos = pos->next;
41 } 39 }
42 return 0; 40 return 0;
43} 41}
44 42
45static const struct pnp_device_id * match_device(struct pnp_driver *drv, struct pnp_dev *dev) 43static const struct pnp_device_id *match_device(struct pnp_driver *drv,
44 struct pnp_dev *dev)
46{ 45{
47 const struct pnp_device_id *drv_id = drv->id_table; 46 const struct pnp_device_id *drv_id = drv->id_table;
47
48 if (!drv_id) 48 if (!drv_id)
49 return NULL; 49 return NULL;
50 50
@@ -59,7 +59,7 @@ static const struct pnp_device_id * match_device(struct pnp_driver *drv, struct
59int pnp_device_attach(struct pnp_dev *pnp_dev) 59int pnp_device_attach(struct pnp_dev *pnp_dev)
60{ 60{
61 spin_lock(&pnp_lock); 61 spin_lock(&pnp_lock);
62 if(pnp_dev->status != PNP_READY){ 62 if (pnp_dev->status != PNP_READY) {
63 spin_unlock(&pnp_lock); 63 spin_unlock(&pnp_lock);
64 return -EBUSY; 64 return -EBUSY;
65 } 65 }
@@ -86,7 +86,8 @@ static int pnp_device_probe(struct device *dev)
86 pnp_dev = to_pnp_dev(dev); 86 pnp_dev = to_pnp_dev(dev);
87 pnp_drv = to_pnp_driver(dev->driver); 87 pnp_drv = to_pnp_driver(dev->driver);
88 88
89 pnp_dbg("match found with the PnP device '%s' and the driver '%s'", dev->bus_id,pnp_drv->name); 89 pnp_dbg("match found with the PnP device '%s' and the driver '%s'",
90 dev->bus_id, pnp_drv->name);
90 91
91 error = pnp_device_attach(pnp_dev); 92 error = pnp_device_attach(pnp_dev);
92 if (error < 0) 93 if (error < 0)
@@ -99,7 +100,7 @@ static int pnp_device_probe(struct device *dev)
99 return error; 100 return error;
100 } 101 }
101 } else if ((pnp_drv->flags & PNP_DRIVER_RES_DISABLE) 102 } else if ((pnp_drv->flags & PNP_DRIVER_RES_DISABLE)
102 == PNP_DRIVER_RES_DISABLE) { 103 == PNP_DRIVER_RES_DISABLE) {
103 error = pnp_disable_dev(pnp_dev); 104 error = pnp_disable_dev(pnp_dev);
104 if (error < 0) 105 if (error < 0)
105 return error; 106 return error;
@@ -110,22 +111,22 @@ static int pnp_device_probe(struct device *dev)
110 if (dev_id != NULL) 111 if (dev_id != NULL)
111 error = pnp_drv->probe(pnp_dev, dev_id); 112 error = pnp_drv->probe(pnp_dev, dev_id);
112 } 113 }
113 if (error >= 0){ 114 if (error >= 0) {
114 pnp_dev->driver = pnp_drv; 115 pnp_dev->driver = pnp_drv;
115 error = 0; 116 error = 0;
116 } else 117 } else
117 goto fail; 118 goto fail;
118 return error; 119 return error;
119 120
120fail: 121 fail:
121 pnp_device_detach(pnp_dev); 122 pnp_device_detach(pnp_dev);
122 return error; 123 return error;
123} 124}
124 125
125static int pnp_device_remove(struct device *dev) 126static int pnp_device_remove(struct device *dev)
126{ 127{
127 struct pnp_dev * pnp_dev = to_pnp_dev(dev); 128 struct pnp_dev *pnp_dev = to_pnp_dev(dev);
128 struct pnp_driver * drv = pnp_dev->driver; 129 struct pnp_driver *drv = pnp_dev->driver;
129 130
130 if (drv) { 131 if (drv) {
131 if (drv->remove) 132 if (drv->remove)
@@ -138,8 +139,9 @@ static int pnp_device_remove(struct device *dev)
138 139
139static int pnp_bus_match(struct device *dev, struct device_driver *drv) 140static int pnp_bus_match(struct device *dev, struct device_driver *drv)
140{ 141{
141 struct pnp_dev * pnp_dev = to_pnp_dev(dev); 142 struct pnp_dev *pnp_dev = to_pnp_dev(dev);
142 struct pnp_driver * pnp_drv = to_pnp_driver(drv); 143 struct pnp_driver *pnp_drv = to_pnp_driver(drv);
144
143 if (match_device(pnp_drv, pnp_dev) == NULL) 145 if (match_device(pnp_drv, pnp_dev) == NULL)
144 return 0; 146 return 0;
145 return 1; 147 return 1;
@@ -147,8 +149,8 @@ static int pnp_bus_match(struct device *dev, struct device_driver *drv)
147 149
148static int pnp_bus_suspend(struct device *dev, pm_message_t state) 150static int pnp_bus_suspend(struct device *dev, pm_message_t state)
149{ 151{
150 struct pnp_dev * pnp_dev = to_pnp_dev(dev); 152 struct pnp_dev *pnp_dev = to_pnp_dev(dev);
151 struct pnp_driver * pnp_drv = pnp_dev->driver; 153 struct pnp_driver *pnp_drv = pnp_dev->driver;
152 int error; 154 int error;
153 155
154 if (!pnp_drv) 156 if (!pnp_drv)
@@ -162,23 +164,28 @@ static int pnp_bus_suspend(struct device *dev, pm_message_t state)
162 164
163 if (!(pnp_drv->flags & PNP_DRIVER_RES_DO_NOT_CHANGE) && 165 if (!(pnp_drv->flags & PNP_DRIVER_RES_DO_NOT_CHANGE) &&
164 pnp_can_disable(pnp_dev)) { 166 pnp_can_disable(pnp_dev)) {
165 error = pnp_stop_dev(pnp_dev); 167 error = pnp_stop_dev(pnp_dev);
166 if (error) 168 if (error)
167 return error; 169 return error;
168 } 170 }
169 171
172 if (pnp_dev->protocol && pnp_dev->protocol->suspend)
173 pnp_dev->protocol->suspend(pnp_dev, state);
170 return 0; 174 return 0;
171} 175}
172 176
173static int pnp_bus_resume(struct device *dev) 177static int pnp_bus_resume(struct device *dev)
174{ 178{
175 struct pnp_dev * pnp_dev = to_pnp_dev(dev); 179 struct pnp_dev *pnp_dev = to_pnp_dev(dev);
176 struct pnp_driver * pnp_drv = pnp_dev->driver; 180 struct pnp_driver *pnp_drv = pnp_dev->driver;
177 int error; 181 int error;
178 182
179 if (!pnp_drv) 183 if (!pnp_drv)
180 return 0; 184 return 0;
181 185
186 if (pnp_dev->protocol && pnp_dev->protocol->resume)
187 pnp_dev->protocol->resume(pnp_dev);
188
182 if (!(pnp_drv->flags & PNP_DRIVER_RES_DO_NOT_CHANGE)) { 189 if (!(pnp_drv->flags & PNP_DRIVER_RES_DO_NOT_CHANGE)) {
183 error = pnp_start_dev(pnp_dev); 190 error = pnp_start_dev(pnp_dev);
184 if (error) 191 if (error)
@@ -192,12 +199,12 @@ static int pnp_bus_resume(struct device *dev)
192} 199}
193 200
194struct bus_type pnp_bus_type = { 201struct bus_type pnp_bus_type = {
195 .name = "pnp", 202 .name = "pnp",
196 .match = pnp_bus_match, 203 .match = pnp_bus_match,
197 .probe = pnp_device_probe, 204 .probe = pnp_device_probe,
198 .remove = pnp_device_remove, 205 .remove = pnp_device_remove,
199 .suspend = pnp_bus_suspend, 206 .suspend = pnp_bus_suspend,
200 .resume = pnp_bus_resume, 207 .resume = pnp_bus_resume,
201}; 208};
202 209
203int pnp_register_driver(struct pnp_driver *drv) 210int pnp_register_driver(struct pnp_driver *drv)
@@ -220,12 +227,11 @@ void pnp_unregister_driver(struct pnp_driver *drv)
220 * pnp_add_id - adds an EISA id to the specified device 227 * pnp_add_id - adds an EISA id to the specified device
221 * @id: pointer to a pnp_id structure 228 * @id: pointer to a pnp_id structure
222 * @dev: pointer to the desired device 229 * @dev: pointer to the desired device
223 *
224 */ 230 */
225
226int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev) 231int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev)
227{ 232{
228 struct pnp_id *ptr; 233 struct pnp_id *ptr;
234
229 if (!id) 235 if (!id)
230 return -EINVAL; 236 return -EINVAL;
231 if (!dev) 237 if (!dev)
@@ -243,8 +249,5 @@ int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev)
243 249
244EXPORT_SYMBOL(pnp_register_driver); 250EXPORT_SYMBOL(pnp_register_driver);
245EXPORT_SYMBOL(pnp_unregister_driver); 251EXPORT_SYMBOL(pnp_unregister_driver);
246#if 0
247EXPORT_SYMBOL(pnp_add_id);
248#endif
249EXPORT_SYMBOL(pnp_device_attach); 252EXPORT_SYMBOL(pnp_device_attach);
250EXPORT_SYMBOL(pnp_device_detach); 253EXPORT_SYMBOL(pnp_device_detach);
diff --git a/drivers/pnp/interface.c b/drivers/pnp/interface.c
index ac9fcd499f3f..fe6684e13e82 100644
--- a/drivers/pnp/interface.c
+++ b/drivers/pnp/interface.c
@@ -3,7 +3,6 @@
3 * 3 *
4 * Some code, especially possible resource dumping is based on isapnp_proc.c (c) Jaroslav Kysela <perex@suse.cz> 4 * Some code, especially possible resource dumping is based on isapnp_proc.c (c) Jaroslav Kysela <perex@suse.cz>
5 * Copyright 2002 Adam Belay <ambx1@neo.rr.com> 5 * Copyright 2002 Adam Belay <ambx1@neo.rr.com>
6 *
7 */ 6 */
8 7
9#include <linux/pnp.h> 8#include <linux/pnp.h>
@@ -29,7 +28,7 @@ struct pnp_info_buffer {
29 28
30typedef struct pnp_info_buffer pnp_info_buffer_t; 29typedef struct pnp_info_buffer pnp_info_buffer_t;
31 30
32static int pnp_printf(pnp_info_buffer_t * buffer, char *fmt,...) 31static int pnp_printf(pnp_info_buffer_t * buffer, char *fmt, ...)
33{ 32{
34 va_list args; 33 va_list args;
35 int res; 34 int res;
@@ -48,14 +47,18 @@ static int pnp_printf(pnp_info_buffer_t * buffer, char *fmt,...)
48 return res; 47 return res;
49} 48}
50 49
51static void pnp_print_port(pnp_info_buffer_t *buffer, char *space, struct pnp_port *port) 50static void pnp_print_port(pnp_info_buffer_t * buffer, char *space,
51 struct pnp_port *port)
52{ 52{
53 pnp_printf(buffer, "%sport 0x%x-0x%x, align 0x%x, size 0x%x, %i-bit address decoding\n", 53 pnp_printf(buffer,
54 space, port->min, port->max, port->align ? (port->align-1) : 0, port->size, 54 "%sport 0x%x-0x%x, align 0x%x, size 0x%x, %i-bit address decoding\n",
55 port->flags & PNP_PORT_FLAG_16BITADDR ? 16 : 10); 55 space, port->min, port->max,
56 port->align ? (port->align - 1) : 0, port->size,
57 port->flags & PNP_PORT_FLAG_16BITADDR ? 16 : 10);
56} 58}
57 59
58static void pnp_print_irq(pnp_info_buffer_t *buffer, char *space, struct pnp_irq *irq) 60static void pnp_print_irq(pnp_info_buffer_t * buffer, char *space,
61 struct pnp_irq *irq)
59{ 62{
60 int first = 1, i; 63 int first = 1, i;
61 64
@@ -85,14 +88,15 @@ static void pnp_print_irq(pnp_info_buffer_t *buffer, char *space, struct pnp_irq
85 pnp_printf(buffer, "\n"); 88 pnp_printf(buffer, "\n");
86} 89}
87 90
88static void pnp_print_dma(pnp_info_buffer_t *buffer, char *space, struct pnp_dma *dma) 91static void pnp_print_dma(pnp_info_buffer_t * buffer, char *space,
92 struct pnp_dma *dma)
89{ 93{
90 int first = 1, i; 94 int first = 1, i;
91 char *s; 95 char *s;
92 96
93 pnp_printf(buffer, "%sdma ", space); 97 pnp_printf(buffer, "%sdma ", space);
94 for (i = 0; i < 8; i++) 98 for (i = 0; i < 8; i++)
95 if (dma->map & (1<<i)) { 99 if (dma->map & (1 << i)) {
96 if (!first) { 100 if (!first) {
97 pnp_printf(buffer, ","); 101 pnp_printf(buffer, ",");
98 } else { 102 } else {
@@ -136,12 +140,13 @@ static void pnp_print_dma(pnp_info_buffer_t *buffer, char *space, struct pnp_dma
136 pnp_printf(buffer, " %s\n", s); 140 pnp_printf(buffer, " %s\n", s);
137} 141}
138 142
139static void pnp_print_mem(pnp_info_buffer_t *buffer, char *space, struct pnp_mem *mem) 143static void pnp_print_mem(pnp_info_buffer_t * buffer, char *space,
144 struct pnp_mem *mem)
140{ 145{
141 char *s; 146 char *s;
142 147
143 pnp_printf(buffer, "%sMemory 0x%x-0x%x, align 0x%x, size 0x%x", 148 pnp_printf(buffer, "%sMemory 0x%x-0x%x, align 0x%x, size 0x%x",
144 space, mem->min, mem->max, mem->align, mem->size); 149 space, mem->min, mem->max, mem->align, mem->size);
145 if (mem->flags & IORESOURCE_MEM_WRITEABLE) 150 if (mem->flags & IORESOURCE_MEM_WRITEABLE)
146 pnp_printf(buffer, ", writeable"); 151 pnp_printf(buffer, ", writeable");
147 if (mem->flags & IORESOURCE_MEM_CACHEABLE) 152 if (mem->flags & IORESOURCE_MEM_CACHEABLE)
@@ -168,7 +173,7 @@ static void pnp_print_mem(pnp_info_buffer_t *buffer, char *space, struct pnp_mem
168 pnp_printf(buffer, ", %s\n", s); 173 pnp_printf(buffer, ", %s\n", s);
169} 174}
170 175
171static void pnp_print_option(pnp_info_buffer_t *buffer, char *space, 176static void pnp_print_option(pnp_info_buffer_t * buffer, char *space,
172 struct pnp_option *option, int dep) 177 struct pnp_option *option, int dep)
173{ 178{
174 char *s; 179 char *s;
@@ -179,19 +184,19 @@ static void pnp_print_option(pnp_info_buffer_t *buffer, char *space,
179 184
180 if (dep) { 185 if (dep) {
181 switch (option->priority) { 186 switch (option->priority) {
182 case PNP_RES_PRIORITY_PREFERRED: 187 case PNP_RES_PRIORITY_PREFERRED:
183 s = "preferred"; 188 s = "preferred";
184 break; 189 break;
185 case PNP_RES_PRIORITY_ACCEPTABLE: 190 case PNP_RES_PRIORITY_ACCEPTABLE:
186 s = "acceptable"; 191 s = "acceptable";
187 break; 192 break;
188 case PNP_RES_PRIORITY_FUNCTIONAL: 193 case PNP_RES_PRIORITY_FUNCTIONAL:
189 s = "functional"; 194 s = "functional";
190 break; 195 break;
191 default: 196 default:
192 s = "invalid"; 197 s = "invalid";
193 } 198 }
194 pnp_printf(buffer, "Dependent: %02i - Priority %s\n",dep, s); 199 pnp_printf(buffer, "Dependent: %02i - Priority %s\n", dep, s);
195 } 200 }
196 201
197 for (port = option->port; port; port = port->next) 202 for (port = option->port; port; port = port->next)
@@ -204,16 +209,16 @@ static void pnp_print_option(pnp_info_buffer_t *buffer, char *space,
204 pnp_print_mem(buffer, space, mem); 209 pnp_print_mem(buffer, space, mem);
205} 210}
206 211
207 212static ssize_t pnp_show_options(struct device *dmdev,
208static ssize_t pnp_show_options(struct device *dmdev, struct device_attribute *attr, char *buf) 213 struct device_attribute *attr, char *buf)
209{ 214{
210 struct pnp_dev *dev = to_pnp_dev(dmdev); 215 struct pnp_dev *dev = to_pnp_dev(dmdev);
211 struct pnp_option * independent = dev->independent; 216 struct pnp_option *independent = dev->independent;
212 struct pnp_option * dependent = dev->dependent; 217 struct pnp_option *dependent = dev->dependent;
213 int ret, dep = 1; 218 int ret, dep = 1;
214 219
215 pnp_info_buffer_t *buffer = (pnp_info_buffer_t *) 220 pnp_info_buffer_t *buffer = (pnp_info_buffer_t *)
216 pnp_alloc(sizeof(pnp_info_buffer_t)); 221 pnp_alloc(sizeof(pnp_info_buffer_t));
217 if (!buffer) 222 if (!buffer)
218 return -ENOMEM; 223 return -ENOMEM;
219 224
@@ -223,7 +228,7 @@ static ssize_t pnp_show_options(struct device *dmdev, struct device_attribute *a
223 if (independent) 228 if (independent)
224 pnp_print_option(buffer, "", independent, 0); 229 pnp_print_option(buffer, "", independent, 0);
225 230
226 while (dependent){ 231 while (dependent) {
227 pnp_print_option(buffer, " ", dependent, dep); 232 pnp_print_option(buffer, " ", dependent, dep);
228 dependent = dependent->next; 233 dependent = dependent->next;
229 dep++; 234 dep++;
@@ -233,10 +238,11 @@ static ssize_t pnp_show_options(struct device *dmdev, struct device_attribute *a
233 return ret; 238 return ret;
234} 239}
235 240
236static DEVICE_ATTR(options,S_IRUGO,pnp_show_options,NULL); 241static DEVICE_ATTR(options, S_IRUGO, pnp_show_options, NULL);
237 242
238 243static ssize_t pnp_show_current_resources(struct device *dmdev,
239static ssize_t pnp_show_current_resources(struct device *dmdev, struct device_attribute *attr, char *buf) 244 struct device_attribute *attr,
245 char *buf)
240{ 246{
241 struct pnp_dev *dev = to_pnp_dev(dmdev); 247 struct pnp_dev *dev = to_pnp_dev(dmdev);
242 int i, ret; 248 int i, ret;
@@ -252,52 +258,56 @@ static ssize_t pnp_show_current_resources(struct device *dmdev, struct device_at
252 buffer->buffer = buf; 258 buffer->buffer = buf;
253 buffer->curr = buffer->buffer; 259 buffer->curr = buffer->buffer;
254 260
255 pnp_printf(buffer,"state = "); 261 pnp_printf(buffer, "state = ");
256 if (dev->active) 262 if (dev->active)
257 pnp_printf(buffer,"active\n"); 263 pnp_printf(buffer, "active\n");
258 else 264 else
259 pnp_printf(buffer,"disabled\n"); 265 pnp_printf(buffer, "disabled\n");
260 266
261 for (i = 0; i < PNP_MAX_PORT; i++) { 267 for (i = 0; i < PNP_MAX_PORT; i++) {
262 if (pnp_port_valid(dev, i)) { 268 if (pnp_port_valid(dev, i)) {
263 pnp_printf(buffer,"io"); 269 pnp_printf(buffer, "io");
264 if (pnp_port_flags(dev, i) & IORESOURCE_DISABLED) 270 if (pnp_port_flags(dev, i) & IORESOURCE_DISABLED)
265 pnp_printf(buffer," disabled\n"); 271 pnp_printf(buffer, " disabled\n");
266 else 272 else
267 pnp_printf(buffer," 0x%llx-0x%llx\n", 273 pnp_printf(buffer, " 0x%llx-0x%llx\n",
268 (unsigned long long)pnp_port_start(dev, i), 274 (unsigned long long)
269 (unsigned long long)pnp_port_end(dev, i)); 275 pnp_port_start(dev, i),
276 (unsigned long long)pnp_port_end(dev,
277 i));
270 } 278 }
271 } 279 }
272 for (i = 0; i < PNP_MAX_MEM; i++) { 280 for (i = 0; i < PNP_MAX_MEM; i++) {
273 if (pnp_mem_valid(dev, i)) { 281 if (pnp_mem_valid(dev, i)) {
274 pnp_printf(buffer,"mem"); 282 pnp_printf(buffer, "mem");
275 if (pnp_mem_flags(dev, i) & IORESOURCE_DISABLED) 283 if (pnp_mem_flags(dev, i) & IORESOURCE_DISABLED)
276 pnp_printf(buffer," disabled\n"); 284 pnp_printf(buffer, " disabled\n");
277 else 285 else
278 pnp_printf(buffer," 0x%llx-0x%llx\n", 286 pnp_printf(buffer, " 0x%llx-0x%llx\n",
279 (unsigned long long)pnp_mem_start(dev, i), 287 (unsigned long long)
280 (unsigned long long)pnp_mem_end(dev, i)); 288 pnp_mem_start(dev, i),
289 (unsigned long long)pnp_mem_end(dev,
290 i));
281 } 291 }
282 } 292 }
283 for (i = 0; i < PNP_MAX_IRQ; i++) { 293 for (i = 0; i < PNP_MAX_IRQ; i++) {
284 if (pnp_irq_valid(dev, i)) { 294 if (pnp_irq_valid(dev, i)) {
285 pnp_printf(buffer,"irq"); 295 pnp_printf(buffer, "irq");
286 if (pnp_irq_flags(dev, i) & IORESOURCE_DISABLED) 296 if (pnp_irq_flags(dev, i) & IORESOURCE_DISABLED)
287 pnp_printf(buffer," disabled\n"); 297 pnp_printf(buffer, " disabled\n");
288 else 298 else
289 pnp_printf(buffer," %lld\n", 299 pnp_printf(buffer, " %lld\n",
290 (unsigned long long)pnp_irq(dev, i)); 300 (unsigned long long)pnp_irq(dev, i));
291 } 301 }
292 } 302 }
293 for (i = 0; i < PNP_MAX_DMA; i++) { 303 for (i = 0; i < PNP_MAX_DMA; i++) {
294 if (pnp_dma_valid(dev, i)) { 304 if (pnp_dma_valid(dev, i)) {
295 pnp_printf(buffer,"dma"); 305 pnp_printf(buffer, "dma");
296 if (pnp_dma_flags(dev, i) & IORESOURCE_DISABLED) 306 if (pnp_dma_flags(dev, i) & IORESOURCE_DISABLED)
297 pnp_printf(buffer," disabled\n"); 307 pnp_printf(buffer, " disabled\n");
298 else 308 else
299 pnp_printf(buffer," %lld\n", 309 pnp_printf(buffer, " %lld\n",
300 (unsigned long long)pnp_dma(dev, i)); 310 (unsigned long long)pnp_dma(dev, i));
301 } 311 }
302 } 312 }
303 ret = (buffer->curr - buf); 313 ret = (buffer->curr - buf);
@@ -308,55 +318,57 @@ static ssize_t pnp_show_current_resources(struct device *dmdev, struct device_at
308extern struct semaphore pnp_res_mutex; 318extern struct semaphore pnp_res_mutex;
309 319
310static ssize_t 320static ssize_t
311pnp_set_current_resources(struct device * dmdev, struct device_attribute *attr, const char * ubuf, size_t count) 321pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
322 const char *ubuf, size_t count)
312{ 323{
313 struct pnp_dev *dev = to_pnp_dev(dmdev); 324 struct pnp_dev *dev = to_pnp_dev(dmdev);
314 char *buf = (void *)ubuf; 325 char *buf = (void *)ubuf;
315 int retval = 0; 326 int retval = 0;
316 327
317 if (dev->status & PNP_ATTACHED) { 328 if (dev->status & PNP_ATTACHED) {
318 retval = -EBUSY; 329 retval = -EBUSY;
319 pnp_info("Device %s cannot be configured because it is in use.", dev->dev.bus_id); 330 pnp_info("Device %s cannot be configured because it is in use.",
331 dev->dev.bus_id);
320 goto done; 332 goto done;
321 } 333 }
322 334
323 while (isspace(*buf)) 335 while (isspace(*buf))
324 ++buf; 336 ++buf;
325 if (!strnicmp(buf,"disable",7)) { 337 if (!strnicmp(buf, "disable", 7)) {
326 retval = pnp_disable_dev(dev); 338 retval = pnp_disable_dev(dev);
327 goto done; 339 goto done;
328 } 340 }
329 if (!strnicmp(buf,"activate",8)) { 341 if (!strnicmp(buf, "activate", 8)) {
330 retval = pnp_activate_dev(dev); 342 retval = pnp_activate_dev(dev);
331 goto done; 343 goto done;
332 } 344 }
333 if (!strnicmp(buf,"fill",4)) { 345 if (!strnicmp(buf, "fill", 4)) {
334 if (dev->active) 346 if (dev->active)
335 goto done; 347 goto done;
336 retval = pnp_auto_config_dev(dev); 348 retval = pnp_auto_config_dev(dev);
337 goto done; 349 goto done;
338 } 350 }
339 if (!strnicmp(buf,"auto",4)) { 351 if (!strnicmp(buf, "auto", 4)) {
340 if (dev->active) 352 if (dev->active)
341 goto done; 353 goto done;
342 pnp_init_resource_table(&dev->res); 354 pnp_init_resource_table(&dev->res);
343 retval = pnp_auto_config_dev(dev); 355 retval = pnp_auto_config_dev(dev);
344 goto done; 356 goto done;
345 } 357 }
346 if (!strnicmp(buf,"clear",5)) { 358 if (!strnicmp(buf, "clear", 5)) {
347 if (dev->active) 359 if (dev->active)
348 goto done; 360 goto done;
349 pnp_init_resource_table(&dev->res); 361 pnp_init_resource_table(&dev->res);
350 goto done; 362 goto done;
351 } 363 }
352 if (!strnicmp(buf,"get",3)) { 364 if (!strnicmp(buf, "get", 3)) {
353 down(&pnp_res_mutex); 365 down(&pnp_res_mutex);
354 if (pnp_can_read(dev)) 366 if (pnp_can_read(dev))
355 dev->protocol->get(dev, &dev->res); 367 dev->protocol->get(dev, &dev->res);
356 up(&pnp_res_mutex); 368 up(&pnp_res_mutex);
357 goto done; 369 goto done;
358 } 370 }
359 if (!strnicmp(buf,"set",3)) { 371 if (!strnicmp(buf, "set", 3)) {
360 int nport = 0, nmem = 0, nirq = 0, ndma = 0; 372 int nport = 0, nmem = 0, nirq = 0, ndma = 0;
361 if (dev->active) 373 if (dev->active)
362 goto done; 374 goto done;
@@ -366,65 +378,77 @@ pnp_set_current_resources(struct device * dmdev, struct device_attribute *attr,
366 while (1) { 378 while (1) {
367 while (isspace(*buf)) 379 while (isspace(*buf))
368 ++buf; 380 ++buf;
369 if (!strnicmp(buf,"io",2)) { 381 if (!strnicmp(buf, "io", 2)) {
370 buf += 2; 382 buf += 2;
371 while (isspace(*buf)) 383 while (isspace(*buf))
372 ++buf; 384 ++buf;
373 dev->res.port_resource[nport].start = simple_strtoul(buf,&buf,0); 385 dev->res.port_resource[nport].start =
386 simple_strtoul(buf, &buf, 0);
374 while (isspace(*buf)) 387 while (isspace(*buf))
375 ++buf; 388 ++buf;
376 if(*buf == '-') { 389 if (*buf == '-') {
377 buf += 1; 390 buf += 1;
378 while (isspace(*buf)) 391 while (isspace(*buf))
379 ++buf; 392 ++buf;
380 dev->res.port_resource[nport].end = simple_strtoul(buf,&buf,0); 393 dev->res.port_resource[nport].end =
394 simple_strtoul(buf, &buf, 0);
381 } else 395 } else
382 dev->res.port_resource[nport].end = dev->res.port_resource[nport].start; 396 dev->res.port_resource[nport].end =
383 dev->res.port_resource[nport].flags = IORESOURCE_IO; 397 dev->res.port_resource[nport].start;
398 dev->res.port_resource[nport].flags =
399 IORESOURCE_IO;
384 nport++; 400 nport++;
385 if (nport >= PNP_MAX_PORT) 401 if (nport >= PNP_MAX_PORT)
386 break; 402 break;
387 continue; 403 continue;
388 } 404 }
389 if (!strnicmp(buf,"mem",3)) { 405 if (!strnicmp(buf, "mem", 3)) {
390 buf += 3; 406 buf += 3;
391 while (isspace(*buf)) 407 while (isspace(*buf))
392 ++buf; 408 ++buf;
393 dev->res.mem_resource[nmem].start = simple_strtoul(buf,&buf,0); 409 dev->res.mem_resource[nmem].start =
410 simple_strtoul(buf, &buf, 0);
394 while (isspace(*buf)) 411 while (isspace(*buf))
395 ++buf; 412 ++buf;
396 if(*buf == '-') { 413 if (*buf == '-') {
397 buf += 1; 414 buf += 1;
398 while (isspace(*buf)) 415 while (isspace(*buf))
399 ++buf; 416 ++buf;
400 dev->res.mem_resource[nmem].end = simple_strtoul(buf,&buf,0); 417 dev->res.mem_resource[nmem].end =
418 simple_strtoul(buf, &buf, 0);
401 } else 419 } else
402 dev->res.mem_resource[nmem].end = dev->res.mem_resource[nmem].start; 420 dev->res.mem_resource[nmem].end =
403 dev->res.mem_resource[nmem].flags = IORESOURCE_MEM; 421 dev->res.mem_resource[nmem].start;
422 dev->res.mem_resource[nmem].flags =
423 IORESOURCE_MEM;
404 nmem++; 424 nmem++;
405 if (nmem >= PNP_MAX_MEM) 425 if (nmem >= PNP_MAX_MEM)
406 break; 426 break;
407 continue; 427 continue;
408 } 428 }
409 if (!strnicmp(buf,"irq",3)) { 429 if (!strnicmp(buf, "irq", 3)) {
410 buf += 3; 430 buf += 3;
411 while (isspace(*buf)) 431 while (isspace(*buf))
412 ++buf; 432 ++buf;
413 dev->res.irq_resource[nirq].start = 433 dev->res.irq_resource[nirq].start =
414 dev->res.irq_resource[nirq].end = simple_strtoul(buf,&buf,0); 434 dev->res.irq_resource[nirq].end =
415 dev->res.irq_resource[nirq].flags = IORESOURCE_IRQ; 435 simple_strtoul(buf, &buf, 0);
436 dev->res.irq_resource[nirq].flags =
437 IORESOURCE_IRQ;
416 nirq++; 438 nirq++;
417 if (nirq >= PNP_MAX_IRQ) 439 if (nirq >= PNP_MAX_IRQ)
418 break; 440 break;
419 continue; 441 continue;
420 } 442 }
421 if (!strnicmp(buf,"dma",3)) { 443 if (!strnicmp(buf, "dma", 3)) {
422 buf += 3; 444 buf += 3;
423 while (isspace(*buf)) 445 while (isspace(*buf))
424 ++buf; 446 ++buf;
425 dev->res.dma_resource[ndma].start = 447 dev->res.dma_resource[ndma].start =
426 dev->res.dma_resource[ndma].end = simple_strtoul(buf,&buf,0); 448 dev->res.dma_resource[ndma].end =
427 dev->res.dma_resource[ndma].flags = IORESOURCE_DMA; 449 simple_strtoul(buf, &buf, 0);
450 dev->res.dma_resource[ndma].flags =
451 IORESOURCE_DMA;
428 ndma++; 452 ndma++;
429 if (ndma >= PNP_MAX_DMA) 453 if (ndma >= PNP_MAX_DMA)
430 break; 454 break;
@@ -435,45 +459,50 @@ pnp_set_current_resources(struct device * dmdev, struct device_attribute *attr,
435 up(&pnp_res_mutex); 459 up(&pnp_res_mutex);
436 goto done; 460 goto done;
437 } 461 }
438 done: 462 done:
439 if (retval < 0) 463 if (retval < 0)
440 return retval; 464 return retval;
441 return count; 465 return count;
442} 466}
443 467
444static DEVICE_ATTR(resources,S_IRUGO | S_IWUSR, 468static DEVICE_ATTR(resources, S_IRUGO | S_IWUSR,
445 pnp_show_current_resources,pnp_set_current_resources); 469 pnp_show_current_resources, pnp_set_current_resources);
446 470
447static ssize_t pnp_show_current_ids(struct device *dmdev, struct device_attribute *attr, char *buf) 471static ssize_t pnp_show_current_ids(struct device *dmdev,
472 struct device_attribute *attr, char *buf)
448{ 473{
449 char *str = buf; 474 char *str = buf;
450 struct pnp_dev *dev = to_pnp_dev(dmdev); 475 struct pnp_dev *dev = to_pnp_dev(dmdev);
451 struct pnp_id * pos = dev->id; 476 struct pnp_id *pos = dev->id;
452 477
453 while (pos) { 478 while (pos) {
454 str += sprintf(str,"%s\n", pos->id); 479 str += sprintf(str, "%s\n", pos->id);
455 pos = pos->next; 480 pos = pos->next;
456 } 481 }
457 return (str - buf); 482 return (str - buf);
458} 483}
459 484
460static DEVICE_ATTR(id,S_IRUGO,pnp_show_current_ids,NULL); 485static DEVICE_ATTR(id, S_IRUGO, pnp_show_current_ids, NULL);
461 486
462int pnp_interface_attach_device(struct pnp_dev *dev) 487int pnp_interface_attach_device(struct pnp_dev *dev)
463{ 488{
464 int rc = device_create_file(&dev->dev,&dev_attr_options); 489 int rc = device_create_file(&dev->dev, &dev_attr_options);
465 if (rc) goto err; 490
466 rc = device_create_file(&dev->dev,&dev_attr_resources); 491 if (rc)
467 if (rc) goto err_opt; 492 goto err;
468 rc = device_create_file(&dev->dev,&dev_attr_id); 493 rc = device_create_file(&dev->dev, &dev_attr_resources);
469 if (rc) goto err_res; 494 if (rc)
495 goto err_opt;
496 rc = device_create_file(&dev->dev, &dev_attr_id);
497 if (rc)
498 goto err_res;
470 499
471 return 0; 500 return 0;
472 501
473err_res: 502 err_res:
474 device_remove_file(&dev->dev,&dev_attr_resources); 503 device_remove_file(&dev->dev, &dev_attr_resources);
475err_opt: 504 err_opt:
476 device_remove_file(&dev->dev,&dev_attr_options); 505 device_remove_file(&dev->dev, &dev_attr_options);
477err: 506 err:
478 return rc; 507 return rc;
479} 508}
diff --git a/drivers/pnp/isapnp/compat.c b/drivers/pnp/isapnp/compat.c
index 0697ab88a9ac..10bdcc4d4f7b 100644
--- a/drivers/pnp/isapnp/compat.c
+++ b/drivers/pnp/isapnp/compat.c
@@ -3,34 +3,30 @@
3 * the old isapnp APIs. If possible use the new APIs instead. 3 * the old isapnp APIs. If possible use the new APIs instead.
4 * 4 *
5 * Copyright 2002 Adam Belay <ambx1@neo.rr.com> 5 * Copyright 2002 Adam Belay <ambx1@neo.rr.com>
6 *
7 */ 6 */
8
9/* TODO: see if more isapnp functions are needed here */
10 7
11#include <linux/module.h> 8#include <linux/module.h>
12#include <linux/isapnp.h> 9#include <linux/isapnp.h>
13#include <linux/string.h> 10#include <linux/string.h>
14 11
15static void pnp_convert_id(char *buf, unsigned short vendor, unsigned short device) 12static void pnp_convert_id(char *buf, unsigned short vendor,
13 unsigned short device)
16{ 14{
17 sprintf(buf, "%c%c%c%x%x%x%x", 15 sprintf(buf, "%c%c%c%x%x%x%x",
18 'A' + ((vendor >> 2) & 0x3f) - 1, 16 'A' + ((vendor >> 2) & 0x3f) - 1,
19 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1, 17 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
20 'A' + ((vendor >> 8) & 0x1f) - 1, 18 'A' + ((vendor >> 8) & 0x1f) - 1,
21 (device >> 4) & 0x0f, 19 (device >> 4) & 0x0f, device & 0x0f,
22 device & 0x0f, 20 (device >> 12) & 0x0f, (device >> 8) & 0x0f);
23 (device >> 12) & 0x0f,
24 (device >> 8) & 0x0f);
25} 21}
26 22
27struct pnp_card *pnp_find_card(unsigned short vendor, 23struct pnp_card *pnp_find_card(unsigned short vendor, unsigned short device,
28 unsigned short device,
29 struct pnp_card *from) 24 struct pnp_card *from)
30{ 25{
31 char id[8]; 26 char id[8];
32 char any[8]; 27 char any[8];
33 struct list_head *list; 28 struct list_head *list;
29
34 pnp_convert_id(id, vendor, device); 30 pnp_convert_id(id, vendor, device);
35 pnp_convert_id(any, ISAPNP_ANY_ID, ISAPNP_ANY_ID); 31 pnp_convert_id(any, ISAPNP_ANY_ID, ISAPNP_ANY_ID);
36 32
@@ -38,20 +34,20 @@ struct pnp_card *pnp_find_card(unsigned short vendor,
38 34
39 while (list != &pnp_cards) { 35 while (list != &pnp_cards) {
40 struct pnp_card *card = global_to_pnp_card(list); 36 struct pnp_card *card = global_to_pnp_card(list);
41 if (compare_pnp_id(card->id,id) || (memcmp(id,any,7)==0)) 37
38 if (compare_pnp_id(card->id, id) || (memcmp(id, any, 7) == 0))
42 return card; 39 return card;
43 list = list->next; 40 list = list->next;
44 } 41 }
45 return NULL; 42 return NULL;
46} 43}
47 44
48struct pnp_dev *pnp_find_dev(struct pnp_card *card, 45struct pnp_dev *pnp_find_dev(struct pnp_card *card, unsigned short vendor,
49 unsigned short vendor, 46 unsigned short function, struct pnp_dev *from)
50 unsigned short function,
51 struct pnp_dev *from)
52{ 47{
53 char id[8]; 48 char id[8];
54 char any[8]; 49 char any[8];
50
55 pnp_convert_id(id, vendor, function); 51 pnp_convert_id(id, vendor, function);
56 pnp_convert_id(any, ISAPNP_ANY_ID, ISAPNP_ANY_ID); 52 pnp_convert_id(any, ISAPNP_ANY_ID, ISAPNP_ANY_ID);
57 if (card == NULL) { /* look for a logical device from all cards */ 53 if (card == NULL) { /* look for a logical device from all cards */
@@ -63,7 +59,9 @@ struct pnp_dev *pnp_find_dev(struct pnp_card *card,
63 59
64 while (list != &pnp_global) { 60 while (list != &pnp_global) {
65 struct pnp_dev *dev = global_to_pnp_dev(list); 61 struct pnp_dev *dev = global_to_pnp_dev(list);
66 if (compare_pnp_id(dev->id,id) || (memcmp(id,any,7)==0)) 62
63 if (compare_pnp_id(dev->id, id) ||
64 (memcmp(id, any, 7) == 0))
67 return dev; 65 return dev;
68 list = list->next; 66 list = list->next;
69 } 67 }
@@ -78,7 +76,8 @@ struct pnp_dev *pnp_find_dev(struct pnp_card *card,
78 } 76 }
79 while (list != &card->devices) { 77 while (list != &card->devices) {
80 struct pnp_dev *dev = card_to_pnp_dev(list); 78 struct pnp_dev *dev = card_to_pnp_dev(list);
81 if (compare_pnp_id(dev->id,id)) 79
80 if (compare_pnp_id(dev->id, id))
82 return dev; 81 return dev;
83 list = list->next; 82 list = list->next;
84 } 83 }
diff --git a/drivers/pnp/isapnp/core.c b/drivers/pnp/isapnp/core.c
index 914d00c423ad..b4e2aa995b53 100644
--- a/drivers/pnp/isapnp/core.c
+++ b/drivers/pnp/isapnp/core.c
@@ -51,10 +51,10 @@
51#define ISAPNP_DEBUG 51#define ISAPNP_DEBUG
52#endif 52#endif
53 53
54int isapnp_disable; /* Disable ISA PnP */ 54int isapnp_disable; /* Disable ISA PnP */
55static int isapnp_rdp; /* Read Data Port */ 55static int isapnp_rdp; /* Read Data Port */
56static int isapnp_reset = 1; /* reset all PnP cards (deactivate) */ 56static int isapnp_reset = 1; /* reset all PnP cards (deactivate) */
57static int isapnp_verbose = 1; /* verbose mode */ 57static int isapnp_verbose = 1; /* verbose mode */
58 58
59MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); 59MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
60MODULE_DESCRIPTION("Generic ISA Plug & Play support"); 60MODULE_DESCRIPTION("Generic ISA Plug & Play support");
@@ -126,7 +126,7 @@ static unsigned short isapnp_read_word(unsigned char idx)
126 unsigned short val; 126 unsigned short val;
127 127
128 val = isapnp_read_byte(idx); 128 val = isapnp_read_byte(idx);
129 val = (val << 8) + isapnp_read_byte(idx+1); 129 val = (val << 8) + isapnp_read_byte(idx + 1);
130 return val; 130 return val;
131} 131}
132 132
@@ -139,7 +139,7 @@ void isapnp_write_byte(unsigned char idx, unsigned char val)
139static void isapnp_write_word(unsigned char idx, unsigned short val) 139static void isapnp_write_word(unsigned char idx, unsigned short val)
140{ 140{
141 isapnp_write_byte(idx, val >> 8); 141 isapnp_write_byte(idx, val >> 8);
142 isapnp_write_byte(idx+1, val); 142 isapnp_write_byte(idx + 1, val);
143} 143}
144 144
145static void isapnp_key(void) 145static void isapnp_key(void)
@@ -193,7 +193,7 @@ static void isapnp_deactivate(unsigned char logdev)
193static void __init isapnp_peek(unsigned char *data, int bytes) 193static void __init isapnp_peek(unsigned char *data, int bytes)
194{ 194{
195 int i, j; 195 int i, j;
196 unsigned char d=0; 196 unsigned char d = 0;
197 197
198 for (i = 1; i <= bytes; i++) { 198 for (i = 1; i <= bytes; i++) {
199 for (j = 0; j < 20; j++) { 199 for (j = 0; j < 20; j++) {
@@ -220,19 +220,18 @@ static int isapnp_next_rdp(void)
220{ 220{
221 int rdp = isapnp_rdp; 221 int rdp = isapnp_rdp;
222 static int old_rdp = 0; 222 static int old_rdp = 0;
223 223
224 if(old_rdp) 224 if (old_rdp) {
225 {
226 release_region(old_rdp, 1); 225 release_region(old_rdp, 1);
227 old_rdp = 0; 226 old_rdp = 0;
228 } 227 }
229 while (rdp <= 0x3ff) { 228 while (rdp <= 0x3ff) {
230 /* 229 /*
231 * We cannot use NE2000 probe spaces for ISAPnP or we 230 * We cannot use NE2000 probe spaces for ISAPnP or we
232 * will lock up machines. 231 * will lock up machines.
233 */ 232 */
234 if ((rdp < 0x280 || rdp > 0x380) && request_region(rdp, 1, "ISAPnP")) 233 if ((rdp < 0x280 || rdp > 0x380)
235 { 234 && request_region(rdp, 1, "ISAPnP")) {
236 isapnp_rdp = rdp; 235 isapnp_rdp = rdp;
237 old_rdp = rdp; 236 old_rdp = rdp;
238 return 0; 237 return 0;
@@ -253,7 +252,6 @@ static inline void isapnp_set_rdp(void)
253 * Perform an isolation. The port selection code now tries to avoid 252 * Perform an isolation. The port selection code now tries to avoid
254 * "dangerous to read" ports. 253 * "dangerous to read" ports.
255 */ 254 */
256
257static int __init isapnp_isolate_rdp_select(void) 255static int __init isapnp_isolate_rdp_select(void)
258{ 256{
259 isapnp_wait(); 257 isapnp_wait();
@@ -282,7 +280,6 @@ static int __init isapnp_isolate_rdp_select(void)
282/* 280/*
283 * Isolate (assign uniqued CSN) to all ISA PnP devices. 281 * Isolate (assign uniqued CSN) to all ISA PnP devices.
284 */ 282 */
285
286static int __init isapnp_isolate(void) 283static int __init isapnp_isolate(void)
287{ 284{
288 unsigned char checksum = 0x6a; 285 unsigned char checksum = 0x6a;
@@ -305,7 +302,9 @@ static int __init isapnp_isolate(void)
305 udelay(250); 302 udelay(250);
306 if (data == 0x55aa) 303 if (data == 0x55aa)
307 bit = 0x01; 304 bit = 0x01;
308 checksum = ((((checksum ^ (checksum >> 1)) & 0x01) ^ bit) << 7) | (checksum >> 1); 305 checksum =
306 ((((checksum ^ (checksum >> 1)) & 0x01) ^ bit) << 7)
307 | (checksum >> 1);
309 bit = 0x00; 308 bit = 0x00;
310 } 309 }
311 for (i = 65; i <= 72; i++) { 310 for (i = 65; i <= 72; i++) {
@@ -351,13 +350,12 @@ static int __init isapnp_isolate(void)
351/* 350/*
352 * Read one tag from stream. 351 * Read one tag from stream.
353 */ 352 */
354
355static int __init isapnp_read_tag(unsigned char *type, unsigned short *size) 353static int __init isapnp_read_tag(unsigned char *type, unsigned short *size)
356{ 354{
357 unsigned char tag, tmp[2]; 355 unsigned char tag, tmp[2];
358 356
359 isapnp_peek(&tag, 1); 357 isapnp_peek(&tag, 1);
360 if (tag == 0) /* invalid tag */ 358 if (tag == 0) /* invalid tag */
361 return -1; 359 return -1;
362 if (tag & 0x80) { /* large item */ 360 if (tag & 0x80) { /* large item */
363 *type = tag; 361 *type = tag;
@@ -368,7 +366,8 @@ static int __init isapnp_read_tag(unsigned char *type, unsigned short *size)
368 *size = tag & 0x07; 366 *size = tag & 0x07;
369 } 367 }
370#if 0 368#if 0
371 printk(KERN_DEBUG "tag = 0x%x, type = 0x%x, size = %i\n", tag, *type, *size); 369 printk(KERN_DEBUG "tag = 0x%x, type = 0x%x, size = %i\n", tag, *type,
370 *size);
372#endif 371#endif
373 if (*type == 0xff && *size == 0xffff) /* probably invalid data */ 372 if (*type == 0xff && *size == 0xffff) /* probably invalid data */
374 return -1; 373 return -1;
@@ -378,7 +377,6 @@ static int __init isapnp_read_tag(unsigned char *type, unsigned short *size)
378/* 377/*
379 * Skip specified number of bytes from stream. 378 * Skip specified number of bytes from stream.
380 */ 379 */
381
382static void __init isapnp_skip_bytes(int count) 380static void __init isapnp_skip_bytes(int count)
383{ 381{
384 isapnp_peek(NULL, count); 382 isapnp_peek(NULL, count);
@@ -387,31 +385,30 @@ static void __init isapnp_skip_bytes(int count)
387/* 385/*
388 * Parse EISA id. 386 * Parse EISA id.
389 */ 387 */
390 388static void isapnp_parse_id(struct pnp_dev *dev, unsigned short vendor,
391static void isapnp_parse_id(struct pnp_dev * dev, unsigned short vendor, unsigned short device) 389 unsigned short device)
392{ 390{
393 struct pnp_id * id; 391 struct pnp_id *id;
392
394 if (!dev) 393 if (!dev)
395 return; 394 return;
396 id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL); 395 id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
397 if (!id) 396 if (!id)
398 return; 397 return;
399 sprintf(id->id, "%c%c%c%x%x%x%x", 398 sprintf(id->id, "%c%c%c%x%x%x%x",
400 'A' + ((vendor >> 2) & 0x3f) - 1, 399 'A' + ((vendor >> 2) & 0x3f) - 1,
401 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1, 400 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
402 'A' + ((vendor >> 8) & 0x1f) - 1, 401 'A' + ((vendor >> 8) & 0x1f) - 1,
403 (device >> 4) & 0x0f, 402 (device >> 4) & 0x0f,
404 device & 0x0f, 403 device & 0x0f, (device >> 12) & 0x0f, (device >> 8) & 0x0f);
405 (device >> 12) & 0x0f,
406 (device >> 8) & 0x0f);
407 pnp_add_id(id, dev); 404 pnp_add_id(id, dev);
408} 405}
409 406
410/* 407/*
411 * Parse logical device tag. 408 * Parse logical device tag.
412 */ 409 */
413 410static struct pnp_dev *__init isapnp_parse_device(struct pnp_card *card,
414static struct pnp_dev * __init isapnp_parse_device(struct pnp_card *card, int size, int number) 411 int size, int number)
415{ 412{
416 unsigned char tmp[6]; 413 unsigned char tmp[6];
417 struct pnp_dev *dev; 414 struct pnp_dev *dev;
@@ -435,13 +432,11 @@ static struct pnp_dev * __init isapnp_parse_device(struct pnp_card *card, int si
435 return dev; 432 return dev;
436} 433}
437 434
438
439/* 435/*
440 * Add IRQ resource to resources list. 436 * Add IRQ resource to resources list.
441 */ 437 */
442
443static void __init isapnp_parse_irq_resource(struct pnp_option *option, 438static void __init isapnp_parse_irq_resource(struct pnp_option *option,
444 int size) 439 int size)
445{ 440{
446 unsigned char tmp[3]; 441 unsigned char tmp[3];
447 struct pnp_irq *irq; 442 struct pnp_irq *irq;
@@ -458,15 +453,13 @@ static void __init isapnp_parse_irq_resource(struct pnp_option *option,
458 else 453 else
459 irq->flags = IORESOURCE_IRQ_HIGHEDGE; 454 irq->flags = IORESOURCE_IRQ_HIGHEDGE;
460 pnp_register_irq_resource(option, irq); 455 pnp_register_irq_resource(option, irq);
461 return;
462} 456}
463 457
464/* 458/*
465 * Add DMA resource to resources list. 459 * Add DMA resource to resources list.
466 */ 460 */
467
468static void __init isapnp_parse_dma_resource(struct pnp_option *option, 461static void __init isapnp_parse_dma_resource(struct pnp_option *option,
469 int size) 462 int size)
470{ 463{
471 unsigned char tmp[2]; 464 unsigned char tmp[2];
472 struct pnp_dma *dma; 465 struct pnp_dma *dma;
@@ -478,15 +471,13 @@ static void __init isapnp_parse_dma_resource(struct pnp_option *option,
478 dma->map = tmp[0]; 471 dma->map = tmp[0];
479 dma->flags = tmp[1]; 472 dma->flags = tmp[1];
480 pnp_register_dma_resource(option, dma); 473 pnp_register_dma_resource(option, dma);
481 return;
482} 474}
483 475
484/* 476/*
485 * Add port resource to resources list. 477 * Add port resource to resources list.
486 */ 478 */
487
488static void __init isapnp_parse_port_resource(struct pnp_option *option, 479static void __init isapnp_parse_port_resource(struct pnp_option *option,
489 int size) 480 int size)
490{ 481{
491 unsigned char tmp[7]; 482 unsigned char tmp[7];
492 struct pnp_port *port; 483 struct pnp_port *port;
@@ -500,16 +491,14 @@ static void __init isapnp_parse_port_resource(struct pnp_option *option,
500 port->align = tmp[5]; 491 port->align = tmp[5];
501 port->size = tmp[6]; 492 port->size = tmp[6];
502 port->flags = tmp[0] ? PNP_PORT_FLAG_16BITADDR : 0; 493 port->flags = tmp[0] ? PNP_PORT_FLAG_16BITADDR : 0;
503 pnp_register_port_resource(option,port); 494 pnp_register_port_resource(option, port);
504 return;
505} 495}
506 496
507/* 497/*
508 * Add fixed port resource to resources list. 498 * Add fixed port resource to resources list.
509 */ 499 */
510
511static void __init isapnp_parse_fixed_port_resource(struct pnp_option *option, 500static void __init isapnp_parse_fixed_port_resource(struct pnp_option *option,
512 int size) 501 int size)
513{ 502{
514 unsigned char tmp[3]; 503 unsigned char tmp[3];
515 struct pnp_port *port; 504 struct pnp_port *port;
@@ -522,16 +511,14 @@ static void __init isapnp_parse_fixed_port_resource(struct pnp_option *option,
522 port->size = tmp[2]; 511 port->size = tmp[2];
523 port->align = 0; 512 port->align = 0;
524 port->flags = PNP_PORT_FLAG_FIXED; 513 port->flags = PNP_PORT_FLAG_FIXED;
525 pnp_register_port_resource(option,port); 514 pnp_register_port_resource(option, port);
526 return;
527} 515}
528 516
529/* 517/*
530 * Add memory resource to resources list. 518 * Add memory resource to resources list.
531 */ 519 */
532
533static void __init isapnp_parse_mem_resource(struct pnp_option *option, 520static void __init isapnp_parse_mem_resource(struct pnp_option *option,
534 int size) 521 int size)
535{ 522{
536 unsigned char tmp[9]; 523 unsigned char tmp[9];
537 struct pnp_mem *mem; 524 struct pnp_mem *mem;
@@ -545,16 +532,14 @@ static void __init isapnp_parse_mem_resource(struct pnp_option *option,
545 mem->align = (tmp[6] << 8) | tmp[5]; 532 mem->align = (tmp[6] << 8) | tmp[5];
546 mem->size = ((tmp[8] << 8) | tmp[7]) << 8; 533 mem->size = ((tmp[8] << 8) | tmp[7]) << 8;
547 mem->flags = tmp[0]; 534 mem->flags = tmp[0];
548 pnp_register_mem_resource(option,mem); 535 pnp_register_mem_resource(option, mem);
549 return;
550} 536}
551 537
552/* 538/*
553 * Add 32-bit memory resource to resources list. 539 * Add 32-bit memory resource to resources list.
554 */ 540 */
555
556static void __init isapnp_parse_mem32_resource(struct pnp_option *option, 541static void __init isapnp_parse_mem32_resource(struct pnp_option *option,
557 int size) 542 int size)
558{ 543{
559 unsigned char tmp[17]; 544 unsigned char tmp[17];
560 struct pnp_mem *mem; 545 struct pnp_mem *mem;
@@ -565,18 +550,19 @@ static void __init isapnp_parse_mem32_resource(struct pnp_option *option,
565 return; 550 return;
566 mem->min = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1]; 551 mem->min = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1];
567 mem->max = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5]; 552 mem->max = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5];
568 mem->align = (tmp[12] << 24) | (tmp[11] << 16) | (tmp[10] << 8) | tmp[9]; 553 mem->align =
569 mem->size = (tmp[16] << 24) | (tmp[15] << 16) | (tmp[14] << 8) | tmp[13]; 554 (tmp[12] << 24) | (tmp[11] << 16) | (tmp[10] << 8) | tmp[9];
555 mem->size =
556 (tmp[16] << 24) | (tmp[15] << 16) | (tmp[14] << 8) | tmp[13];
570 mem->flags = tmp[0]; 557 mem->flags = tmp[0];
571 pnp_register_mem_resource(option,mem); 558 pnp_register_mem_resource(option, mem);
572} 559}
573 560
574/* 561/*
575 * Add 32-bit fixed memory resource to resources list. 562 * Add 32-bit fixed memory resource to resources list.
576 */ 563 */
577
578static void __init isapnp_parse_fixed_mem32_resource(struct pnp_option *option, 564static void __init isapnp_parse_fixed_mem32_resource(struct pnp_option *option,
579 int size) 565 int size)
580{ 566{
581 unsigned char tmp[9]; 567 unsigned char tmp[9];
582 struct pnp_mem *mem; 568 struct pnp_mem *mem;
@@ -585,28 +571,29 @@ static void __init isapnp_parse_fixed_mem32_resource(struct pnp_option *option,
585 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); 571 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
586 if (!mem) 572 if (!mem)
587 return; 573 return;
588 mem->min = mem->max = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1]; 574 mem->min = mem->max =
575 (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1];
589 mem->size = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5]; 576 mem->size = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5];
590 mem->align = 0; 577 mem->align = 0;
591 mem->flags = tmp[0]; 578 mem->flags = tmp[0];
592 pnp_register_mem_resource(option,mem); 579 pnp_register_mem_resource(option, mem);
593} 580}
594 581
595/* 582/*
596 * Parse card name for ISA PnP device. 583 * Parse card name for ISA PnP device.
597 */ 584 */
598
599static void __init 585static void __init
600isapnp_parse_name(char *name, unsigned int name_max, unsigned short *size) 586isapnp_parse_name(char *name, unsigned int name_max, unsigned short *size)
601{ 587{
602 if (name[0] == '\0') { 588 if (name[0] == '\0') {
603 unsigned short size1 = *size >= name_max ? (name_max - 1) : *size; 589 unsigned short size1 =
590 *size >= name_max ? (name_max - 1) : *size;
604 isapnp_peek(name, size1); 591 isapnp_peek(name, size1);
605 name[size1] = '\0'; 592 name[size1] = '\0';
606 *size -= size1; 593 *size -= size1;
607 594
608 /* clean whitespace from end of string */ 595 /* clean whitespace from end of string */
609 while (size1 > 0 && name[--size1] == ' ') 596 while (size1 > 0 && name[--size1] == ' ')
610 name[size1] = '\0'; 597 name[size1] = '\0';
611 } 598 }
612} 599}
@@ -614,7 +601,6 @@ isapnp_parse_name(char *name, unsigned int name_max, unsigned short *size)
614/* 601/*
615 * Parse resource map for logical device. 602 * Parse resource map for logical device.
616 */ 603 */
617
618static int __init isapnp_create_device(struct pnp_card *card, 604static int __init isapnp_create_device(struct pnp_card *card,
619 unsigned short size) 605 unsigned short size)
620{ 606{
@@ -622,6 +608,7 @@ static int __init isapnp_create_device(struct pnp_card *card,
622 unsigned char type, tmp[17]; 608 unsigned char type, tmp[17];
623 struct pnp_option *option; 609 struct pnp_option *option;
624 struct pnp_dev *dev; 610 struct pnp_dev *dev;
611
625 if ((dev = isapnp_parse_device(card, size, number++)) == NULL) 612 if ((dev = isapnp_parse_device(card, size, number++)) == NULL)
626 return 1; 613 return 1;
627 option = pnp_register_independent_option(dev); 614 option = pnp_register_independent_option(dev);
@@ -629,17 +616,19 @@ static int __init isapnp_create_device(struct pnp_card *card,
629 kfree(dev); 616 kfree(dev);
630 return 1; 617 return 1;
631 } 618 }
632 pnp_add_card_device(card,dev); 619 pnp_add_card_device(card, dev);
633 620
634 while (1) { 621 while (1) {
635 if (isapnp_read_tag(&type, &size)<0) 622 if (isapnp_read_tag(&type, &size) < 0)
636 return 1; 623 return 1;
637 if (skip && type != _STAG_LOGDEVID && type != _STAG_END) 624 if (skip && type != _STAG_LOGDEVID && type != _STAG_END)
638 goto __skip; 625 goto __skip;
639 switch (type) { 626 switch (type) {
640 case _STAG_LOGDEVID: 627 case _STAG_LOGDEVID:
641 if (size >= 5 && size <= 6) { 628 if (size >= 5 && size <= 6) {
642 if ((dev = isapnp_parse_device(card, size, number++)) == NULL) 629 if ((dev =
630 isapnp_parse_device(card, size,
631 number++)) == NULL)
643 return 1; 632 return 1;
644 size = 0; 633 size = 0;
645 skip = 0; 634 skip = 0;
@@ -648,7 +637,7 @@ static int __init isapnp_create_device(struct pnp_card *card,
648 kfree(dev); 637 kfree(dev);
649 return 1; 638 return 1;
650 } 639 }
651 pnp_add_card_device(card,dev); 640 pnp_add_card_device(card, dev);
652 } else { 641 } else {
653 skip = 1; 642 skip = 1;
654 } 643 }
@@ -658,7 +647,8 @@ static int __init isapnp_create_device(struct pnp_card *card,
658 case _STAG_COMPATDEVID: 647 case _STAG_COMPATDEVID:
659 if (size == 4 && compat < DEVICE_COUNT_COMPATIBLE) { 648 if (size == 4 && compat < DEVICE_COUNT_COMPATIBLE) {
660 isapnp_peek(tmp, 4); 649 isapnp_peek(tmp, 4);
661 isapnp_parse_id(dev,(tmp[1] << 8) | tmp[0], (tmp[3] << 8) | tmp[2]); 650 isapnp_parse_id(dev, (tmp[1] << 8) | tmp[0],
651 (tmp[3] << 8) | tmp[2]);
662 compat++; 652 compat++;
663 size = 0; 653 size = 0;
664 } 654 }
@@ -684,7 +674,7 @@ static int __init isapnp_create_device(struct pnp_card *card,
684 priority = 0x100 | tmp[0]; 674 priority = 0x100 | tmp[0];
685 size = 0; 675 size = 0;
686 } 676 }
687 option = pnp_register_dependent_option(dev,priority); 677 option = pnp_register_dependent_option(dev, priority);
688 if (!option) 678 if (!option)
689 return 1; 679 return 1;
690 break; 680 break;
@@ -739,11 +729,13 @@ static int __init isapnp_create_device(struct pnp_card *card,
739 isapnp_skip_bytes(size); 729 isapnp_skip_bytes(size);
740 return 1; 730 return 1;
741 default: 731 default:
742 printk(KERN_ERR "isapnp: unexpected or unknown tag type 0x%x for logical device %i (device %i), ignored\n", type, dev->number, card->number); 732 printk(KERN_ERR
733 "isapnp: unexpected or unknown tag type 0x%x for logical device %i (device %i), ignored\n",
734 type, dev->number, card->number);
743 } 735 }
744 __skip: 736 __skip:
745 if (size > 0) 737 if (size > 0)
746 isapnp_skip_bytes(size); 738 isapnp_skip_bytes(size);
747 } 739 }
748 return 0; 740 return 0;
749} 741}
@@ -751,14 +743,13 @@ static int __init isapnp_create_device(struct pnp_card *card,
751/* 743/*
752 * Parse resource map for ISA PnP card. 744 * Parse resource map for ISA PnP card.
753 */ 745 */
754
755static void __init isapnp_parse_resource_map(struct pnp_card *card) 746static void __init isapnp_parse_resource_map(struct pnp_card *card)
756{ 747{
757 unsigned char type, tmp[17]; 748 unsigned char type, tmp[17];
758 unsigned short size; 749 unsigned short size;
759 750
760 while (1) { 751 while (1) {
761 if (isapnp_read_tag(&type, &size)<0) 752 if (isapnp_read_tag(&type, &size) < 0)
762 return; 753 return;
763 switch (type) { 754 switch (type) {
764 case _STAG_PNPVERNO: 755 case _STAG_PNPVERNO:
@@ -771,7 +762,7 @@ static void __init isapnp_parse_resource_map(struct pnp_card *card)
771 break; 762 break;
772 case _STAG_LOGDEVID: 763 case _STAG_LOGDEVID:
773 if (size >= 5 && size <= 6) { 764 if (size >= 5 && size <= 6) {
774 if (isapnp_create_device(card, size)==1) 765 if (isapnp_create_device(card, size) == 1)
775 return; 766 return;
776 size = 0; 767 size = 0;
777 } 768 }
@@ -779,7 +770,8 @@ static void __init isapnp_parse_resource_map(struct pnp_card *card)
779 case _STAG_VENDOR: 770 case _STAG_VENDOR:
780 break; 771 break;
781 case _LTAG_ANSISTR: 772 case _LTAG_ANSISTR:
782 isapnp_parse_name(card->name, sizeof(card->name), &size); 773 isapnp_parse_name(card->name, sizeof(card->name),
774 &size);
783 break; 775 break;
784 case _LTAG_UNICODESTR: 776 case _LTAG_UNICODESTR:
785 /* silently ignore */ 777 /* silently ignore */
@@ -792,18 +784,19 @@ static void __init isapnp_parse_resource_map(struct pnp_card *card)
792 isapnp_skip_bytes(size); 784 isapnp_skip_bytes(size);
793 return; 785 return;
794 default: 786 default:
795 printk(KERN_ERR "isapnp: unexpected or unknown tag type 0x%x for device %i, ignored\n", type, card->number); 787 printk(KERN_ERR
788 "isapnp: unexpected or unknown tag type 0x%x for device %i, ignored\n",
789 type, card->number);
796 } 790 }
797 __skip: 791 __skip:
798 if (size > 0) 792 if (size > 0)
799 isapnp_skip_bytes(size); 793 isapnp_skip_bytes(size);
800 } 794 }
801} 795}
802 796
803/* 797/*
804 * Compute ISA PnP checksum for first eight bytes. 798 * Compute ISA PnP checksum for first eight bytes.
805 */ 799 */
806
807static unsigned char __init isapnp_checksum(unsigned char *data) 800static unsigned char __init isapnp_checksum(unsigned char *data)
808{ 801{
809 int i, j; 802 int i, j;
@@ -815,7 +808,9 @@ static unsigned char __init isapnp_checksum(unsigned char *data)
815 bit = 0; 808 bit = 0;
816 if (b & (1 << j)) 809 if (b & (1 << j))
817 bit = 1; 810 bit = 1;
818 checksum = ((((checksum ^ (checksum >> 1)) & 0x01) ^ bit) << 7) | (checksum >> 1); 811 checksum =
812 ((((checksum ^ (checksum >> 1)) & 0x01) ^ bit) << 7)
813 | (checksum >> 1);
819 } 814 }
820 } 815 }
821 return checksum; 816 return checksum;
@@ -824,27 +819,25 @@ static unsigned char __init isapnp_checksum(unsigned char *data)
824/* 819/*
825 * Parse EISA id for ISA PnP card. 820 * Parse EISA id for ISA PnP card.
826 */ 821 */
827 822static void isapnp_parse_card_id(struct pnp_card *card, unsigned short vendor,
828static void isapnp_parse_card_id(struct pnp_card * card, unsigned short vendor, unsigned short device) 823 unsigned short device)
829{ 824{
830 struct pnp_id * id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL); 825 struct pnp_id *id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
826
831 if (!id) 827 if (!id)
832 return; 828 return;
833 sprintf(id->id, "%c%c%c%x%x%x%x", 829 sprintf(id->id, "%c%c%c%x%x%x%x",
834 'A' + ((vendor >> 2) & 0x3f) - 1, 830 'A' + ((vendor >> 2) & 0x3f) - 1,
835 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1, 831 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
836 'A' + ((vendor >> 8) & 0x1f) - 1, 832 'A' + ((vendor >> 8) & 0x1f) - 1,
837 (device >> 4) & 0x0f, 833 (device >> 4) & 0x0f,
838 device & 0x0f, 834 device & 0x0f, (device >> 12) & 0x0f, (device >> 8) & 0x0f);
839 (device >> 12) & 0x0f, 835 pnp_add_card_id(id, card);
840 (device >> 8) & 0x0f);
841 pnp_add_card_id(id,card);
842} 836}
843 837
844/* 838/*
845 * Build device list for all present ISA PnP devices. 839 * Build device list for all present ISA PnP devices.
846 */ 840 */
847
848static int __init isapnp_build_device_list(void) 841static int __init isapnp_build_device_list(void)
849{ 842{
850 int csn; 843 int csn;
@@ -858,22 +851,29 @@ static int __init isapnp_build_device_list(void)
858 isapnp_peek(header, 9); 851 isapnp_peek(header, 9);
859 checksum = isapnp_checksum(header); 852 checksum = isapnp_checksum(header);
860#if 0 853#if 0
861 printk(KERN_DEBUG "vendor: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", 854 printk(KERN_DEBUG
862 header[0], header[1], header[2], header[3], 855 "vendor: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
863 header[4], header[5], header[6], header[7], header[8]); 856 header[0], header[1], header[2], header[3], header[4],
857 header[5], header[6], header[7], header[8]);
864 printk(KERN_DEBUG "checksum = 0x%x\n", checksum); 858 printk(KERN_DEBUG "checksum = 0x%x\n", checksum);
865#endif 859#endif
866 if ((card = kzalloc(sizeof(struct pnp_card), GFP_KERNEL)) == NULL) 860 if ((card =
861 kzalloc(sizeof(struct pnp_card), GFP_KERNEL)) == NULL)
867 continue; 862 continue;
868 863
869 card->number = csn; 864 card->number = csn;
870 INIT_LIST_HEAD(&card->devices); 865 INIT_LIST_HEAD(&card->devices);
871 isapnp_parse_card_id(card, (header[1] << 8) | header[0], (header[3] << 8) | header[2]); 866 isapnp_parse_card_id(card, (header[1] << 8) | header[0],
872 card->serial = (header[7] << 24) | (header[6] << 16) | (header[5] << 8) | header[4]; 867 (header[3] << 8) | header[2]);
868 card->serial =
869 (header[7] << 24) | (header[6] << 16) | (header[5] << 8) |
870 header[4];
873 isapnp_checksum_value = 0x00; 871 isapnp_checksum_value = 0x00;
874 isapnp_parse_resource_map(card); 872 isapnp_parse_resource_map(card);
875 if (isapnp_checksum_value != 0x00) 873 if (isapnp_checksum_value != 0x00)
876 printk(KERN_ERR "isapnp: checksum for device %i is not valid (0x%x)\n", csn, isapnp_checksum_value); 874 printk(KERN_ERR
875 "isapnp: checksum for device %i is not valid (0x%x)\n",
876 csn, isapnp_checksum_value);
877 card->checksum = isapnp_checksum_value; 877 card->checksum = isapnp_checksum_value;
878 card->protocol = &isapnp_protocol; 878 card->protocol = &isapnp_protocol;
879 879
@@ -890,6 +890,7 @@ static int __init isapnp_build_device_list(void)
890int isapnp_present(void) 890int isapnp_present(void)
891{ 891{
892 struct pnp_card *card; 892 struct pnp_card *card;
893
893 pnp_for_each_card(card) { 894 pnp_for_each_card(card) {
894 if (card->protocol == &isapnp_protocol) 895 if (card->protocol == &isapnp_protocol)
895 return 1; 896 return 1;
@@ -911,13 +912,13 @@ int isapnp_cfg_begin(int csn, int logdev)
911 /* it is possible to set RDP only in the isolation phase */ 912 /* it is possible to set RDP only in the isolation phase */
912 /* Jens Thoms Toerring <Jens.Toerring@physik.fu-berlin.de> */ 913 /* Jens Thoms Toerring <Jens.Toerring@physik.fu-berlin.de> */
913 isapnp_write_byte(0x02, 0x04); /* clear CSN of card */ 914 isapnp_write_byte(0x02, 0x04); /* clear CSN of card */
914 mdelay(2); /* is this necessary? */ 915 mdelay(2); /* is this necessary? */
915 isapnp_wake(csn); /* bring card into sleep state */ 916 isapnp_wake(csn); /* bring card into sleep state */
916 isapnp_wake(0); /* bring card into isolation state */ 917 isapnp_wake(0); /* bring card into isolation state */
917 isapnp_set_rdp(); /* reset the RDP port */ 918 isapnp_set_rdp(); /* reset the RDP port */
918 udelay(1000); /* delay 1000us */ 919 udelay(1000); /* delay 1000us */
919 isapnp_write_byte(0x06, csn); /* reset CSN to previous value */ 920 isapnp_write_byte(0x06, csn); /* reset CSN to previous value */
920 udelay(250); /* is this necessary? */ 921 udelay(250); /* is this necessary? */
921#endif 922#endif
922 if (logdev >= 0) 923 if (logdev >= 0)
923 isapnp_device(logdev); 924 isapnp_device(logdev);
@@ -931,12 +932,10 @@ int isapnp_cfg_end(void)
931 return 0; 932 return 0;
932} 933}
933 934
934
935/* 935/*
936 * Inititialization. 936 * Initialization.
937 */ 937 */
938 938
939
940EXPORT_SYMBOL(isapnp_protocol); 939EXPORT_SYMBOL(isapnp_protocol);
941EXPORT_SYMBOL(isapnp_present); 940EXPORT_SYMBOL(isapnp_present);
942EXPORT_SYMBOL(isapnp_cfg_begin); 941EXPORT_SYMBOL(isapnp_cfg_begin);
@@ -946,7 +945,8 @@ EXPORT_SYMBOL(isapnp_read_byte);
946#endif 945#endif
947EXPORT_SYMBOL(isapnp_write_byte); 946EXPORT_SYMBOL(isapnp_write_byte);
948 947
949static int isapnp_read_resources(struct pnp_dev *dev, struct pnp_resource_table *res) 948static int isapnp_read_resources(struct pnp_dev *dev,
949 struct pnp_resource_table *res)
950{ 950{
951 int tmp, ret; 951 int tmp, ret;
952 952
@@ -960,31 +960,37 @@ static int isapnp_read_resources(struct pnp_dev *dev, struct pnp_resource_table
960 res->port_resource[tmp].flags = IORESOURCE_IO; 960 res->port_resource[tmp].flags = IORESOURCE_IO;
961 } 961 }
962 for (tmp = 0; tmp < PNP_MAX_MEM; tmp++) { 962 for (tmp = 0; tmp < PNP_MAX_MEM; tmp++) {
963 ret = isapnp_read_word(ISAPNP_CFG_MEM + (tmp << 3)) << 8; 963 ret =
964 isapnp_read_word(ISAPNP_CFG_MEM + (tmp << 3)) << 8;
964 if (!ret) 965 if (!ret)
965 continue; 966 continue;
966 res->mem_resource[tmp].start = ret; 967 res->mem_resource[tmp].start = ret;
967 res->mem_resource[tmp].flags = IORESOURCE_MEM; 968 res->mem_resource[tmp].flags = IORESOURCE_MEM;
968 } 969 }
969 for (tmp = 0; tmp < PNP_MAX_IRQ; tmp++) { 970 for (tmp = 0; tmp < PNP_MAX_IRQ; tmp++) {
970 ret = (isapnp_read_word(ISAPNP_CFG_IRQ + (tmp << 1)) >> 8); 971 ret =
972 (isapnp_read_word(ISAPNP_CFG_IRQ + (tmp << 1)) >>
973 8);
971 if (!ret) 974 if (!ret)
972 continue; 975 continue;
973 res->irq_resource[tmp].start = res->irq_resource[tmp].end = ret; 976 res->irq_resource[tmp].start =
977 res->irq_resource[tmp].end = ret;
974 res->irq_resource[tmp].flags = IORESOURCE_IRQ; 978 res->irq_resource[tmp].flags = IORESOURCE_IRQ;
975 } 979 }
976 for (tmp = 0; tmp < PNP_MAX_DMA; tmp++) { 980 for (tmp = 0; tmp < PNP_MAX_DMA; tmp++) {
977 ret = isapnp_read_byte(ISAPNP_CFG_DMA + tmp); 981 ret = isapnp_read_byte(ISAPNP_CFG_DMA + tmp);
978 if (ret == 4) 982 if (ret == 4)
979 continue; 983 continue;
980 res->dma_resource[tmp].start = res->dma_resource[tmp].end = ret; 984 res->dma_resource[tmp].start =
985 res->dma_resource[tmp].end = ret;
981 res->dma_resource[tmp].flags = IORESOURCE_DMA; 986 res->dma_resource[tmp].flags = IORESOURCE_DMA;
982 } 987 }
983 } 988 }
984 return 0; 989 return 0;
985} 990}
986 991
987static int isapnp_get_resources(struct pnp_dev *dev, struct pnp_resource_table * res) 992static int isapnp_get_resources(struct pnp_dev *dev,
993 struct pnp_resource_table *res)
988{ 994{
989 int ret; 995 int ret;
990 pnp_init_resource_table(res); 996 pnp_init_resource_table(res);
@@ -994,24 +1000,44 @@ static int isapnp_get_resources(struct pnp_dev *dev, struct pnp_resource_table *
994 return ret; 1000 return ret;
995} 1001}
996 1002
997static int isapnp_set_resources(struct pnp_dev *dev, struct pnp_resource_table * res) 1003static int isapnp_set_resources(struct pnp_dev *dev,
1004 struct pnp_resource_table *res)
998{ 1005{
999 int tmp; 1006 int tmp;
1000 1007
1001 isapnp_cfg_begin(dev->card->number, dev->number); 1008 isapnp_cfg_begin(dev->card->number, dev->number);
1002 dev->active = 1; 1009 dev->active = 1;
1003 for (tmp = 0; tmp < PNP_MAX_PORT && (res->port_resource[tmp].flags & (IORESOURCE_IO | IORESOURCE_UNSET)) == IORESOURCE_IO; tmp++) 1010 for (tmp = 0;
1004 isapnp_write_word(ISAPNP_CFG_PORT+(tmp<<1), res->port_resource[tmp].start); 1011 tmp < PNP_MAX_PORT
1005 for (tmp = 0; tmp < PNP_MAX_IRQ && (res->irq_resource[tmp].flags & (IORESOURCE_IRQ | IORESOURCE_UNSET)) == IORESOURCE_IRQ; tmp++) { 1012 && (res->port_resource[tmp].
1013 flags & (IORESOURCE_IO | IORESOURCE_UNSET)) == IORESOURCE_IO;
1014 tmp++)
1015 isapnp_write_word(ISAPNP_CFG_PORT + (tmp << 1),
1016 res->port_resource[tmp].start);
1017 for (tmp = 0;
1018 tmp < PNP_MAX_IRQ
1019 && (res->irq_resource[tmp].
1020 flags & (IORESOURCE_IRQ | IORESOURCE_UNSET)) == IORESOURCE_IRQ;
1021 tmp++) {
1006 int irq = res->irq_resource[tmp].start; 1022 int irq = res->irq_resource[tmp].start;
1007 if (irq == 2) 1023 if (irq == 2)
1008 irq = 9; 1024 irq = 9;
1009 isapnp_write_byte(ISAPNP_CFG_IRQ+(tmp<<1), irq); 1025 isapnp_write_byte(ISAPNP_CFG_IRQ + (tmp << 1), irq);
1010 } 1026 }
1011 for (tmp = 0; tmp < PNP_MAX_DMA && (res->dma_resource[tmp].flags & (IORESOURCE_DMA | IORESOURCE_UNSET)) == IORESOURCE_DMA; tmp++) 1027 for (tmp = 0;
1012 isapnp_write_byte(ISAPNP_CFG_DMA+tmp, res->dma_resource[tmp].start); 1028 tmp < PNP_MAX_DMA
1013 for (tmp = 0; tmp < PNP_MAX_MEM && (res->mem_resource[tmp].flags & (IORESOURCE_MEM | IORESOURCE_UNSET)) == IORESOURCE_MEM; tmp++) 1029 && (res->dma_resource[tmp].
1014 isapnp_write_word(ISAPNP_CFG_MEM+(tmp<<3), (res->mem_resource[tmp].start >> 8) & 0xffff); 1030 flags & (IORESOURCE_DMA | IORESOURCE_UNSET)) == IORESOURCE_DMA;
1031 tmp++)
1032 isapnp_write_byte(ISAPNP_CFG_DMA + tmp,
1033 res->dma_resource[tmp].start);
1034 for (tmp = 0;
1035 tmp < PNP_MAX_MEM
1036 && (res->mem_resource[tmp].
1037 flags & (IORESOURCE_MEM | IORESOURCE_UNSET)) == IORESOURCE_MEM;
1038 tmp++)
1039 isapnp_write_word(ISAPNP_CFG_MEM + (tmp << 3),
1040 (res->mem_resource[tmp].start >> 8) & 0xffff);
1015 /* FIXME: We aren't handling 32bit mems properly here */ 1041 /* FIXME: We aren't handling 32bit mems properly here */
1016 isapnp_activate(dev->number); 1042 isapnp_activate(dev->number);
1017 isapnp_cfg_end(); 1043 isapnp_cfg_end();
@@ -1030,9 +1056,9 @@ static int isapnp_disable_resources(struct pnp_dev *dev)
1030} 1056}
1031 1057
1032struct pnp_protocol isapnp_protocol = { 1058struct pnp_protocol isapnp_protocol = {
1033 .name = "ISA Plug and Play", 1059 .name = "ISA Plug and Play",
1034 .get = isapnp_get_resources, 1060 .get = isapnp_get_resources,
1035 .set = isapnp_set_resources, 1061 .set = isapnp_set_resources,
1036 .disable = isapnp_disable_resources, 1062 .disable = isapnp_disable_resources,
1037}; 1063};
1038 1064
@@ -1053,31 +1079,36 @@ static int __init isapnp_init(void)
1053#endif 1079#endif
1054#ifdef ISAPNP_REGION_OK 1080#ifdef ISAPNP_REGION_OK
1055 if (!request_region(_PIDXR, 1, "isapnp index")) { 1081 if (!request_region(_PIDXR, 1, "isapnp index")) {
1056 printk(KERN_ERR "isapnp: Index Register 0x%x already used\n", _PIDXR); 1082 printk(KERN_ERR "isapnp: Index Register 0x%x already used\n",
1083 _PIDXR);
1057 return -EBUSY; 1084 return -EBUSY;
1058 } 1085 }
1059#endif 1086#endif
1060 if (!request_region(_PNPWRP, 1, "isapnp write")) { 1087 if (!request_region(_PNPWRP, 1, "isapnp write")) {
1061 printk(KERN_ERR "isapnp: Write Data Register 0x%x already used\n", _PNPWRP); 1088 printk(KERN_ERR
1089 "isapnp: Write Data Register 0x%x already used\n",
1090 _PNPWRP);
1062#ifdef ISAPNP_REGION_OK 1091#ifdef ISAPNP_REGION_OK
1063 release_region(_PIDXR, 1); 1092 release_region(_PIDXR, 1);
1064#endif 1093#endif
1065 return -EBUSY; 1094 return -EBUSY;
1066 } 1095 }
1067 1096
1068 if(pnp_register_protocol(&isapnp_protocol)<0) 1097 if (pnp_register_protocol(&isapnp_protocol) < 0)
1069 return -EBUSY; 1098 return -EBUSY;
1070 1099
1071 /* 1100 /*
1072 * Print a message. The existing ISAPnP code is hanging machines 1101 * Print a message. The existing ISAPnP code is hanging machines
1073 * so let the user know where. 1102 * so let the user know where.
1074 */ 1103 */
1075 1104
1076 printk(KERN_INFO "isapnp: Scanning for PnP cards...\n"); 1105 printk(KERN_INFO "isapnp: Scanning for PnP cards...\n");
1077 if (isapnp_rdp >= 0x203 && isapnp_rdp <= 0x3ff) { 1106 if (isapnp_rdp >= 0x203 && isapnp_rdp <= 0x3ff) {
1078 isapnp_rdp |= 3; 1107 isapnp_rdp |= 3;
1079 if (!request_region(isapnp_rdp, 1, "isapnp read")) { 1108 if (!request_region(isapnp_rdp, 1, "isapnp read")) {
1080 printk(KERN_ERR "isapnp: Read Data Register 0x%x already used\n", isapnp_rdp); 1109 printk(KERN_ERR
1110 "isapnp: Read Data Register 0x%x already used\n",
1111 isapnp_rdp);
1081#ifdef ISAPNP_REGION_OK 1112#ifdef ISAPNP_REGION_OK
1082 release_region(_PIDXR, 1); 1113 release_region(_PIDXR, 1);
1083#endif 1114#endif
@@ -1089,14 +1120,14 @@ static int __init isapnp_init(void)
1089 isapnp_detected = 1; 1120 isapnp_detected = 1;
1090 if (isapnp_rdp < 0x203 || isapnp_rdp > 0x3ff) { 1121 if (isapnp_rdp < 0x203 || isapnp_rdp > 0x3ff) {
1091 cards = isapnp_isolate(); 1122 cards = isapnp_isolate();
1092 if (cards < 0 || 1123 if (cards < 0 || (isapnp_rdp < 0x203 || isapnp_rdp > 0x3ff)) {
1093 (isapnp_rdp < 0x203 || isapnp_rdp > 0x3ff)) {
1094#ifdef ISAPNP_REGION_OK 1124#ifdef ISAPNP_REGION_OK
1095 release_region(_PIDXR, 1); 1125 release_region(_PIDXR, 1);
1096#endif 1126#endif
1097 release_region(_PNPWRP, 1); 1127 release_region(_PNPWRP, 1);
1098 isapnp_detected = 0; 1128 isapnp_detected = 0;
1099 printk(KERN_INFO "isapnp: No Plug & Play device found\n"); 1129 printk(KERN_INFO
1130 "isapnp: No Plug & Play device found\n");
1100 return 0; 1131 return 0;
1101 } 1132 }
1102 request_region(isapnp_rdp, 1, "isapnp read"); 1133 request_region(isapnp_rdp, 1, "isapnp read");
@@ -1104,19 +1135,23 @@ static int __init isapnp_init(void)
1104 isapnp_build_device_list(); 1135 isapnp_build_device_list();
1105 cards = 0; 1136 cards = 0;
1106 1137
1107 protocol_for_each_card(&isapnp_protocol,card) { 1138 protocol_for_each_card(&isapnp_protocol, card) {
1108 cards++; 1139 cards++;
1109 if (isapnp_verbose) { 1140 if (isapnp_verbose) {
1110 printk(KERN_INFO "isapnp: Card '%s'\n", card->name[0]?card->name:"Unknown"); 1141 printk(KERN_INFO "isapnp: Card '%s'\n",
1142 card->name[0] ? card->name : "Unknown");
1111 if (isapnp_verbose < 2) 1143 if (isapnp_verbose < 2)
1112 continue; 1144 continue;
1113 card_for_each_dev(card,dev) { 1145 card_for_each_dev(card, dev) {
1114 printk(KERN_INFO "isapnp: Device '%s'\n", dev->name[0]?dev->name:"Unknown"); 1146 printk(KERN_INFO "isapnp: Device '%s'\n",
1147 dev->name[0] ? dev->name : "Unknown");
1115 } 1148 }
1116 } 1149 }
1117 } 1150 }
1118 if (cards) { 1151 if (cards) {
1119 printk(KERN_INFO "isapnp: %i Plug & Play card%s detected total\n", cards, cards>1?"s":""); 1152 printk(KERN_INFO
1153 "isapnp: %i Plug & Play card%s detected total\n", cards,
1154 cards > 1 ? "s" : "");
1120 } else { 1155 } else {
1121 printk(KERN_INFO "isapnp: No Plug & Play card found\n"); 1156 printk(KERN_INFO "isapnp: No Plug & Play card found\n");
1122 } 1157 }
@@ -1141,11 +1176,10 @@ __setup("noisapnp", isapnp_setup_disable);
1141 1176
1142static int __init isapnp_setup_isapnp(char *str) 1177static int __init isapnp_setup_isapnp(char *str)
1143{ 1178{
1144 (void)((get_option(&str,&isapnp_rdp) == 2) && 1179 (void)((get_option(&str, &isapnp_rdp) == 2) &&
1145 (get_option(&str,&isapnp_reset) == 2) && 1180 (get_option(&str, &isapnp_reset) == 2) &&
1146 (get_option(&str,&isapnp_verbose) == 2)); 1181 (get_option(&str, &isapnp_verbose) == 2));
1147 return 1; 1182 return 1;
1148} 1183}
1149 1184
1150__setup("isapnp=", isapnp_setup_isapnp); 1185__setup("isapnp=", isapnp_setup_isapnp);
1151
diff --git a/drivers/pnp/isapnp/proc.c b/drivers/pnp/isapnp/proc.c
index 40b724ebe23b..3fbc0f9ffc26 100644
--- a/drivers/pnp/isapnp/proc.c
+++ b/drivers/pnp/isapnp/proc.c
@@ -2,7 +2,6 @@
2 * ISA Plug & Play support 2 * ISA Plug & Play support
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz> 3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
4 * 4 *
5 *
6 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or 7 * the Free Software Foundation; either version 2 of the License, or
@@ -16,7 +15,6 @@
16 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software 16 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 */ 18 */
21 19
22#include <linux/module.h> 20#include <linux/module.h>
@@ -54,7 +52,8 @@ static loff_t isapnp_proc_bus_lseek(struct file *file, loff_t off, int whence)
54 return (file->f_pos = new); 52 return (file->f_pos = new);
55} 53}
56 54
57static ssize_t isapnp_proc_bus_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) 55static ssize_t isapnp_proc_bus_read(struct file *file, char __user * buf,
56 size_t nbytes, loff_t * ppos)
58{ 57{
59 struct inode *ino = file->f_path.dentry->d_inode; 58 struct inode *ino = file->f_path.dentry->d_inode;
60 struct proc_dir_entry *dp = PDE(ino); 59 struct proc_dir_entry *dp = PDE(ino);
@@ -74,7 +73,7 @@ static ssize_t isapnp_proc_bus_read(struct file *file, char __user *buf, size_t
74 return -EINVAL; 73 return -EINVAL;
75 74
76 isapnp_cfg_begin(dev->card->number, dev->number); 75 isapnp_cfg_begin(dev->card->number, dev->number);
77 for ( ; pos < 256 && cnt > 0; pos++, buf++, cnt--) { 76 for (; pos < 256 && cnt > 0; pos++, buf++, cnt--) {
78 unsigned char val; 77 unsigned char val;
79 val = isapnp_read_byte(pos); 78 val = isapnp_read_byte(pos);
80 __put_user(val, buf); 79 __put_user(val, buf);
@@ -85,10 +84,9 @@ static ssize_t isapnp_proc_bus_read(struct file *file, char __user *buf, size_t
85 return nbytes; 84 return nbytes;
86} 85}
87 86
88static const struct file_operations isapnp_proc_bus_file_operations = 87static const struct file_operations isapnp_proc_bus_file_operations = {
89{ 88 .llseek = isapnp_proc_bus_lseek,
90 .llseek = isapnp_proc_bus_lseek, 89 .read = isapnp_proc_bus_read,
91 .read = isapnp_proc_bus_read,
92}; 90};
93 91
94static int isapnp_proc_attach_device(struct pnp_dev *dev) 92static int isapnp_proc_attach_device(struct pnp_dev *dev)
@@ -139,13 +137,14 @@ static int __exit isapnp_proc_detach_bus(struct pnp_card *bus)
139 remove_proc_entry(name, isapnp_proc_bus_dir); 137 remove_proc_entry(name, isapnp_proc_bus_dir);
140 return 0; 138 return 0;
141} 139}
142#endif /* MODULE */ 140#endif /* MODULE */
143 141
144int __init isapnp_proc_init(void) 142int __init isapnp_proc_init(void)
145{ 143{
146 struct pnp_dev *dev; 144 struct pnp_dev *dev;
145
147 isapnp_proc_bus_dir = proc_mkdir("isapnp", proc_bus); 146 isapnp_proc_bus_dir = proc_mkdir("isapnp", proc_bus);
148 protocol_for_each_dev(&isapnp_protocol,dev) { 147 protocol_for_each_dev(&isapnp_protocol, dev) {
149 isapnp_proc_attach_device(dev); 148 isapnp_proc_attach_device(dev);
150 } 149 }
151 return 0; 150 return 0;
@@ -167,4 +166,4 @@ int __exit isapnp_proc_done(void)
167 remove_proc_entry("isapnp", proc_bus); 166 remove_proc_entry("isapnp", proc_bus);
168 return 0; 167 return 0;
169} 168}
170#endif /* MODULE */ 169#endif /* MODULE */
diff --git a/drivers/pnp/manager.c b/drivers/pnp/manager.c
index 57e6ab1004d0..3bda513a6bd3 100644
--- a/drivers/pnp/manager.c
+++ b/drivers/pnp/manager.c
@@ -3,7 +3,6 @@
3 * 3 *
4 * based on isapnp.c resource management (c) Jaroslav Kysela <perex@suse.cz> 4 * based on isapnp.c resource management (c) Jaroslav Kysela <perex@suse.cz>
5 * Copyright 2003 Adam Belay <ambx1@neo.rr.com> 5 * Copyright 2003 Adam Belay <ambx1@neo.rr.com>
6 *
7 */ 6 */
8 7
9#include <linux/errno.h> 8#include <linux/errno.h>
@@ -26,7 +25,8 @@ static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx)
26 return -EINVAL; 25 return -EINVAL;
27 26
28 if (idx >= PNP_MAX_PORT) { 27 if (idx >= PNP_MAX_PORT) {
29 pnp_err("More than 4 ports is incompatible with pnp specifications."); 28 pnp_err
29 ("More than 4 ports is incompatible with pnp specifications.");
30 /* pretend we were successful so at least the manager won't try again */ 30 /* pretend we were successful so at least the manager won't try again */
31 return 1; 31 return 1;
32 } 32 }
@@ -41,11 +41,11 @@ static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx)
41 41
42 /* set the initial values */ 42 /* set the initial values */
43 *flags |= rule->flags | IORESOURCE_IO; 43 *flags |= rule->flags | IORESOURCE_IO;
44 *flags &= ~IORESOURCE_UNSET; 44 *flags &= ~IORESOURCE_UNSET;
45 45
46 if (!rule->size) { 46 if (!rule->size) {
47 *flags |= IORESOURCE_DISABLED; 47 *flags |= IORESOURCE_DISABLED;
48 return 1; /* skip disabled resource requests */ 48 return 1; /* skip disabled resource requests */
49 } 49 }
50 50
51 *start = rule->min; 51 *start = rule->min;
@@ -70,7 +70,8 @@ static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx)
70 return -EINVAL; 70 return -EINVAL;
71 71
72 if (idx >= PNP_MAX_MEM) { 72 if (idx >= PNP_MAX_MEM) {
73 pnp_err("More than 8 mems is incompatible with pnp specifications."); 73 pnp_err
74 ("More than 8 mems is incompatible with pnp specifications.");
74 /* pretend we were successful so at least the manager won't try again */ 75 /* pretend we were successful so at least the manager won't try again */
75 return 1; 76 return 1;
76 } 77 }
@@ -85,7 +86,7 @@ static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx)
85 86
86 /* set the initial values */ 87 /* set the initial values */
87 *flags |= rule->flags | IORESOURCE_MEM; 88 *flags |= rule->flags | IORESOURCE_MEM;
88 *flags &= ~IORESOURCE_UNSET; 89 *flags &= ~IORESOURCE_UNSET;
89 90
90 /* convert pnp flags to standard Linux flags */ 91 /* convert pnp flags to standard Linux flags */
91 if (!(rule->flags & IORESOURCE_MEM_WRITEABLE)) 92 if (!(rule->flags & IORESOURCE_MEM_WRITEABLE))
@@ -99,11 +100,11 @@ static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx)
99 100
100 if (!rule->size) { 101 if (!rule->size) {
101 *flags |= IORESOURCE_DISABLED; 102 *flags |= IORESOURCE_DISABLED;
102 return 1; /* skip disabled resource requests */ 103 return 1; /* skip disabled resource requests */
103 } 104 }
104 105
105 *start = rule->min; 106 *start = rule->min;
106 *end = *start + rule->size -1; 107 *end = *start + rule->size - 1;
107 108
108 /* run through until pnp_check_mem is happy */ 109 /* run through until pnp_check_mem is happy */
109 while (!pnp_check_mem(dev, idx)) { 110 while (!pnp_check_mem(dev, idx)) {
@@ -115,7 +116,7 @@ static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx)
115 return 1; 116 return 1;
116} 117}
117 118
118static int pnp_assign_irq(struct pnp_dev * dev, struct pnp_irq *rule, int idx) 119static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx)
119{ 120{
120 resource_size_t *start, *end; 121 resource_size_t *start, *end;
121 unsigned long *flags; 122 unsigned long *flags;
@@ -130,7 +131,8 @@ static int pnp_assign_irq(struct pnp_dev * dev, struct pnp_irq *rule, int idx)
130 return -EINVAL; 131 return -EINVAL;
131 132
132 if (idx >= PNP_MAX_IRQ) { 133 if (idx >= PNP_MAX_IRQ) {
133 pnp_err("More than 2 irqs is incompatible with pnp specifications."); 134 pnp_err
135 ("More than 2 irqs is incompatible with pnp specifications.");
134 /* pretend we were successful so at least the manager won't try again */ 136 /* pretend we were successful so at least the manager won't try again */
135 return 1; 137 return 1;
136 } 138 }
@@ -145,11 +147,11 @@ static int pnp_assign_irq(struct pnp_dev * dev, struct pnp_irq *rule, int idx)
145 147
146 /* set the initial values */ 148 /* set the initial values */
147 *flags |= rule->flags | IORESOURCE_IRQ; 149 *flags |= rule->flags | IORESOURCE_IRQ;
148 *flags &= ~IORESOURCE_UNSET; 150 *flags &= ~IORESOURCE_UNSET;
149 151
150 if (bitmap_empty(rule->map, PNP_IRQ_NR)) { 152 if (bitmap_empty(rule->map, PNP_IRQ_NR)) {
151 *flags |= IORESOURCE_DISABLED; 153 *flags |= IORESOURCE_DISABLED;
152 return 1; /* skip disabled resource requests */ 154 return 1; /* skip disabled resource requests */
153 } 155 }
154 156
155 /* TBD: need check for >16 IRQ */ 157 /* TBD: need check for >16 IRQ */
@@ -159,9 +161,9 @@ static int pnp_assign_irq(struct pnp_dev * dev, struct pnp_irq *rule, int idx)
159 return 1; 161 return 1;
160 } 162 }
161 for (i = 0; i < 16; i++) { 163 for (i = 0; i < 16; i++) {
162 if(test_bit(xtab[i], rule->map)) { 164 if (test_bit(xtab[i], rule->map)) {
163 *start = *end = xtab[i]; 165 *start = *end = xtab[i];
164 if(pnp_check_irq(dev, idx)) 166 if (pnp_check_irq(dev, idx))
165 return 1; 167 return 1;
166 } 168 }
167 } 169 }
@@ -183,7 +185,8 @@ static int pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)
183 return -EINVAL; 185 return -EINVAL;
184 186
185 if (idx >= PNP_MAX_DMA) { 187 if (idx >= PNP_MAX_DMA) {
186 pnp_err("More than 2 dmas is incompatible with pnp specifications."); 188 pnp_err
189 ("More than 2 dmas is incompatible with pnp specifications.");
187 /* pretend we were successful so at least the manager won't try again */ 190 /* pretend we were successful so at least the manager won't try again */
188 return 1; 191 return 1;
189 } 192 }
@@ -198,17 +201,17 @@ static int pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)
198 201
199 /* set the initial values */ 202 /* set the initial values */
200 *flags |= rule->flags | IORESOURCE_DMA; 203 *flags |= rule->flags | IORESOURCE_DMA;
201 *flags &= ~IORESOURCE_UNSET; 204 *flags &= ~IORESOURCE_UNSET;
202 205
203 if (!rule->map) { 206 if (!rule->map) {
204 *flags |= IORESOURCE_DISABLED; 207 *flags |= IORESOURCE_DISABLED;
205 return 1; /* skip disabled resource requests */ 208 return 1; /* skip disabled resource requests */
206 } 209 }
207 210
208 for (i = 0; i < 8; i++) { 211 for (i = 0; i < 8; i++) {
209 if(rule->map & (1<<xtab[i])) { 212 if (rule->map & (1 << xtab[i])) {
210 *start = *end = xtab[i]; 213 *start = *end = xtab[i];
211 if(pnp_check_dma(dev, idx)) 214 if (pnp_check_dma(dev, idx))
212 return 1; 215 return 1;
213 } 216 }
214 } 217 }
@@ -218,72 +221,80 @@ static int pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)
218/** 221/**
219 * pnp_init_resources - Resets a resource table to default values. 222 * pnp_init_resources - Resets a resource table to default values.
220 * @table: pointer to the desired resource table 223 * @table: pointer to the desired resource table
221 *
222 */ 224 */
223void pnp_init_resource_table(struct pnp_resource_table *table) 225void pnp_init_resource_table(struct pnp_resource_table *table)
224{ 226{
225 int idx; 227 int idx;
228
226 for (idx = 0; idx < PNP_MAX_IRQ; idx++) { 229 for (idx = 0; idx < PNP_MAX_IRQ; idx++) {
227 table->irq_resource[idx].name = NULL; 230 table->irq_resource[idx].name = NULL;
228 table->irq_resource[idx].start = -1; 231 table->irq_resource[idx].start = -1;
229 table->irq_resource[idx].end = -1; 232 table->irq_resource[idx].end = -1;
230 table->irq_resource[idx].flags = IORESOURCE_IRQ | IORESOURCE_AUTO | IORESOURCE_UNSET; 233 table->irq_resource[idx].flags =
234 IORESOURCE_IRQ | IORESOURCE_AUTO | IORESOURCE_UNSET;
231 } 235 }
232 for (idx = 0; idx < PNP_MAX_DMA; idx++) { 236 for (idx = 0; idx < PNP_MAX_DMA; idx++) {
233 table->dma_resource[idx].name = NULL; 237 table->dma_resource[idx].name = NULL;
234 table->dma_resource[idx].start = -1; 238 table->dma_resource[idx].start = -1;
235 table->dma_resource[idx].end = -1; 239 table->dma_resource[idx].end = -1;
236 table->dma_resource[idx].flags = IORESOURCE_DMA | IORESOURCE_AUTO | IORESOURCE_UNSET; 240 table->dma_resource[idx].flags =
241 IORESOURCE_DMA | IORESOURCE_AUTO | IORESOURCE_UNSET;
237 } 242 }
238 for (idx = 0; idx < PNP_MAX_PORT; idx++) { 243 for (idx = 0; idx < PNP_MAX_PORT; idx++) {
239 table->port_resource[idx].name = NULL; 244 table->port_resource[idx].name = NULL;
240 table->port_resource[idx].start = 0; 245 table->port_resource[idx].start = 0;
241 table->port_resource[idx].end = 0; 246 table->port_resource[idx].end = 0;
242 table->port_resource[idx].flags = IORESOURCE_IO | IORESOURCE_AUTO | IORESOURCE_UNSET; 247 table->port_resource[idx].flags =
248 IORESOURCE_IO | IORESOURCE_AUTO | IORESOURCE_UNSET;
243 } 249 }
244 for (idx = 0; idx < PNP_MAX_MEM; idx++) { 250 for (idx = 0; idx < PNP_MAX_MEM; idx++) {
245 table->mem_resource[idx].name = NULL; 251 table->mem_resource[idx].name = NULL;
246 table->mem_resource[idx].start = 0; 252 table->mem_resource[idx].start = 0;
247 table->mem_resource[idx].end = 0; 253 table->mem_resource[idx].end = 0;
248 table->mem_resource[idx].flags = IORESOURCE_MEM | IORESOURCE_AUTO | IORESOURCE_UNSET; 254 table->mem_resource[idx].flags =
255 IORESOURCE_MEM | IORESOURCE_AUTO | IORESOURCE_UNSET;
249 } 256 }
250} 257}
251 258
252/** 259/**
253 * pnp_clean_resources - clears resources that were not manually set 260 * pnp_clean_resources - clears resources that were not manually set
254 * @res: the resources to clean 261 * @res: the resources to clean
255 *
256 */ 262 */
257static void pnp_clean_resource_table(struct pnp_resource_table * res) 263static void pnp_clean_resource_table(struct pnp_resource_table *res)
258{ 264{
259 int idx; 265 int idx;
266
260 for (idx = 0; idx < PNP_MAX_IRQ; idx++) { 267 for (idx = 0; idx < PNP_MAX_IRQ; idx++) {
261 if (!(res->irq_resource[idx].flags & IORESOURCE_AUTO)) 268 if (!(res->irq_resource[idx].flags & IORESOURCE_AUTO))
262 continue; 269 continue;
263 res->irq_resource[idx].start = -1; 270 res->irq_resource[idx].start = -1;
264 res->irq_resource[idx].end = -1; 271 res->irq_resource[idx].end = -1;
265 res->irq_resource[idx].flags = IORESOURCE_IRQ | IORESOURCE_AUTO | IORESOURCE_UNSET; 272 res->irq_resource[idx].flags =
273 IORESOURCE_IRQ | IORESOURCE_AUTO | IORESOURCE_UNSET;
266 } 274 }
267 for (idx = 0; idx < PNP_MAX_DMA; idx++) { 275 for (idx = 0; idx < PNP_MAX_DMA; idx++) {
268 if (!(res->dma_resource[idx].flags & IORESOURCE_AUTO)) 276 if (!(res->dma_resource[idx].flags & IORESOURCE_AUTO))
269 continue; 277 continue;
270 res->dma_resource[idx].start = -1; 278 res->dma_resource[idx].start = -1;
271 res->dma_resource[idx].end = -1; 279 res->dma_resource[idx].end = -1;
272 res->dma_resource[idx].flags = IORESOURCE_DMA | IORESOURCE_AUTO | IORESOURCE_UNSET; 280 res->dma_resource[idx].flags =
281 IORESOURCE_DMA | IORESOURCE_AUTO | IORESOURCE_UNSET;
273 } 282 }
274 for (idx = 0; idx < PNP_MAX_PORT; idx++) { 283 for (idx = 0; idx < PNP_MAX_PORT; idx++) {
275 if (!(res->port_resource[idx].flags & IORESOURCE_AUTO)) 284 if (!(res->port_resource[idx].flags & IORESOURCE_AUTO))
276 continue; 285 continue;
277 res->port_resource[idx].start = 0; 286 res->port_resource[idx].start = 0;
278 res->port_resource[idx].end = 0; 287 res->port_resource[idx].end = 0;
279 res->port_resource[idx].flags = IORESOURCE_IO | IORESOURCE_AUTO | IORESOURCE_UNSET; 288 res->port_resource[idx].flags =
289 IORESOURCE_IO | IORESOURCE_AUTO | IORESOURCE_UNSET;
280 } 290 }
281 for (idx = 0; idx < PNP_MAX_MEM; idx++) { 291 for (idx = 0; idx < PNP_MAX_MEM; idx++) {
282 if (!(res->mem_resource[idx].flags & IORESOURCE_AUTO)) 292 if (!(res->mem_resource[idx].flags & IORESOURCE_AUTO))
283 continue; 293 continue;
284 res->mem_resource[idx].start = 0; 294 res->mem_resource[idx].start = 0;
285 res->mem_resource[idx].end = 0; 295 res->mem_resource[idx].end = 0;
286 res->mem_resource[idx].flags = IORESOURCE_MEM | IORESOURCE_AUTO | IORESOURCE_UNSET; 296 res->mem_resource[idx].flags =
297 IORESOURCE_MEM | IORESOURCE_AUTO | IORESOURCE_UNSET;
287 } 298 }
288} 299}
289 300
@@ -306,7 +317,7 @@ static int pnp_assign_resources(struct pnp_dev *dev, int depnum)
306 return -ENODEV; 317 return -ENODEV;
307 318
308 down(&pnp_res_mutex); 319 down(&pnp_res_mutex);
309 pnp_clean_resource_table(&dev->res); /* start with a fresh slate */ 320 pnp_clean_resource_table(&dev->res); /* start with a fresh slate */
310 if (dev->independent) { 321 if (dev->independent) {
311 port = dev->independent->port; 322 port = dev->independent->port;
312 mem = dev->independent->mem; 323 mem = dev->independent->mem;
@@ -341,10 +352,11 @@ static int pnp_assign_resources(struct pnp_dev *dev, int depnum)
341 if (depnum) { 352 if (depnum) {
342 struct pnp_option *dep; 353 struct pnp_option *dep;
343 int i; 354 int i;
344 for (i=1,dep=dev->dependent; i<depnum; i++, dep=dep->next) 355 for (i = 1, dep = dev->dependent; i < depnum;
345 if(!dep) 356 i++, dep = dep->next)
357 if (!dep)
346 goto fail; 358 goto fail;
347 port =dep->port; 359 port = dep->port;
348 mem = dep->mem; 360 mem = dep->mem;
349 irq = dep->irq; 361 irq = dep->irq;
350 dma = dep->dma; 362 dma = dep->dma;
@@ -378,7 +390,7 @@ static int pnp_assign_resources(struct pnp_dev *dev, int depnum)
378 up(&pnp_res_mutex); 390 up(&pnp_res_mutex);
379 return 1; 391 return 1;
380 392
381fail: 393 fail:
382 pnp_clean_resource_table(&dev->res); 394 pnp_clean_resource_table(&dev->res);
383 up(&pnp_res_mutex); 395 up(&pnp_res_mutex);
384 return 0; 396 return 0;
@@ -392,10 +404,12 @@ fail:
392 * 404 *
393 * This function can be used by drivers that want to manually set thier resources. 405 * This function can be used by drivers that want to manually set thier resources.
394 */ 406 */
395int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table * res, int mode) 407int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res,
408 int mode)
396{ 409{
397 int i; 410 int i;
398 struct pnp_resource_table * bak; 411 struct pnp_resource_table *bak;
412
399 if (!dev || !res) 413 if (!dev || !res)
400 return -EINVAL; 414 return -EINVAL;
401 if (!pnp_can_configure(dev)) 415 if (!pnp_can_configure(dev))
@@ -409,19 +423,19 @@ int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table * res,
409 dev->res = *res; 423 dev->res = *res;
410 if (!(mode & PNP_CONFIG_FORCE)) { 424 if (!(mode & PNP_CONFIG_FORCE)) {
411 for (i = 0; i < PNP_MAX_PORT; i++) { 425 for (i = 0; i < PNP_MAX_PORT; i++) {
412 if(!pnp_check_port(dev,i)) 426 if (!pnp_check_port(dev, i))
413 goto fail; 427 goto fail;
414 } 428 }
415 for (i = 0; i < PNP_MAX_MEM; i++) { 429 for (i = 0; i < PNP_MAX_MEM; i++) {
416 if(!pnp_check_mem(dev,i)) 430 if (!pnp_check_mem(dev, i))
417 goto fail; 431 goto fail;
418 } 432 }
419 for (i = 0; i < PNP_MAX_IRQ; i++) { 433 for (i = 0; i < PNP_MAX_IRQ; i++) {
420 if(!pnp_check_irq(dev,i)) 434 if (!pnp_check_irq(dev, i))
421 goto fail; 435 goto fail;
422 } 436 }
423 for (i = 0; i < PNP_MAX_DMA; i++) { 437 for (i = 0; i < PNP_MAX_DMA; i++) {
424 if(!pnp_check_dma(dev,i)) 438 if (!pnp_check_dma(dev, i))
425 goto fail; 439 goto fail;
426 } 440 }
427 } 441 }
@@ -430,7 +444,7 @@ int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table * res,
430 kfree(bak); 444 kfree(bak);
431 return 0; 445 return 0;
432 446
433fail: 447 fail:
434 dev->res = *bak; 448 dev->res = *bak;
435 up(&pnp_res_mutex); 449 up(&pnp_res_mutex);
436 kfree(bak); 450 kfree(bak);
@@ -440,18 +454,18 @@ fail:
440/** 454/**
441 * pnp_auto_config_dev - automatically assigns resources to a device 455 * pnp_auto_config_dev - automatically assigns resources to a device
442 * @dev: pointer to the desired device 456 * @dev: pointer to the desired device
443 *
444 */ 457 */
445int pnp_auto_config_dev(struct pnp_dev *dev) 458int pnp_auto_config_dev(struct pnp_dev *dev)
446{ 459{
447 struct pnp_option *dep; 460 struct pnp_option *dep;
448 int i = 1; 461 int i = 1;
449 462
450 if(!dev) 463 if (!dev)
451 return -EINVAL; 464 return -EINVAL;
452 465
453 if(!pnp_can_configure(dev)) { 466 if (!pnp_can_configure(dev)) {
454 pnp_dbg("Device %s does not support resource configuration.", dev->dev.bus_id); 467 pnp_dbg("Device %s does not support resource configuration.",
468 dev->dev.bus_id);
455 return -ENODEV; 469 return -ENODEV;
456 } 470 }
457 471
@@ -476,23 +490,22 @@ int pnp_auto_config_dev(struct pnp_dev *dev)
476 * pnp_start_dev - low-level start of the PnP device 490 * pnp_start_dev - low-level start of the PnP device
477 * @dev: pointer to the desired device 491 * @dev: pointer to the desired device
478 * 492 *
479 * assumes that resources have alread been allocated 493 * assumes that resources have already been allocated
480 */ 494 */
481
482int pnp_start_dev(struct pnp_dev *dev) 495int pnp_start_dev(struct pnp_dev *dev)
483{ 496{
484 if (!pnp_can_write(dev)) { 497 if (!pnp_can_write(dev)) {
485 pnp_dbg("Device %s does not support activation.", dev->dev.bus_id); 498 pnp_dbg("Device %s does not support activation.",
499 dev->dev.bus_id);
486 return -EINVAL; 500 return -EINVAL;
487 } 501 }
488 502
489 if (dev->protocol->set(dev, &dev->res)<0) { 503 if (dev->protocol->set(dev, &dev->res) < 0) {
490 pnp_err("Failed to activate device %s.", dev->dev.bus_id); 504 pnp_err("Failed to activate device %s.", dev->dev.bus_id);
491 return -EIO; 505 return -EIO;
492 } 506 }
493 507
494 pnp_info("Device %s activated.", dev->dev.bus_id); 508 pnp_info("Device %s activated.", dev->dev.bus_id);
495
496 return 0; 509 return 0;
497} 510}
498 511
@@ -502,20 +515,19 @@ int pnp_start_dev(struct pnp_dev *dev)
502 * 515 *
503 * does not free resources 516 * does not free resources
504 */ 517 */
505
506int pnp_stop_dev(struct pnp_dev *dev) 518int pnp_stop_dev(struct pnp_dev *dev)
507{ 519{
508 if (!pnp_can_disable(dev)) { 520 if (!pnp_can_disable(dev)) {
509 pnp_dbg("Device %s does not support disabling.", dev->dev.bus_id); 521 pnp_dbg("Device %s does not support disabling.",
522 dev->dev.bus_id);
510 return -EINVAL; 523 return -EINVAL;
511 } 524 }
512 if (dev->protocol->disable(dev)<0) { 525 if (dev->protocol->disable(dev) < 0) {
513 pnp_err("Failed to disable device %s.", dev->dev.bus_id); 526 pnp_err("Failed to disable device %s.", dev->dev.bus_id);
514 return -EIO; 527 return -EIO;
515 } 528 }
516 529
517 pnp_info("Device %s disabled.", dev->dev.bus_id); 530 pnp_info("Device %s disabled.", dev->dev.bus_id);
518
519 return 0; 531 return 0;
520} 532}
521 533
@@ -531,9 +543,8 @@ int pnp_activate_dev(struct pnp_dev *dev)
531 543
532 if (!dev) 544 if (!dev)
533 return -EINVAL; 545 return -EINVAL;
534 if (dev->active) { 546 if (dev->active)
535 return 0; /* the device is already active */ 547 return 0; /* the device is already active */
536 }
537 548
538 /* ensure resources are allocated */ 549 /* ensure resources are allocated */
539 if (pnp_auto_config_dev(dev)) 550 if (pnp_auto_config_dev(dev))
@@ -544,7 +555,6 @@ int pnp_activate_dev(struct pnp_dev *dev)
544 return error; 555 return error;
545 556
546 dev->active = 1; 557 dev->active = 1;
547
548 return 1; 558 return 1;
549} 559}
550 560
@@ -558,11 +568,10 @@ int pnp_disable_dev(struct pnp_dev *dev)
558{ 568{
559 int error; 569 int error;
560 570
561 if (!dev) 571 if (!dev)
562 return -EINVAL; 572 return -EINVAL;
563 if (!dev->active) { 573 if (!dev->active)
564 return 0; /* the device is already disabled */ 574 return 0; /* the device is already disabled */
565 }
566 575
567 error = pnp_stop_dev(dev); 576 error = pnp_stop_dev(dev);
568 if (error) 577 if (error)
@@ -583,10 +592,9 @@ int pnp_disable_dev(struct pnp_dev *dev)
583 * @resource: pointer to resource to be changed 592 * @resource: pointer to resource to be changed
584 * @start: start of region 593 * @start: start of region
585 * @size: size of region 594 * @size: size of region
586 *
587 */ 595 */
588void pnp_resource_change(struct resource *resource, resource_size_t start, 596void pnp_resource_change(struct resource *resource, resource_size_t start,
589 resource_size_t size) 597 resource_size_t size)
590{ 598{
591 if (resource == NULL) 599 if (resource == NULL)
592 return; 600 return;
@@ -595,11 +603,7 @@ void pnp_resource_change(struct resource *resource, resource_size_t start,
595 resource->end = start + size - 1; 603 resource->end = start + size - 1;
596} 604}
597 605
598
599EXPORT_SYMBOL(pnp_manual_config_dev); 606EXPORT_SYMBOL(pnp_manual_config_dev);
600#if 0
601EXPORT_SYMBOL(pnp_auto_config_dev);
602#endif
603EXPORT_SYMBOL(pnp_start_dev); 607EXPORT_SYMBOL(pnp_start_dev);
604EXPORT_SYMBOL(pnp_stop_dev); 608EXPORT_SYMBOL(pnp_stop_dev);
605EXPORT_SYMBOL(pnp_activate_dev); 609EXPORT_SYMBOL(pnp_activate_dev);
diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c
index a00548799e98..616fc72190bf 100644
--- a/drivers/pnp/pnpacpi/core.c
+++ b/drivers/pnp/pnpacpi/core.c
@@ -21,7 +21,10 @@
21 21
22#include <linux/acpi.h> 22#include <linux/acpi.h>
23#include <linux/pnp.h> 23#include <linux/pnp.h>
24#include <linux/mod_devicetable.h>
24#include <acpi/acpi_bus.h> 25#include <acpi/acpi_bus.h>
26#include <acpi/actypes.h>
27
25#include "pnpacpi.h" 28#include "pnpacpi.h"
26 29
27static int num = 0; 30static int num = 0;
@@ -31,17 +34,19 @@ static int num = 0;
31 * used by the kernel (PCI root, ...), as it is harmless and there were 34 * used by the kernel (PCI root, ...), as it is harmless and there were
32 * already present in pnpbios. But there is an exception for devices that 35 * already present in pnpbios. But there is an exception for devices that
33 * have irqs (PIC, Timer) because we call acpi_register_gsi. 36 * have irqs (PIC, Timer) because we call acpi_register_gsi.
34 * Finaly only devices that have a CRS method need to be in this list. 37 * Finally, only devices that have a CRS method need to be in this list.
35 */ 38 */
36static char __initdata excluded_id_list[] = 39static struct __initdata acpi_device_id excluded_id_list[] = {
37 "PNP0C09," /* EC */ 40 {"PNP0C09", 0}, /* EC */
38 "PNP0C0F," /* Link device */ 41 {"PNP0C0F", 0}, /* Link device */
39 "PNP0000," /* PIC */ 42 {"PNP0000", 0}, /* PIC */
40 "PNP0100," /* Timer */ 43 {"PNP0100", 0}, /* Timer */
41 ; 44 {"", 0},
45};
46
42static inline int is_exclusive_device(struct acpi_device *dev) 47static inline int is_exclusive_device(struct acpi_device *dev)
43{ 48{
44 return (!acpi_match_ids(dev, excluded_id_list)); 49 return (!acpi_match_device_ids(dev, excluded_id_list));
45} 50}
46 51
47/* 52/*
@@ -79,15 +84,18 @@ static void __init pnpidacpi_to_pnpid(char *id, char *str)
79 str[7] = '\0'; 84 str[7] = '\0';
80} 85}
81 86
82static int pnpacpi_get_resources(struct pnp_dev * dev, struct pnp_resource_table * res) 87static int pnpacpi_get_resources(struct pnp_dev *dev,
88 struct pnp_resource_table *res)
83{ 89{
84 acpi_status status; 90 acpi_status status;
85 status = pnpacpi_parse_allocated_resource((acpi_handle)dev->data, 91
86 &dev->res); 92 status = pnpacpi_parse_allocated_resource((acpi_handle) dev->data,
93 &dev->res);
87 return ACPI_FAILURE(status) ? -ENODEV : 0; 94 return ACPI_FAILURE(status) ? -ENODEV : 0;
88} 95}
89 96
90static int pnpacpi_set_resources(struct pnp_dev * dev, struct pnp_resource_table * res) 97static int pnpacpi_set_resources(struct pnp_dev *dev,
98 struct pnp_resource_table *res)
91{ 99{
92 acpi_handle handle = dev->data; 100 acpi_handle handle = dev->data;
93 struct acpi_buffer buffer; 101 struct acpi_buffer buffer;
@@ -114,16 +122,36 @@ static int pnpacpi_disable_resources(struct pnp_dev *dev)
114 acpi_status status; 122 acpi_status status;
115 123
116 /* acpi_unregister_gsi(pnp_irq(dev, 0)); */ 124 /* acpi_unregister_gsi(pnp_irq(dev, 0)); */
117 status = acpi_evaluate_object((acpi_handle)dev->data, 125 status = acpi_evaluate_object((acpi_handle) dev->data,
118 "_DIS", NULL, NULL); 126 "_DIS", NULL, NULL);
119 return ACPI_FAILURE(status) ? -ENODEV : 0; 127 return ACPI_FAILURE(status) ? -ENODEV : 0;
120} 128}
121 129
130#ifdef CONFIG_ACPI_SLEEP
131static int pnpacpi_suspend(struct pnp_dev *dev, pm_message_t state)
132{
133 return acpi_bus_set_power((acpi_handle) dev->data,
134 acpi_pm_device_sleep_state(&dev->dev,
135 device_may_wakeup
136 (&dev->dev),
137 NULL));
138}
139
140static int pnpacpi_resume(struct pnp_dev *dev)
141{
142 return acpi_bus_set_power((acpi_handle) dev->data, ACPI_STATE_D0);
143}
144#endif
145
122static struct pnp_protocol pnpacpi_protocol = { 146static struct pnp_protocol pnpacpi_protocol = {
123 .name = "Plug and Play ACPI", 147 .name = "Plug and Play ACPI",
124 .get = pnpacpi_get_resources, 148 .get = pnpacpi_get_resources,
125 .set = pnpacpi_set_resources, 149 .set = pnpacpi_set_resources,
126 .disable = pnpacpi_disable_resources, 150 .disable = pnpacpi_disable_resources,
151#ifdef CONFIG_ACPI_SLEEP
152 .suspend = pnpacpi_suspend,
153 .resume = pnpacpi_resume,
154#endif
127}; 155};
128 156
129static int __init pnpacpi_add_device(struct acpi_device *device) 157static int __init pnpacpi_add_device(struct acpi_device *device)
@@ -135,17 +163,17 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
135 163
136 status = acpi_get_handle(device->handle, "_CRS", &temp); 164 status = acpi_get_handle(device->handle, "_CRS", &temp);
137 if (ACPI_FAILURE(status) || !ispnpidacpi(acpi_device_hid(device)) || 165 if (ACPI_FAILURE(status) || !ispnpidacpi(acpi_device_hid(device)) ||
138 is_exclusive_device(device)) 166 is_exclusive_device(device))
139 return 0; 167 return 0;
140 168
141 pnp_dbg("ACPI device : hid %s", acpi_device_hid(device)); 169 pnp_dbg("ACPI device : hid %s", acpi_device_hid(device));
142 dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL); 170 dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
143 if (!dev) { 171 if (!dev) {
144 pnp_err("Out of memory"); 172 pnp_err("Out of memory");
145 return -ENOMEM; 173 return -ENOMEM;
146 } 174 }
147 dev->data = device->handle; 175 dev->data = device->handle;
148 /* .enabled means if the device can decode the resources */ 176 /* .enabled means the device can decode the resources */
149 dev->active = device->status.enabled; 177 dev->active = device->status.enabled;
150 status = acpi_get_handle(device->handle, "_SRS", &temp); 178 status = acpi_get_handle(device->handle, "_SRS", &temp);
151 if (ACPI_SUCCESS(status)) 179 if (ACPI_SUCCESS(status))
@@ -175,20 +203,23 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
175 pnpidacpi_to_pnpid(acpi_device_hid(device), dev_id->id); 203 pnpidacpi_to_pnpid(acpi_device_hid(device), dev_id->id);
176 pnp_add_id(dev_id, dev); 204 pnp_add_id(dev_id, dev);
177 205
178 if(dev->active) { 206 if (dev->active) {
179 /* parse allocated resource */ 207 /* parse allocated resource */
180 status = pnpacpi_parse_allocated_resource(device->handle, &dev->res); 208 status = pnpacpi_parse_allocated_resource(device->handle,
209 &dev->res);
181 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { 210 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
182 pnp_err("PnPACPI: METHOD_NAME__CRS failure for %s", dev_id->id); 211 pnp_err("PnPACPI: METHOD_NAME__CRS failure for %s",
212 dev_id->id);
183 goto err1; 213 goto err1;
184 } 214 }
185 } 215 }
186 216
187 if(dev->capabilities & PNP_CONFIGURABLE) { 217 if (dev->capabilities & PNP_CONFIGURABLE) {
188 status = pnpacpi_parse_resource_option_data(device->handle, 218 status = pnpacpi_parse_resource_option_data(device->handle,
189 dev); 219 dev);
190 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { 220 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
191 pnp_err("PnPACPI: METHOD_NAME__PRS failure for %s", dev_id->id); 221 pnp_err("PnPACPI: METHOD_NAME__PRS failure for %s",
222 dev_id->id);
192 goto err1; 223 goto err1;
193 } 224 }
194 } 225 }
@@ -214,18 +245,19 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
214 if (!dev->active) 245 if (!dev->active)
215 pnp_init_resource_table(&dev->res); 246 pnp_init_resource_table(&dev->res);
216 pnp_add_device(dev); 247 pnp_add_device(dev);
217 num ++; 248 num++;
218 249
219 return AE_OK; 250 return AE_OK;
220err1: 251 err1:
221 kfree(dev_id); 252 kfree(dev_id);
222err: 253 err:
223 kfree(dev); 254 kfree(dev);
224 return -EINVAL; 255 return -EINVAL;
225} 256}
226 257
227static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle, 258static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle,
228 u32 lvl, void *context, void **rv) 259 u32 lvl, void *context,
260 void **rv)
229{ 261{
230 struct acpi_device *device; 262 struct acpi_device *device;
231 263
@@ -238,23 +270,22 @@ static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle,
238 270
239static int __init acpi_pnp_match(struct device *dev, void *_pnp) 271static int __init acpi_pnp_match(struct device *dev, void *_pnp)
240{ 272{
241 struct acpi_device *acpi = to_acpi_device(dev); 273 struct acpi_device *acpi = to_acpi_device(dev);
242 struct pnp_dev *pnp = _pnp; 274 struct pnp_dev *pnp = _pnp;
243 275
244 /* true means it matched */ 276 /* true means it matched */
245 return acpi->flags.hardware_id 277 return acpi->flags.hardware_id
246 && !acpi_get_physical_device(acpi->handle) 278 && !acpi_get_physical_device(acpi->handle)
247 && compare_pnp_id(pnp->id, acpi->pnp.hardware_id); 279 && compare_pnp_id(pnp->id, acpi->pnp.hardware_id);
248} 280}
249 281
250static int __init acpi_pnp_find_device(struct device *dev, acpi_handle *handle) 282static int __init acpi_pnp_find_device(struct device *dev, acpi_handle * handle)
251{ 283{
252 struct device *adev; 284 struct device *adev;
253 struct acpi_device *acpi; 285 struct acpi_device *acpi;
254 286
255 adev = bus_find_device(&acpi_bus_type, NULL, 287 adev = bus_find_device(&acpi_bus_type, NULL,
256 to_pnp_dev(dev), 288 to_pnp_dev(dev), acpi_pnp_match);
257 acpi_pnp_match);
258 if (!adev) 289 if (!adev)
259 return -ENODEV; 290 return -ENODEV;
260 291
@@ -268,7 +299,7 @@ static int __init acpi_pnp_find_device(struct device *dev, acpi_handle *handle)
268 * pnpdev->dev.archdata.acpi_handle point to its ACPI sibling. 299 * pnpdev->dev.archdata.acpi_handle point to its ACPI sibling.
269 */ 300 */
270static struct acpi_bus_type __initdata acpi_pnp_bus = { 301static struct acpi_bus_type __initdata acpi_pnp_bus = {
271 .bus = &pnp_bus_type, 302 .bus = &pnp_bus_type,
272 .find_device = acpi_pnp_find_device, 303 .find_device = acpi_pnp_find_device,
273}; 304};
274 305
@@ -288,6 +319,7 @@ static int __init pnpacpi_init(void)
288 pnp_platform_devices = 1; 319 pnp_platform_devices = 1;
289 return 0; 320 return 0;
290} 321}
322
291subsys_initcall(pnpacpi_init); 323subsys_initcall(pnpacpi_init);
292 324
293static int __init pnpacpi_setup(char *str) 325static int __init pnpacpi_setup(char *str)
@@ -298,8 +330,5 @@ static int __init pnpacpi_setup(char *str)
298 pnpacpi_disabled = 1; 330 pnpacpi_disabled = 1;
299 return 1; 331 return 1;
300} 332}
301__setup("pnpacpi=", pnpacpi_setup);
302 333
303#if 0 334__setup("pnpacpi=", pnpacpi_setup);
304EXPORT_SYMBOL(pnpacpi_protocol);
305#endif
diff --git a/drivers/pnp/pnpacpi/rsparser.c b/drivers/pnp/pnpacpi/rsparser.c
index 118ac9779b3c..ce5027feb3da 100644
--- a/drivers/pnp/pnpacpi/rsparser.c
+++ b/drivers/pnp/pnpacpi/rsparser.c
@@ -40,8 +40,7 @@ static int irq_flags(int triggering, int polarity)
40 flag = IORESOURCE_IRQ_LOWLEVEL; 40 flag = IORESOURCE_IRQ_LOWLEVEL;
41 else 41 else
42 flag = IORESOURCE_IRQ_HIGHLEVEL; 42 flag = IORESOURCE_IRQ_HIGHLEVEL;
43 } 43 } else {
44 else {
45 if (polarity == ACPI_ACTIVE_LOW) 44 if (polarity == ACPI_ACTIVE_LOW)
46 flag = IORESOURCE_IRQ_LOWEDGE; 45 flag = IORESOURCE_IRQ_LOWEDGE;
47 else 46 else
@@ -72,9 +71,9 @@ static void decode_irq_flags(int flag, int *triggering, int *polarity)
72 } 71 }
73} 72}
74 73
75static void 74static void pnpacpi_parse_allocated_irqresource(struct pnp_resource_table *res,
76pnpacpi_parse_allocated_irqresource(struct pnp_resource_table *res, u32 gsi, 75 u32 gsi, int triggering,
77 int triggering, int polarity, int shareable) 76 int polarity, int shareable)
78{ 77{
79 int i = 0; 78 int i = 0;
80 int irq; 79 int irq;
@@ -83,12 +82,12 @@ pnpacpi_parse_allocated_irqresource(struct pnp_resource_table *res, u32 gsi,
83 return; 82 return;
84 83
85 while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) && 84 while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) &&
86 i < PNP_MAX_IRQ) 85 i < PNP_MAX_IRQ)
87 i++; 86 i++;
88 if (i >= PNP_MAX_IRQ) 87 if (i >= PNP_MAX_IRQ)
89 return; 88 return;
90 89
91 res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag 90 res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag
92 res->irq_resource[i].flags |= irq_flags(triggering, polarity); 91 res->irq_resource[i].flags |= irq_flags(triggering, polarity);
93 irq = acpi_register_gsi(gsi, triggering, polarity); 92 irq = acpi_register_gsi(gsi, triggering, polarity);
94 if (irq < 0) { 93 if (irq < 0) {
@@ -147,17 +146,19 @@ static int dma_flags(int type, int bus_master, int transfer)
147 return flags; 146 return flags;
148} 147}
149 148
150static void 149static void pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res,
151pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res, u32 dma, 150 u32 dma, int type,
152 int type, int bus_master, int transfer) 151 int bus_master, int transfer)
153{ 152{
154 int i = 0; 153 int i = 0;
154
155 while (i < PNP_MAX_DMA && 155 while (i < PNP_MAX_DMA &&
156 !(res->dma_resource[i].flags & IORESOURCE_UNSET)) 156 !(res->dma_resource[i].flags & IORESOURCE_UNSET))
157 i++; 157 i++;
158 if (i < PNP_MAX_DMA) { 158 if (i < PNP_MAX_DMA) {
159 res->dma_resource[i].flags = IORESOURCE_DMA; // Also clears _UNSET flag 159 res->dma_resource[i].flags = IORESOURCE_DMA; // Also clears _UNSET flag
160 res->dma_resource[i].flags |= dma_flags(type, bus_master, transfer); 160 res->dma_resource[i].flags |=
161 dma_flags(type, bus_master, transfer);
161 if (dma == -1) { 162 if (dma == -1) {
162 res->dma_resource[i].flags |= IORESOURCE_DISABLED; 163 res->dma_resource[i].flags |= IORESOURCE_DISABLED;
163 return; 164 return;
@@ -167,19 +168,19 @@ pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res, u32 dma,
167 } 168 }
168} 169}
169 170
170static void 171static void pnpacpi_parse_allocated_ioresource(struct pnp_resource_table *res,
171pnpacpi_parse_allocated_ioresource(struct pnp_resource_table *res, 172 u64 io, u64 len, int io_decode)
172 u64 io, u64 len, int io_decode)
173{ 173{
174 int i = 0; 174 int i = 0;
175
175 while (!(res->port_resource[i].flags & IORESOURCE_UNSET) && 176 while (!(res->port_resource[i].flags & IORESOURCE_UNSET) &&
176 i < PNP_MAX_PORT) 177 i < PNP_MAX_PORT)
177 i++; 178 i++;
178 if (i < PNP_MAX_PORT) { 179 if (i < PNP_MAX_PORT) {
179 res->port_resource[i].flags = IORESOURCE_IO; // Also clears _UNSET flag 180 res->port_resource[i].flags = IORESOURCE_IO; // Also clears _UNSET flag
180 if (io_decode == ACPI_DECODE_16) 181 if (io_decode == ACPI_DECODE_16)
181 res->port_resource[i].flags |= PNP_PORT_FLAG_16BITADDR; 182 res->port_resource[i].flags |= PNP_PORT_FLAG_16BITADDR;
182 if (len <= 0 || (io + len -1) >= 0x10003) { 183 if (len <= 0 || (io + len - 1) >= 0x10003) {
183 res->port_resource[i].flags |= IORESOURCE_DISABLED; 184 res->port_resource[i].flags |= IORESOURCE_DISABLED;
184 return; 185 return;
185 } 186 }
@@ -188,21 +189,22 @@ pnpacpi_parse_allocated_ioresource(struct pnp_resource_table *res,
188 } 189 }
189} 190}
190 191
191static void 192static void pnpacpi_parse_allocated_memresource(struct pnp_resource_table *res,
192pnpacpi_parse_allocated_memresource(struct pnp_resource_table *res, 193 u64 mem, u64 len,
193 u64 mem, u64 len, int write_protect) 194 int write_protect)
194{ 195{
195 int i = 0; 196 int i = 0;
197
196 while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) && 198 while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) &&
197 (i < PNP_MAX_MEM)) 199 (i < PNP_MAX_MEM))
198 i++; 200 i++;
199 if (i < PNP_MAX_MEM) { 201 if (i < PNP_MAX_MEM) {
200 res->mem_resource[i].flags = IORESOURCE_MEM; // Also clears _UNSET flag 202 res->mem_resource[i].flags = IORESOURCE_MEM; // Also clears _UNSET flag
201 if (len <= 0) { 203 if (len <= 0) {
202 res->mem_resource[i].flags |= IORESOURCE_DISABLED; 204 res->mem_resource[i].flags |= IORESOURCE_DISABLED;
203 return; 205 return;
204 } 206 }
205 if(write_protect == ACPI_READ_WRITE_MEMORY) 207 if (write_protect == ACPI_READ_WRITE_MEMORY)
206 res->mem_resource[i].flags |= IORESOURCE_MEM_WRITEABLE; 208 res->mem_resource[i].flags |= IORESOURCE_MEM_WRITEABLE;
207 209
208 res->mem_resource[i].start = mem; 210 res->mem_resource[i].start = mem;
@@ -210,9 +212,8 @@ pnpacpi_parse_allocated_memresource(struct pnp_resource_table *res,
210 } 212 }
211} 213}
212 214
213static void 215static void pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res_table,
214pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res_table, 216 struct acpi_resource *res)
215 struct acpi_resource *res)
216{ 217{
217 struct acpi_resource_address64 addr, *p = &addr; 218 struct acpi_resource_address64 addr, *p = &addr;
218 acpi_status status; 219 acpi_status status;
@@ -220,7 +221,7 @@ pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res_table,
220 status = acpi_resource_to_address64(res, p); 221 status = acpi_resource_to_address64(res, p);
221 if (!ACPI_SUCCESS(status)) { 222 if (!ACPI_SUCCESS(status)) {
222 pnp_warn("PnPACPI: failed to convert resource type %d", 223 pnp_warn("PnPACPI: failed to convert resource type %d",
223 res->type); 224 res->type);
224 return; 225 return;
225 } 226 }
226 227
@@ -229,17 +230,20 @@ pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res_table,
229 230
230 if (p->resource_type == ACPI_MEMORY_RANGE) 231 if (p->resource_type == ACPI_MEMORY_RANGE)
231 pnpacpi_parse_allocated_memresource(res_table, 232 pnpacpi_parse_allocated_memresource(res_table,
232 p->minimum, p->address_length, p->info.mem.write_protect); 233 p->minimum, p->address_length,
234 p->info.mem.write_protect);
233 else if (p->resource_type == ACPI_IO_RANGE) 235 else if (p->resource_type == ACPI_IO_RANGE)
234 pnpacpi_parse_allocated_ioresource(res_table, 236 pnpacpi_parse_allocated_ioresource(res_table,
235 p->minimum, p->address_length, 237 p->minimum, p->address_length,
236 p->granularity == 0xfff ? ACPI_DECODE_10 : ACPI_DECODE_16); 238 p->granularity == 0xfff ? ACPI_DECODE_10 :
239 ACPI_DECODE_16);
237} 240}
238 241
239static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res, 242static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
240 void *data) 243 void *data)
241{ 244{
242 struct pnp_resource_table *res_table = (struct pnp_resource_table *)data; 245 struct pnp_resource_table *res_table =
246 (struct pnp_resource_table *)data;
243 int i; 247 int i;
244 248
245 switch (res->type) { 249 switch (res->type) {
@@ -260,17 +264,17 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
260 case ACPI_RESOURCE_TYPE_DMA: 264 case ACPI_RESOURCE_TYPE_DMA:
261 if (res->data.dma.channel_count > 0) 265 if (res->data.dma.channel_count > 0)
262 pnpacpi_parse_allocated_dmaresource(res_table, 266 pnpacpi_parse_allocated_dmaresource(res_table,
263 res->data.dma.channels[0], 267 res->data.dma.channels[0],
264 res->data.dma.type, 268 res->data.dma.type,
265 res->data.dma.bus_master, 269 res->data.dma.bus_master,
266 res->data.dma.transfer); 270 res->data.dma.transfer);
267 break; 271 break;
268 272
269 case ACPI_RESOURCE_TYPE_IO: 273 case ACPI_RESOURCE_TYPE_IO:
270 pnpacpi_parse_allocated_ioresource(res_table, 274 pnpacpi_parse_allocated_ioresource(res_table,
271 res->data.io.minimum, 275 res->data.io.minimum,
272 res->data.io.address_length, 276 res->data.io.address_length,
273 res->data.io.io_decode); 277 res->data.io.io_decode);
274 break; 278 break;
275 279
276 case ACPI_RESOURCE_TYPE_START_DEPENDENT: 280 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
@@ -279,9 +283,9 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
279 283
280 case ACPI_RESOURCE_TYPE_FIXED_IO: 284 case ACPI_RESOURCE_TYPE_FIXED_IO:
281 pnpacpi_parse_allocated_ioresource(res_table, 285 pnpacpi_parse_allocated_ioresource(res_table,
282 res->data.fixed_io.address, 286 res->data.fixed_io.address,
283 res->data.fixed_io.address_length, 287 res->data.fixed_io.address_length,
284 ACPI_DECODE_10); 288 ACPI_DECODE_10);
285 break; 289 break;
286 290
287 case ACPI_RESOURCE_TYPE_VENDOR: 291 case ACPI_RESOURCE_TYPE_VENDOR:
@@ -292,21 +296,21 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
292 296
293 case ACPI_RESOURCE_TYPE_MEMORY24: 297 case ACPI_RESOURCE_TYPE_MEMORY24:
294 pnpacpi_parse_allocated_memresource(res_table, 298 pnpacpi_parse_allocated_memresource(res_table,
295 res->data.memory24.minimum, 299 res->data.memory24.minimum,
296 res->data.memory24.address_length, 300 res->data.memory24.address_length,
297 res->data.memory24.write_protect); 301 res->data.memory24.write_protect);
298 break; 302 break;
299 case ACPI_RESOURCE_TYPE_MEMORY32: 303 case ACPI_RESOURCE_TYPE_MEMORY32:
300 pnpacpi_parse_allocated_memresource(res_table, 304 pnpacpi_parse_allocated_memresource(res_table,
301 res->data.memory32.minimum, 305 res->data.memory32.minimum,
302 res->data.memory32.address_length, 306 res->data.memory32.address_length,
303 res->data.memory32.write_protect); 307 res->data.memory32.write_protect);
304 break; 308 break;
305 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: 309 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
306 pnpacpi_parse_allocated_memresource(res_table, 310 pnpacpi_parse_allocated_memresource(res_table,
307 res->data.fixed_memory32.address, 311 res->data.fixed_memory32.address,
308 res->data.fixed_memory32.address_length, 312 res->data.fixed_memory32.address_length,
309 res->data.fixed_memory32.write_protect); 313 res->data.fixed_memory32.write_protect);
310 break; 314 break;
311 case ACPI_RESOURCE_TYPE_ADDRESS16: 315 case ACPI_RESOURCE_TYPE_ADDRESS16:
312 case ACPI_RESOURCE_TYPE_ADDRESS32: 316 case ACPI_RESOURCE_TYPE_ADDRESS32:
@@ -343,18 +347,21 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
343 return AE_OK; 347 return AE_OK;
344} 348}
345 349
346acpi_status pnpacpi_parse_allocated_resource(acpi_handle handle, struct pnp_resource_table *res) 350acpi_status pnpacpi_parse_allocated_resource(acpi_handle handle,
351 struct pnp_resource_table * res)
347{ 352{
348 /* Blank the resource table values */ 353 /* Blank the resource table values */
349 pnp_init_resource_table(res); 354 pnp_init_resource_table(res);
350 355
351 return acpi_walk_resources(handle, METHOD_NAME__CRS, pnpacpi_allocated_resource, res); 356 return acpi_walk_resources(handle, METHOD_NAME__CRS,
357 pnpacpi_allocated_resource, res);
352} 358}
353 359
354static void pnpacpi_parse_dma_option(struct pnp_option *option, struct acpi_resource_dma *p) 360static void pnpacpi_parse_dma_option(struct pnp_option *option,
361 struct acpi_resource_dma *p)
355{ 362{
356 int i; 363 int i;
357 struct pnp_dma * dma; 364 struct pnp_dma *dma;
358 365
359 if (p->channel_count == 0) 366 if (p->channel_count == 0)
360 return; 367 return;
@@ -362,18 +369,16 @@ static void pnpacpi_parse_dma_option(struct pnp_option *option, struct acpi_reso
362 if (!dma) 369 if (!dma)
363 return; 370 return;
364 371
365 for(i = 0; i < p->channel_count; i++) 372 for (i = 0; i < p->channel_count; i++)
366 dma->map |= 1 << p->channels[i]; 373 dma->map |= 1 << p->channels[i];
367 374
368 dma->flags = dma_flags(p->type, p->bus_master, p->transfer); 375 dma->flags = dma_flags(p->type, p->bus_master, p->transfer);
369 376
370 pnp_register_dma_resource(option, dma); 377 pnp_register_dma_resource(option, dma);
371 return;
372} 378}
373 379
374
375static void pnpacpi_parse_irq_option(struct pnp_option *option, 380static void pnpacpi_parse_irq_option(struct pnp_option *option,
376 struct acpi_resource_irq *p) 381 struct acpi_resource_irq *p)
377{ 382{
378 int i; 383 int i;
379 struct pnp_irq *irq; 384 struct pnp_irq *irq;
@@ -384,17 +389,16 @@ static void pnpacpi_parse_irq_option(struct pnp_option *option,
384 if (!irq) 389 if (!irq)
385 return; 390 return;
386 391
387 for(i = 0; i < p->interrupt_count; i++) 392 for (i = 0; i < p->interrupt_count; i++)
388 if (p->interrupts[i]) 393 if (p->interrupts[i])
389 __set_bit(p->interrupts[i], irq->map); 394 __set_bit(p->interrupts[i], irq->map);
390 irq->flags = irq_flags(p->triggering, p->polarity); 395 irq->flags = irq_flags(p->triggering, p->polarity);
391 396
392 pnp_register_irq_resource(option, irq); 397 pnp_register_irq_resource(option, irq);
393 return;
394} 398}
395 399
396static void pnpacpi_parse_ext_irq_option(struct pnp_option *option, 400static void pnpacpi_parse_ext_irq_option(struct pnp_option *option,
397 struct acpi_resource_extended_irq *p) 401 struct acpi_resource_extended_irq *p)
398{ 402{
399 int i; 403 int i;
400 struct pnp_irq *irq; 404 struct pnp_irq *irq;
@@ -405,18 +409,16 @@ static void pnpacpi_parse_ext_irq_option(struct pnp_option *option,
405 if (!irq) 409 if (!irq)
406 return; 410 return;
407 411
408 for(i = 0; i < p->interrupt_count; i++) 412 for (i = 0; i < p->interrupt_count; i++)
409 if (p->interrupts[i]) 413 if (p->interrupts[i])
410 __set_bit(p->interrupts[i], irq->map); 414 __set_bit(p->interrupts[i], irq->map);
411 irq->flags = irq_flags(p->triggering, p->polarity); 415 irq->flags = irq_flags(p->triggering, p->polarity);
412 416
413 pnp_register_irq_resource(option, irq); 417 pnp_register_irq_resource(option, irq);
414 return;
415} 418}
416 419
417static void 420static void pnpacpi_parse_port_option(struct pnp_option *option,
418pnpacpi_parse_port_option(struct pnp_option *option, 421 struct acpi_resource_io *io)
419 struct acpi_resource_io *io)
420{ 422{
421 struct pnp_port *port; 423 struct pnp_port *port;
422 424
@@ -430,14 +432,12 @@ pnpacpi_parse_port_option(struct pnp_option *option,
430 port->align = io->alignment; 432 port->align = io->alignment;
431 port->size = io->address_length; 433 port->size = io->address_length;
432 port->flags = ACPI_DECODE_16 == io->io_decode ? 434 port->flags = ACPI_DECODE_16 == io->io_decode ?
433 PNP_PORT_FLAG_16BITADDR : 0; 435 PNP_PORT_FLAG_16BITADDR : 0;
434 pnp_register_port_resource(option, port); 436 pnp_register_port_resource(option, port);
435 return;
436} 437}
437 438
438static void 439static void pnpacpi_parse_fixed_port_option(struct pnp_option *option,
439pnpacpi_parse_fixed_port_option(struct pnp_option *option, 440 struct acpi_resource_fixed_io *io)
440 struct acpi_resource_fixed_io *io)
441{ 441{
442 struct pnp_port *port; 442 struct pnp_port *port;
443 443
@@ -451,12 +451,10 @@ pnpacpi_parse_fixed_port_option(struct pnp_option *option,
451 port->align = 0; 451 port->align = 0;
452 port->flags = PNP_PORT_FLAG_FIXED; 452 port->flags = PNP_PORT_FLAG_FIXED;
453 pnp_register_port_resource(option, port); 453 pnp_register_port_resource(option, port);
454 return;
455} 454}
456 455
457static void 456static void pnpacpi_parse_mem24_option(struct pnp_option *option,
458pnpacpi_parse_mem24_option(struct pnp_option *option, 457 struct acpi_resource_memory24 *p)
459 struct acpi_resource_memory24 *p)
460{ 458{
461 struct pnp_mem *mem; 459 struct pnp_mem *mem;
462 460
@@ -471,15 +469,13 @@ pnpacpi_parse_mem24_option(struct pnp_option *option,
471 mem->size = p->address_length; 469 mem->size = p->address_length;
472 470
473 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ? 471 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
474 IORESOURCE_MEM_WRITEABLE : 0; 472 IORESOURCE_MEM_WRITEABLE : 0;
475 473
476 pnp_register_mem_resource(option, mem); 474 pnp_register_mem_resource(option, mem);
477 return;
478} 475}
479 476
480static void 477static void pnpacpi_parse_mem32_option(struct pnp_option *option,
481pnpacpi_parse_mem32_option(struct pnp_option *option, 478 struct acpi_resource_memory32 *p)
482 struct acpi_resource_memory32 *p)
483{ 479{
484 struct pnp_mem *mem; 480 struct pnp_mem *mem;
485 481
@@ -494,15 +490,13 @@ pnpacpi_parse_mem32_option(struct pnp_option *option,
494 mem->size = p->address_length; 490 mem->size = p->address_length;
495 491
496 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ? 492 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
497 IORESOURCE_MEM_WRITEABLE : 0; 493 IORESOURCE_MEM_WRITEABLE : 0;
498 494
499 pnp_register_mem_resource(option, mem); 495 pnp_register_mem_resource(option, mem);
500 return;
501} 496}
502 497
503static void 498static void pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
504pnpacpi_parse_fixed_mem32_option(struct pnp_option *option, 499 struct acpi_resource_fixed_memory32 *p)
505 struct acpi_resource_fixed_memory32 *p)
506{ 500{
507 struct pnp_mem *mem; 501 struct pnp_mem *mem;
508 502
@@ -516,14 +510,13 @@ pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
516 mem->align = 0; 510 mem->align = 0;
517 511
518 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ? 512 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
519 IORESOURCE_MEM_WRITEABLE : 0; 513 IORESOURCE_MEM_WRITEABLE : 0;
520 514
521 pnp_register_mem_resource(option, mem); 515 pnp_register_mem_resource(option, mem);
522 return;
523} 516}
524 517
525static void 518static void pnpacpi_parse_address_option(struct pnp_option *option,
526pnpacpi_parse_address_option(struct pnp_option *option, struct acpi_resource *r) 519 struct acpi_resource *r)
527{ 520{
528 struct acpi_resource_address64 addr, *p = &addr; 521 struct acpi_resource_address64 addr, *p = &addr;
529 acpi_status status; 522 acpi_status status;
@@ -532,7 +525,8 @@ pnpacpi_parse_address_option(struct pnp_option *option, struct acpi_resource *r)
532 525
533 status = acpi_resource_to_address64(r, p); 526 status = acpi_resource_to_address64(r, p);
534 if (!ACPI_SUCCESS(status)) { 527 if (!ACPI_SUCCESS(status)) {
535 pnp_warn("PnPACPI: failed to convert resource type %d", r->type); 528 pnp_warn("PnPACPI: failed to convert resource type %d",
529 r->type);
536 return; 530 return;
537 } 531 }
538 532
@@ -547,7 +541,8 @@ pnpacpi_parse_address_option(struct pnp_option *option, struct acpi_resource *r)
547 mem->size = p->address_length; 541 mem->size = p->address_length;
548 mem->align = 0; 542 mem->align = 0;
549 mem->flags = (p->info.mem.write_protect == 543 mem->flags = (p->info.mem.write_protect ==
550 ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE : 0; 544 ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE
545 : 0;
551 pnp_register_mem_resource(option, mem); 546 pnp_register_mem_resource(option, mem);
552 } else if (p->resource_type == ACPI_IO_RANGE) { 547 } else if (p->resource_type == ACPI_IO_RANGE) {
553 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); 548 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
@@ -568,109 +563,108 @@ struct acpipnp_parse_option_s {
568}; 563};
569 564
570static acpi_status pnpacpi_option_resource(struct acpi_resource *res, 565static acpi_status pnpacpi_option_resource(struct acpi_resource *res,
571 void *data) 566 void *data)
572{ 567{
573 int priority = 0; 568 int priority = 0;
574 struct acpipnp_parse_option_s *parse_data = (struct acpipnp_parse_option_s *)data; 569 struct acpipnp_parse_option_s *parse_data =
570 (struct acpipnp_parse_option_s *)data;
575 struct pnp_dev *dev = parse_data->dev; 571 struct pnp_dev *dev = parse_data->dev;
576 struct pnp_option *option = parse_data->option; 572 struct pnp_option *option = parse_data->option;
577 573
578 switch (res->type) { 574 switch (res->type) {
579 case ACPI_RESOURCE_TYPE_IRQ: 575 case ACPI_RESOURCE_TYPE_IRQ:
580 pnpacpi_parse_irq_option(option, &res->data.irq); 576 pnpacpi_parse_irq_option(option, &res->data.irq);
581 break; 577 break;
582 578
583 case ACPI_RESOURCE_TYPE_DMA: 579 case ACPI_RESOURCE_TYPE_DMA:
584 pnpacpi_parse_dma_option(option, &res->data.dma); 580 pnpacpi_parse_dma_option(option, &res->data.dma);
585 break; 581 break;
586 582
587 case ACPI_RESOURCE_TYPE_START_DEPENDENT: 583 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
588 switch (res->data.start_dpf.compatibility_priority) { 584 switch (res->data.start_dpf.compatibility_priority) {
589 case ACPI_GOOD_CONFIGURATION: 585 case ACPI_GOOD_CONFIGURATION:
590 priority = PNP_RES_PRIORITY_PREFERRED; 586 priority = PNP_RES_PRIORITY_PREFERRED;
591 break;
592
593 case ACPI_ACCEPTABLE_CONFIGURATION:
594 priority = PNP_RES_PRIORITY_ACCEPTABLE;
595 break;
596
597 case ACPI_SUB_OPTIMAL_CONFIGURATION:
598 priority = PNP_RES_PRIORITY_FUNCTIONAL;
599 break;
600 default:
601 priority = PNP_RES_PRIORITY_INVALID;
602 break;
603 }
604 /* TBD: Considering performace/robustness bits */
605 option = pnp_register_dependent_option(dev, priority);
606 if (!option)
607 return AE_ERROR;
608 parse_data->option = option;
609 break; 587 break;
610 588
611 case ACPI_RESOURCE_TYPE_END_DEPENDENT: 589 case ACPI_ACCEPTABLE_CONFIGURATION:
612 /*only one EndDependentFn is allowed*/ 590 priority = PNP_RES_PRIORITY_ACCEPTABLE;
613 if (!parse_data->option_independent) {
614 pnp_warn("PnPACPI: more than one EndDependentFn");
615 return AE_ERROR;
616 }
617 parse_data->option = parse_data->option_independent;
618 parse_data->option_independent = NULL;
619 break; 591 break;
620 592
621 case ACPI_RESOURCE_TYPE_IO: 593 case ACPI_SUB_OPTIMAL_CONFIGURATION:
622 pnpacpi_parse_port_option(option, &res->data.io); 594 priority = PNP_RES_PRIORITY_FUNCTIONAL;
623 break; 595 break;
624 596 default:
625 case ACPI_RESOURCE_TYPE_FIXED_IO: 597 priority = PNP_RES_PRIORITY_INVALID;
626 pnpacpi_parse_fixed_port_option(option,
627 &res->data.fixed_io);
628 break; 598 break;
599 }
600 /* TBD: Consider performance/robustness bits */
601 option = pnp_register_dependent_option(dev, priority);
602 if (!option)
603 return AE_ERROR;
604 parse_data->option = option;
605 break;
629 606
630 case ACPI_RESOURCE_TYPE_VENDOR: 607 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
631 case ACPI_RESOURCE_TYPE_END_TAG: 608 /*only one EndDependentFn is allowed */
632 break; 609 if (!parse_data->option_independent) {
610 pnp_warn("PnPACPI: more than one EndDependentFn");
611 return AE_ERROR;
612 }
613 parse_data->option = parse_data->option_independent;
614 parse_data->option_independent = NULL;
615 break;
633 616
634 case ACPI_RESOURCE_TYPE_MEMORY24: 617 case ACPI_RESOURCE_TYPE_IO:
635 pnpacpi_parse_mem24_option(option, &res->data.memory24); 618 pnpacpi_parse_port_option(option, &res->data.io);
636 break; 619 break;
637 620
638 case ACPI_RESOURCE_TYPE_MEMORY32: 621 case ACPI_RESOURCE_TYPE_FIXED_IO:
639 pnpacpi_parse_mem32_option(option, &res->data.memory32); 622 pnpacpi_parse_fixed_port_option(option, &res->data.fixed_io);
640 break; 623 break;
641 624
642 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: 625 case ACPI_RESOURCE_TYPE_VENDOR:
643 pnpacpi_parse_fixed_mem32_option(option, 626 case ACPI_RESOURCE_TYPE_END_TAG:
644 &res->data.fixed_memory32); 627 break;
645 break;
646 628
647 case ACPI_RESOURCE_TYPE_ADDRESS16: 629 case ACPI_RESOURCE_TYPE_MEMORY24:
648 case ACPI_RESOURCE_TYPE_ADDRESS32: 630 pnpacpi_parse_mem24_option(option, &res->data.memory24);
649 case ACPI_RESOURCE_TYPE_ADDRESS64: 631 break;
650 pnpacpi_parse_address_option(option, res);
651 break;
652 632
653 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64: 633 case ACPI_RESOURCE_TYPE_MEMORY32:
654 break; 634 pnpacpi_parse_mem32_option(option, &res->data.memory32);
635 break;
655 636
656 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: 637 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
657 pnpacpi_parse_ext_irq_option(option, 638 pnpacpi_parse_fixed_mem32_option(option,
658 &res->data.extended_irq); 639 &res->data.fixed_memory32);
659 break; 640 break;
660 641
661 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER: 642 case ACPI_RESOURCE_TYPE_ADDRESS16:
662 break; 643 case ACPI_RESOURCE_TYPE_ADDRESS32:
644 case ACPI_RESOURCE_TYPE_ADDRESS64:
645 pnpacpi_parse_address_option(option, res);
646 break;
663 647
664 default: 648 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
665 pnp_warn("PnPACPI: unknown resource type %d", res->type); 649 break;
666 return AE_ERROR; 650
651 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
652 pnpacpi_parse_ext_irq_option(option, &res->data.extended_irq);
653 break;
654
655 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
656 break;
657
658 default:
659 pnp_warn("PnPACPI: unknown resource type %d", res->type);
660 return AE_ERROR;
667 } 661 }
668 662
669 return AE_OK; 663 return AE_OK;
670} 664}
671 665
672acpi_status pnpacpi_parse_resource_option_data(acpi_handle handle, 666acpi_status pnpacpi_parse_resource_option_data(acpi_handle handle,
673 struct pnp_dev *dev) 667 struct pnp_dev * dev)
674{ 668{
675 acpi_status status; 669 acpi_status status;
676 struct acpipnp_parse_option_s parse_data; 670 struct acpipnp_parse_option_s parse_data;
@@ -681,7 +675,7 @@ acpi_status pnpacpi_parse_resource_option_data(acpi_handle handle,
681 parse_data.option_independent = parse_data.option; 675 parse_data.option_independent = parse_data.option;
682 parse_data.dev = dev; 676 parse_data.dev = dev;
683 status = acpi_walk_resources(handle, METHOD_NAME__PRS, 677 status = acpi_walk_resources(handle, METHOD_NAME__PRS,
684 pnpacpi_option_resource, &parse_data); 678 pnpacpi_option_resource, &parse_data);
685 679
686 return status; 680 return status;
687} 681}
@@ -709,7 +703,7 @@ static int pnpacpi_supported_resource(struct acpi_resource *res)
709 * Set resource 703 * Set resource
710 */ 704 */
711static acpi_status pnpacpi_count_resources(struct acpi_resource *res, 705static acpi_status pnpacpi_count_resources(struct acpi_resource *res,
712 void *data) 706 void *data)
713{ 707{
714 int *res_cnt = (int *)data; 708 int *res_cnt = (int *)data;
715 709
@@ -732,14 +726,14 @@ static acpi_status pnpacpi_type_resources(struct acpi_resource *res, void *data)
732} 726}
733 727
734int pnpacpi_build_resource_template(acpi_handle handle, 728int pnpacpi_build_resource_template(acpi_handle handle,
735 struct acpi_buffer *buffer) 729 struct acpi_buffer *buffer)
736{ 730{
737 struct acpi_resource *resource; 731 struct acpi_resource *resource;
738 int res_cnt = 0; 732 int res_cnt = 0;
739 acpi_status status; 733 acpi_status status;
740 734
741 status = acpi_walk_resources(handle, METHOD_NAME__CRS, 735 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
742 pnpacpi_count_resources, &res_cnt); 736 pnpacpi_count_resources, &res_cnt);
743 if (ACPI_FAILURE(status)) { 737 if (ACPI_FAILURE(status)) {
744 pnp_err("Evaluate _CRS failed"); 738 pnp_err("Evaluate _CRS failed");
745 return -EINVAL; 739 return -EINVAL;
@@ -753,7 +747,7 @@ int pnpacpi_build_resource_template(acpi_handle handle,
753 pnp_dbg("Res cnt %d", res_cnt); 747 pnp_dbg("Res cnt %d", res_cnt);
754 resource = (struct acpi_resource *)buffer->pointer; 748 resource = (struct acpi_resource *)buffer->pointer;
755 status = acpi_walk_resources(handle, METHOD_NAME__CRS, 749 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
756 pnpacpi_type_resources, &resource); 750 pnpacpi_type_resources, &resource);
757 if (ACPI_FAILURE(status)) { 751 if (ACPI_FAILURE(status)) {
758 kfree(buffer->pointer); 752 kfree(buffer->pointer);
759 pnp_err("Evaluate _CRS failed"); 753 pnp_err("Evaluate _CRS failed");
@@ -766,7 +760,7 @@ int pnpacpi_build_resource_template(acpi_handle handle,
766} 760}
767 761
768static void pnpacpi_encode_irq(struct acpi_resource *resource, 762static void pnpacpi_encode_irq(struct acpi_resource *resource,
769 struct resource *p) 763 struct resource *p)
770{ 764{
771 int triggering, polarity; 765 int triggering, polarity;
772 766
@@ -782,7 +776,7 @@ static void pnpacpi_encode_irq(struct acpi_resource *resource,
782} 776}
783 777
784static void pnpacpi_encode_ext_irq(struct acpi_resource *resource, 778static void pnpacpi_encode_ext_irq(struct acpi_resource *resource,
785 struct resource *p) 779 struct resource *p)
786{ 780{
787 int triggering, polarity; 781 int triggering, polarity;
788 782
@@ -799,32 +793,32 @@ static void pnpacpi_encode_ext_irq(struct acpi_resource *resource,
799} 793}
800 794
801static void pnpacpi_encode_dma(struct acpi_resource *resource, 795static void pnpacpi_encode_dma(struct acpi_resource *resource,
802 struct resource *p) 796 struct resource *p)
803{ 797{
804 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */ 798 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
805 switch (p->flags & IORESOURCE_DMA_SPEED_MASK) { 799 switch (p->flags & IORESOURCE_DMA_SPEED_MASK) {
806 case IORESOURCE_DMA_TYPEA: 800 case IORESOURCE_DMA_TYPEA:
807 resource->data.dma.type = ACPI_TYPE_A; 801 resource->data.dma.type = ACPI_TYPE_A;
808 break; 802 break;
809 case IORESOURCE_DMA_TYPEB: 803 case IORESOURCE_DMA_TYPEB:
810 resource->data.dma.type = ACPI_TYPE_B; 804 resource->data.dma.type = ACPI_TYPE_B;
811 break; 805 break;
812 case IORESOURCE_DMA_TYPEF: 806 case IORESOURCE_DMA_TYPEF:
813 resource->data.dma.type = ACPI_TYPE_F; 807 resource->data.dma.type = ACPI_TYPE_F;
814 break; 808 break;
815 default: 809 default:
816 resource->data.dma.type = ACPI_COMPATIBILITY; 810 resource->data.dma.type = ACPI_COMPATIBILITY;
817 } 811 }
818 812
819 switch (p->flags & IORESOURCE_DMA_TYPE_MASK) { 813 switch (p->flags & IORESOURCE_DMA_TYPE_MASK) {
820 case IORESOURCE_DMA_8BIT: 814 case IORESOURCE_DMA_8BIT:
821 resource->data.dma.transfer = ACPI_TRANSFER_8; 815 resource->data.dma.transfer = ACPI_TRANSFER_8;
822 break; 816 break;
823 case IORESOURCE_DMA_8AND16BIT: 817 case IORESOURCE_DMA_8AND16BIT:
824 resource->data.dma.transfer = ACPI_TRANSFER_8_16; 818 resource->data.dma.transfer = ACPI_TRANSFER_8_16;
825 break; 819 break;
826 default: 820 default:
827 resource->data.dma.transfer = ACPI_TRANSFER_16; 821 resource->data.dma.transfer = ACPI_TRANSFER_16;
828 } 822 }
829 823
830 resource->data.dma.bus_master = !!(p->flags & IORESOURCE_DMA_MASTER); 824 resource->data.dma.bus_master = !!(p->flags & IORESOURCE_DMA_MASTER);
@@ -833,31 +827,31 @@ static void pnpacpi_encode_dma(struct acpi_resource *resource,
833} 827}
834 828
835static void pnpacpi_encode_io(struct acpi_resource *resource, 829static void pnpacpi_encode_io(struct acpi_resource *resource,
836 struct resource *p) 830 struct resource *p)
837{ 831{
838 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */ 832 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
839 resource->data.io.io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR)? 833 resource->data.io.io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ?
840 ACPI_DECODE_16 : ACPI_DECODE_10; 834 ACPI_DECODE_16 : ACPI_DECODE_10;
841 resource->data.io.minimum = p->start; 835 resource->data.io.minimum = p->start;
842 resource->data.io.maximum = p->end; 836 resource->data.io.maximum = p->end;
843 resource->data.io.alignment = 0; /* Correct? */ 837 resource->data.io.alignment = 0; /* Correct? */
844 resource->data.io.address_length = p->end - p->start + 1; 838 resource->data.io.address_length = p->end - p->start + 1;
845} 839}
846 840
847static void pnpacpi_encode_fixed_io(struct acpi_resource *resource, 841static void pnpacpi_encode_fixed_io(struct acpi_resource *resource,
848 struct resource *p) 842 struct resource *p)
849{ 843{
850 resource->data.fixed_io.address = p->start; 844 resource->data.fixed_io.address = p->start;
851 resource->data.fixed_io.address_length = p->end - p->start + 1; 845 resource->data.fixed_io.address_length = p->end - p->start + 1;
852} 846}
853 847
854static void pnpacpi_encode_mem24(struct acpi_resource *resource, 848static void pnpacpi_encode_mem24(struct acpi_resource *resource,
855 struct resource *p) 849 struct resource *p)
856{ 850{
857 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */ 851 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
858 resource->data.memory24.write_protect = 852 resource->data.memory24.write_protect =
859 (p->flags & IORESOURCE_MEM_WRITEABLE) ? 853 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
860 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; 854 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
861 resource->data.memory24.minimum = p->start; 855 resource->data.memory24.minimum = p->start;
862 resource->data.memory24.maximum = p->end; 856 resource->data.memory24.maximum = p->end;
863 resource->data.memory24.alignment = 0; 857 resource->data.memory24.alignment = 0;
@@ -865,11 +859,11 @@ static void pnpacpi_encode_mem24(struct acpi_resource *resource,
865} 859}
866 860
867static void pnpacpi_encode_mem32(struct acpi_resource *resource, 861static void pnpacpi_encode_mem32(struct acpi_resource *resource,
868 struct resource *p) 862 struct resource *p)
869{ 863{
870 resource->data.memory32.write_protect = 864 resource->data.memory32.write_protect =
871 (p->flags & IORESOURCE_MEM_WRITEABLE) ? 865 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
872 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; 866 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
873 resource->data.memory32.minimum = p->start; 867 resource->data.memory32.minimum = p->start;
874 resource->data.memory32.maximum = p->end; 868 resource->data.memory32.maximum = p->end;
875 resource->data.memory32.alignment = 0; 869 resource->data.memory32.alignment = 0;
@@ -877,74 +871,77 @@ static void pnpacpi_encode_mem32(struct acpi_resource *resource,
877} 871}
878 872
879static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource, 873static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource,
880 struct resource *p) 874 struct resource *p)
881{ 875{
882 resource->data.fixed_memory32.write_protect = 876 resource->data.fixed_memory32.write_protect =
883 (p->flags & IORESOURCE_MEM_WRITEABLE) ? 877 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
884 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; 878 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
885 resource->data.fixed_memory32.address = p->start; 879 resource->data.fixed_memory32.address = p->start;
886 resource->data.fixed_memory32.address_length = p->end - p->start + 1; 880 resource->data.fixed_memory32.address_length = p->end - p->start + 1;
887} 881}
888 882
889int pnpacpi_encode_resources(struct pnp_resource_table *res_table, 883int pnpacpi_encode_resources(struct pnp_resource_table *res_table,
890 struct acpi_buffer *buffer) 884 struct acpi_buffer *buffer)
891{ 885{
892 int i = 0; 886 int i = 0;
893 /* pnpacpi_build_resource_template allocates extra mem */ 887 /* pnpacpi_build_resource_template allocates extra mem */
894 int res_cnt = (buffer->length - 1)/sizeof(struct acpi_resource) - 1; 888 int res_cnt = (buffer->length - 1) / sizeof(struct acpi_resource) - 1;
895 struct acpi_resource *resource = (struct acpi_resource*)buffer->pointer; 889 struct acpi_resource *resource =
890 (struct acpi_resource *)buffer->pointer;
896 int port = 0, irq = 0, dma = 0, mem = 0; 891 int port = 0, irq = 0, dma = 0, mem = 0;
897 892
898 pnp_dbg("res cnt %d", res_cnt); 893 pnp_dbg("res cnt %d", res_cnt);
899 while (i < res_cnt) { 894 while (i < res_cnt) {
900 switch(resource->type) { 895 switch (resource->type) {
901 case ACPI_RESOURCE_TYPE_IRQ: 896 case ACPI_RESOURCE_TYPE_IRQ:
902 pnp_dbg("Encode irq"); 897 pnp_dbg("Encode irq");
903 pnpacpi_encode_irq(resource, 898 pnpacpi_encode_irq(resource,
904 &res_table->irq_resource[irq]); 899 &res_table->irq_resource[irq]);
905 irq++; 900 irq++;
906 break; 901 break;
907 902
908 case ACPI_RESOURCE_TYPE_DMA: 903 case ACPI_RESOURCE_TYPE_DMA:
909 pnp_dbg("Encode dma"); 904 pnp_dbg("Encode dma");
910 pnpacpi_encode_dma(resource, 905 pnpacpi_encode_dma(resource,
911 &res_table->dma_resource[dma]); 906 &res_table->dma_resource[dma]);
912 dma++; 907 dma++;
913 break; 908 break;
914 case ACPI_RESOURCE_TYPE_IO: 909 case ACPI_RESOURCE_TYPE_IO:
915 pnp_dbg("Encode io"); 910 pnp_dbg("Encode io");
916 pnpacpi_encode_io(resource, 911 pnpacpi_encode_io(resource,
917 &res_table->port_resource[port]); 912 &res_table->port_resource[port]);
918 port++; 913 port++;
919 break; 914 break;
920 case ACPI_RESOURCE_TYPE_FIXED_IO: 915 case ACPI_RESOURCE_TYPE_FIXED_IO:
921 pnp_dbg("Encode fixed io"); 916 pnp_dbg("Encode fixed io");
922 pnpacpi_encode_fixed_io(resource, 917 pnpacpi_encode_fixed_io(resource,
923 &res_table->port_resource[port]); 918 &res_table->
919 port_resource[port]);
924 port++; 920 port++;
925 break; 921 break;
926 case ACPI_RESOURCE_TYPE_MEMORY24: 922 case ACPI_RESOURCE_TYPE_MEMORY24:
927 pnp_dbg("Encode mem24"); 923 pnp_dbg("Encode mem24");
928 pnpacpi_encode_mem24(resource, 924 pnpacpi_encode_mem24(resource,
929 &res_table->mem_resource[mem]); 925 &res_table->mem_resource[mem]);
930 mem++; 926 mem++;
931 break; 927 break;
932 case ACPI_RESOURCE_TYPE_MEMORY32: 928 case ACPI_RESOURCE_TYPE_MEMORY32:
933 pnp_dbg("Encode mem32"); 929 pnp_dbg("Encode mem32");
934 pnpacpi_encode_mem32(resource, 930 pnpacpi_encode_mem32(resource,
935 &res_table->mem_resource[mem]); 931 &res_table->mem_resource[mem]);
936 mem++; 932 mem++;
937 break; 933 break;
938 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: 934 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
939 pnp_dbg("Encode fixed mem32"); 935 pnp_dbg("Encode fixed mem32");
940 pnpacpi_encode_fixed_mem32(resource, 936 pnpacpi_encode_fixed_mem32(resource,
941 &res_table->mem_resource[mem]); 937 &res_table->
938 mem_resource[mem]);
942 mem++; 939 mem++;
943 break; 940 break;
944 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: 941 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
945 pnp_dbg("Encode ext irq"); 942 pnp_dbg("Encode ext irq");
946 pnpacpi_encode_ext_irq(resource, 943 pnpacpi_encode_ext_irq(resource,
947 &res_table->irq_resource[irq]); 944 &res_table->irq_resource[irq]);
948 irq++; 945 irq++;
949 break; 946 break;
950 case ACPI_RESOURCE_TYPE_START_DEPENDENT: 947 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
@@ -956,7 +953,7 @@ int pnpacpi_encode_resources(struct pnp_resource_table *res_table,
956 case ACPI_RESOURCE_TYPE_ADDRESS64: 953 case ACPI_RESOURCE_TYPE_ADDRESS64:
957 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64: 954 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
958 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER: 955 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
959 default: /* other type */ 956 default: /* other type */
960 pnp_warn("unknown resource type %d", resource->type); 957 pnp_warn("unknown resource type %d", resource->type);
961 return -EINVAL; 958 return -EINVAL;
962 } 959 }
diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
index a1f0b0ba2bfe..5dba68fe33f5 100644
--- a/drivers/pnp/pnpbios/bioscalls.c
+++ b/drivers/pnp/pnpbios/bioscalls.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * bioscalls.c - the lowlevel layer of the PnPBIOS driver 2 * bioscalls.c - the lowlevel layer of the PnPBIOS driver
3 *
4 */ 3 */
5 4
6#include <linux/types.h> 5#include <linux/types.h>
@@ -26,11 +25,10 @@
26#include "pnpbios.h" 25#include "pnpbios.h"
27 26
28static struct { 27static struct {
29 u16 offset; 28 u16 offset;
30 u16 segment; 29 u16 segment;
31} pnp_bios_callpoint; 30} pnp_bios_callpoint;
32 31
33
34/* 32/*
35 * These are some opcodes for a "static asmlinkage" 33 * These are some opcodes for a "static asmlinkage"
36 * As this code is *not* executed inside the linux kernel segment, but in a 34 * As this code is *not* executed inside the linux kernel segment, but in a
@@ -44,8 +42,7 @@ static struct {
44 42
45asmlinkage void pnp_bios_callfunc(void); 43asmlinkage void pnp_bios_callfunc(void);
46 44
47__asm__( 45__asm__(".text \n"
48 ".text \n"
49 __ALIGN_STR "\n" 46 __ALIGN_STR "\n"
50 "pnp_bios_callfunc:\n" 47 "pnp_bios_callfunc:\n"
51 " pushl %edx \n" 48 " pushl %edx \n"
@@ -55,8 +52,7 @@ __asm__(
55 " lcallw *pnp_bios_callpoint\n" 52 " lcallw *pnp_bios_callpoint\n"
56 " addl $16, %esp \n" 53 " addl $16, %esp \n"
57 " lret \n" 54 " lret \n"
58 ".previous \n" 55 ".previous \n");
59);
60 56
61#define Q2_SET_SEL(cpu, selname, address, size) \ 57#define Q2_SET_SEL(cpu, selname, address, size) \
62do { \ 58do { \
@@ -78,7 +74,6 @@ u32 pnp_bios_is_utter_crap = 0;
78 74
79static spinlock_t pnp_bios_lock; 75static spinlock_t pnp_bios_lock;
80 76
81
82/* 77/*
83 * Support Functions 78 * Support Functions
84 */ 79 */
@@ -97,7 +92,7 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
97 * PnP BIOSes are generally not terribly re-entrant. 92 * PnP BIOSes are generally not terribly re-entrant.
98 * Also, don't rely on them to save everything correctly. 93 * Also, don't rely on them to save everything correctly.
99 */ 94 */
100 if(pnp_bios_is_utter_crap) 95 if (pnp_bios_is_utter_crap)
101 return PNP_FUNCTION_NOT_SUPPORTED; 96 return PNP_FUNCTION_NOT_SUPPORTED;
102 97
103 cpu = get_cpu(); 98 cpu = get_cpu();
@@ -113,112 +108,128 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
113 if (ts2_size) 108 if (ts2_size)
114 Q2_SET_SEL(smp_processor_id(), PNP_TS2, ts2_base, ts2_size); 109 Q2_SET_SEL(smp_processor_id(), PNP_TS2, ts2_base, ts2_size);
115 110
116 __asm__ __volatile__( 111 __asm__ __volatile__("pushl %%ebp\n\t"
117 "pushl %%ebp\n\t" 112 "pushl %%edi\n\t"
118 "pushl %%edi\n\t" 113 "pushl %%esi\n\t"
119 "pushl %%esi\n\t" 114 "pushl %%ds\n\t"
120 "pushl %%ds\n\t" 115 "pushl %%es\n\t"
121 "pushl %%es\n\t" 116 "pushl %%fs\n\t"
122 "pushl %%fs\n\t" 117 "pushl %%gs\n\t"
123 "pushl %%gs\n\t" 118 "pushfl\n\t"
124 "pushfl\n\t" 119 "movl %%esp, pnp_bios_fault_esp\n\t"
125 "movl %%esp, pnp_bios_fault_esp\n\t" 120 "movl $1f, pnp_bios_fault_eip\n\t"
126 "movl $1f, pnp_bios_fault_eip\n\t" 121 "lcall %5,%6\n\t"
127 "lcall %5,%6\n\t" 122 "1:popfl\n\t"
128 "1:popfl\n\t" 123 "popl %%gs\n\t"
129 "popl %%gs\n\t" 124 "popl %%fs\n\t"
130 "popl %%fs\n\t" 125 "popl %%es\n\t"
131 "popl %%es\n\t" 126 "popl %%ds\n\t"
132 "popl %%ds\n\t" 127 "popl %%esi\n\t"
133 "popl %%esi\n\t" 128 "popl %%edi\n\t"
134 "popl %%edi\n\t" 129 "popl %%ebp\n\t":"=a"(status)
135 "popl %%ebp\n\t" 130 :"0"((func) | (((u32) arg1) << 16)),
136 : "=a" (status) 131 "b"((arg2) | (((u32) arg3) << 16)),
137 : "0" ((func) | (((u32)arg1) << 16)), 132 "c"((arg4) | (((u32) arg5) << 16)),
138 "b" ((arg2) | (((u32)arg3) << 16)), 133 "d"((arg6) | (((u32) arg7) << 16)),
139 "c" ((arg4) | (((u32)arg5) << 16)), 134 "i"(PNP_CS32), "i"(0)
140 "d" ((arg6) | (((u32)arg7) << 16)), 135 :"memory");
141 "i" (PNP_CS32),
142 "i" (0)
143 : "memory"
144 );
145 spin_unlock_irqrestore(&pnp_bios_lock, flags); 136 spin_unlock_irqrestore(&pnp_bios_lock, flags);
146 137
147 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40; 138 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
148 put_cpu(); 139 put_cpu();
149 140
150 /* If we get here and this is set then the PnP BIOS faulted on us. */ 141 /* If we get here and this is set then the PnP BIOS faulted on us. */
151 if(pnp_bios_is_utter_crap) 142 if (pnp_bios_is_utter_crap) {
152 { 143 printk(KERN_ERR
153 printk(KERN_ERR "PnPBIOS: Warning! Your PnP BIOS caused a fatal error. Attempting to continue\n"); 144 "PnPBIOS: Warning! Your PnP BIOS caused a fatal error. Attempting to continue\n");
154 printk(KERN_ERR "PnPBIOS: You may need to reboot with the \"pnpbios=off\" option to operate stably\n"); 145 printk(KERN_ERR
155 printk(KERN_ERR "PnPBIOS: Check with your vendor for an updated BIOS\n"); 146 "PnPBIOS: You may need to reboot with the \"pnpbios=off\" option to operate stably\n");
147 printk(KERN_ERR
148 "PnPBIOS: Check with your vendor for an updated BIOS\n");
156 } 149 }
157 150
158 return status; 151 return status;
159} 152}
160 153
161void pnpbios_print_status(const char * module, u16 status) 154void pnpbios_print_status(const char *module, u16 status)
162{ 155{
163 switch(status) { 156 switch (status) {
164 case PNP_SUCCESS: 157 case PNP_SUCCESS:
165 printk(KERN_ERR "PnPBIOS: %s: function successful\n", module); 158 printk(KERN_ERR "PnPBIOS: %s: function successful\n", module);
166 break; 159 break;
167 case PNP_NOT_SET_STATICALLY: 160 case PNP_NOT_SET_STATICALLY:
168 printk(KERN_ERR "PnPBIOS: %s: unable to set static resources\n", module); 161 printk(KERN_ERR "PnPBIOS: %s: unable to set static resources\n",
162 module);
169 break; 163 break;
170 case PNP_UNKNOWN_FUNCTION: 164 case PNP_UNKNOWN_FUNCTION:
171 printk(KERN_ERR "PnPBIOS: %s: invalid function number passed\n", module); 165 printk(KERN_ERR "PnPBIOS: %s: invalid function number passed\n",
166 module);
172 break; 167 break;
173 case PNP_FUNCTION_NOT_SUPPORTED: 168 case PNP_FUNCTION_NOT_SUPPORTED:
174 printk(KERN_ERR "PnPBIOS: %s: function not supported on this system\n", module); 169 printk(KERN_ERR
170 "PnPBIOS: %s: function not supported on this system\n",
171 module);
175 break; 172 break;
176 case PNP_INVALID_HANDLE: 173 case PNP_INVALID_HANDLE:
177 printk(KERN_ERR "PnPBIOS: %s: invalid handle\n", module); 174 printk(KERN_ERR "PnPBIOS: %s: invalid handle\n", module);
178 break; 175 break;
179 case PNP_BAD_PARAMETER: 176 case PNP_BAD_PARAMETER:
180 printk(KERN_ERR "PnPBIOS: %s: invalid parameters were passed\n", module); 177 printk(KERN_ERR "PnPBIOS: %s: invalid parameters were passed\n",
178 module);
181 break; 179 break;
182 case PNP_SET_FAILED: 180 case PNP_SET_FAILED:
183 printk(KERN_ERR "PnPBIOS: %s: unable to set resources\n", module); 181 printk(KERN_ERR "PnPBIOS: %s: unable to set resources\n",
182 module);
184 break; 183 break;
185 case PNP_EVENTS_NOT_PENDING: 184 case PNP_EVENTS_NOT_PENDING:
186 printk(KERN_ERR "PnPBIOS: %s: no events are pending\n", module); 185 printk(KERN_ERR "PnPBIOS: %s: no events are pending\n", module);
187 break; 186 break;
188 case PNP_SYSTEM_NOT_DOCKED: 187 case PNP_SYSTEM_NOT_DOCKED:
189 printk(KERN_ERR "PnPBIOS: %s: the system is not docked\n", module); 188 printk(KERN_ERR "PnPBIOS: %s: the system is not docked\n",
189 module);
190 break; 190 break;
191 case PNP_NO_ISA_PNP_CARDS: 191 case PNP_NO_ISA_PNP_CARDS:
192 printk(KERN_ERR "PnPBIOS: %s: no isapnp cards are installed on this system\n", module); 192 printk(KERN_ERR
193 "PnPBIOS: %s: no isapnp cards are installed on this system\n",
194 module);
193 break; 195 break;
194 case PNP_UNABLE_TO_DETERMINE_DOCK_CAPABILITIES: 196 case PNP_UNABLE_TO_DETERMINE_DOCK_CAPABILITIES:
195 printk(KERN_ERR "PnPBIOS: %s: cannot determine the capabilities of the docking station\n", module); 197 printk(KERN_ERR
198 "PnPBIOS: %s: cannot determine the capabilities of the docking station\n",
199 module);
196 break; 200 break;
197 case PNP_CONFIG_CHANGE_FAILED_NO_BATTERY: 201 case PNP_CONFIG_CHANGE_FAILED_NO_BATTERY:
198 printk(KERN_ERR "PnPBIOS: %s: unable to undock, the system does not have a battery\n", module); 202 printk(KERN_ERR
203 "PnPBIOS: %s: unable to undock, the system does not have a battery\n",
204 module);
199 break; 205 break;
200 case PNP_CONFIG_CHANGE_FAILED_RESOURCE_CONFLICT: 206 case PNP_CONFIG_CHANGE_FAILED_RESOURCE_CONFLICT:
201 printk(KERN_ERR "PnPBIOS: %s: could not dock due to resource conflicts\n", module); 207 printk(KERN_ERR
208 "PnPBIOS: %s: could not dock due to resource conflicts\n",
209 module);
202 break; 210 break;
203 case PNP_BUFFER_TOO_SMALL: 211 case PNP_BUFFER_TOO_SMALL:
204 printk(KERN_ERR "PnPBIOS: %s: the buffer passed is too small\n", module); 212 printk(KERN_ERR "PnPBIOS: %s: the buffer passed is too small\n",
213 module);
205 break; 214 break;
206 case PNP_USE_ESCD_SUPPORT: 215 case PNP_USE_ESCD_SUPPORT:
207 printk(KERN_ERR "PnPBIOS: %s: use ESCD instead\n", module); 216 printk(KERN_ERR "PnPBIOS: %s: use ESCD instead\n", module);
208 break; 217 break;
209 case PNP_MESSAGE_NOT_SUPPORTED: 218 case PNP_MESSAGE_NOT_SUPPORTED:
210 printk(KERN_ERR "PnPBIOS: %s: the message is unsupported\n", module); 219 printk(KERN_ERR "PnPBIOS: %s: the message is unsupported\n",
220 module);
211 break; 221 break;
212 case PNP_HARDWARE_ERROR: 222 case PNP_HARDWARE_ERROR:
213 printk(KERN_ERR "PnPBIOS: %s: a hardware failure has occured\n", module); 223 printk(KERN_ERR "PnPBIOS: %s: a hardware failure has occured\n",
224 module);
214 break; 225 break;
215 default: 226 default:
216 printk(KERN_ERR "PnPBIOS: %s: unexpected status 0x%x\n", module, status); 227 printk(KERN_ERR "PnPBIOS: %s: unexpected status 0x%x\n", module,
228 status);
217 break; 229 break;
218 } 230 }
219} 231}
220 232
221
222/* 233/*
223 * PnP BIOS Low Level Calls 234 * PnP BIOS Low Level Calls
224 */ 235 */
@@ -243,19 +254,22 @@ void pnpbios_print_status(const char * module, u16 status)
243static int __pnp_bios_dev_node_info(struct pnp_dev_node_info *data) 254static int __pnp_bios_dev_node_info(struct pnp_dev_node_info *data)
244{ 255{
245 u16 status; 256 u16 status;
257
246 if (!pnp_bios_present()) 258 if (!pnp_bios_present())
247 return PNP_FUNCTION_NOT_SUPPORTED; 259 return PNP_FUNCTION_NOT_SUPPORTED;
248 status = call_pnp_bios(PNP_GET_NUM_SYS_DEV_NODES, 0, PNP_TS1, 2, PNP_TS1, PNP_DS, 0, 0, 260 status = call_pnp_bios(PNP_GET_NUM_SYS_DEV_NODES, 0, PNP_TS1, 2,
249 data, sizeof(struct pnp_dev_node_info), NULL, 0); 261 PNP_TS1, PNP_DS, 0, 0, data,
262 sizeof(struct pnp_dev_node_info), NULL, 0);
250 data->no_nodes &= 0xff; 263 data->no_nodes &= 0xff;
251 return status; 264 return status;
252} 265}
253 266
254int pnp_bios_dev_node_info(struct pnp_dev_node_info *data) 267int pnp_bios_dev_node_info(struct pnp_dev_node_info *data)
255{ 268{
256 int status = __pnp_bios_dev_node_info( data ); 269 int status = __pnp_bios_dev_node_info(data);
257 if ( status ) 270
258 pnpbios_print_status( "dev_node_info", status ); 271 if (status)
272 pnpbios_print_status("dev_node_info", status);
259 return status; 273 return status;
260} 274}
261 275
@@ -273,17 +287,20 @@ int pnp_bios_dev_node_info(struct pnp_dev_node_info *data)
273 * or volatile current (0) config 287 * or volatile current (0) config
274 * Output: *nodenum=next node or 0xff if no more nodes 288 * Output: *nodenum=next node or 0xff if no more nodes
275 */ 289 */
276static int __pnp_bios_get_dev_node(u8 *nodenum, char boot, struct pnp_bios_node *data) 290static int __pnp_bios_get_dev_node(u8 *nodenum, char boot,
291 struct pnp_bios_node *data)
277{ 292{
278 u16 status; 293 u16 status;
279 u16 tmp_nodenum; 294 u16 tmp_nodenum;
295
280 if (!pnp_bios_present()) 296 if (!pnp_bios_present())
281 return PNP_FUNCTION_NOT_SUPPORTED; 297 return PNP_FUNCTION_NOT_SUPPORTED;
282 if ( !boot && pnpbios_dont_use_current_config ) 298 if (!boot && pnpbios_dont_use_current_config)
283 return PNP_FUNCTION_NOT_SUPPORTED; 299 return PNP_FUNCTION_NOT_SUPPORTED;
284 tmp_nodenum = *nodenum; 300 tmp_nodenum = *nodenum;
285 status = call_pnp_bios(PNP_GET_SYS_DEV_NODE, 0, PNP_TS1, 0, PNP_TS2, boot ? 2 : 1, PNP_DS, 0, 301 status = call_pnp_bios(PNP_GET_SYS_DEV_NODE, 0, PNP_TS1, 0, PNP_TS2,
286 &tmp_nodenum, sizeof(tmp_nodenum), data, 65536); 302 boot ? 2 : 1, PNP_DS, 0, &tmp_nodenum,
303 sizeof(tmp_nodenum), data, 65536);
287 *nodenum = tmp_nodenum; 304 *nodenum = tmp_nodenum;
288 return status; 305 return status;
289} 306}
@@ -291,104 +308,66 @@ static int __pnp_bios_get_dev_node(u8 *nodenum, char boot, struct pnp_bios_node
291int pnp_bios_get_dev_node(u8 *nodenum, char boot, struct pnp_bios_node *data) 308int pnp_bios_get_dev_node(u8 *nodenum, char boot, struct pnp_bios_node *data)
292{ 309{
293 int status; 310 int status;
294 status = __pnp_bios_get_dev_node( nodenum, boot, data ); 311
295 if ( status ) 312 status = __pnp_bios_get_dev_node(nodenum, boot, data);
296 pnpbios_print_status( "get_dev_node", status ); 313 if (status)
314 pnpbios_print_status("get_dev_node", status);
297 return status; 315 return status;
298} 316}
299 317
300
301/* 318/*
302 * Call PnP BIOS with function 0x02, "set system device node" 319 * Call PnP BIOS with function 0x02, "set system device node"
303 * Input: *nodenum = desired node, 320 * Input: *nodenum = desired node,
304 * boot = whether to set nonvolatile boot (!=0) 321 * boot = whether to set nonvolatile boot (!=0)
305 * or volatile current (0) config 322 * or volatile current (0) config
306 */ 323 */
307static int __pnp_bios_set_dev_node(u8 nodenum, char boot, struct pnp_bios_node *data) 324static int __pnp_bios_set_dev_node(u8 nodenum, char boot,
325 struct pnp_bios_node *data)
308{ 326{
309 u16 status; 327 u16 status;
328
310 if (!pnp_bios_present()) 329 if (!pnp_bios_present())
311 return PNP_FUNCTION_NOT_SUPPORTED; 330 return PNP_FUNCTION_NOT_SUPPORTED;
312 if ( !boot && pnpbios_dont_use_current_config ) 331 if (!boot && pnpbios_dont_use_current_config)
313 return PNP_FUNCTION_NOT_SUPPORTED; 332 return PNP_FUNCTION_NOT_SUPPORTED;
314 status = call_pnp_bios(PNP_SET_SYS_DEV_NODE, nodenum, 0, PNP_TS1, boot ? 2 : 1, PNP_DS, 0, 0, 333 status = call_pnp_bios(PNP_SET_SYS_DEV_NODE, nodenum, 0, PNP_TS1,
315 data, 65536, NULL, 0); 334 boot ? 2 : 1, PNP_DS, 0, 0, data, 65536, NULL,
335 0);
316 return status; 336 return status;
317} 337}
318 338
319int pnp_bios_set_dev_node(u8 nodenum, char boot, struct pnp_bios_node *data) 339int pnp_bios_set_dev_node(u8 nodenum, char boot, struct pnp_bios_node *data)
320{ 340{
321 int status; 341 int status;
322 status = __pnp_bios_set_dev_node( nodenum, boot, data ); 342
323 if ( status ) { 343 status = __pnp_bios_set_dev_node(nodenum, boot, data);
324 pnpbios_print_status( "set_dev_node", status ); 344 if (status) {
345 pnpbios_print_status("set_dev_node", status);
325 return status; 346 return status;
326 } 347 }
327 if ( !boot ) { /* Update devlist */ 348 if (!boot) { /* Update devlist */
328 status = pnp_bios_get_dev_node( &nodenum, boot, data ); 349 status = pnp_bios_get_dev_node(&nodenum, boot, data);
329 if ( status ) 350 if (status)
330 return status; 351 return status;
331 } 352 }
332 return status; 353 return status;
333} 354}
334 355
335#if needed
336/*
337 * Call PnP BIOS with function 0x03, "get event"
338 */
339static int pnp_bios_get_event(u16 *event)
340{
341 u16 status;
342 if (!pnp_bios_present())
343 return PNP_FUNCTION_NOT_SUPPORTED;
344 status = call_pnp_bios(PNP_GET_EVENT, 0, PNP_TS1, PNP_DS, 0, 0 ,0 ,0,
345 event, sizeof(u16), NULL, 0);
346 return status;
347}
348#endif
349
350#if needed
351/*
352 * Call PnP BIOS with function 0x04, "send message"
353 */
354static int pnp_bios_send_message(u16 message)
355{
356 u16 status;
357 if (!pnp_bios_present())
358 return PNP_FUNCTION_NOT_SUPPORTED;
359 status = call_pnp_bios(PNP_SEND_MESSAGE, message, PNP_DS, 0, 0, 0, 0, 0, 0, 0, 0, 0);
360 return status;
361}
362#endif
363
364/* 356/*
365 * Call PnP BIOS with function 0x05, "get docking station information" 357 * Call PnP BIOS with function 0x05, "get docking station information"
366 */ 358 */
367int pnp_bios_dock_station_info(struct pnp_docking_station_info *data) 359int pnp_bios_dock_station_info(struct pnp_docking_station_info *data)
368{ 360{
369 u16 status; 361 u16 status;
370 if (!pnp_bios_present())
371 return PNP_FUNCTION_NOT_SUPPORTED;
372 status = call_pnp_bios(PNP_GET_DOCKING_STATION_INFORMATION, 0, PNP_TS1, PNP_DS, 0, 0, 0, 0,
373 data, sizeof(struct pnp_docking_station_info), NULL, 0);
374 return status;
375}
376 362
377#if needed
378/*
379 * Call PnP BIOS with function 0x09, "set statically allocated resource
380 * information"
381 */
382static int pnp_bios_set_stat_res(char *info)
383{
384 u16 status;
385 if (!pnp_bios_present()) 363 if (!pnp_bios_present())
386 return PNP_FUNCTION_NOT_SUPPORTED; 364 return PNP_FUNCTION_NOT_SUPPORTED;
387 status = call_pnp_bios(PNP_SET_STATIC_ALLOCED_RES_INFO, 0, PNP_TS1, PNP_DS, 0, 0, 0, 0, 365 status = call_pnp_bios(PNP_GET_DOCKING_STATION_INFORMATION, 0, PNP_TS1,
388 info, *((u16 *) info), 0, 0); 366 PNP_DS, 0, 0, 0, 0, data,
367 sizeof(struct pnp_docking_station_info), NULL,
368 0);
389 return status; 369 return status;
390} 370}
391#endif
392 371
393/* 372/*
394 * Call PnP BIOS with function 0x0a, "get statically allocated resource 373 * Call PnP BIOS with function 0x0a, "get statically allocated resource
@@ -397,36 +376,23 @@ static int pnp_bios_set_stat_res(char *info)
397static int __pnp_bios_get_stat_res(char *info) 376static int __pnp_bios_get_stat_res(char *info)
398{ 377{
399 u16 status; 378 u16 status;
379
400 if (!pnp_bios_present()) 380 if (!pnp_bios_present())
401 return PNP_FUNCTION_NOT_SUPPORTED; 381 return PNP_FUNCTION_NOT_SUPPORTED;
402 status = call_pnp_bios(PNP_GET_STATIC_ALLOCED_RES_INFO, 0, PNP_TS1, PNP_DS, 0, 0, 0, 0, 382 status = call_pnp_bios(PNP_GET_STATIC_ALLOCED_RES_INFO, 0, PNP_TS1,
403 info, 65536, NULL, 0); 383 PNP_DS, 0, 0, 0, 0, info, 65536, NULL, 0);
404 return status; 384 return status;
405} 385}
406 386
407int pnp_bios_get_stat_res(char *info) 387int pnp_bios_get_stat_res(char *info)
408{ 388{
409 int status; 389 int status;
410 status = __pnp_bios_get_stat_res( info );
411 if ( status )
412 pnpbios_print_status( "get_stat_res", status );
413 return status;
414}
415 390
416#if needed 391 status = __pnp_bios_get_stat_res(info);
417/* 392 if (status)
418 * Call PnP BIOS with function 0x0b, "get APM id table" 393 pnpbios_print_status("get_stat_res", status);
419 */
420static int pnp_bios_apm_id_table(char *table, u16 *size)
421{
422 u16 status;
423 if (!pnp_bios_present())
424 return PNP_FUNCTION_NOT_SUPPORTED;
425 status = call_pnp_bios(PNP_GET_APM_ID_TABLE, 0, PNP_TS2, 0, PNP_TS1, PNP_DS, 0, 0,
426 table, *size, size, sizeof(u16));
427 return status; 394 return status;
428} 395}
429#endif
430 396
431/* 397/*
432 * Call PnP BIOS with function 0x40, "get isa pnp configuration structure" 398 * Call PnP BIOS with function 0x40, "get isa pnp configuration structure"
@@ -434,19 +400,22 @@ static int pnp_bios_apm_id_table(char *table, u16 *size)
434static int __pnp_bios_isapnp_config(struct pnp_isa_config_struc *data) 400static int __pnp_bios_isapnp_config(struct pnp_isa_config_struc *data)
435{ 401{
436 u16 status; 402 u16 status;
403
437 if (!pnp_bios_present()) 404 if (!pnp_bios_present())
438 return PNP_FUNCTION_NOT_SUPPORTED; 405 return PNP_FUNCTION_NOT_SUPPORTED;
439 status = call_pnp_bios(PNP_GET_PNP_ISA_CONFIG_STRUC, 0, PNP_TS1, PNP_DS, 0, 0, 0, 0, 406 status = call_pnp_bios(PNP_GET_PNP_ISA_CONFIG_STRUC, 0, PNP_TS1, PNP_DS,
440 data, sizeof(struct pnp_isa_config_struc), NULL, 0); 407 0, 0, 0, 0, data,
408 sizeof(struct pnp_isa_config_struc), NULL, 0);
441 return status; 409 return status;
442} 410}
443 411
444int pnp_bios_isapnp_config(struct pnp_isa_config_struc *data) 412int pnp_bios_isapnp_config(struct pnp_isa_config_struc *data)
445{ 413{
446 int status; 414 int status;
447 status = __pnp_bios_isapnp_config( data ); 415
448 if ( status ) 416 status = __pnp_bios_isapnp_config(data);
449 pnpbios_print_status( "isapnp_config", status ); 417 if (status)
418 pnpbios_print_status("isapnp_config", status);
450 return status; 419 return status;
451} 420}
452 421
@@ -456,19 +425,22 @@ int pnp_bios_isapnp_config(struct pnp_isa_config_struc *data)
456static int __pnp_bios_escd_info(struct escd_info_struc *data) 425static int __pnp_bios_escd_info(struct escd_info_struc *data)
457{ 426{
458 u16 status; 427 u16 status;
428
459 if (!pnp_bios_present()) 429 if (!pnp_bios_present())
460 return ESCD_FUNCTION_NOT_SUPPORTED; 430 return ESCD_FUNCTION_NOT_SUPPORTED;
461 status = call_pnp_bios(PNP_GET_ESCD_INFO, 0, PNP_TS1, 2, PNP_TS1, 4, PNP_TS1, PNP_DS, 431 status = call_pnp_bios(PNP_GET_ESCD_INFO, 0, PNP_TS1, 2, PNP_TS1, 4,
462 data, sizeof(struct escd_info_struc), NULL, 0); 432 PNP_TS1, PNP_DS, data,
433 sizeof(struct escd_info_struc), NULL, 0);
463 return status; 434 return status;
464} 435}
465 436
466int pnp_bios_escd_info(struct escd_info_struc *data) 437int pnp_bios_escd_info(struct escd_info_struc *data)
467{ 438{
468 int status; 439 int status;
469 status = __pnp_bios_escd_info( data ); 440
470 if ( status ) 441 status = __pnp_bios_escd_info(data);
471 pnpbios_print_status( "escd_info", status ); 442 if (status)
443 pnpbios_print_status("escd_info", status);
472 return status; 444 return status;
473} 445}
474 446
@@ -479,57 +451,42 @@ int pnp_bios_escd_info(struct escd_info_struc *data)
479static int __pnp_bios_read_escd(char *data, u32 nvram_base) 451static int __pnp_bios_read_escd(char *data, u32 nvram_base)
480{ 452{
481 u16 status; 453 u16 status;
454
482 if (!pnp_bios_present()) 455 if (!pnp_bios_present())
483 return ESCD_FUNCTION_NOT_SUPPORTED; 456 return ESCD_FUNCTION_NOT_SUPPORTED;
484 status = call_pnp_bios(PNP_READ_ESCD, 0, PNP_TS1, PNP_TS2, PNP_DS, 0, 0, 0, 457 status = call_pnp_bios(PNP_READ_ESCD, 0, PNP_TS1, PNP_TS2, PNP_DS, 0, 0,
485 data, 65536, __va(nvram_base), 65536); 458 0, data, 65536, __va(nvram_base), 65536);
486 return status; 459 return status;
487} 460}
488 461
489int pnp_bios_read_escd(char *data, u32 nvram_base) 462int pnp_bios_read_escd(char *data, u32 nvram_base)
490{ 463{
491 int status; 464 int status;
492 status = __pnp_bios_read_escd( data, nvram_base );
493 if ( status )
494 pnpbios_print_status( "read_escd", status );
495 return status;
496}
497 465
498#if needed 466 status = __pnp_bios_read_escd(data, nvram_base);
499/* 467 if (status)
500 * Call PnP BIOS function 0x43, "write ESCD" 468 pnpbios_print_status("read_escd", status);
501 */
502static int pnp_bios_write_escd(char *data, u32 nvram_base)
503{
504 u16 status;
505 if (!pnp_bios_present())
506 return ESCD_FUNCTION_NOT_SUPPORTED;
507 status = call_pnp_bios(PNP_WRITE_ESCD, 0, PNP_TS1, PNP_TS2, PNP_DS, 0, 0, 0,
508 data, 65536, __va(nvram_base), 65536);
509 return status; 469 return status;
510} 470}
511#endif
512
513
514/*
515 * Initialization
516 */
517 471
518void pnpbios_calls_init(union pnp_bios_install_struct *header) 472void pnpbios_calls_init(union pnp_bios_install_struct *header)
519{ 473{
520 int i; 474 int i;
475
521 spin_lock_init(&pnp_bios_lock); 476 spin_lock_init(&pnp_bios_lock);
522 pnp_bios_callpoint.offset = header->fields.pm16offset; 477 pnp_bios_callpoint.offset = header->fields.pm16offset;
523 pnp_bios_callpoint.segment = PNP_CS16; 478 pnp_bios_callpoint.segment = PNP_CS16;
524 479
525 set_base(bad_bios_desc, __va((unsigned long)0x40 << 4)); 480 set_base(bad_bios_desc, __va((unsigned long)0x40 << 4));
526 _set_limit((char *)&bad_bios_desc, 4095 - (0x40 << 4)); 481 _set_limit((char *)&bad_bios_desc, 4095 - (0x40 << 4));
527 for (i = 0; i < NR_CPUS; i++) { 482 for (i = 0; i < NR_CPUS; i++) {
528 struct desc_struct *gdt = get_cpu_gdt_table(i); 483 struct desc_struct *gdt = get_cpu_gdt_table(i);
529 if (!gdt) 484 if (!gdt)
530 continue; 485 continue;
531 set_base(gdt[GDT_ENTRY_PNPBIOS_CS32], &pnp_bios_callfunc); 486 set_base(gdt[GDT_ENTRY_PNPBIOS_CS32], &pnp_bios_callfunc);
532 set_base(gdt[GDT_ENTRY_PNPBIOS_CS16], __va(header->fields.pm16cseg)); 487 set_base(gdt[GDT_ENTRY_PNPBIOS_CS16],
533 set_base(gdt[GDT_ENTRY_PNPBIOS_DS], __va(header->fields.pm16dseg)); 488 __va(header->fields.pm16cseg));
534 } 489 set_base(gdt[GDT_ENTRY_PNPBIOS_DS],
490 __va(header->fields.pm16dseg));
491 }
535} 492}
diff --git a/drivers/pnp/pnpbios/core.c b/drivers/pnp/pnpbios/core.c
index ed112ee16012..3692a099b45f 100644
--- a/drivers/pnp/pnpbios/core.c
+++ b/drivers/pnp/pnpbios/core.c
@@ -32,7 +32,7 @@
32 * along with this program; if not, write to the Free Software 32 * along with this program; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 */ 34 */
35 35
36/* Change Log 36/* Change Log
37 * 37 *
38 * Adam Belay - <ambx1@neo.rr.com> - March 16, 2003 38 * Adam Belay - <ambx1@neo.rr.com> - March 16, 2003
@@ -71,14 +71,13 @@
71 71
72#include "pnpbios.h" 72#include "pnpbios.h"
73 73
74
75/* 74/*
76 * 75 *
77 * PnP BIOS INTERFACE 76 * PnP BIOS INTERFACE
78 * 77 *
79 */ 78 */
80 79
81static union pnp_bios_install_struct * pnp_bios_install = NULL; 80static union pnp_bios_install_struct *pnp_bios_install = NULL;
82 81
83int pnp_bios_present(void) 82int pnp_bios_present(void)
84{ 83{
@@ -101,36 +100,35 @@ static struct completion unload_sem;
101/* 100/*
102 * (Much of this belongs in a shared routine somewhere) 101 * (Much of this belongs in a shared routine somewhere)
103 */ 102 */
104
105static int pnp_dock_event(int dock, struct pnp_docking_station_info *info) 103static int pnp_dock_event(int dock, struct pnp_docking_station_info *info)
106{ 104{
107 char *argv [3], **envp, *buf, *scratch; 105 char *argv[3], **envp, *buf, *scratch;
108 int i = 0, value; 106 int i = 0, value;
109 107
110 if (!current->fs->root) { 108 if (!current->fs->root)
111 return -EAGAIN; 109 return -EAGAIN;
112 } 110 if (!(envp = kcalloc(20, sizeof(char *), GFP_KERNEL)))
113 if (!(envp = kcalloc(20, sizeof (char *), GFP_KERNEL))) {
114 return -ENOMEM; 111 return -ENOMEM;
115 }
116 if (!(buf = kzalloc(256, GFP_KERNEL))) { 112 if (!(buf = kzalloc(256, GFP_KERNEL))) {
117 kfree (envp); 113 kfree(envp);
118 return -ENOMEM; 114 return -ENOMEM;
119 } 115 }
120 116
121 /* FIXME: if there are actual users of this, it should be integrated into 117 /* FIXME: if there are actual users of this, it should be
122 * the driver core and use the usual infrastructure like sysfs and uevents */ 118 * integrated into the driver core and use the usual infrastructure
123 argv [0] = "/sbin/pnpbios"; 119 * like sysfs and uevents
124 argv [1] = "dock"; 120 */
125 argv [2] = NULL; 121 argv[0] = "/sbin/pnpbios";
122 argv[1] = "dock";
123 argv[2] = NULL;
126 124
127 /* minimal command environment */ 125 /* minimal command environment */
128 envp [i++] = "HOME=/"; 126 envp[i++] = "HOME=/";
129 envp [i++] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin"; 127 envp[i++] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
130 128
131#ifdef DEBUG 129#ifdef DEBUG
132 /* hint that policy agent should enter no-stdout debug mode */ 130 /* hint that policy agent should enter no-stdout debug mode */
133 envp [i++] = "DEBUG=kernel"; 131 envp[i++] = "DEBUG=kernel";
134#endif 132#endif
135 /* extensible set of named bus-specific parameters, 133 /* extensible set of named bus-specific parameters,
136 * supporting multiple driver selection algorithms. 134 * supporting multiple driver selection algorithms.
@@ -138,33 +136,33 @@ static int pnp_dock_event(int dock, struct pnp_docking_station_info *info)
138 scratch = buf; 136 scratch = buf;
139 137
140 /* action: add, remove */ 138 /* action: add, remove */
141 envp [i++] = scratch; 139 envp[i++] = scratch;
142 scratch += sprintf (scratch, "ACTION=%s", dock?"add":"remove") + 1; 140 scratch += sprintf(scratch, "ACTION=%s", dock ? "add" : "remove") + 1;
143 141
144 /* Report the ident for the dock */ 142 /* Report the ident for the dock */
145 envp [i++] = scratch; 143 envp[i++] = scratch;
146 scratch += sprintf (scratch, "DOCK=%x/%x/%x", 144 scratch += sprintf(scratch, "DOCK=%x/%x/%x",
147 info->location_id, info->serial, info->capabilities); 145 info->location_id, info->serial, info->capabilities);
148 envp[i] = NULL; 146 envp[i] = NULL;
149 147
150 value = call_usermodehelper (argv [0], argv, envp, UMH_WAIT_EXEC); 148 value = call_usermodehelper(argv [0], argv, envp, UMH_WAIT_EXEC);
151 kfree (buf); 149 kfree(buf);
152 kfree (envp); 150 kfree(envp);
153 return 0; 151 return 0;
154} 152}
155 153
156/* 154/*
157 * Poll the PnP docking at regular intervals 155 * Poll the PnP docking at regular intervals
158 */ 156 */
159static int pnp_dock_thread(void * unused) 157static int pnp_dock_thread(void *unused)
160{ 158{
161 static struct pnp_docking_station_info now; 159 static struct pnp_docking_station_info now;
162 int docked = -1, d = 0; 160 int docked = -1, d = 0;
161
163 set_freezable(); 162 set_freezable();
164 while (!unloading) 163 while (!unloading) {
165 {
166 int status; 164 int status;
167 165
168 /* 166 /*
169 * Poll every 2 seconds 167 * Poll every 2 seconds
170 */ 168 */
@@ -175,30 +173,29 @@ static int pnp_dock_thread(void * unused)
175 173
176 status = pnp_bios_dock_station_info(&now); 174 status = pnp_bios_dock_station_info(&now);
177 175
178 switch(status) 176 switch (status) {
179 {
180 /* 177 /*
181 * No dock to manage 178 * No dock to manage
182 */ 179 */
183 case PNP_FUNCTION_NOT_SUPPORTED: 180 case PNP_FUNCTION_NOT_SUPPORTED:
184 complete_and_exit(&unload_sem, 0); 181 complete_and_exit(&unload_sem, 0);
185 case PNP_SYSTEM_NOT_DOCKED: 182 case PNP_SYSTEM_NOT_DOCKED:
186 d = 0; 183 d = 0;
187 break; 184 break;
188 case PNP_SUCCESS: 185 case PNP_SUCCESS:
189 d = 1; 186 d = 1;
190 break; 187 break;
191 default: 188 default:
192 pnpbios_print_status( "pnp_dock_thread", status ); 189 pnpbios_print_status("pnp_dock_thread", status);
193 continue; 190 continue;
194 } 191 }
195 if(d != docked) 192 if (d != docked) {
196 { 193 if (pnp_dock_event(d, &now) == 0) {
197 if(pnp_dock_event(d, &now)==0)
198 {
199 docked = d; 194 docked = d;
200#if 0 195#if 0
201 printk(KERN_INFO "PnPBIOS: Docking station %stached\n", docked?"at":"de"); 196 printk(KERN_INFO
197 "PnPBIOS: Docking station %stached\n",
198 docked ? "at" : "de");
202#endif 199#endif
203 } 200 }
204 } 201 }
@@ -206,21 +203,21 @@ static int pnp_dock_thread(void * unused)
206 complete_and_exit(&unload_sem, 0); 203 complete_and_exit(&unload_sem, 0);
207} 204}
208 205
209#endif /* CONFIG_HOTPLUG */ 206#endif /* CONFIG_HOTPLUG */
210 207
211static int pnpbios_get_resources(struct pnp_dev * dev, struct pnp_resource_table * res) 208static int pnpbios_get_resources(struct pnp_dev *dev,
209 struct pnp_resource_table *res)
212{ 210{
213 u8 nodenum = dev->number; 211 u8 nodenum = dev->number;
214 struct pnp_bios_node * node; 212 struct pnp_bios_node *node;
215 213
216 /* just in case */ 214 if (!pnpbios_is_dynamic(dev))
217 if(!pnpbios_is_dynamic(dev))
218 return -EPERM; 215 return -EPERM;
219 216
220 node = kzalloc(node_info.max_node_size, GFP_KERNEL); 217 node = kzalloc(node_info.max_node_size, GFP_KERNEL);
221 if (!node) 218 if (!node)
222 return -1; 219 return -1;
223 if (pnp_bios_get_dev_node(&nodenum, (char )PNPMODE_DYNAMIC, node)) { 220 if (pnp_bios_get_dev_node(&nodenum, (char)PNPMODE_DYNAMIC, node)) {
224 kfree(node); 221 kfree(node);
225 return -ENODEV; 222 return -ENODEV;
226 } 223 }
@@ -230,24 +227,24 @@ static int pnpbios_get_resources(struct pnp_dev * dev, struct pnp_resource_table
230 return 0; 227 return 0;
231} 228}
232 229
233static int pnpbios_set_resources(struct pnp_dev * dev, struct pnp_resource_table * res) 230static int pnpbios_set_resources(struct pnp_dev *dev,
231 struct pnp_resource_table *res)
234{ 232{
235 u8 nodenum = dev->number; 233 u8 nodenum = dev->number;
236 struct pnp_bios_node * node; 234 struct pnp_bios_node *node;
237 int ret; 235 int ret;
238 236
239 /* just in case */
240 if (!pnpbios_is_dynamic(dev)) 237 if (!pnpbios_is_dynamic(dev))
241 return -EPERM; 238 return -EPERM;
242 239
243 node = kzalloc(node_info.max_node_size, GFP_KERNEL); 240 node = kzalloc(node_info.max_node_size, GFP_KERNEL);
244 if (!node) 241 if (!node)
245 return -1; 242 return -1;
246 if (pnp_bios_get_dev_node(&nodenum, (char )PNPMODE_DYNAMIC, node)) { 243 if (pnp_bios_get_dev_node(&nodenum, (char)PNPMODE_DYNAMIC, node)) {
247 kfree(node); 244 kfree(node);
248 return -ENODEV; 245 return -ENODEV;
249 } 246 }
250 if(pnpbios_write_resources_to_node(res, node)<0) { 247 if (pnpbios_write_resources_to_node(res, node) < 0) {
251 kfree(node); 248 kfree(node);
252 return -1; 249 return -1;
253 } 250 }
@@ -258,18 +255,19 @@ static int pnpbios_set_resources(struct pnp_dev * dev, struct pnp_resource_table
258 return ret; 255 return ret;
259} 256}
260 257
261static void pnpbios_zero_data_stream(struct pnp_bios_node * node) 258static void pnpbios_zero_data_stream(struct pnp_bios_node *node)
262{ 259{
263 unsigned char * p = (char *)node->data; 260 unsigned char *p = (char *)node->data;
264 unsigned char * end = (char *)(node->data + node->size); 261 unsigned char *end = (char *)(node->data + node->size);
265 unsigned int len; 262 unsigned int len;
266 int i; 263 int i;
264
267 while ((char *)p < (char *)end) { 265 while ((char *)p < (char *)end) {
268 if(p[0] & 0x80) { /* large tag */ 266 if (p[0] & 0x80) { /* large tag */
269 len = (p[2] << 8) | p[1]; 267 len = (p[2] << 8) | p[1];
270 p += 3; 268 p += 3;
271 } else { 269 } else {
272 if (((p[0]>>3) & 0x0f) == 0x0f) 270 if (((p[0] >> 3) & 0x0f) == 0x0f)
273 return; 271 return;
274 len = p[0] & 0x07; 272 len = p[0] & 0x07;
275 p += 1; 273 p += 1;
@@ -278,24 +276,24 @@ static void pnpbios_zero_data_stream(struct pnp_bios_node * node)
278 p[i] = 0; 276 p[i] = 0;
279 p += len; 277 p += len;
280 } 278 }
281 printk(KERN_ERR "PnPBIOS: Resource structure did not contain an end tag.\n"); 279 printk(KERN_ERR
280 "PnPBIOS: Resource structure did not contain an end tag.\n");
282} 281}
283 282
284static int pnpbios_disable_resources(struct pnp_dev *dev) 283static int pnpbios_disable_resources(struct pnp_dev *dev)
285{ 284{
286 struct pnp_bios_node * node; 285 struct pnp_bios_node *node;
287 u8 nodenum = dev->number; 286 u8 nodenum = dev->number;
288 int ret; 287 int ret;
289 288
290 /* just in case */ 289 if (dev->flags & PNPBIOS_NO_DISABLE || !pnpbios_is_dynamic(dev))
291 if(dev->flags & PNPBIOS_NO_DISABLE || !pnpbios_is_dynamic(dev))
292 return -EPERM; 290 return -EPERM;
293 291
294 node = kzalloc(node_info.max_node_size, GFP_KERNEL); 292 node = kzalloc(node_info.max_node_size, GFP_KERNEL);
295 if (!node) 293 if (!node)
296 return -ENOMEM; 294 return -ENOMEM;
297 295
298 if (pnp_bios_get_dev_node(&nodenum, (char )PNPMODE_DYNAMIC, node)) { 296 if (pnp_bios_get_dev_node(&nodenum, (char)PNPMODE_DYNAMIC, node)) {
299 kfree(node); 297 kfree(node);
300 return -ENODEV; 298 return -ENODEV;
301 } 299 }
@@ -311,22 +309,22 @@ static int pnpbios_disable_resources(struct pnp_dev *dev)
311/* PnP Layer support */ 309/* PnP Layer support */
312 310
313struct pnp_protocol pnpbios_protocol = { 311struct pnp_protocol pnpbios_protocol = {
314 .name = "Plug and Play BIOS", 312 .name = "Plug and Play BIOS",
315 .get = pnpbios_get_resources, 313 .get = pnpbios_get_resources,
316 .set = pnpbios_set_resources, 314 .set = pnpbios_set_resources,
317 .disable = pnpbios_disable_resources, 315 .disable = pnpbios_disable_resources,
318}; 316};
319 317
320static int insert_device(struct pnp_dev *dev, struct pnp_bios_node * node) 318static int insert_device(struct pnp_dev *dev, struct pnp_bios_node *node)
321{ 319{
322 struct list_head * pos; 320 struct list_head *pos;
323 struct pnp_dev * pnp_dev; 321 struct pnp_dev *pnp_dev;
324 struct pnp_id *dev_id; 322 struct pnp_id *dev_id;
325 char id[8]; 323 char id[8];
326 324
327 /* check if the device is already added */ 325 /* check if the device is already added */
328 dev->number = node->handle; 326 dev->number = node->handle;
329 list_for_each (pos, &pnpbios_protocol.devices){ 327 list_for_each(pos, &pnpbios_protocol.devices) {
330 pnp_dev = list_entry(pos, struct pnp_dev, protocol_list); 328 pnp_dev = list_entry(pos, struct pnp_dev, protocol_list);
331 if (dev->number == pnp_dev->number) 329 if (dev->number == pnp_dev->number)
332 return -1; 330 return -1;
@@ -336,8 +334,8 @@ static int insert_device(struct pnp_dev *dev, struct pnp_bios_node * node)
336 dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL); 334 dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
337 if (!dev_id) 335 if (!dev_id)
338 return -1; 336 return -1;
339 pnpid32_to_pnpid(node->eisa_id,id); 337 pnpid32_to_pnpid(node->eisa_id, id);
340 memcpy(dev_id->id,id,7); 338 memcpy(dev_id->id, id, 7);
341 pnp_add_id(dev_id, dev); 339 pnp_add_id(dev_id, dev);
342 pnpbios_parse_data_stream(dev, node); 340 pnpbios_parse_data_stream(dev, node);
343 dev->active = pnp_is_active(dev); 341 dev->active = pnp_is_active(dev);
@@ -375,35 +373,41 @@ static void __init build_devlist(void)
375 if (!node) 373 if (!node)
376 return; 374 return;
377 375
378 for(nodenum=0; nodenum<0xff; ) { 376 for (nodenum = 0; nodenum < 0xff;) {
379 u8 thisnodenum = nodenum; 377 u8 thisnodenum = nodenum;
380 /* eventually we will want to use PNPMODE_STATIC here but for now 378 /* eventually we will want to use PNPMODE_STATIC here but for now
381 * dynamic will help us catch buggy bioses to add to the blacklist. 379 * dynamic will help us catch buggy bioses to add to the blacklist.
382 */ 380 */
383 if (!pnpbios_dont_use_current_config) { 381 if (!pnpbios_dont_use_current_config) {
384 if (pnp_bios_get_dev_node(&nodenum, (char )PNPMODE_DYNAMIC, node)) 382 if (pnp_bios_get_dev_node
383 (&nodenum, (char)PNPMODE_DYNAMIC, node))
385 break; 384 break;
386 } else { 385 } else {
387 if (pnp_bios_get_dev_node(&nodenum, (char )PNPMODE_STATIC, node)) 386 if (pnp_bios_get_dev_node
387 (&nodenum, (char)PNPMODE_STATIC, node))
388 break; 388 break;
389 } 389 }
390 nodes_got++; 390 nodes_got++;
391 dev = kzalloc(sizeof (struct pnp_dev), GFP_KERNEL); 391 dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
392 if (!dev) 392 if (!dev)
393 break; 393 break;
394 if(insert_device(dev,node)<0) 394 if (insert_device(dev, node) < 0)
395 kfree(dev); 395 kfree(dev);
396 else 396 else
397 devs++; 397 devs++;
398 if (nodenum <= thisnodenum) { 398 if (nodenum <= thisnodenum) {
399 printk(KERN_ERR "PnPBIOS: build_devlist: Node number 0x%x is out of sequence following node 0x%x. Aborting.\n", (unsigned int)nodenum, (unsigned int)thisnodenum); 399 printk(KERN_ERR
400 "PnPBIOS: build_devlist: Node number 0x%x is out of sequence following node 0x%x. Aborting.\n",
401 (unsigned int)nodenum,
402 (unsigned int)thisnodenum);
400 break; 403 break;
401 } 404 }
402 } 405 }
403 kfree(node); 406 kfree(node);
404 407
405 printk(KERN_INFO "PnPBIOS: %i node%s reported by PnP BIOS; %i recorded by driver\n", 408 printk(KERN_INFO
406 nodes_got, nodes_got != 1 ? "s" : "", devs); 409 "PnPBIOS: %i node%s reported by PnP BIOS; %i recorded by driver\n",
410 nodes_got, nodes_got != 1 ? "s" : "", devs);
407} 411}
408 412
409/* 413/*
@@ -412,8 +416,8 @@ static void __init build_devlist(void)
412 * 416 *
413 */ 417 */
414 418
415static int pnpbios_disabled; /* = 0 */ 419static int pnpbios_disabled;
416int pnpbios_dont_use_current_config; /* = 0 */ 420int pnpbios_dont_use_current_config;
417 421
418#ifndef MODULE 422#ifndef MODULE
419static int __init pnpbios_setup(char *str) 423static int __init pnpbios_setup(char *str)
@@ -422,9 +426,9 @@ static int __init pnpbios_setup(char *str)
422 426
423 while ((str != NULL) && (*str != '\0')) { 427 while ((str != NULL) && (*str != '\0')) {
424 if (strncmp(str, "off", 3) == 0) 428 if (strncmp(str, "off", 3) == 0)
425 pnpbios_disabled=1; 429 pnpbios_disabled = 1;
426 if (strncmp(str, "on", 2) == 0) 430 if (strncmp(str, "on", 2) == 0)
427 pnpbios_disabled=0; 431 pnpbios_disabled = 0;
428 invert = (strncmp(str, "no-", 3) == 0); 432 invert = (strncmp(str, "no-", 3) == 0);
429 if (invert) 433 if (invert)
430 str += 3; 434 str += 3;
@@ -453,35 +457,41 @@ static int __init pnpbios_probe_system(void)
453 printk(KERN_INFO "PnPBIOS: Scanning system for PnP BIOS support...\n"); 457 printk(KERN_INFO "PnPBIOS: Scanning system for PnP BIOS support...\n");
454 458
455 /* 459 /*
456 * Search the defined area (0xf0000-0xffff0) for a valid PnP BIOS 460 * Search the defined area (0xf0000-0xffff0) for a valid PnP BIOS
457 * structure and, if one is found, sets up the selectors and 461 * structure and, if one is found, sets up the selectors and
458 * entry points 462 * entry points
459 */ 463 */
460 for (check = (union pnp_bios_install_struct *) __va(0xf0000); 464 for (check = (union pnp_bios_install_struct *)__va(0xf0000);
461 check < (union pnp_bios_install_struct *) __va(0xffff0); 465 check < (union pnp_bios_install_struct *)__va(0xffff0);
462 check = (void *)check + 16) { 466 check = (void *)check + 16) {
463 if (check->fields.signature != PNP_SIGNATURE) 467 if (check->fields.signature != PNP_SIGNATURE)
464 continue; 468 continue;
465 printk(KERN_INFO "PnPBIOS: Found PnP BIOS installation structure at 0x%p\n", check); 469 printk(KERN_INFO
470 "PnPBIOS: Found PnP BIOS installation structure at 0x%p\n",
471 check);
466 length = check->fields.length; 472 length = check->fields.length;
467 if (!length) { 473 if (!length) {
468 printk(KERN_ERR "PnPBIOS: installation structure is invalid, skipping\n"); 474 printk(KERN_ERR
475 "PnPBIOS: installation structure is invalid, skipping\n");
469 continue; 476 continue;
470 } 477 }
471 for (sum = 0, i = 0; i < length; i++) 478 for (sum = 0, i = 0; i < length; i++)
472 sum += check->chars[i]; 479 sum += check->chars[i];
473 if (sum) { 480 if (sum) {
474 printk(KERN_ERR "PnPBIOS: installation structure is corrupted, skipping\n"); 481 printk(KERN_ERR
482 "PnPBIOS: installation structure is corrupted, skipping\n");
475 continue; 483 continue;
476 } 484 }
477 if (check->fields.version < 0x10) { 485 if (check->fields.version < 0x10) {
478 printk(KERN_WARNING "PnPBIOS: PnP BIOS version %d.%d is not supported\n", 486 printk(KERN_WARNING
487 "PnPBIOS: PnP BIOS version %d.%d is not supported\n",
479 check->fields.version >> 4, 488 check->fields.version >> 4,
480 check->fields.version & 15); 489 check->fields.version & 15);
481 continue; 490 continue;
482 } 491 }
483 printk(KERN_INFO "PnPBIOS: PnP BIOS version %d.%d, entry 0x%x:0x%x, dseg 0x%x\n", 492 printk(KERN_INFO
484 check->fields.version >> 4, check->fields.version & 15, 493 "PnPBIOS: PnP BIOS version %d.%d, entry 0x%x:0x%x, dseg 0x%x\n",
494 check->fields.version >> 4, check->fields.version & 15,
485 check->fields.pm16cseg, check->fields.pm16offset, 495 check->fields.pm16cseg, check->fields.pm16offset,
486 check->fields.pm16dseg); 496 check->fields.pm16dseg);
487 pnp_bios_install = check; 497 pnp_bios_install = check;
@@ -499,25 +509,25 @@ static int __init exploding_pnp_bios(struct dmi_system_id *d)
499} 509}
500 510
501static struct dmi_system_id pnpbios_dmi_table[] __initdata = { 511static struct dmi_system_id pnpbios_dmi_table[] __initdata = {
502 { /* PnPBIOS GPF on boot */ 512 { /* PnPBIOS GPF on boot */
503 .callback = exploding_pnp_bios, 513 .callback = exploding_pnp_bios,
504 .ident = "Higraded P14H", 514 .ident = "Higraded P14H",
505 .matches = { 515 .matches = {
506 DMI_MATCH(DMI_BIOS_VENDOR, "American Megatrends Inc."), 516 DMI_MATCH(DMI_BIOS_VENDOR, "American Megatrends Inc."),
507 DMI_MATCH(DMI_BIOS_VERSION, "07.00T"), 517 DMI_MATCH(DMI_BIOS_VERSION, "07.00T"),
508 DMI_MATCH(DMI_SYS_VENDOR, "Higraded"), 518 DMI_MATCH(DMI_SYS_VENDOR, "Higraded"),
509 DMI_MATCH(DMI_PRODUCT_NAME, "P14H"), 519 DMI_MATCH(DMI_PRODUCT_NAME, "P14H"),
510 }, 520 },
511 }, 521 },
512 { /* PnPBIOS GPF on boot */ 522 { /* PnPBIOS GPF on boot */
513 .callback = exploding_pnp_bios, 523 .callback = exploding_pnp_bios,
514 .ident = "ASUS P4P800", 524 .ident = "ASUS P4P800",
515 .matches = { 525 .matches = {
516 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer Inc."), 526 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer Inc."),
517 DMI_MATCH(DMI_BOARD_NAME, "P4P800"), 527 DMI_MATCH(DMI_BOARD_NAME, "P4P800"),
518 }, 528 },
519 }, 529 },
520 { } 530 {}
521}; 531};
522 532
523static int __init pnpbios_init(void) 533static int __init pnpbios_init(void)
@@ -533,14 +543,13 @@ static int __init pnpbios_init(void)
533 printk(KERN_INFO "PnPBIOS: Disabled\n"); 543 printk(KERN_INFO "PnPBIOS: Disabled\n");
534 return -ENODEV; 544 return -ENODEV;
535 } 545 }
536
537#ifdef CONFIG_PNPACPI 546#ifdef CONFIG_PNPACPI
538 if (!acpi_disabled && !pnpacpi_disabled) { 547 if (!acpi_disabled && !pnpacpi_disabled) {
539 pnpbios_disabled = 1; 548 pnpbios_disabled = 1;
540 printk(KERN_INFO "PnPBIOS: Disabled by ACPI PNP\n"); 549 printk(KERN_INFO "PnPBIOS: Disabled by ACPI PNP\n");
541 return -ENODEV; 550 return -ENODEV;
542 } 551 }
543#endif /* CONFIG_ACPI */ 552#endif /* CONFIG_ACPI */
544 553
545 /* scan the system for pnpbios support */ 554 /* scan the system for pnpbios support */
546 if (!pnpbios_probe_system()) 555 if (!pnpbios_probe_system())
@@ -552,14 +561,16 @@ static int __init pnpbios_init(void)
552 /* read the node info */ 561 /* read the node info */
553 ret = pnp_bios_dev_node_info(&node_info); 562 ret = pnp_bios_dev_node_info(&node_info);
554 if (ret) { 563 if (ret) {
555 printk(KERN_ERR "PnPBIOS: Unable to get node info. Aborting.\n"); 564 printk(KERN_ERR
565 "PnPBIOS: Unable to get node info. Aborting.\n");
556 return ret; 566 return ret;
557 } 567 }
558 568
559 /* register with the pnp layer */ 569 /* register with the pnp layer */
560 ret = pnp_register_protocol(&pnpbios_protocol); 570 ret = pnp_register_protocol(&pnpbios_protocol);
561 if (ret) { 571 if (ret) {
562 printk(KERN_ERR "PnPBIOS: Unable to register driver. Aborting.\n"); 572 printk(KERN_ERR
573 "PnPBIOS: Unable to register driver. Aborting.\n");
563 return ret; 574 return ret;
564 } 575 }
565 576
diff --git a/drivers/pnp/pnpbios/proc.c b/drivers/pnp/pnpbios/proc.c
index 8027073f7919..9c8c07701b65 100644
--- a/drivers/pnp/pnpbios/proc.c
+++ b/drivers/pnp/pnpbios/proc.c
@@ -18,9 +18,6 @@
18 * The other files are human-readable. 18 * The other files are human-readable.
19 */ 19 */
20 20
21//#include <pcmcia/config.h>
22//#include <pcmcia/k_compat.h>
23
24#include <linux/module.h> 21#include <linux/module.h>
25#include <linux/kernel.h> 22#include <linux/kernel.h>
26#include <linux/slab.h> 23#include <linux/slab.h>
@@ -37,42 +34,37 @@ static struct proc_dir_entry *proc_pnp = NULL;
37static struct proc_dir_entry *proc_pnp_boot = NULL; 34static struct proc_dir_entry *proc_pnp_boot = NULL;
38 35
39static int proc_read_pnpconfig(char *buf, char **start, off_t pos, 36static int proc_read_pnpconfig(char *buf, char **start, off_t pos,
40 int count, int *eof, void *data) 37 int count, int *eof, void *data)
41{ 38{
42 struct pnp_isa_config_struc pnps; 39 struct pnp_isa_config_struc pnps;
43 40
44 if (pnp_bios_isapnp_config(&pnps)) 41 if (pnp_bios_isapnp_config(&pnps))
45 return -EIO; 42 return -EIO;
46 return snprintf(buf, count, 43 return snprintf(buf, count,
47 "structure_revision %d\n" 44 "structure_revision %d\n"
48 "number_of_CSNs %d\n" 45 "number_of_CSNs %d\n"
49 "ISA_read_data_port 0x%x\n", 46 "ISA_read_data_port 0x%x\n",
50 pnps.revision, 47 pnps.revision, pnps.no_csns, pnps.isa_rd_data_port);
51 pnps.no_csns,
52 pnps.isa_rd_data_port
53 );
54} 48}
55 49
56static int proc_read_escdinfo(char *buf, char **start, off_t pos, 50static int proc_read_escdinfo(char *buf, char **start, off_t pos,
57 int count, int *eof, void *data) 51 int count, int *eof, void *data)
58{ 52{
59 struct escd_info_struc escd; 53 struct escd_info_struc escd;
60 54
61 if (pnp_bios_escd_info(&escd)) 55 if (pnp_bios_escd_info(&escd))
62 return -EIO; 56 return -EIO;
63 return snprintf(buf, count, 57 return snprintf(buf, count,
64 "min_ESCD_write_size %d\n" 58 "min_ESCD_write_size %d\n"
65 "ESCD_size %d\n" 59 "ESCD_size %d\n"
66 "NVRAM_base 0x%x\n", 60 "NVRAM_base 0x%x\n",
67 escd.min_escd_write_size, 61 escd.min_escd_write_size,
68 escd.escd_size, 62 escd.escd_size, escd.nv_storage_base);
69 escd.nv_storage_base
70 );
71} 63}
72 64
73#define MAX_SANE_ESCD_SIZE (32*1024) 65#define MAX_SANE_ESCD_SIZE (32*1024)
74static int proc_read_escd(char *buf, char **start, off_t pos, 66static int proc_read_escd(char *buf, char **start, off_t pos,
75 int count, int *eof, void *data) 67 int count, int *eof, void *data)
76{ 68{
77 struct escd_info_struc escd; 69 struct escd_info_struc escd;
78 char *tmpbuf; 70 char *tmpbuf;
@@ -83,30 +75,36 @@ static int proc_read_escd(char *buf, char **start, off_t pos,
83 75
84 /* sanity check */ 76 /* sanity check */
85 if (escd.escd_size > MAX_SANE_ESCD_SIZE) { 77 if (escd.escd_size > MAX_SANE_ESCD_SIZE) {
86 printk(KERN_ERR "PnPBIOS: proc_read_escd: ESCD size reported by BIOS escd_info call is too great\n"); 78 printk(KERN_ERR
79 "PnPBIOS: proc_read_escd: ESCD size reported by BIOS escd_info call is too great\n");
87 return -EFBIG; 80 return -EFBIG;
88 } 81 }
89 82
90 tmpbuf = kzalloc(escd.escd_size, GFP_KERNEL); 83 tmpbuf = kzalloc(escd.escd_size, GFP_KERNEL);
91 if (!tmpbuf) return -ENOMEM; 84 if (!tmpbuf)
85 return -ENOMEM;
92 86
93 if (pnp_bios_read_escd(tmpbuf, escd.nv_storage_base)) { 87 if (pnp_bios_read_escd(tmpbuf, escd.nv_storage_base)) {
94 kfree(tmpbuf); 88 kfree(tmpbuf);
95 return -EIO; 89 return -EIO;
96 } 90 }
97 91
98 escd_size = (unsigned char)(tmpbuf[0]) + (unsigned char)(tmpbuf[1])*256; 92 escd_size =
93 (unsigned char)(tmpbuf[0]) + (unsigned char)(tmpbuf[1]) * 256;
99 94
100 /* sanity check */ 95 /* sanity check */
101 if (escd_size > MAX_SANE_ESCD_SIZE) { 96 if (escd_size > MAX_SANE_ESCD_SIZE) {
102 printk(KERN_ERR "PnPBIOS: proc_read_escd: ESCD size reported by BIOS read_escd call is too great\n"); 97 printk(KERN_ERR
98 "PnPBIOS: proc_read_escd: ESCD size reported by BIOS read_escd call is too great\n");
103 return -EFBIG; 99 return -EFBIG;
104 } 100 }
105 101
106 escd_left_to_read = escd_size - pos; 102 escd_left_to_read = escd_size - pos;
107 if (escd_left_to_read < 0) escd_left_to_read = 0; 103 if (escd_left_to_read < 0)
108 if (escd_left_to_read == 0) *eof = 1; 104 escd_left_to_read = 0;
109 n = min(count,escd_left_to_read); 105 if (escd_left_to_read == 0)
106 *eof = 1;
107 n = min(count, escd_left_to_read);
110 memcpy(buf, tmpbuf + pos, n); 108 memcpy(buf, tmpbuf + pos, n);
111 kfree(tmpbuf); 109 kfree(tmpbuf);
112 *start = buf; 110 *start = buf;
@@ -114,17 +112,17 @@ static int proc_read_escd(char *buf, char **start, off_t pos,
114} 112}
115 113
116static int proc_read_legacyres(char *buf, char **start, off_t pos, 114static int proc_read_legacyres(char *buf, char **start, off_t pos,
117 int count, int *eof, void *data) 115 int count, int *eof, void *data)
118{ 116{
119 /* Assume that the following won't overflow the buffer */ 117 /* Assume that the following won't overflow the buffer */
120 if (pnp_bios_get_stat_res(buf)) 118 if (pnp_bios_get_stat_res(buf))
121 return -EIO; 119 return -EIO;
122 120
123 return count; // FIXME: Return actual length 121 return count; // FIXME: Return actual length
124} 122}
125 123
126static int proc_read_devices(char *buf, char **start, off_t pos, 124static int proc_read_devices(char *buf, char **start, off_t pos,
127 int count, int *eof, void *data) 125 int count, int *eof, void *data)
128{ 126{
129 struct pnp_bios_node *node; 127 struct pnp_bios_node *node;
130 u8 nodenum; 128 u8 nodenum;
@@ -134,9 +132,10 @@ static int proc_read_devices(char *buf, char **start, off_t pos,
134 return 0; 132 return 0;
135 133
136 node = kzalloc(node_info.max_node_size, GFP_KERNEL); 134 node = kzalloc(node_info.max_node_size, GFP_KERNEL);
137 if (!node) return -ENOMEM; 135 if (!node)
136 return -ENOMEM;
138 137
139 for (nodenum=pos; nodenum<0xff; ) { 138 for (nodenum = pos; nodenum < 0xff;) {
140 u8 thisnodenum = nodenum; 139 u8 thisnodenum = nodenum;
141 /* 26 = the number of characters per line sprintf'ed */ 140 /* 26 = the number of characters per line sprintf'ed */
142 if ((p - buf + 26) > count) 141 if ((p - buf + 26) > count)
@@ -148,7 +147,11 @@ static int proc_read_devices(char *buf, char **start, off_t pos,
148 node->type_code[0], node->type_code[1], 147 node->type_code[0], node->type_code[1],
149 node->type_code[2], node->flags); 148 node->type_code[2], node->flags);
150 if (nodenum <= thisnodenum) { 149 if (nodenum <= thisnodenum) {
151 printk(KERN_ERR "%s Node number 0x%x is out of sequence following node 0x%x. Aborting.\n", "PnPBIOS: proc_read_devices:", (unsigned int)nodenum, (unsigned int)thisnodenum); 150 printk(KERN_ERR
151 "%s Node number 0x%x is out of sequence following node 0x%x. Aborting.\n",
152 "PnPBIOS: proc_read_devices:",
153 (unsigned int)nodenum,
154 (unsigned int)thisnodenum);
152 *eof = 1; 155 *eof = 1;
153 break; 156 break;
154 } 157 }
@@ -156,12 +159,12 @@ static int proc_read_devices(char *buf, char **start, off_t pos,
156 kfree(node); 159 kfree(node);
157 if (nodenum == 0xff) 160 if (nodenum == 0xff)
158 *eof = 1; 161 *eof = 1;
159 *start = (char *)((off_t)nodenum - pos); 162 *start = (char *)((off_t) nodenum - pos);
160 return p - buf; 163 return p - buf;
161} 164}
162 165
163static int proc_read_node(char *buf, char **start, off_t pos, 166static int proc_read_node(char *buf, char **start, off_t pos,
164 int count, int *eof, void *data) 167 int count, int *eof, void *data)
165{ 168{
166 struct pnp_bios_node *node; 169 struct pnp_bios_node *node;
167 int boot = (long)data >> 8; 170 int boot = (long)data >> 8;
@@ -169,7 +172,8 @@ static int proc_read_node(char *buf, char **start, off_t pos,
169 int len; 172 int len;
170 173
171 node = kzalloc(node_info.max_node_size, GFP_KERNEL); 174 node = kzalloc(node_info.max_node_size, GFP_KERNEL);
172 if (!node) return -ENOMEM; 175 if (!node)
176 return -ENOMEM;
173 if (pnp_bios_get_dev_node(&nodenum, boot, node)) { 177 if (pnp_bios_get_dev_node(&nodenum, boot, node)) {
174 kfree(node); 178 kfree(node);
175 return -EIO; 179 return -EIO;
@@ -180,8 +184,8 @@ static int proc_read_node(char *buf, char **start, off_t pos,
180 return len; 184 return len;
181} 185}
182 186
183static int proc_write_node(struct file *file, const char __user *buf, 187static int proc_write_node(struct file *file, const char __user * buf,
184 unsigned long count, void *data) 188 unsigned long count, void *data)
185{ 189{
186 struct pnp_bios_node *node; 190 struct pnp_bios_node *node;
187 int boot = (long)data >> 8; 191 int boot = (long)data >> 8;
@@ -208,12 +212,12 @@ static int proc_write_node(struct file *file, const char __user *buf,
208 goto out; 212 goto out;
209 } 213 }
210 ret = count; 214 ret = count;
211out: 215 out:
212 kfree(node); 216 kfree(node);
213 return ret; 217 return ret;
214} 218}
215 219
216int pnpbios_interface_attach_device(struct pnp_bios_node * node) 220int pnpbios_interface_attach_device(struct pnp_bios_node *node)
217{ 221{
218 char name[3]; 222 char name[3];
219 struct proc_dir_entry *ent; 223 struct proc_dir_entry *ent;
@@ -222,7 +226,7 @@ int pnpbios_interface_attach_device(struct pnp_bios_node * node)
222 226
223 if (!proc_pnp) 227 if (!proc_pnp)
224 return -EIO; 228 return -EIO;
225 if ( !pnpbios_dont_use_current_config ) { 229 if (!pnpbios_dont_use_current_config) {
226 ent = create_proc_entry(name, 0, proc_pnp); 230 ent = create_proc_entry(name, 0, proc_pnp);
227 if (ent) { 231 if (ent) {
228 ent->read_proc = proc_read_node; 232 ent->read_proc = proc_read_node;
@@ -237,7 +241,7 @@ int pnpbios_interface_attach_device(struct pnp_bios_node * node)
237 if (ent) { 241 if (ent) {
238 ent->read_proc = proc_read_node; 242 ent->read_proc = proc_read_node;
239 ent->write_proc = proc_write_node; 243 ent->write_proc = proc_write_node;
240 ent->data = (void *)(long)(node->handle+0x100); 244 ent->data = (void *)(long)(node->handle + 0x100);
241 return 0; 245 return 0;
242 } 246 }
243 247
@@ -249,7 +253,7 @@ int pnpbios_interface_attach_device(struct pnp_bios_node * node)
249 * work and the pnpbios_dont_use_current_config flag 253 * work and the pnpbios_dont_use_current_config flag
250 * should already have been set to the appropriate value 254 * should already have been set to the appropriate value
251 */ 255 */
252int __init pnpbios_proc_init( void ) 256int __init pnpbios_proc_init(void)
253{ 257{
254 proc_pnp = proc_mkdir("pnp", proc_bus); 258 proc_pnp = proc_mkdir("pnp", proc_bus);
255 if (!proc_pnp) 259 if (!proc_pnp)
@@ -258,10 +262,13 @@ int __init pnpbios_proc_init( void )
258 if (!proc_pnp_boot) 262 if (!proc_pnp_boot)
259 return -EIO; 263 return -EIO;
260 create_proc_read_entry("devices", 0, proc_pnp, proc_read_devices, NULL); 264 create_proc_read_entry("devices", 0, proc_pnp, proc_read_devices, NULL);
261 create_proc_read_entry("configuration_info", 0, proc_pnp, proc_read_pnpconfig, NULL); 265 create_proc_read_entry("configuration_info", 0, proc_pnp,
262 create_proc_read_entry("escd_info", 0, proc_pnp, proc_read_escdinfo, NULL); 266 proc_read_pnpconfig, NULL);
267 create_proc_read_entry("escd_info", 0, proc_pnp, proc_read_escdinfo,
268 NULL);
263 create_proc_read_entry("escd", S_IRUSR, proc_pnp, proc_read_escd, NULL); 269 create_proc_read_entry("escd", S_IRUSR, proc_pnp, proc_read_escd, NULL);
264 create_proc_read_entry("legacy_device_resources", 0, proc_pnp, proc_read_legacyres, NULL); 270 create_proc_read_entry("legacy_device_resources", 0, proc_pnp,
271 proc_read_legacyres, NULL);
265 272
266 return 0; 273 return 0;
267} 274}
@@ -274,9 +281,9 @@ void __exit pnpbios_proc_exit(void)
274 if (!proc_pnp) 281 if (!proc_pnp)
275 return; 282 return;
276 283
277 for (i=0; i<0xff; i++) { 284 for (i = 0; i < 0xff; i++) {
278 sprintf(name, "%02x", i); 285 sprintf(name, "%02x", i);
279 if ( !pnpbios_dont_use_current_config ) 286 if (!pnpbios_dont_use_current_config)
280 remove_proc_entry(name, proc_pnp); 287 remove_proc_entry(name, proc_pnp);
281 remove_proc_entry(name, proc_pnp_boot); 288 remove_proc_entry(name, proc_pnp_boot);
282 } 289 }
@@ -287,6 +294,4 @@ void __exit pnpbios_proc_exit(void)
287 remove_proc_entry("devices", proc_pnp); 294 remove_proc_entry("devices", proc_pnp);
288 remove_proc_entry("boot", proc_pnp); 295 remove_proc_entry("boot", proc_pnp);
289 remove_proc_entry("pnp", proc_bus); 296 remove_proc_entry("pnp", proc_bus);
290
291 return;
292} 297}
diff --git a/drivers/pnp/pnpbios/rsparser.c b/drivers/pnp/pnpbios/rsparser.c
index 3c2ab8394e3f..04ecd7b67230 100644
--- a/drivers/pnp/pnpbios/rsparser.c
+++ b/drivers/pnp/pnpbios/rsparser.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * rsparser.c - parses and encodes pnpbios resource data streams 2 * rsparser.c - parses and encodes pnpbios resource data streams
3 *
4 */ 3 */
5 4
6#include <linux/ctype.h> 5#include <linux/ctype.h>
@@ -12,8 +11,10 @@
12#ifdef CONFIG_PCI 11#ifdef CONFIG_PCI
13#include <linux/pci.h> 12#include <linux/pci.h>
14#else 13#else
15inline void pcibios_penalize_isa_irq(int irq, int active) {} 14inline void pcibios_penalize_isa_irq(int irq, int active)
16#endif /* CONFIG_PCI */ 15{
16}
17#endif /* CONFIG_PCI */
17 18
18#include "pnpbios.h" 19#include "pnpbios.h"
19 20
@@ -52,75 +53,88 @@ inline void pcibios_penalize_isa_irq(int irq, int active) {}
52 * Allocated Resources 53 * Allocated Resources
53 */ 54 */
54 55
55static void 56static void pnpbios_parse_allocated_irqresource(struct pnp_resource_table *res,
56pnpbios_parse_allocated_irqresource(struct pnp_resource_table * res, int irq) 57 int irq)
57{ 58{
58 int i = 0; 59 int i = 0;
59 while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) && i < PNP_MAX_IRQ) i++; 60
61 while (!(res->irq_resource[i].flags & IORESOURCE_UNSET)
62 && i < PNP_MAX_IRQ)
63 i++;
60 if (i < PNP_MAX_IRQ) { 64 if (i < PNP_MAX_IRQ) {
61 res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag 65 res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag
62 if (irq == -1) { 66 if (irq == -1) {
63 res->irq_resource[i].flags |= IORESOURCE_DISABLED; 67 res->irq_resource[i].flags |= IORESOURCE_DISABLED;
64 return; 68 return;
65 } 69 }
66 res->irq_resource[i].start = 70 res->irq_resource[i].start =
67 res->irq_resource[i].end = (unsigned long) irq; 71 res->irq_resource[i].end = (unsigned long)irq;
68 pcibios_penalize_isa_irq(irq, 1); 72 pcibios_penalize_isa_irq(irq, 1);
69 } 73 }
70} 74}
71 75
72static void 76static void pnpbios_parse_allocated_dmaresource(struct pnp_resource_table *res,
73pnpbios_parse_allocated_dmaresource(struct pnp_resource_table * res, int dma) 77 int dma)
74{ 78{
75 int i = 0; 79 int i = 0;
80
76 while (i < PNP_MAX_DMA && 81 while (i < PNP_MAX_DMA &&
77 !(res->dma_resource[i].flags & IORESOURCE_UNSET)) 82 !(res->dma_resource[i].flags & IORESOURCE_UNSET))
78 i++; 83 i++;
79 if (i < PNP_MAX_DMA) { 84 if (i < PNP_MAX_DMA) {
80 res->dma_resource[i].flags = IORESOURCE_DMA; // Also clears _UNSET flag 85 res->dma_resource[i].flags = IORESOURCE_DMA; // Also clears _UNSET flag
81 if (dma == -1) { 86 if (dma == -1) {
82 res->dma_resource[i].flags |= IORESOURCE_DISABLED; 87 res->dma_resource[i].flags |= IORESOURCE_DISABLED;
83 return; 88 return;
84 } 89 }
85 res->dma_resource[i].start = 90 res->dma_resource[i].start =
86 res->dma_resource[i].end = (unsigned long) dma; 91 res->dma_resource[i].end = (unsigned long)dma;
87 } 92 }
88} 93}
89 94
90static void 95static void pnpbios_parse_allocated_ioresource(struct pnp_resource_table *res,
91pnpbios_parse_allocated_ioresource(struct pnp_resource_table * res, int io, int len) 96 int io, int len)
92{ 97{
93 int i = 0; 98 int i = 0;
94 while (!(res->port_resource[i].flags & IORESOURCE_UNSET) && i < PNP_MAX_PORT) i++; 99
100 while (!(res->port_resource[i].flags & IORESOURCE_UNSET)
101 && i < PNP_MAX_PORT)
102 i++;
95 if (i < PNP_MAX_PORT) { 103 if (i < PNP_MAX_PORT) {
96 res->port_resource[i].flags = IORESOURCE_IO; // Also clears _UNSET flag 104 res->port_resource[i].flags = IORESOURCE_IO; // Also clears _UNSET flag
97 if (len <= 0 || (io + len -1) >= 0x10003) { 105 if (len <= 0 || (io + len - 1) >= 0x10003) {
98 res->port_resource[i].flags |= IORESOURCE_DISABLED; 106 res->port_resource[i].flags |= IORESOURCE_DISABLED;
99 return; 107 return;
100 } 108 }
101 res->port_resource[i].start = (unsigned long) io; 109 res->port_resource[i].start = (unsigned long)io;
102 res->port_resource[i].end = (unsigned long)(io + len - 1); 110 res->port_resource[i].end = (unsigned long)(io + len - 1);
103 } 111 }
104} 112}
105 113
106static void 114static void pnpbios_parse_allocated_memresource(struct pnp_resource_table *res,
107pnpbios_parse_allocated_memresource(struct pnp_resource_table * res, int mem, int len) 115 int mem, int len)
108{ 116{
109 int i = 0; 117 int i = 0;
110 while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) && i < PNP_MAX_MEM) i++; 118
119 while (!(res->mem_resource[i].flags & IORESOURCE_UNSET)
120 && i < PNP_MAX_MEM)
121 i++;
111 if (i < PNP_MAX_MEM) { 122 if (i < PNP_MAX_MEM) {
112 res->mem_resource[i].flags = IORESOURCE_MEM; // Also clears _UNSET flag 123 res->mem_resource[i].flags = IORESOURCE_MEM; // Also clears _UNSET flag
113 if (len <= 0) { 124 if (len <= 0) {
114 res->mem_resource[i].flags |= IORESOURCE_DISABLED; 125 res->mem_resource[i].flags |= IORESOURCE_DISABLED;
115 return; 126 return;
116 } 127 }
117 res->mem_resource[i].start = (unsigned long) mem; 128 res->mem_resource[i].start = (unsigned long)mem;
118 res->mem_resource[i].end = (unsigned long)(mem + len - 1); 129 res->mem_resource[i].end = (unsigned long)(mem + len - 1);
119 } 130 }
120} 131}
121 132
122static unsigned char * 133static unsigned char *pnpbios_parse_allocated_resource_data(unsigned char *p,
123pnpbios_parse_allocated_resource_data(unsigned char * p, unsigned char * end, struct pnp_resource_table * res) 134 unsigned char *end,
135 struct
136 pnp_resource_table
137 *res)
124{ 138{
125 unsigned int len, tag; 139 unsigned int len, tag;
126 int io, size, mask, i; 140 int io, size, mask, i;
@@ -134,12 +148,12 @@ pnpbios_parse_allocated_resource_data(unsigned char * p, unsigned char * end, st
134 while ((char *)p < (char *)end) { 148 while ((char *)p < (char *)end) {
135 149
136 /* determine the type of tag */ 150 /* determine the type of tag */
137 if (p[0] & LARGE_TAG) { /* large tag */ 151 if (p[0] & LARGE_TAG) { /* large tag */
138 len = (p[2] << 8) | p[1]; 152 len = (p[2] << 8) | p[1];
139 tag = p[0]; 153 tag = p[0];
140 } else { /* small tag */ 154 } else { /* small tag */
141 len = p[0] & 0x07; 155 len = p[0] & 0x07;
142 tag = ((p[0]>>3) & 0x0f); 156 tag = ((p[0] >> 3) & 0x0f);
143 } 157 }
144 158
145 switch (tag) { 159 switch (tag) {
@@ -147,8 +161,8 @@ pnpbios_parse_allocated_resource_data(unsigned char * p, unsigned char * end, st
147 case LARGE_TAG_MEM: 161 case LARGE_TAG_MEM:
148 if (len != 9) 162 if (len != 9)
149 goto len_err; 163 goto len_err;
150 io = *(short *) &p[4]; 164 io = *(short *)&p[4];
151 size = *(short *) &p[10]; 165 size = *(short *)&p[10];
152 pnpbios_parse_allocated_memresource(res, io, size); 166 pnpbios_parse_allocated_memresource(res, io, size);
153 break; 167 break;
154 168
@@ -163,16 +177,16 @@ pnpbios_parse_allocated_resource_data(unsigned char * p, unsigned char * end, st
163 case LARGE_TAG_MEM32: 177 case LARGE_TAG_MEM32:
164 if (len != 17) 178 if (len != 17)
165 goto len_err; 179 goto len_err;
166 io = *(int *) &p[4]; 180 io = *(int *)&p[4];
167 size = *(int *) &p[16]; 181 size = *(int *)&p[16];
168 pnpbios_parse_allocated_memresource(res, io, size); 182 pnpbios_parse_allocated_memresource(res, io, size);
169 break; 183 break;
170 184
171 case LARGE_TAG_FIXEDMEM32: 185 case LARGE_TAG_FIXEDMEM32:
172 if (len != 9) 186 if (len != 9)
173 goto len_err; 187 goto len_err;
174 io = *(int *) &p[4]; 188 io = *(int *)&p[4];
175 size = *(int *) &p[8]; 189 size = *(int *)&p[8];
176 pnpbios_parse_allocated_memresource(res, io, size); 190 pnpbios_parse_allocated_memresource(res, io, size);
177 break; 191 break;
178 192
@@ -180,9 +194,10 @@ pnpbios_parse_allocated_resource_data(unsigned char * p, unsigned char * end, st
180 if (len < 2 || len > 3) 194 if (len < 2 || len > 3)
181 goto len_err; 195 goto len_err;
182 io = -1; 196 io = -1;
183 mask= p[1] + p[2]*256; 197 mask = p[1] + p[2] * 256;
184 for (i=0;i<16;i++, mask=mask>>1) 198 for (i = 0; i < 16; i++, mask = mask >> 1)
185 if(mask & 0x01) io=i; 199 if (mask & 0x01)
200 io = i;
186 pnpbios_parse_allocated_irqresource(res, io); 201 pnpbios_parse_allocated_irqresource(res, io);
187 break; 202 break;
188 203
@@ -191,15 +206,16 @@ pnpbios_parse_allocated_resource_data(unsigned char * p, unsigned char * end, st
191 goto len_err; 206 goto len_err;
192 io = -1; 207 io = -1;
193 mask = p[1]; 208 mask = p[1];
194 for (i=0;i<8;i++, mask = mask>>1) 209 for (i = 0; i < 8; i++, mask = mask >> 1)
195 if(mask & 0x01) io=i; 210 if (mask & 0x01)
211 io = i;
196 pnpbios_parse_allocated_dmaresource(res, io); 212 pnpbios_parse_allocated_dmaresource(res, io);
197 break; 213 break;
198 214
199 case SMALL_TAG_PORT: 215 case SMALL_TAG_PORT:
200 if (len != 7) 216 if (len != 7)
201 goto len_err; 217 goto len_err;
202 io = p[2] + p[3] *256; 218 io = p[2] + p[3] * 256;
203 size = p[7]; 219 size = p[7];
204 pnpbios_parse_allocated_ioresource(res, io, size); 220 pnpbios_parse_allocated_ioresource(res, io, size);
205 break; 221 break;
@@ -218,12 +234,14 @@ pnpbios_parse_allocated_resource_data(unsigned char * p, unsigned char * end, st
218 234
219 case SMALL_TAG_END: 235 case SMALL_TAG_END:
220 p = p + 2; 236 p = p + 2;
221 return (unsigned char *)p; 237 return (unsigned char *)p;
222 break; 238 break;
223 239
224 default: /* an unkown tag */ 240 default: /* an unkown tag */
225 len_err: 241 len_err:
226 printk(KERN_ERR "PnPBIOS: Unknown tag '0x%x', length '%d'.\n", tag, len); 242 printk(KERN_ERR
243 "PnPBIOS: Unknown tag '0x%x', length '%d'.\n",
244 tag, len);
227 break; 245 break;
228 } 246 }
229 247
@@ -234,20 +252,21 @@ pnpbios_parse_allocated_resource_data(unsigned char * p, unsigned char * end, st
234 p += len + 1; 252 p += len + 1;
235 } 253 }
236 254
237 printk(KERN_ERR "PnPBIOS: Resource structure does not contain an end tag.\n"); 255 printk(KERN_ERR
256 "PnPBIOS: Resource structure does not contain an end tag.\n");
238 257
239 return NULL; 258 return NULL;
240} 259}
241 260
242
243/* 261/*
244 * Resource Configuration Options 262 * Resource Configuration Options
245 */ 263 */
246 264
247static void 265static void pnpbios_parse_mem_option(unsigned char *p, int size,
248pnpbios_parse_mem_option(unsigned char *p, int size, struct pnp_option *option) 266 struct pnp_option *option)
249{ 267{
250 struct pnp_mem * mem; 268 struct pnp_mem *mem;
269
251 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); 270 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
252 if (!mem) 271 if (!mem)
253 return; 272 return;
@@ -256,14 +275,14 @@ pnpbios_parse_mem_option(unsigned char *p, int size, struct pnp_option *option)
256 mem->align = (p[9] << 8) | p[8]; 275 mem->align = (p[9] << 8) | p[8];
257 mem->size = ((p[11] << 8) | p[10]) << 8; 276 mem->size = ((p[11] << 8) | p[10]) << 8;
258 mem->flags = p[3]; 277 mem->flags = p[3];
259 pnp_register_mem_resource(option,mem); 278 pnp_register_mem_resource(option, mem);
260 return;
261} 279}
262 280
263static void 281static void pnpbios_parse_mem32_option(unsigned char *p, int size,
264pnpbios_parse_mem32_option(unsigned char *p, int size, struct pnp_option *option) 282 struct pnp_option *option)
265{ 283{
266 struct pnp_mem * mem; 284 struct pnp_mem *mem;
285
267 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); 286 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
268 if (!mem) 287 if (!mem)
269 return; 288 return;
@@ -272,14 +291,13 @@ pnpbios_parse_mem32_option(unsigned char *p, int size, struct pnp_option *option
272 mem->align = (p[15] << 24) | (p[14] << 16) | (p[13] << 8) | p[12]; 291 mem->align = (p[15] << 24) | (p[14] << 16) | (p[13] << 8) | p[12];
273 mem->size = (p[19] << 24) | (p[18] << 16) | (p[17] << 8) | p[16]; 292 mem->size = (p[19] << 24) | (p[18] << 16) | (p[17] << 8) | p[16];
274 mem->flags = p[3]; 293 mem->flags = p[3];
275 pnp_register_mem_resource(option,mem); 294 pnp_register_mem_resource(option, mem);
276 return;
277} 295}
278 296
279static void 297static void pnpbios_parse_fixed_mem32_option(unsigned char *p, int size,
280pnpbios_parse_fixed_mem32_option(unsigned char *p, int size, struct pnp_option *option) 298 struct pnp_option *option)
281{ 299{
282 struct pnp_mem * mem; 300 struct pnp_mem *mem;
283 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); 301 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
284 if (!mem) 302 if (!mem)
285 return; 303 return;
@@ -287,14 +305,13 @@ pnpbios_parse_fixed_mem32_option(unsigned char *p, int size, struct pnp_option *
287 mem->size = (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | p[8]; 305 mem->size = (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | p[8];
288 mem->align = 0; 306 mem->align = 0;
289 mem->flags = p[3]; 307 mem->flags = p[3];
290 pnp_register_mem_resource(option,mem); 308 pnp_register_mem_resource(option, mem);
291 return;
292} 309}
293 310
294static void 311static void pnpbios_parse_irq_option(unsigned char *p, int size,
295pnpbios_parse_irq_option(unsigned char *p, int size, struct pnp_option *option) 312 struct pnp_option *option)
296{ 313{
297 struct pnp_irq * irq; 314 struct pnp_irq *irq;
298 unsigned long bits; 315 unsigned long bits;
299 316
300 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL); 317 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
@@ -306,27 +323,27 @@ pnpbios_parse_irq_option(unsigned char *p, int size, struct pnp_option *option)
306 irq->flags = p[3]; 323 irq->flags = p[3];
307 else 324 else
308 irq->flags = IORESOURCE_IRQ_HIGHEDGE; 325 irq->flags = IORESOURCE_IRQ_HIGHEDGE;
309 pnp_register_irq_resource(option,irq); 326 pnp_register_irq_resource(option, irq);
310 return;
311} 327}
312 328
313static void 329static void pnpbios_parse_dma_option(unsigned char *p, int size,
314pnpbios_parse_dma_option(unsigned char *p, int size, struct pnp_option *option) 330 struct pnp_option *option)
315{ 331{
316 struct pnp_dma * dma; 332 struct pnp_dma *dma;
333
317 dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL); 334 dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL);
318 if (!dma) 335 if (!dma)
319 return; 336 return;
320 dma->map = p[1]; 337 dma->map = p[1];
321 dma->flags = p[2]; 338 dma->flags = p[2];
322 pnp_register_dma_resource(option,dma); 339 pnp_register_dma_resource(option, dma);
323 return;
324} 340}
325 341
326static void 342static void pnpbios_parse_port_option(unsigned char *p, int size,
327pnpbios_parse_port_option(unsigned char *p, int size, struct pnp_option *option) 343 struct pnp_option *option)
328{ 344{
329 struct pnp_port * port; 345 struct pnp_port *port;
346
330 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); 347 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
331 if (!port) 348 if (!port)
332 return; 349 return;
@@ -335,14 +352,14 @@ pnpbios_parse_port_option(unsigned char *p, int size, struct pnp_option *option)
335 port->align = p[6]; 352 port->align = p[6];
336 port->size = p[7]; 353 port->size = p[7];
337 port->flags = p[1] ? PNP_PORT_FLAG_16BITADDR : 0; 354 port->flags = p[1] ? PNP_PORT_FLAG_16BITADDR : 0;
338 pnp_register_port_resource(option,port); 355 pnp_register_port_resource(option, port);
339 return;
340} 356}
341 357
342static void 358static void pnpbios_parse_fixed_port_option(unsigned char *p, int size,
343pnpbios_parse_fixed_port_option(unsigned char *p, int size, struct pnp_option *option) 359 struct pnp_option *option)
344{ 360{
345 struct pnp_port * port; 361 struct pnp_port *port;
362
346 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); 363 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
347 if (!port) 364 if (!port)
348 return; 365 return;
@@ -350,12 +367,12 @@ pnpbios_parse_fixed_port_option(unsigned char *p, int size, struct pnp_option *o
350 port->size = p[3]; 367 port->size = p[3];
351 port->align = 0; 368 port->align = 0;
352 port->flags = PNP_PORT_FLAG_FIXED; 369 port->flags = PNP_PORT_FLAG_FIXED;
353 pnp_register_port_resource(option,port); 370 pnp_register_port_resource(option, port);
354 return;
355} 371}
356 372
357static unsigned char * 373static unsigned char *pnpbios_parse_resource_option_data(unsigned char *p,
358pnpbios_parse_resource_option_data(unsigned char * p, unsigned char * end, struct pnp_dev *dev) 374 unsigned char *end,
375 struct pnp_dev *dev)
359{ 376{
360 unsigned int len, tag; 377 unsigned int len, tag;
361 int priority = 0; 378 int priority = 0;
@@ -371,12 +388,12 @@ pnpbios_parse_resource_option_data(unsigned char * p, unsigned char * end, struc
371 while ((char *)p < (char *)end) { 388 while ((char *)p < (char *)end) {
372 389
373 /* determine the type of tag */ 390 /* determine the type of tag */
374 if (p[0] & LARGE_TAG) { /* large tag */ 391 if (p[0] & LARGE_TAG) { /* large tag */
375 len = (p[2] << 8) | p[1]; 392 len = (p[2] << 8) | p[1];
376 tag = p[0]; 393 tag = p[0];
377 } else { /* small tag */ 394 } else { /* small tag */
378 len = p[0] & 0x07; 395 len = p[0] & 0x07;
379 tag = ((p[0]>>3) & 0x0f); 396 tag = ((p[0] >> 3) & 0x0f);
380 } 397 }
381 398
382 switch (tag) { 399 switch (tag) {
@@ -442,16 +459,19 @@ pnpbios_parse_resource_option_data(unsigned char * p, unsigned char * end, struc
442 if (len != 0) 459 if (len != 0)
443 goto len_err; 460 goto len_err;
444 if (option_independent == option) 461 if (option_independent == option)
445 printk(KERN_WARNING "PnPBIOS: Missing SMALL_TAG_STARTDEP tag\n"); 462 printk(KERN_WARNING
463 "PnPBIOS: Missing SMALL_TAG_STARTDEP tag\n");
446 option = option_independent; 464 option = option_independent;
447 break; 465 break;
448 466
449 case SMALL_TAG_END: 467 case SMALL_TAG_END:
450 return p + 2; 468 return p + 2;
451 469
452 default: /* an unkown tag */ 470 default: /* an unkown tag */
453 len_err: 471 len_err:
454 printk(KERN_ERR "PnPBIOS: Unknown tag '0x%x', length '%d'.\n", tag, len); 472 printk(KERN_ERR
473 "PnPBIOS: Unknown tag '0x%x', length '%d'.\n",
474 tag, len);
455 break; 475 break;
456 } 476 }
457 477
@@ -462,19 +482,18 @@ pnpbios_parse_resource_option_data(unsigned char * p, unsigned char * end, struc
462 p += len + 1; 482 p += len + 1;
463 } 483 }
464 484
465 printk(KERN_ERR "PnPBIOS: Resource structure does not contain an end tag.\n"); 485 printk(KERN_ERR
486 "PnPBIOS: Resource structure does not contain an end tag.\n");
466 487
467 return NULL; 488 return NULL;
468} 489}
469 490
470
471/* 491/*
472 * Compatible Device IDs 492 * Compatible Device IDs
473 */ 493 */
474 494
475#define HEX(id,a) hex[((id)>>a) & 15] 495#define HEX(id,a) hex[((id)>>a) & 15]
476#define CHAR(id,a) (0x40 + (((id)>>a) & 31)) 496#define CHAR(id,a) (0x40 + (((id)>>a) & 31))
477//
478 497
479void pnpid32_to_pnpid(u32 id, char *str) 498void pnpid32_to_pnpid(u32 id, char *str)
480{ 499{
@@ -483,21 +502,20 @@ void pnpid32_to_pnpid(u32 id, char *str)
483 id = be32_to_cpu(id); 502 id = be32_to_cpu(id);
484 str[0] = CHAR(id, 26); 503 str[0] = CHAR(id, 26);
485 str[1] = CHAR(id, 21); 504 str[1] = CHAR(id, 21);
486 str[2] = CHAR(id,16); 505 str[2] = CHAR(id, 16);
487 str[3] = HEX(id, 12); 506 str[3] = HEX(id, 12);
488 str[4] = HEX(id, 8); 507 str[4] = HEX(id, 8);
489 str[5] = HEX(id, 4); 508 str[5] = HEX(id, 4);
490 str[6] = HEX(id, 0); 509 str[6] = HEX(id, 0);
491 str[7] = '\0'; 510 str[7] = '\0';
492
493 return;
494} 511}
495// 512
496#undef CHAR 513#undef CHAR
497#undef HEX 514#undef HEX
498 515
499static unsigned char * 516static unsigned char *pnpbios_parse_compatible_ids(unsigned char *p,
500pnpbios_parse_compatible_ids(unsigned char *p, unsigned char *end, struct pnp_dev *dev) 517 unsigned char *end,
518 struct pnp_dev *dev)
501{ 519{
502 int len, tag; 520 int len, tag;
503 char id[8]; 521 char id[8];
@@ -509,40 +527,45 @@ pnpbios_parse_compatible_ids(unsigned char *p, unsigned char *end, struct pnp_de
509 while ((char *)p < (char *)end) { 527 while ((char *)p < (char *)end) {
510 528
511 /* determine the type of tag */ 529 /* determine the type of tag */
512 if (p[0] & LARGE_TAG) { /* large tag */ 530 if (p[0] & LARGE_TAG) { /* large tag */
513 len = (p[2] << 8) | p[1]; 531 len = (p[2] << 8) | p[1];
514 tag = p[0]; 532 tag = p[0];
515 } else { /* small tag */ 533 } else { /* small tag */
516 len = p[0] & 0x07; 534 len = p[0] & 0x07;
517 tag = ((p[0]>>3) & 0x0f); 535 tag = ((p[0] >> 3) & 0x0f);
518 } 536 }
519 537
520 switch (tag) { 538 switch (tag) {
521 539
522 case LARGE_TAG_ANSISTR: 540 case LARGE_TAG_ANSISTR:
523 strncpy(dev->name, p + 3, len >= PNP_NAME_LEN ? PNP_NAME_LEN - 2 : len); 541 strncpy(dev->name, p + 3,
524 dev->name[len >= PNP_NAME_LEN ? PNP_NAME_LEN - 1 : len] = '\0'; 542 len >= PNP_NAME_LEN ? PNP_NAME_LEN - 2 : len);
543 dev->name[len >=
544 PNP_NAME_LEN ? PNP_NAME_LEN - 1 : len] = '\0';
525 break; 545 break;
526 546
527 case SMALL_TAG_COMPATDEVID: /* compatible ID */ 547 case SMALL_TAG_COMPATDEVID: /* compatible ID */
528 if (len != 4) 548 if (len != 4)
529 goto len_err; 549 goto len_err;
530 dev_id = kzalloc(sizeof (struct pnp_id), GFP_KERNEL); 550 dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
531 if (!dev_id) 551 if (!dev_id)
532 return NULL; 552 return NULL;
533 pnpid32_to_pnpid(p[1] | p[2] << 8 | p[3] << 16 | p[4] << 24,id); 553 pnpid32_to_pnpid(p[1] | p[2] << 8 | p[3] << 16 | p[4] <<
554 24, id);
534 memcpy(&dev_id->id, id, 7); 555 memcpy(&dev_id->id, id, 7);
535 pnp_add_id(dev_id, dev); 556 pnp_add_id(dev_id, dev);
536 break; 557 break;
537 558
538 case SMALL_TAG_END: 559 case SMALL_TAG_END:
539 p = p + 2; 560 p = p + 2;
540 return (unsigned char *)p; 561 return (unsigned char *)p;
541 break; 562 break;
542 563
543 default: /* an unkown tag */ 564 default: /* an unkown tag */
544 len_err: 565 len_err:
545 printk(KERN_ERR "PnPBIOS: Unknown tag '0x%x', length '%d'.\n", tag, len); 566 printk(KERN_ERR
567 "PnPBIOS: Unknown tag '0x%x', length '%d'.\n",
568 tag, len);
546 break; 569 break;
547 } 570 }
548 571
@@ -553,33 +576,34 @@ pnpbios_parse_compatible_ids(unsigned char *p, unsigned char *end, struct pnp_de
553 p += len + 1; 576 p += len + 1;
554 } 577 }
555 578
556 printk(KERN_ERR "PnPBIOS: Resource structure does not contain an end tag.\n"); 579 printk(KERN_ERR
580 "PnPBIOS: Resource structure does not contain an end tag.\n");
557 581
558 return NULL; 582 return NULL;
559} 583}
560 584
561
562/* 585/*
563 * Allocated Resource Encoding 586 * Allocated Resource Encoding
564 */ 587 */
565 588
566static void pnpbios_encode_mem(unsigned char *p, struct resource * res) 589static void pnpbios_encode_mem(unsigned char *p, struct resource *res)
567{ 590{
568 unsigned long base = res->start; 591 unsigned long base = res->start;
569 unsigned long len = res->end - res->start + 1; 592 unsigned long len = res->end - res->start + 1;
593
570 p[4] = (base >> 8) & 0xff; 594 p[4] = (base >> 8) & 0xff;
571 p[5] = ((base >> 8) >> 8) & 0xff; 595 p[5] = ((base >> 8) >> 8) & 0xff;
572 p[6] = (base >> 8) & 0xff; 596 p[6] = (base >> 8) & 0xff;
573 p[7] = ((base >> 8) >> 8) & 0xff; 597 p[7] = ((base >> 8) >> 8) & 0xff;
574 p[10] = (len >> 8) & 0xff; 598 p[10] = (len >> 8) & 0xff;
575 p[11] = ((len >> 8) >> 8) & 0xff; 599 p[11] = ((len >> 8) >> 8) & 0xff;
576 return;
577} 600}
578 601
579static void pnpbios_encode_mem32(unsigned char *p, struct resource * res) 602static void pnpbios_encode_mem32(unsigned char *p, struct resource *res)
580{ 603{
581 unsigned long base = res->start; 604 unsigned long base = res->start;
582 unsigned long len = res->end - res->start + 1; 605 unsigned long len = res->end - res->start + 1;
606
583 p[4] = base & 0xff; 607 p[4] = base & 0xff;
584 p[5] = (base >> 8) & 0xff; 608 p[5] = (base >> 8) & 0xff;
585 p[6] = (base >> 16) & 0xff; 609 p[6] = (base >> 16) & 0xff;
@@ -592,12 +616,13 @@ static void pnpbios_encode_mem32(unsigned char *p, struct resource * res)
592 p[17] = (len >> 8) & 0xff; 616 p[17] = (len >> 8) & 0xff;
593 p[18] = (len >> 16) & 0xff; 617 p[18] = (len >> 16) & 0xff;
594 p[19] = (len >> 24) & 0xff; 618 p[19] = (len >> 24) & 0xff;
595 return;
596} 619}
597 620
598static void pnpbios_encode_fixed_mem32(unsigned char *p, struct resource * res) 621static void pnpbios_encode_fixed_mem32(unsigned char *p, struct resource *res)
599{ unsigned long base = res->start; 622{
623 unsigned long base = res->start;
600 unsigned long len = res->end - res->start + 1; 624 unsigned long len = res->end - res->start + 1;
625
601 p[4] = base & 0xff; 626 p[4] = base & 0xff;
602 p[5] = (base >> 8) & 0xff; 627 p[5] = (base >> 8) & 0xff;
603 p[6] = (base >> 16) & 0xff; 628 p[6] = (base >> 16) & 0xff;
@@ -606,50 +631,52 @@ static void pnpbios_encode_fixed_mem32(unsigned char *p, struct resource * res)
606 p[9] = (len >> 8) & 0xff; 631 p[9] = (len >> 8) & 0xff;
607 p[10] = (len >> 16) & 0xff; 632 p[10] = (len >> 16) & 0xff;
608 p[11] = (len >> 24) & 0xff; 633 p[11] = (len >> 24) & 0xff;
609 return;
610} 634}
611 635
612static void pnpbios_encode_irq(unsigned char *p, struct resource * res) 636static void pnpbios_encode_irq(unsigned char *p, struct resource *res)
613{ 637{
614 unsigned long map = 0; 638 unsigned long map = 0;
639
615 map = 1 << res->start; 640 map = 1 << res->start;
616 p[1] = map & 0xff; 641 p[1] = map & 0xff;
617 p[2] = (map >> 8) & 0xff; 642 p[2] = (map >> 8) & 0xff;
618 return;
619} 643}
620 644
621static void pnpbios_encode_dma(unsigned char *p, struct resource * res) 645static void pnpbios_encode_dma(unsigned char *p, struct resource *res)
622{ 646{
623 unsigned long map = 0; 647 unsigned long map = 0;
648
624 map = 1 << res->start; 649 map = 1 << res->start;
625 p[1] = map & 0xff; 650 p[1] = map & 0xff;
626 return;
627} 651}
628 652
629static void pnpbios_encode_port(unsigned char *p, struct resource * res) 653static void pnpbios_encode_port(unsigned char *p, struct resource *res)
630{ 654{
631 unsigned long base = res->start; 655 unsigned long base = res->start;
632 unsigned long len = res->end - res->start + 1; 656 unsigned long len = res->end - res->start + 1;
657
633 p[2] = base & 0xff; 658 p[2] = base & 0xff;
634 p[3] = (base >> 8) & 0xff; 659 p[3] = (base >> 8) & 0xff;
635 p[4] = base & 0xff; 660 p[4] = base & 0xff;
636 p[5] = (base >> 8) & 0xff; 661 p[5] = (base >> 8) & 0xff;
637 p[7] = len & 0xff; 662 p[7] = len & 0xff;
638 return;
639} 663}
640 664
641static void pnpbios_encode_fixed_port(unsigned char *p, struct resource * res) 665static void pnpbios_encode_fixed_port(unsigned char *p, struct resource *res)
642{ 666{
643 unsigned long base = res->start; 667 unsigned long base = res->start;
644 unsigned long len = res->end - res->start + 1; 668 unsigned long len = res->end - res->start + 1;
669
645 p[1] = base & 0xff; 670 p[1] = base & 0xff;
646 p[2] = (base >> 8) & 0xff; 671 p[2] = (base >> 8) & 0xff;
647 p[3] = len & 0xff; 672 p[3] = len & 0xff;
648 return;
649} 673}
650 674
651static unsigned char * 675static unsigned char *pnpbios_encode_allocated_resource_data(unsigned char *p,
652pnpbios_encode_allocated_resource_data(unsigned char * p, unsigned char * end, struct pnp_resource_table * res) 676 unsigned char *end,
677 struct
678 pnp_resource_table
679 *res)
653{ 680{
654 unsigned int len, tag; 681 unsigned int len, tag;
655 int port = 0, irq = 0, dma = 0, mem = 0; 682 int port = 0, irq = 0, dma = 0, mem = 0;
@@ -660,12 +687,12 @@ pnpbios_encode_allocated_resource_data(unsigned char * p, unsigned char * end, s
660 while ((char *)p < (char *)end) { 687 while ((char *)p < (char *)end) {
661 688
662 /* determine the type of tag */ 689 /* determine the type of tag */
663 if (p[0] & LARGE_TAG) { /* large tag */ 690 if (p[0] & LARGE_TAG) { /* large tag */
664 len = (p[2] << 8) | p[1]; 691 len = (p[2] << 8) | p[1];
665 tag = p[0]; 692 tag = p[0];
666 } else { /* small tag */ 693 } else { /* small tag */
667 len = p[0] & 0x07; 694 len = p[0] & 0x07;
668 tag = ((p[0]>>3) & 0x0f); 695 tag = ((p[0] >> 3) & 0x0f);
669 } 696 }
670 697
671 switch (tag) { 698 switch (tag) {
@@ -725,12 +752,14 @@ pnpbios_encode_allocated_resource_data(unsigned char * p, unsigned char * end, s
725 752
726 case SMALL_TAG_END: 753 case SMALL_TAG_END:
727 p = p + 2; 754 p = p + 2;
728 return (unsigned char *)p; 755 return (unsigned char *)p;
729 break; 756 break;
730 757
731 default: /* an unkown tag */ 758 default: /* an unkown tag */
732 len_err: 759 len_err:
733 printk(KERN_ERR "PnPBIOS: Unknown tag '0x%x', length '%d'.\n", tag, len); 760 printk(KERN_ERR
761 "PnPBIOS: Unknown tag '0x%x', length '%d'.\n",
762 tag, len);
734 break; 763 break;
735 } 764 }
736 765
@@ -741,52 +770,52 @@ pnpbios_encode_allocated_resource_data(unsigned char * p, unsigned char * end, s
741 p += len + 1; 770 p += len + 1;
742 } 771 }
743 772
744 printk(KERN_ERR "PnPBIOS: Resource structure does not contain an end tag.\n"); 773 printk(KERN_ERR
774 "PnPBIOS: Resource structure does not contain an end tag.\n");
745 775
746 return NULL; 776 return NULL;
747} 777}
748 778
749
750/* 779/*
751 * Core Parsing Functions 780 * Core Parsing Functions
752 */ 781 */
753 782
754int 783int pnpbios_parse_data_stream(struct pnp_dev *dev, struct pnp_bios_node *node)
755pnpbios_parse_data_stream(struct pnp_dev *dev, struct pnp_bios_node * node)
756{ 784{
757 unsigned char * p = (char *)node->data; 785 unsigned char *p = (char *)node->data;
758 unsigned char * end = (char *)(node->data + node->size); 786 unsigned char *end = (char *)(node->data + node->size);
759 p = pnpbios_parse_allocated_resource_data(p,end,&dev->res); 787
788 p = pnpbios_parse_allocated_resource_data(p, end, &dev->res);
760 if (!p) 789 if (!p)
761 return -EIO; 790 return -EIO;
762 p = pnpbios_parse_resource_option_data(p,end,dev); 791 p = pnpbios_parse_resource_option_data(p, end, dev);
763 if (!p) 792 if (!p)
764 return -EIO; 793 return -EIO;
765 p = pnpbios_parse_compatible_ids(p,end,dev); 794 p = pnpbios_parse_compatible_ids(p, end, dev);
766 if (!p) 795 if (!p)
767 return -EIO; 796 return -EIO;
768 return 0; 797 return 0;
769} 798}
770 799
771int 800int pnpbios_read_resources_from_node(struct pnp_resource_table *res,
772pnpbios_read_resources_from_node(struct pnp_resource_table *res, 801 struct pnp_bios_node *node)
773 struct pnp_bios_node * node)
774{ 802{
775 unsigned char * p = (char *)node->data; 803 unsigned char *p = (char *)node->data;
776 unsigned char * end = (char *)(node->data + node->size); 804 unsigned char *end = (char *)(node->data + node->size);
777 p = pnpbios_parse_allocated_resource_data(p,end,res); 805
806 p = pnpbios_parse_allocated_resource_data(p, end, res);
778 if (!p) 807 if (!p)
779 return -EIO; 808 return -EIO;
780 return 0; 809 return 0;
781} 810}
782 811
783int 812int pnpbios_write_resources_to_node(struct pnp_resource_table *res,
784pnpbios_write_resources_to_node(struct pnp_resource_table *res, 813 struct pnp_bios_node *node)
785 struct pnp_bios_node * node)
786{ 814{
787 unsigned char * p = (char *)node->data; 815 unsigned char *p = (char *)node->data;
788 unsigned char * end = (char *)(node->data + node->size); 816 unsigned char *end = (char *)(node->data + node->size);
789 p = pnpbios_encode_allocated_resource_data(p,end,res); 817
818 p = pnpbios_encode_allocated_resource_data(p, end, res);
790 if (!p) 819 if (!p)
791 return -EIO; 820 return -EIO;
792 return 0; 821 return 0;
diff --git a/drivers/pnp/quirks.c b/drivers/pnp/quirks.c
index 7c3236690cc3..90755d4cdb9f 100644
--- a/drivers/pnp/quirks.c
+++ b/drivers/pnp/quirks.c
@@ -19,7 +19,6 @@
19#include <linux/io.h> 19#include <linux/io.h>
20#include "base.h" 20#include "base.h"
21 21
22
23static void quirk_awe32_resources(struct pnp_dev *dev) 22static void quirk_awe32_resources(struct pnp_dev *dev)
24{ 23{
25 struct pnp_port *port, *port2, *port3; 24 struct pnp_port *port, *port2, *port3;
@@ -31,7 +30,7 @@ static void quirk_awe32_resources(struct pnp_dev *dev)
31 * two extra ports (at offset 0x400 and 0x800 from the one given) by 30 * two extra ports (at offset 0x400 and 0x800 from the one given) by
32 * hand. 31 * hand.
33 */ 32 */
34 for ( ; res ; res = res->next ) { 33 for (; res; res = res->next) {
35 port2 = pnp_alloc(sizeof(struct pnp_port)); 34 port2 = pnp_alloc(sizeof(struct pnp_port));
36 if (!port2) 35 if (!port2)
37 return; 36 return;
@@ -58,18 +57,19 @@ static void quirk_cmi8330_resources(struct pnp_dev *dev)
58 struct pnp_option *res = dev->dependent; 57 struct pnp_option *res = dev->dependent;
59 unsigned long tmp; 58 unsigned long tmp;
60 59
61 for ( ; res ; res = res->next ) { 60 for (; res; res = res->next) {
62 61
63 struct pnp_irq *irq; 62 struct pnp_irq *irq;
64 struct pnp_dma *dma; 63 struct pnp_dma *dma;
65 64
66 for( irq = res->irq; irq; irq = irq->next ) { // Valid irqs are 5, 7, 10 65 for (irq = res->irq; irq; irq = irq->next) { // Valid irqs are 5, 7, 10
67 tmp = 0x04A0; 66 tmp = 0x04A0;
68 bitmap_copy(irq->map, &tmp, 16); // 0000 0100 1010 0000 67 bitmap_copy(irq->map, &tmp, 16); // 0000 0100 1010 0000
69 } 68 }
70 69
71 for( dma = res->dma; dma; dma = dma->next ) // Valid 8bit dma channels are 1,3 70 for (dma = res->dma; dma; dma = dma->next) // Valid 8bit dma channels are 1,3
72 if( ( dma->flags & IORESOURCE_DMA_TYPE_MASK ) == IORESOURCE_DMA_8BIT ) 71 if ((dma->flags & IORESOURCE_DMA_TYPE_MASK) ==
72 IORESOURCE_DMA_8BIT)
73 dma->map = 0x000A; 73 dma->map = 0x000A;
74 } 74 }
75 printk(KERN_INFO "pnp: CMI8330 quirk - fixing interrupts and dma\n"); 75 printk(KERN_INFO "pnp: CMI8330 quirk - fixing interrupts and dma\n");
@@ -79,7 +79,7 @@ static void quirk_sb16audio_resources(struct pnp_dev *dev)
79{ 79{
80 struct pnp_port *port; 80 struct pnp_port *port;
81 struct pnp_option *res = dev->dependent; 81 struct pnp_option *res = dev->dependent;
82 int changed = 0; 82 int changed = 0;
83 83
84 /* 84 /*
85 * The default range on the mpu port for these devices is 0x388-0x388. 85 * The default range on the mpu port for these devices is 0x388-0x388.
@@ -87,24 +87,24 @@ static void quirk_sb16audio_resources(struct pnp_dev *dev)
87 * auto-configured. 87 * auto-configured.
88 */ 88 */
89 89
90 for( ; res ; res = res->next ) { 90 for (; res; res = res->next) {
91 port = res->port; 91 port = res->port;
92 if(!port) 92 if (!port)
93 continue; 93 continue;
94 port = port->next; 94 port = port->next;
95 if(!port) 95 if (!port)
96 continue; 96 continue;
97 port = port->next; 97 port = port->next;
98 if(!port) 98 if (!port)
99 continue; 99 continue;
100 if(port->min != port->max) 100 if (port->min != port->max)
101 continue; 101 continue;
102 port->max += 0x70; 102 port->max += 0x70;
103 changed = 1; 103 changed = 1;
104 } 104 }
105 if(changed) 105 if (changed)
106 printk(KERN_INFO "pnp: SB audio device quirk - increasing port range\n"); 106 printk(KERN_INFO
107 return; 107 "pnp: SB audio device quirk - increasing port range\n");
108} 108}
109 109
110static int quirk_smc_fir_enabled(struct pnp_dev *dev) 110static int quirk_smc_fir_enabled(struct pnp_dev *dev)
@@ -124,7 +124,7 @@ static int quirk_smc_fir_enabled(struct pnp_dev *dev)
124 outb(bank, firbase + 7); 124 outb(bank, firbase + 7);
125 125
126 high = inb(firbase + 0); 126 high = inb(firbase + 0);
127 low = inb(firbase + 1); 127 low = inb(firbase + 1);
128 chip = inb(firbase + 2); 128 chip = inb(firbase + 2);
129 129
130 /* This corresponds to the check in smsc_ircc_present() */ 130 /* This corresponds to the check in smsc_ircc_present() */
@@ -153,8 +153,8 @@ static void quirk_smc_enable(struct pnp_dev *dev)
153 */ 153 */
154 dev_err(&dev->dev, "%s not responding at SIR 0x%lx, FIR 0x%lx; " 154 dev_err(&dev->dev, "%s not responding at SIR 0x%lx, FIR 0x%lx; "
155 "auto-configuring\n", dev->id->id, 155 "auto-configuring\n", dev->id->id,
156 (unsigned long) pnp_port_start(dev, 0), 156 (unsigned long)pnp_port_start(dev, 0),
157 (unsigned long) pnp_port_start(dev, 1)); 157 (unsigned long)pnp_port_start(dev, 1));
158 158
159 pnp_disable_dev(dev); 159 pnp_disable_dev(dev);
160 pnp_init_resource_table(&dev->res); 160 pnp_init_resource_table(&dev->res);
@@ -162,8 +162,8 @@ static void quirk_smc_enable(struct pnp_dev *dev)
162 pnp_activate_dev(dev); 162 pnp_activate_dev(dev);
163 if (quirk_smc_fir_enabled(dev)) { 163 if (quirk_smc_fir_enabled(dev)) {
164 dev_err(&dev->dev, "responds at SIR 0x%lx, FIR 0x%lx\n", 164 dev_err(&dev->dev, "responds at SIR 0x%lx, FIR 0x%lx\n",
165 (unsigned long) pnp_port_start(dev, 0), 165 (unsigned long)pnp_port_start(dev, 0),
166 (unsigned long) pnp_port_start(dev, 1)); 166 (unsigned long)pnp_port_start(dev, 1));
167 return; 167 return;
168 } 168 }
169 169
@@ -175,8 +175,8 @@ static void quirk_smc_enable(struct pnp_dev *dev)
175 */ 175 */
176 dev_err(&dev->dev, "not responding at SIR 0x%lx, FIR 0x%lx; " 176 dev_err(&dev->dev, "not responding at SIR 0x%lx, FIR 0x%lx; "
177 "swapping SIR/FIR and reconfiguring\n", 177 "swapping SIR/FIR and reconfiguring\n",
178 (unsigned long) pnp_port_start(dev, 0), 178 (unsigned long)pnp_port_start(dev, 0),
179 (unsigned long) pnp_port_start(dev, 1)); 179 (unsigned long)pnp_port_start(dev, 1));
180 180
181 /* 181 /*
182 * Clear IORESOURCE_AUTO so pnp_activate_dev() doesn't reassign 182 * Clear IORESOURCE_AUTO so pnp_activate_dev() doesn't reassign
@@ -200,8 +200,8 @@ static void quirk_smc_enable(struct pnp_dev *dev)
200 200
201 if (quirk_smc_fir_enabled(dev)) { 201 if (quirk_smc_fir_enabled(dev)) {
202 dev_err(&dev->dev, "responds at SIR 0x%lx, FIR 0x%lx\n", 202 dev_err(&dev->dev, "responds at SIR 0x%lx, FIR 0x%lx\n",
203 (unsigned long) pnp_port_start(dev, 0), 203 (unsigned long)pnp_port_start(dev, 0),
204 (unsigned long) pnp_port_start(dev, 1)); 204 (unsigned long)pnp_port_start(dev, 1));
205 return; 205 return;
206 } 206 }
207 207
@@ -209,7 +209,6 @@ static void quirk_smc_enable(struct pnp_dev *dev)
209 "email bjorn.helgaas@hp.com\n"); 209 "email bjorn.helgaas@hp.com\n");
210} 210}
211 211
212
213/* 212/*
214 * PnP Quirks 213 * PnP Quirks
215 * Cards or devices that need some tweaking due to incomplete resource info 214 * Cards or devices that need some tweaking due to incomplete resource info
@@ -217,21 +216,21 @@ static void quirk_smc_enable(struct pnp_dev *dev)
217 216
218static struct pnp_fixup pnp_fixups[] = { 217static struct pnp_fixup pnp_fixups[] = {
219 /* Soundblaster awe io port quirk */ 218 /* Soundblaster awe io port quirk */
220 { "CTL0021", quirk_awe32_resources }, 219 {"CTL0021", quirk_awe32_resources},
221 { "CTL0022", quirk_awe32_resources }, 220 {"CTL0022", quirk_awe32_resources},
222 { "CTL0023", quirk_awe32_resources }, 221 {"CTL0023", quirk_awe32_resources},
223 /* CMI 8330 interrupt and dma fix */ 222 /* CMI 8330 interrupt and dma fix */
224 { "@X@0001", quirk_cmi8330_resources }, 223 {"@X@0001", quirk_cmi8330_resources},
225 /* Soundblaster audio device io port range quirk */ 224 /* Soundblaster audio device io port range quirk */
226 { "CTL0001", quirk_sb16audio_resources }, 225 {"CTL0001", quirk_sb16audio_resources},
227 { "CTL0031", quirk_sb16audio_resources }, 226 {"CTL0031", quirk_sb16audio_resources},
228 { "CTL0041", quirk_sb16audio_resources }, 227 {"CTL0041", quirk_sb16audio_resources},
229 { "CTL0042", quirk_sb16audio_resources }, 228 {"CTL0042", quirk_sb16audio_resources},
230 { "CTL0043", quirk_sb16audio_resources }, 229 {"CTL0043", quirk_sb16audio_resources},
231 { "CTL0044", quirk_sb16audio_resources }, 230 {"CTL0044", quirk_sb16audio_resources},
232 { "CTL0045", quirk_sb16audio_resources }, 231 {"CTL0045", quirk_sb16audio_resources},
233 { "SMCf010", quirk_smc_enable }, 232 {"SMCf010", quirk_smc_enable},
234 { "" } 233 {""}
235}; 234};
236 235
237void pnp_fixup_device(struct pnp_dev *dev) 236void pnp_fixup_device(struct pnp_dev *dev)
@@ -239,9 +238,8 @@ void pnp_fixup_device(struct pnp_dev *dev)
239 int i = 0; 238 int i = 0;
240 239
241 while (*pnp_fixups[i].id) { 240 while (*pnp_fixups[i].id) {
242 if (compare_pnp_id(dev->id,pnp_fixups[i].id)) { 241 if (compare_pnp_id(dev->id, pnp_fixups[i].id)) {
243 pnp_dbg("Calling quirk for %s", 242 pnp_dbg("Calling quirk for %s", dev->dev.bus_id);
244 dev->dev.bus_id);
245 pnp_fixups[i].quirk_function(dev); 243 pnp_fixups[i].quirk_function(dev);
246 } 244 }
247 i++; 245 i++;
diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
index a685fbec4604..ea6ec14a0559 100644
--- a/drivers/pnp/resource.c
+++ b/drivers/pnp/resource.c
@@ -3,7 +3,6 @@
3 * 3 *
4 * based on isapnp.c resource management (c) Jaroslav Kysela <perex@suse.cz> 4 * based on isapnp.c resource management (c) Jaroslav Kysela <perex@suse.cz>
5 * Copyright 2003 Adam Belay <ambx1@neo.rr.com> 5 * Copyright 2003 Adam Belay <ambx1@neo.rr.com>
6 *
7 */ 6 */
8 7
9#include <linux/module.h> 8#include <linux/module.h>
@@ -20,21 +19,19 @@
20#include <linux/pnp.h> 19#include <linux/pnp.h>
21#include "base.h" 20#include "base.h"
22 21
23static int pnp_reserve_irq[16] = { [0 ... 15] = -1 }; /* reserve (don't use) some IRQ */ 22static int pnp_reserve_irq[16] = {[0 ... 15] = -1 }; /* reserve (don't use) some IRQ */
24static int pnp_reserve_dma[8] = { [0 ... 7] = -1 }; /* reserve (don't use) some DMA */ 23static int pnp_reserve_dma[8] = {[0 ... 7] = -1 }; /* reserve (don't use) some DMA */
25static int pnp_reserve_io[16] = { [0 ... 15] = -1 }; /* reserve (don't use) some I/O region */ 24static int pnp_reserve_io[16] = {[0 ... 15] = -1 }; /* reserve (don't use) some I/O region */
26static int pnp_reserve_mem[16] = { [0 ... 15] = -1 }; /* reserve (don't use) some memory region */ 25static int pnp_reserve_mem[16] = {[0 ... 15] = -1 }; /* reserve (don't use) some memory region */
27
28 26
29/* 27/*
30 * option registration 28 * option registration
31 */ 29 */
32 30
33static struct pnp_option * pnp_build_option(int priority) 31static struct pnp_option *pnp_build_option(int priority)
34{ 32{
35 struct pnp_option *option = pnp_alloc(sizeof(struct pnp_option)); 33 struct pnp_option *option = pnp_alloc(sizeof(struct pnp_option));
36 34
37 /* check if pnp_alloc ran out of memory */
38 if (!option) 35 if (!option)
39 return NULL; 36 return NULL;
40 37
@@ -46,9 +43,10 @@ static struct pnp_option * pnp_build_option(int priority)
46 return option; 43 return option;
47} 44}
48 45
49struct pnp_option * pnp_register_independent_option(struct pnp_dev *dev) 46struct pnp_option *pnp_register_independent_option(struct pnp_dev *dev)
50{ 47{
51 struct pnp_option *option; 48 struct pnp_option *option;
49
52 if (!dev) 50 if (!dev)
53 return NULL; 51 return NULL;
54 52
@@ -61,9 +59,11 @@ struct pnp_option * pnp_register_independent_option(struct pnp_dev *dev)
61 return option; 59 return option;
62} 60}
63 61
64struct pnp_option * pnp_register_dependent_option(struct pnp_dev *dev, int priority) 62struct pnp_option *pnp_register_dependent_option(struct pnp_dev *dev,
63 int priority)
65{ 64{
66 struct pnp_option *option; 65 struct pnp_option *option;
66
67 if (!dev) 67 if (!dev)
68 return NULL; 68 return NULL;
69 69
@@ -82,6 +82,7 @@ struct pnp_option * pnp_register_dependent_option(struct pnp_dev *dev, int prior
82int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data) 82int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data)
83{ 83{
84 struct pnp_irq *ptr; 84 struct pnp_irq *ptr;
85
85 if (!option) 86 if (!option)
86 return -EINVAL; 87 return -EINVAL;
87 if (!data) 88 if (!data)
@@ -110,6 +111,7 @@ int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data)
110int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data) 111int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data)
111{ 112{
112 struct pnp_dma *ptr; 113 struct pnp_dma *ptr;
114
113 if (!option) 115 if (!option)
114 return -EINVAL; 116 return -EINVAL;
115 if (!data) 117 if (!data)
@@ -129,6 +131,7 @@ int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data)
129int pnp_register_port_resource(struct pnp_option *option, struct pnp_port *data) 131int pnp_register_port_resource(struct pnp_option *option, struct pnp_port *data)
130{ 132{
131 struct pnp_port *ptr; 133 struct pnp_port *ptr;
134
132 if (!option) 135 if (!option)
133 return -EINVAL; 136 return -EINVAL;
134 if (!data) 137 if (!data)
@@ -148,6 +151,7 @@ int pnp_register_port_resource(struct pnp_option *option, struct pnp_port *data)
148int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data) 151int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data)
149{ 152{
150 struct pnp_mem *ptr; 153 struct pnp_mem *ptr;
154
151 if (!option) 155 if (!option)
152 return -EINVAL; 156 return -EINVAL;
153 if (!data) 157 if (!data)
@@ -222,7 +226,6 @@ void pnp_free_option(struct pnp_option *option)
222 } 226 }
223} 227}
224 228
225
226/* 229/*
227 * resource validity checking 230 * resource validity checking
228 */ 231 */
@@ -236,11 +239,12 @@ void pnp_free_option(struct pnp_option *option)
236#define cannot_compare(flags) \ 239#define cannot_compare(flags) \
237((flags) & (IORESOURCE_UNSET | IORESOURCE_DISABLED)) 240((flags) & (IORESOURCE_UNSET | IORESOURCE_DISABLED))
238 241
239int pnp_check_port(struct pnp_dev * dev, int idx) 242int pnp_check_port(struct pnp_dev *dev, int idx)
240{ 243{
241 int tmp; 244 int tmp;
242 struct pnp_dev *tdev; 245 struct pnp_dev *tdev;
243 resource_size_t *port, *end, *tport, *tend; 246 resource_size_t *port, *end, *tport, *tend;
247
244 port = &dev->res.port_resource[idx].start; 248 port = &dev->res.port_resource[idx].start;
245 end = &dev->res.port_resource[idx].end; 249 end = &dev->res.port_resource[idx].end;
246 250
@@ -250,8 +254,8 @@ int pnp_check_port(struct pnp_dev * dev, int idx)
250 254
251 /* check if the resource is already in use, skip if the 255 /* check if the resource is already in use, skip if the
252 * device is active because it itself may be in use */ 256 * device is active because it itself may be in use */
253 if(!dev->active) { 257 if (!dev->active) {
254 if (__check_region(&ioport_resource, *port, length(port,end))) 258 if (__check_region(&ioport_resource, *port, length(port, end)))
255 return 0; 259 return 0;
256 } 260 }
257 261
@@ -259,7 +263,7 @@ int pnp_check_port(struct pnp_dev * dev, int idx)
259 for (tmp = 0; tmp < 8; tmp++) { 263 for (tmp = 0; tmp < 8; tmp++) {
260 int rport = pnp_reserve_io[tmp << 1]; 264 int rport = pnp_reserve_io[tmp << 1];
261 int rend = pnp_reserve_io[(tmp << 1) + 1] + rport - 1; 265 int rend = pnp_reserve_io[(tmp << 1) + 1] + rport - 1;
262 if (ranged_conflict(port,end,&rport,&rend)) 266 if (ranged_conflict(port, end, &rport, &rend))
263 return 0; 267 return 0;
264 } 268 }
265 269
@@ -268,7 +272,7 @@ int pnp_check_port(struct pnp_dev * dev, int idx)
268 if (dev->res.port_resource[tmp].flags & IORESOURCE_IO) { 272 if (dev->res.port_resource[tmp].flags & IORESOURCE_IO) {
269 tport = &dev->res.port_resource[tmp].start; 273 tport = &dev->res.port_resource[tmp].start;
270 tend = &dev->res.port_resource[tmp].end; 274 tend = &dev->res.port_resource[tmp].end;
271 if (ranged_conflict(port,end,tport,tend)) 275 if (ranged_conflict(port, end, tport, tend))
272 return 0; 276 return 0;
273 } 277 }
274 } 278 }
@@ -279,11 +283,12 @@ int pnp_check_port(struct pnp_dev * dev, int idx)
279 continue; 283 continue;
280 for (tmp = 0; tmp < PNP_MAX_PORT; tmp++) { 284 for (tmp = 0; tmp < PNP_MAX_PORT; tmp++) {
281 if (tdev->res.port_resource[tmp].flags & IORESOURCE_IO) { 285 if (tdev->res.port_resource[tmp].flags & IORESOURCE_IO) {
282 if (cannot_compare(tdev->res.port_resource[tmp].flags)) 286 if (cannot_compare
287 (tdev->res.port_resource[tmp].flags))
283 continue; 288 continue;
284 tport = &tdev->res.port_resource[tmp].start; 289 tport = &tdev->res.port_resource[tmp].start;
285 tend = &tdev->res.port_resource[tmp].end; 290 tend = &tdev->res.port_resource[tmp].end;
286 if (ranged_conflict(port,end,tport,tend)) 291 if (ranged_conflict(port, end, tport, tend))
287 return 0; 292 return 0;
288 } 293 }
289 } 294 }
@@ -292,11 +297,12 @@ int pnp_check_port(struct pnp_dev * dev, int idx)
292 return 1; 297 return 1;
293} 298}
294 299
295int pnp_check_mem(struct pnp_dev * dev, int idx) 300int pnp_check_mem(struct pnp_dev *dev, int idx)
296{ 301{
297 int tmp; 302 int tmp;
298 struct pnp_dev *tdev; 303 struct pnp_dev *tdev;
299 resource_size_t *addr, *end, *taddr, *tend; 304 resource_size_t *addr, *end, *taddr, *tend;
305
300 addr = &dev->res.mem_resource[idx].start; 306 addr = &dev->res.mem_resource[idx].start;
301 end = &dev->res.mem_resource[idx].end; 307 end = &dev->res.mem_resource[idx].end;
302 308
@@ -306,8 +312,8 @@ int pnp_check_mem(struct pnp_dev * dev, int idx)
306 312
307 /* check if the resource is already in use, skip if the 313 /* check if the resource is already in use, skip if the
308 * device is active because it itself may be in use */ 314 * device is active because it itself may be in use */
309 if(!dev->active) { 315 if (!dev->active) {
310 if (check_mem_region(*addr, length(addr,end))) 316 if (check_mem_region(*addr, length(addr, end)))
311 return 0; 317 return 0;
312 } 318 }
313 319
@@ -315,7 +321,7 @@ int pnp_check_mem(struct pnp_dev * dev, int idx)
315 for (tmp = 0; tmp < 8; tmp++) { 321 for (tmp = 0; tmp < 8; tmp++) {
316 int raddr = pnp_reserve_mem[tmp << 1]; 322 int raddr = pnp_reserve_mem[tmp << 1];
317 int rend = pnp_reserve_mem[(tmp << 1) + 1] + raddr - 1; 323 int rend = pnp_reserve_mem[(tmp << 1) + 1] + raddr - 1;
318 if (ranged_conflict(addr,end,&raddr,&rend)) 324 if (ranged_conflict(addr, end, &raddr, &rend))
319 return 0; 325 return 0;
320 } 326 }
321 327
@@ -324,7 +330,7 @@ int pnp_check_mem(struct pnp_dev * dev, int idx)
324 if (dev->res.mem_resource[tmp].flags & IORESOURCE_MEM) { 330 if (dev->res.mem_resource[tmp].flags & IORESOURCE_MEM) {
325 taddr = &dev->res.mem_resource[tmp].start; 331 taddr = &dev->res.mem_resource[tmp].start;
326 tend = &dev->res.mem_resource[tmp].end; 332 tend = &dev->res.mem_resource[tmp].end;
327 if (ranged_conflict(addr,end,taddr,tend)) 333 if (ranged_conflict(addr, end, taddr, tend))
328 return 0; 334 return 0;
329 } 335 }
330 } 336 }
@@ -335,11 +341,12 @@ int pnp_check_mem(struct pnp_dev * dev, int idx)
335 continue; 341 continue;
336 for (tmp = 0; tmp < PNP_MAX_MEM; tmp++) { 342 for (tmp = 0; tmp < PNP_MAX_MEM; tmp++) {
337 if (tdev->res.mem_resource[tmp].flags & IORESOURCE_MEM) { 343 if (tdev->res.mem_resource[tmp].flags & IORESOURCE_MEM) {
338 if (cannot_compare(tdev->res.mem_resource[tmp].flags)) 344 if (cannot_compare
345 (tdev->res.mem_resource[tmp].flags))
339 continue; 346 continue;
340 taddr = &tdev->res.mem_resource[tmp].start; 347 taddr = &tdev->res.mem_resource[tmp].start;
341 tend = &tdev->res.mem_resource[tmp].end; 348 tend = &tdev->res.mem_resource[tmp].end;
342 if (ranged_conflict(addr,end,taddr,tend)) 349 if (ranged_conflict(addr, end, taddr, tend))
343 return 0; 350 return 0;
344 } 351 }
345 } 352 }
@@ -353,11 +360,11 @@ static irqreturn_t pnp_test_handler(int irq, void *dev_id)
353 return IRQ_HANDLED; 360 return IRQ_HANDLED;
354} 361}
355 362
356int pnp_check_irq(struct pnp_dev * dev, int idx) 363int pnp_check_irq(struct pnp_dev *dev, int idx)
357{ 364{
358 int tmp; 365 int tmp;
359 struct pnp_dev *tdev; 366 struct pnp_dev *tdev;
360 resource_size_t * irq = &dev->res.irq_resource[idx].start; 367 resource_size_t *irq = &dev->res.irq_resource[idx].start;
361 368
362 /* if the resource doesn't exist, don't complain about it */ 369 /* if the resource doesn't exist, don't complain about it */
363 if (cannot_compare(dev->res.irq_resource[idx].flags)) 370 if (cannot_compare(dev->res.irq_resource[idx].flags))
@@ -394,9 +401,9 @@ int pnp_check_irq(struct pnp_dev * dev, int idx)
394 401
395 /* check if the resource is already in use, skip if the 402 /* check if the resource is already in use, skip if the
396 * device is active because it itself may be in use */ 403 * device is active because it itself may be in use */
397 if(!dev->active) { 404 if (!dev->active) {
398 if (request_irq(*irq, pnp_test_handler, 405 if (request_irq(*irq, pnp_test_handler,
399 IRQF_DISABLED|IRQF_PROBE_SHARED, "pnp", NULL)) 406 IRQF_DISABLED | IRQF_PROBE_SHARED, "pnp", NULL))
400 return 0; 407 return 0;
401 free_irq(*irq, NULL); 408 free_irq(*irq, NULL);
402 } 409 }
@@ -407,7 +414,8 @@ int pnp_check_irq(struct pnp_dev * dev, int idx)
407 continue; 414 continue;
408 for (tmp = 0; tmp < PNP_MAX_IRQ; tmp++) { 415 for (tmp = 0; tmp < PNP_MAX_IRQ; tmp++) {
409 if (tdev->res.irq_resource[tmp].flags & IORESOURCE_IRQ) { 416 if (tdev->res.irq_resource[tmp].flags & IORESOURCE_IRQ) {
410 if (cannot_compare(tdev->res.irq_resource[tmp].flags)) 417 if (cannot_compare
418 (tdev->res.irq_resource[tmp].flags))
411 continue; 419 continue;
412 if ((tdev->res.irq_resource[tmp].start == *irq)) 420 if ((tdev->res.irq_resource[tmp].start == *irq))
413 return 0; 421 return 0;
@@ -418,12 +426,12 @@ int pnp_check_irq(struct pnp_dev * dev, int idx)
418 return 1; 426 return 1;
419} 427}
420 428
421int pnp_check_dma(struct pnp_dev * dev, int idx) 429int pnp_check_dma(struct pnp_dev *dev, int idx)
422{ 430{
423#ifndef CONFIG_IA64 431#ifndef CONFIG_IA64
424 int tmp; 432 int tmp;
425 struct pnp_dev *tdev; 433 struct pnp_dev *tdev;
426 resource_size_t * dma = &dev->res.dma_resource[idx].start; 434 resource_size_t *dma = &dev->res.dma_resource[idx].start;
427 435
428 /* if the resource doesn't exist, don't complain about it */ 436 /* if the resource doesn't exist, don't complain about it */
429 if (cannot_compare(dev->res.dma_resource[idx].flags)) 437 if (cannot_compare(dev->res.dma_resource[idx].flags))
@@ -449,7 +457,7 @@ int pnp_check_dma(struct pnp_dev * dev, int idx)
449 457
450 /* check if the resource is already in use, skip if the 458 /* check if the resource is already in use, skip if the
451 * device is active because it itself may be in use */ 459 * device is active because it itself may be in use */
452 if(!dev->active) { 460 if (!dev->active) {
453 if (request_dma(*dma, "pnp")) 461 if (request_dma(*dma, "pnp"))
454 return 0; 462 return 0;
455 free_dma(*dma); 463 free_dma(*dma);
@@ -461,7 +469,8 @@ int pnp_check_dma(struct pnp_dev * dev, int idx)
461 continue; 469 continue;
462 for (tmp = 0; tmp < PNP_MAX_DMA; tmp++) { 470 for (tmp = 0; tmp < PNP_MAX_DMA; tmp++) {
463 if (tdev->res.dma_resource[tmp].flags & IORESOURCE_DMA) { 471 if (tdev->res.dma_resource[tmp].flags & IORESOURCE_DMA) {
464 if (cannot_compare(tdev->res.dma_resource[tmp].flags)) 472 if (cannot_compare
473 (tdev->res.dma_resource[tmp].flags))
465 continue; 474 continue;
466 if ((tdev->res.dma_resource[tmp].start == *dma)) 475 if ((tdev->res.dma_resource[tmp].start == *dma))
467 return 0; 476 return 0;
@@ -471,30 +480,18 @@ int pnp_check_dma(struct pnp_dev * dev, int idx)
471 480
472 return 1; 481 return 1;
473#else 482#else
474 /* IA64 hasn't legacy DMA */ 483 /* IA64 does not have legacy DMA */
475 return 0; 484 return 0;
476#endif 485#endif
477} 486}
478 487
479
480#if 0
481EXPORT_SYMBOL(pnp_register_dependent_option);
482EXPORT_SYMBOL(pnp_register_independent_option);
483EXPORT_SYMBOL(pnp_register_irq_resource);
484EXPORT_SYMBOL(pnp_register_dma_resource);
485EXPORT_SYMBOL(pnp_register_port_resource);
486EXPORT_SYMBOL(pnp_register_mem_resource);
487#endif /* 0 */
488
489
490/* format is: pnp_reserve_irq=irq1[,irq2] .... */ 488/* format is: pnp_reserve_irq=irq1[,irq2] .... */
491
492static int __init pnp_setup_reserve_irq(char *str) 489static int __init pnp_setup_reserve_irq(char *str)
493{ 490{
494 int i; 491 int i;
495 492
496 for (i = 0; i < 16; i++) 493 for (i = 0; i < 16; i++)
497 if (get_option(&str,&pnp_reserve_irq[i]) != 2) 494 if (get_option(&str, &pnp_reserve_irq[i]) != 2)
498 break; 495 break;
499 return 1; 496 return 1;
500} 497}
@@ -502,13 +499,12 @@ static int __init pnp_setup_reserve_irq(char *str)
502__setup("pnp_reserve_irq=", pnp_setup_reserve_irq); 499__setup("pnp_reserve_irq=", pnp_setup_reserve_irq);
503 500
504/* format is: pnp_reserve_dma=dma1[,dma2] .... */ 501/* format is: pnp_reserve_dma=dma1[,dma2] .... */
505
506static int __init pnp_setup_reserve_dma(char *str) 502static int __init pnp_setup_reserve_dma(char *str)
507{ 503{
508 int i; 504 int i;
509 505
510 for (i = 0; i < 8; i++) 506 for (i = 0; i < 8; i++)
511 if (get_option(&str,&pnp_reserve_dma[i]) != 2) 507 if (get_option(&str, &pnp_reserve_dma[i]) != 2)
512 break; 508 break;
513 return 1; 509 return 1;
514} 510}
@@ -516,13 +512,12 @@ static int __init pnp_setup_reserve_dma(char *str)
516__setup("pnp_reserve_dma=", pnp_setup_reserve_dma); 512__setup("pnp_reserve_dma=", pnp_setup_reserve_dma);
517 513
518/* format is: pnp_reserve_io=io1,size1[,io2,size2] .... */ 514/* format is: pnp_reserve_io=io1,size1[,io2,size2] .... */
519
520static int __init pnp_setup_reserve_io(char *str) 515static int __init pnp_setup_reserve_io(char *str)
521{ 516{
522 int i; 517 int i;
523 518
524 for (i = 0; i < 16; i++) 519 for (i = 0; i < 16; i++)
525 if (get_option(&str,&pnp_reserve_io[i]) != 2) 520 if (get_option(&str, &pnp_reserve_io[i]) != 2)
526 break; 521 break;
527 return 1; 522 return 1;
528} 523}
@@ -530,13 +525,12 @@ static int __init pnp_setup_reserve_io(char *str)
530__setup("pnp_reserve_io=", pnp_setup_reserve_io); 525__setup("pnp_reserve_io=", pnp_setup_reserve_io);
531 526
532/* format is: pnp_reserve_mem=mem1,size1[,mem2,size2] .... */ 527/* format is: pnp_reserve_mem=mem1,size1[,mem2,size2] .... */
533
534static int __init pnp_setup_reserve_mem(char *str) 528static int __init pnp_setup_reserve_mem(char *str)
535{ 529{
536 int i; 530 int i;
537 531
538 for (i = 0; i < 16; i++) 532 for (i = 0; i < 16; i++)
539 if (get_option(&str,&pnp_reserve_mem[i]) != 2) 533 if (get_option(&str, &pnp_reserve_mem[i]) != 2)
540 break; 534 break;
541 return 1; 535 return 1;
542} 536}
diff --git a/drivers/pnp/support.c b/drivers/pnp/support.c
index 946a0dcd627d..13c608f5fb30 100644
--- a/drivers/pnp/support.c
+++ b/drivers/pnp/support.c
@@ -1,8 +1,7 @@
1/* 1/*
2 * support.c - provides standard pnp functions for the use of pnp protocol drivers, 2 * support.c - standard functions for the use of pnp protocol drivers
3 * 3 *
4 * Copyright 2003 Adam Belay <ambx1@neo.rr.com> 4 * Copyright 2003 Adam Belay <ambx1@neo.rr.com>
5 *
6 */ 5 */
7 6
8#include <linux/module.h> 7#include <linux/module.h>
@@ -11,22 +10,18 @@
11#include "base.h" 10#include "base.h"
12 11
13/** 12/**
14 * pnp_is_active - Determines if a device is active based on its current resources 13 * pnp_is_active - Determines if a device is active based on its current
14 * resources
15 * @dev: pointer to the desired PnP device 15 * @dev: pointer to the desired PnP device
16 *
17 */ 16 */
18 17int pnp_is_active(struct pnp_dev *dev)
19int pnp_is_active(struct pnp_dev * dev)
20{ 18{
21 if (!pnp_port_start(dev, 0) && pnp_port_len(dev, 0) <= 1 && 19 if (!pnp_port_start(dev, 0) && pnp_port_len(dev, 0) <= 1 &&
22 !pnp_mem_start(dev, 0) && pnp_mem_len(dev, 0) <= 1 && 20 !pnp_mem_start(dev, 0) && pnp_mem_len(dev, 0) <= 1 &&
23 pnp_irq(dev, 0) == -1 && 21 pnp_irq(dev, 0) == -1 && pnp_dma(dev, 0) == -1)
24 pnp_dma(dev, 0) == -1) 22 return 0;
25 return 0;
26 else 23 else
27 return 1; 24 return 1;
28} 25}
29 26
30
31
32EXPORT_SYMBOL(pnp_is_active); 27EXPORT_SYMBOL(pnp_is_active);
diff --git a/drivers/pnp/system.c b/drivers/pnp/system.c
index a8a95540b1ef..a06f980b3ac9 100644
--- a/drivers/pnp/system.c
+++ b/drivers/pnp/system.c
@@ -16,13 +16,14 @@
16 16
17static const struct pnp_device_id pnp_dev_table[] = { 17static const struct pnp_device_id pnp_dev_table[] = {
18 /* General ID for reserving resources */ 18 /* General ID for reserving resources */
19 { "PNP0c02", 0 }, 19 {"PNP0c02", 0},
20 /* memory controller */ 20 /* memory controller */
21 { "PNP0c01", 0 }, 21 {"PNP0c01", 0},
22 { "", 0 } 22 {"", 0}
23}; 23};
24 24
25static void reserve_range(const char *pnpid, resource_size_t start, resource_size_t end, int port) 25static void reserve_range(const char *pnpid, resource_size_t start,
26 resource_size_t end, int port)
26{ 27{
27 struct resource *res; 28 struct resource *res;
28 char *regionid; 29 char *regionid;
@@ -32,9 +33,9 @@ static void reserve_range(const char *pnpid, resource_size_t start, resource_siz
32 return; 33 return;
33 snprintf(regionid, 16, "pnp %s", pnpid); 34 snprintf(regionid, 16, "pnp %s", pnpid);
34 if (port) 35 if (port)
35 res = request_region(start, end-start+1, regionid); 36 res = request_region(start, end - start + 1, regionid);
36 else 37 else
37 res = request_mem_region(start, end-start+1, regionid); 38 res = request_mem_region(start, end - start + 1, regionid);
38 if (res == NULL) 39 if (res == NULL)
39 kfree(regionid); 40 kfree(regionid);
40 else 41 else
@@ -44,11 +45,10 @@ static void reserve_range(const char *pnpid, resource_size_t start, resource_siz
44 * example do reserve stuff they know about too, so we may well 45 * example do reserve stuff they know about too, so we may well
45 * have double reservations. 46 * have double reservations.
46 */ 47 */
47 printk(KERN_INFO 48 printk(KERN_INFO "pnp: %s: %s range 0x%llx-0x%llx %s reserved\n",
48 "pnp: %s: %s range 0x%llx-0x%llx %s reserved\n", 49 pnpid, port ? "ioport" : "iomem",
49 pnpid, port ? "ioport" : "iomem", 50 (unsigned long long)start, (unsigned long long)end,
50 (unsigned long long)start, (unsigned long long)end, 51 NULL != res ? "has been" : "could not be");
51 NULL != res ? "has been" : "could not be");
52} 52}
53 53
54static void reserve_resources_of_dev(const struct pnp_dev *dev) 54static void reserve_resources_of_dev(const struct pnp_dev *dev)
@@ -74,7 +74,7 @@ static void reserve_resources_of_dev(const struct pnp_dev *dev)
74 continue; /* invalid */ 74 continue; /* invalid */
75 75
76 reserve_range(dev->dev.bus_id, pnp_port_start(dev, i), 76 reserve_range(dev->dev.bus_id, pnp_port_start(dev, i),
77 pnp_port_end(dev, i), 1); 77 pnp_port_end(dev, i), 1);
78 } 78 }
79 79
80 for (i = 0; i < PNP_MAX_MEM; i++) { 80 for (i = 0; i < PNP_MAX_MEM; i++) {
@@ -82,24 +82,22 @@ static void reserve_resources_of_dev(const struct pnp_dev *dev)
82 continue; 82 continue;
83 83
84 reserve_range(dev->dev.bus_id, pnp_mem_start(dev, i), 84 reserve_range(dev->dev.bus_id, pnp_mem_start(dev, i),
85 pnp_mem_end(dev, i), 0); 85 pnp_mem_end(dev, i), 0);
86 } 86 }
87
88 return;
89} 87}
90 88
91static int system_pnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id) 89static int system_pnp_probe(struct pnp_dev *dev,
90 const struct pnp_device_id *dev_id)
92{ 91{
93 reserve_resources_of_dev(dev); 92 reserve_resources_of_dev(dev);
94 return 0; 93 return 0;
95} 94}
96 95
97static struct pnp_driver system_pnp_driver = { 96static struct pnp_driver system_pnp_driver = {
98 .name = "system", 97 .name = "system",
99 .id_table = pnp_dev_table, 98 .id_table = pnp_dev_table,
100 .flags = PNP_DRIVER_RES_DO_NOT_CHANGE, 99 .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
101 .probe = system_pnp_probe, 100 .probe = system_pnp_probe,
102 .remove = NULL,
103}; 101};
104 102
105static int __init pnp_system_init(void) 103static int __init pnp_system_init(void)
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 7ede9e725360..d3a33aa2696f 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -15,34 +15,36 @@ rtc-core-$(CONFIG_RTC_INTF_DEV) += rtc-dev.o
15rtc-core-$(CONFIG_RTC_INTF_PROC) += rtc-proc.o 15rtc-core-$(CONFIG_RTC_INTF_PROC) += rtc-proc.o
16rtc-core-$(CONFIG_RTC_INTF_SYSFS) += rtc-sysfs.o 16rtc-core-$(CONFIG_RTC_INTF_SYSFS) += rtc-sysfs.o
17 17
18# Keep the list ordered.
19
20obj-$(CONFIG_RTC_DRV_AT32AP700X)+= rtc-at32ap700x.o
21obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o
22obj-$(CONFIG_RTC_DRV_BFIN) += rtc-bfin.o
18obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o 23obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o
19obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o 24obj-$(CONFIG_RTC_DRV_DS1216) += rtc-ds1216.o
20obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o
21obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o
22obj-$(CONFIG_RTC_DRV_AT32AP700X) += rtc-at32ap700x.o
23obj-$(CONFIG_RTC_DRV_DS1307) += rtc-ds1307.o 25obj-$(CONFIG_RTC_DRV_DS1307) += rtc-ds1307.o
26obj-$(CONFIG_RTC_DRV_DS1553) += rtc-ds1553.o
24obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o 27obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o
25obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o 28obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o
29obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o
30obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o
31obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o
32obj-$(CONFIG_RTC_DRV_M48T59) += rtc-m48t59.o
33obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o
34obj-$(CONFIG_RTC_DRV_MAX6900) += rtc-max6900.o
35obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o
26obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o 36obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o
27obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o 37obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o
28obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o 38obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o
39obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o
40obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o
41obj-$(CONFIG_RTC_DRV_RS5C348) += rtc-rs5c348.o
29obj-$(CONFIG_RTC_DRV_RS5C372) += rtc-rs5c372.o 42obj-$(CONFIG_RTC_DRV_RS5C372) += rtc-rs5c372.o
30obj-$(CONFIG_RTC_DRV_S3C) += rtc-s3c.o 43obj-$(CONFIG_RTC_DRV_S3C) += rtc-s3c.o
31obj-$(CONFIG_RTC_DRV_RS5C348) += rtc-rs5c348.o
32obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o
33obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o
34obj-$(CONFIG_RTC_DRV_DS1553) += rtc-ds1553.o
35obj-$(CONFIG_RTC_DRV_STK17TA8) += rtc-stk17ta8.o
36obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o
37obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o
38obj-$(CONFIG_RTC_DRV_SA1100) += rtc-sa1100.o 44obj-$(CONFIG_RTC_DRV_SA1100) += rtc-sa1100.o
39obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o
40obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o
41obj-$(CONFIG_RTC_DRV_MAX6900) += rtc-max6900.o
42obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o
43obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o
44obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o
45obj-$(CONFIG_RTC_DRV_SH) += rtc-sh.o 45obj-$(CONFIG_RTC_DRV_SH) += rtc-sh.o
46obj-$(CONFIG_RTC_DRV_BFIN) += rtc-bfin.o 46obj-$(CONFIG_RTC_DRV_STK17TA8) += rtc-stk17ta8.o
47obj-$(CONFIG_RTC_DRV_M48T59) += rtc-m48t59.o 47obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o
48obj-$(CONFIG_RTC_DRV_DS1216) += rtc-ds1216.o 48obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o
49obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o
50obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 8b3cd31d6a61..10ab3b71ffc6 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -46,6 +46,7 @@ static int rtc_suspend(struct device *dev, pm_message_t mesg)
46{ 46{
47 struct rtc_device *rtc = to_rtc_device(dev); 47 struct rtc_device *rtc = to_rtc_device(dev);
48 struct rtc_time tm; 48 struct rtc_time tm;
49 struct timespec ts = current_kernel_time();
49 50
50 if (strncmp(rtc->dev.bus_id, 51 if (strncmp(rtc->dev.bus_id,
51 CONFIG_RTC_HCTOSYS_DEVICE, 52 CONFIG_RTC_HCTOSYS_DEVICE,
@@ -57,8 +58,8 @@ static int rtc_suspend(struct device *dev, pm_message_t mesg)
57 58
58 /* RTC precision is 1 second; adjust delta for avg 1/2 sec err */ 59 /* RTC precision is 1 second; adjust delta for avg 1/2 sec err */
59 set_normalized_timespec(&delta, 60 set_normalized_timespec(&delta,
60 xtime.tv_sec - oldtime, 61 ts.tv_sec - oldtime,
61 xtime.tv_nsec - (NSEC_PER_SEC >> 1)); 62 ts.tv_nsec - (NSEC_PER_SEC >> 1));
62 63
63 return 0; 64 return 0;
64} 65}
diff --git a/drivers/rtc/rtc-bfin.c b/drivers/rtc/rtc-bfin.c
index 260ead959918..1aa709dda0d6 100644
--- a/drivers/rtc/rtc-bfin.c
+++ b/drivers/rtc/rtc-bfin.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Blackfin On-Chip Real Time Clock Driver 2 * Blackfin On-Chip Real Time Clock Driver
3 * Supports BF531/BF532/BF533/BF534/BF536/BF537 3 * Supports BF53[123]/BF53[467]/BF54[2489]
4 * 4 *
5 * Copyright 2004-2007 Analog Devices Inc. 5 * Copyright 2004-2007 Analog Devices Inc.
6 * 6 *
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 5158a625671f..db6f3f0d8982 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -352,7 +352,7 @@ read_rtc:
352 /* oscillator fault? clear flag, and warn */ 352 /* oscillator fault? clear flag, and warn */
353 if (ds1307->regs[DS1307_REG_CONTROL] & DS1338_BIT_OSF) { 353 if (ds1307->regs[DS1307_REG_CONTROL] & DS1338_BIT_OSF) {
354 i2c_smbus_write_byte_data(client, DS1307_REG_CONTROL, 354 i2c_smbus_write_byte_data(client, DS1307_REG_CONTROL,
355 ds1307->regs[DS1337_REG_CONTROL] 355 ds1307->regs[DS1307_REG_CONTROL]
356 & ~DS1338_BIT_OSF); 356 & ~DS1338_BIT_OSF);
357 dev_warn(&client->dev, "SET TIME!\n"); 357 dev_warn(&client->dev, "SET TIME!\n");
358 goto read_rtc; 358 goto read_rtc;
diff --git a/drivers/rtc/rtc-stk17ta8.c b/drivers/rtc/rtc-stk17ta8.c
index f10d3facecbe..8288b6b2bf2b 100644
--- a/drivers/rtc/rtc-stk17ta8.c
+++ b/drivers/rtc/rtc-stk17ta8.c
@@ -258,7 +258,8 @@ static const struct rtc_class_ops stk17ta8_rtc_ops = {
258 .ioctl = stk17ta8_rtc_ioctl, 258 .ioctl = stk17ta8_rtc_ioctl,
259}; 259};
260 260
261static ssize_t stk17ta8_nvram_read(struct kobject *kobj, char *buf, 261static ssize_t stk17ta8_nvram_read(struct kobject *kobj,
262 struct bin_attribute *attr, char *buf,
262 loff_t pos, size_t size) 263 loff_t pos, size_t size)
263{ 264{
264 struct platform_device *pdev = 265 struct platform_device *pdev =
@@ -272,7 +273,8 @@ static ssize_t stk17ta8_nvram_read(struct kobject *kobj, char *buf,
272 return count; 273 return count;
273} 274}
274 275
275static ssize_t stk17ta8_nvram_write(struct kobject *kobj, char *buf, 276static ssize_t stk17ta8_nvram_write(struct kobject *kobj,
277 struct bin_attribute *attr, char *buf,
276 loff_t pos, size_t size) 278 loff_t pos, size_t size)
277{ 279{
278 struct platform_device *pdev = 280 struct platform_device *pdev =
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index bfeca57098fa..e6bfce690ca3 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -1187,7 +1187,7 @@ dasd_end_request_cb(struct dasd_ccw_req * cqr, void *data)
1187static void 1187static void
1188__dasd_process_blk_queue(struct dasd_device * device) 1188__dasd_process_blk_queue(struct dasd_device * device)
1189{ 1189{
1190 request_queue_t *queue; 1190 struct request_queue *queue;
1191 struct request *req; 1191 struct request *req;
1192 struct dasd_ccw_req *cqr; 1192 struct dasd_ccw_req *cqr;
1193 int nr_queued; 1193 int nr_queued;
@@ -1740,7 +1740,7 @@ dasd_cancel_req(struct dasd_ccw_req *cqr)
1740 * Dasd request queue function. Called from ll_rw_blk.c 1740 * Dasd request queue function. Called from ll_rw_blk.c
1741 */ 1741 */
1742static void 1742static void
1743do_dasd_request(request_queue_t * queue) 1743do_dasd_request(struct request_queue * queue)
1744{ 1744{
1745 struct dasd_device *device; 1745 struct dasd_device *device;
1746 1746
diff --git a/drivers/s390/block/dasd_int.h b/drivers/s390/block/dasd_int.h
index 241294cba415..aeda52682446 100644
--- a/drivers/s390/block/dasd_int.h
+++ b/drivers/s390/block/dasd_int.h
@@ -293,7 +293,7 @@ struct dasd_uid {
293struct dasd_device { 293struct dasd_device {
294 /* Block device stuff. */ 294 /* Block device stuff. */
295 struct gendisk *gdp; 295 struct gendisk *gdp;
296 request_queue_t *request_queue; 296 struct request_queue *request_queue;
297 spinlock_t request_queue_lock; 297 spinlock_t request_queue_lock;
298 struct block_device *bdev; 298 struct block_device *bdev;
299 unsigned int devindex; 299 unsigned int devindex;
diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c
index 35765f6a86e0..4d8798bacf97 100644
--- a/drivers/s390/block/dcssblk.c
+++ b/drivers/s390/block/dcssblk.c
@@ -621,7 +621,7 @@ out:
621} 621}
622 622
623static int 623static int
624dcssblk_make_request(request_queue_t *q, struct bio *bio) 624dcssblk_make_request(struct request_queue *q, struct bio *bio)
625{ 625{
626 struct dcssblk_dev_info *dev_info; 626 struct dcssblk_dev_info *dev_info;
627 struct bio_vec *bvec; 627 struct bio_vec *bvec;
diff --git a/drivers/s390/block/xpram.c b/drivers/s390/block/xpram.c
index a04d9120cef0..354a060e5bec 100644
--- a/drivers/s390/block/xpram.c
+++ b/drivers/s390/block/xpram.c
@@ -191,7 +191,7 @@ static unsigned long __init xpram_highest_page_index(void)
191/* 191/*
192 * Block device make request function. 192 * Block device make request function.
193 */ 193 */
194static int xpram_make_request(request_queue_t *q, struct bio *bio) 194static int xpram_make_request(struct request_queue *q, struct bio *bio)
195{ 195{
196 xpram_device_t *xdev = bio->bi_bdev->bd_disk->private_data; 196 xpram_device_t *xdev = bio->bi_bdev->bd_disk->private_data;
197 struct bio_vec *bvec; 197 struct bio_vec *bvec;
diff --git a/drivers/s390/char/Kconfig b/drivers/s390/char/Kconfig
index 3f36cb3910ee..643033890e34 100644
--- a/drivers/s390/char/Kconfig
+++ b/drivers/s390/char/Kconfig
@@ -44,15 +44,9 @@ config CCW_CONSOLE
44 depends on TN3215_CONSOLE || TN3270_CONSOLE 44 depends on TN3215_CONSOLE || TN3270_CONSOLE
45 default y 45 default y
46 46
47config SCLP
48 bool "Support for SCLP"
49 depends on S390
50 help
51 Include support for the SCLP interface to the service element.
52
53config SCLP_TTY 47config SCLP_TTY
54 bool "Support for SCLP line mode terminal" 48 bool "Support for SCLP line mode terminal"
55 depends on SCLP 49 depends on S390
56 help 50 help
57 Include support for IBM SCLP line-mode terminals. 51 Include support for IBM SCLP line-mode terminals.
58 52
@@ -65,7 +59,7 @@ config SCLP_CONSOLE
65 59
66config SCLP_VT220_TTY 60config SCLP_VT220_TTY
67 bool "Support for SCLP VT220-compatible terminal" 61 bool "Support for SCLP VT220-compatible terminal"
68 depends on SCLP 62 depends on S390
69 help 63 help
70 Include support for an IBM SCLP VT220-compatible terminal. 64 Include support for an IBM SCLP VT220-compatible terminal.
71 65
@@ -78,7 +72,7 @@ config SCLP_VT220_CONSOLE
78 72
79config SCLP_CPI 73config SCLP_CPI
80 tristate "Control-Program Identification" 74 tristate "Control-Program Identification"
81 depends on SCLP 75 depends on S390
82 help 76 help
83 This option enables the hardware console interface for system 77 This option enables the hardware console interface for system
84 identification. This is commonly used for workload management and 78 identification. This is commonly used for workload management and
diff --git a/drivers/s390/char/raw3270.c b/drivers/s390/char/raw3270.c
index 743944ad61ec..4f2f81b16cfa 100644
--- a/drivers/s390/char/raw3270.c
+++ b/drivers/s390/char/raw3270.c
@@ -147,8 +147,7 @@ raw3270_request_alloc(size_t size)
147 * Allocate a new 3270 ccw request from bootmem. Only works very 147 * Allocate a new 3270 ccw request from bootmem. Only works very
148 * early in the boot process. Only con3270.c should be using this. 148 * early in the boot process. Only con3270.c should be using this.
149 */ 149 */
150struct raw3270_request * 150struct raw3270_request __init *raw3270_request_alloc_bootmem(size_t size)
151raw3270_request_alloc_bootmem(size_t size)
152{ 151{
153 struct raw3270_request *rq; 152 struct raw3270_request *rq;
154 153
@@ -848,8 +847,7 @@ raw3270_setup_device(struct ccw_device *cdev, struct raw3270 *rp, char *ascebc)
848/* 847/*
849 * Setup 3270 device configured as console. 848 * Setup 3270 device configured as console.
850 */ 849 */
851struct raw3270 * 850struct raw3270 __init *raw3270_setup_console(struct ccw_device *cdev)
852raw3270_setup_console(struct ccw_device *cdev)
853{ 851{
854 struct raw3270 *rp; 852 struct raw3270 *rp;
855 char *ascebc; 853 char *ascebc;
diff --git a/drivers/s390/char/sclp_vt220.c b/drivers/s390/char/sclp_vt220.c
index 726334757bbf..40cd21bc5cc4 100644
--- a/drivers/s390/char/sclp_vt220.c
+++ b/drivers/s390/char/sclp_vt220.c
@@ -621,11 +621,24 @@ sclp_vt220_flush_buffer(struct tty_struct *tty)
621/* 621/*
622 * Initialize all relevant components and register driver with system. 622 * Initialize all relevant components and register driver with system.
623 */ 623 */
624static int 624static void __init __sclp_vt220_cleanup(void)
625__sclp_vt220_init(int early) 625{
626 struct list_head *page, *p;
627
628 list_for_each_safe(page, p, &sclp_vt220_empty) {
629 list_del(page);
630 if (slab_is_available())
631 free_page((unsigned long) page);
632 else
633 free_bootmem((unsigned long) page, PAGE_SIZE);
634 }
635}
636
637static int __init __sclp_vt220_init(void)
626{ 638{
627 void *page; 639 void *page;
628 int i; 640 int i;
641 int num_pages;
629 642
630 if (sclp_vt220_initialized) 643 if (sclp_vt220_initialized)
631 return 0; 644 return 0;
@@ -642,13 +655,16 @@ __sclp_vt220_init(int early)
642 sclp_vt220_flush_later = 0; 655 sclp_vt220_flush_later = 0;
643 656
644 /* Allocate pages for output buffering */ 657 /* Allocate pages for output buffering */
645 for (i = 0; i < (early ? MAX_CONSOLE_PAGES : MAX_KMEM_PAGES); i++) { 658 num_pages = slab_is_available() ? MAX_KMEM_PAGES : MAX_CONSOLE_PAGES;
646 if (early) 659 for (i = 0; i < num_pages; i++) {
647 page = alloc_bootmem_low_pages(PAGE_SIZE); 660 if (slab_is_available())
648 else
649 page = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA); 661 page = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
650 if (!page) 662 else
663 page = alloc_bootmem_low_pages(PAGE_SIZE);
664 if (!page) {
665 __sclp_vt220_cleanup();
651 return -ENOMEM; 666 return -ENOMEM;
667 }
652 list_add_tail((struct list_head *) page, &sclp_vt220_empty); 668 list_add_tail((struct list_head *) page, &sclp_vt220_empty);
653 } 669 }
654 return 0; 670 return 0;
@@ -662,14 +678,13 @@ static const struct tty_operations sclp_vt220_ops = {
662 .flush_chars = sclp_vt220_flush_chars, 678 .flush_chars = sclp_vt220_flush_chars,
663 .write_room = sclp_vt220_write_room, 679 .write_room = sclp_vt220_write_room,
664 .chars_in_buffer = sclp_vt220_chars_in_buffer, 680 .chars_in_buffer = sclp_vt220_chars_in_buffer,
665 .flush_buffer = sclp_vt220_flush_buffer 681 .flush_buffer = sclp_vt220_flush_buffer,
666}; 682};
667 683
668/* 684/*
669 * Register driver with SCLP and Linux and initialize internal tty structures. 685 * Register driver with SCLP and Linux and initialize internal tty structures.
670 */ 686 */
671static int __init 687static int __init sclp_vt220_tty_init(void)
672sclp_vt220_tty_init(void)
673{ 688{
674 struct tty_driver *driver; 689 struct tty_driver *driver;
675 int rc; 690 int rc;
@@ -679,18 +694,15 @@ sclp_vt220_tty_init(void)
679 driver = alloc_tty_driver(1); 694 driver = alloc_tty_driver(1);
680 if (!driver) 695 if (!driver)
681 return -ENOMEM; 696 return -ENOMEM;
682 rc = __sclp_vt220_init(0); 697 rc = __sclp_vt220_init();
683 if (rc) { 698 if (rc)
684 put_tty_driver(driver); 699 goto out_driver;
685 return rc;
686 }
687 rc = sclp_register(&sclp_vt220_register); 700 rc = sclp_register(&sclp_vt220_register);
688 if (rc) { 701 if (rc) {
689 printk(KERN_ERR SCLP_VT220_PRINT_HEADER 702 printk(KERN_ERR SCLP_VT220_PRINT_HEADER
690 "could not register tty - " 703 "could not register tty - "
691 "sclp_register returned %d\n", rc); 704 "sclp_register returned %d\n", rc);
692 put_tty_driver(driver); 705 goto out_init;
693 return rc;
694 } 706 }
695 707
696 driver->owner = THIS_MODULE; 708 driver->owner = THIS_MODULE;
@@ -709,14 +721,20 @@ sclp_vt220_tty_init(void)
709 printk(KERN_ERR SCLP_VT220_PRINT_HEADER 721 printk(KERN_ERR SCLP_VT220_PRINT_HEADER
710 "could not register tty - " 722 "could not register tty - "
711 "tty_register_driver returned %d\n", rc); 723 "tty_register_driver returned %d\n", rc);
712 put_tty_driver(driver); 724 goto out_sclp;
713 return rc;
714 } 725 }
715 sclp_vt220_driver = driver; 726 sclp_vt220_driver = driver;
716 return 0; 727 return 0;
717}
718 728
719module_init(sclp_vt220_tty_init); 729out_sclp:
730 sclp_unregister(&sclp_vt220_register);
731out_init:
732 __sclp_vt220_cleanup();
733out_driver:
734 put_tty_driver(driver);
735 return rc;
736}
737__initcall(sclp_vt220_tty_init);
720 738
721#ifdef CONFIG_SCLP_VT220_CONSOLE 739#ifdef CONFIG_SCLP_VT220_CONSOLE
722 740
@@ -762,7 +780,7 @@ sclp_vt220_con_init(void)
762 780
763 if (!CONSOLE_IS_SCLP) 781 if (!CONSOLE_IS_SCLP)
764 return 0; 782 return 0;
765 rc = __sclp_vt220_init(1); 783 rc = __sclp_vt220_init();
766 if (rc) 784 if (rc)
767 return rc; 785 return rc;
768 /* Attach linux console */ 786 /* Attach linux console */
diff --git a/drivers/s390/char/tape.h b/drivers/s390/char/tape.h
index 3b52f5c1dbef..dddf8d62c153 100644
--- a/drivers/s390/char/tape.h
+++ b/drivers/s390/char/tape.h
@@ -188,7 +188,7 @@ struct tape_blk_data
188{ 188{
189 struct tape_device * device; 189 struct tape_device * device;
190 /* Block device request queue. */ 190 /* Block device request queue. */
191 request_queue_t * request_queue; 191 struct request_queue * request_queue;
192 spinlock_t request_queue_lock; 192 spinlock_t request_queue_lock;
193 193
194 /* Task to move entries from block request to CCS request queue. */ 194 /* Task to move entries from block request to CCS request queue. */
diff --git a/drivers/s390/char/tape_block.c b/drivers/s390/char/tape_block.c
index dd0ecaed592e..eeb92e2ed0cc 100644
--- a/drivers/s390/char/tape_block.c
+++ b/drivers/s390/char/tape_block.c
@@ -147,7 +147,7 @@ static void
147tapeblock_requeue(struct work_struct *work) { 147tapeblock_requeue(struct work_struct *work) {
148 struct tape_blk_data * blkdat; 148 struct tape_blk_data * blkdat;
149 struct tape_device * device; 149 struct tape_device * device;
150 request_queue_t * queue; 150 struct request_queue * queue;
151 int nr_queued; 151 int nr_queued;
152 struct request * req; 152 struct request * req;
153 struct list_head * l; 153 struct list_head * l;
@@ -194,7 +194,7 @@ tapeblock_requeue(struct work_struct *work) {
194 * Tape request queue function. Called from ll_rw_blk.c 194 * Tape request queue function. Called from ll_rw_blk.c
195 */ 195 */
196static void 196static void
197tapeblock_request_fn(request_queue_t *queue) 197tapeblock_request_fn(struct request_queue *queue)
198{ 198{
199 struct tape_device *device; 199 struct tape_device *device;
200 200
diff --git a/drivers/s390/char/vmur.c b/drivers/s390/char/vmur.c
index e90b0f846195..161867cebd8c 100644
--- a/drivers/s390/char/vmur.c
+++ b/drivers/s390/char/vmur.c
@@ -486,7 +486,7 @@ static ssize_t diag14_read(struct file *file, char __user *ubuf, size_t count,
486 } 486 }
487 if (rc) 487 if (rc)
488 goto fail; 488 goto fail;
489 if (reclen) 489 if (reclen && (copied == 0) && (*offs < PAGE_SIZE))
490 *((u16 *) &buf[FILE_RECLEN_OFFSET]) = reclen; 490 *((u16 *) &buf[FILE_RECLEN_OFFSET]) = reclen;
491 len = min(count - copied, PAGE_SIZE - res); 491 len = min(count - copied, PAGE_SIZE - res);
492 if (copy_to_user(ubuf + copied, buf + res, len)) { 492 if (copy_to_user(ubuf + copied, buf + res, len)) {
diff --git a/drivers/s390/cio/blacklist.c b/drivers/s390/cio/blacklist.c
index ec0404874fad..bd5f16f80bf8 100644
--- a/drivers/s390/cio/blacklist.c
+++ b/drivers/s390/cio/blacklist.c
@@ -51,7 +51,7 @@ blacklist_range (range_action action, unsigned int from, unsigned int to,
51 to = from; 51 to = from;
52 52
53 if (from > to || to > __MAX_SUBCHANNEL || ssid > __MAX_SSID) { 53 if (from > to || to > __MAX_SUBCHANNEL || ssid > __MAX_SSID) {
54 printk (KERN_WARNING "Invalid blacklist range " 54 printk (KERN_WARNING "cio: Invalid blacklist range "
55 "0.%x.%04x to 0.%x.%04x, skipping\n", 55 "0.%x.%04x to 0.%x.%04x, skipping\n",
56 ssid, from, ssid, to); 56 ssid, from, ssid, to);
57 return; 57 return;
@@ -119,7 +119,7 @@ blacklist_busid(char **str, int *id0, int *ssid, int *devno)
119 return 0; 119 return 0;
120confused: 120confused:
121 strsep(str, ",\n"); 121 strsep(str, ",\n");
122 printk(KERN_WARNING "Invalid cio_ignore parameter '%s'\n", sav); 122 printk(KERN_WARNING "cio: Invalid cio_ignore parameter '%s'\n", sav);
123 return 1; 123 return 1;
124} 124}
125 125
@@ -166,22 +166,19 @@ blacklist_parse_parameters (char *str, range_action action)
166 continue; 166 continue;
167 } 167 }
168 if (*str == '-') { 168 if (*str == '-') {
169 printk(KERN_WARNING "invalid cio_ignore " 169 printk(KERN_WARNING "cio: invalid cio_ignore "
170 "parameter '%s'\n", 170 "parameter '%s'\n",
171 strsep(&str, ",\n")); 171 strsep(&str, ",\n"));
172 continue; 172 continue;
173 } 173 }
174 if ((from_id0 != to_id0) || 174 if ((from_id0 != to_id0) ||
175 (from_ssid != to_ssid)) { 175 (from_ssid != to_ssid)) {
176 printk(KERN_WARNING "invalid cio_ignore range " 176 printk(KERN_WARNING "cio: invalid cio_ignore "
177 "%x.%x.%04x-%x.%x.%04x\n", 177 "range %x.%x.%04x-%x.%x.%04x\n",
178 from_id0, from_ssid, from, 178 from_id0, from_ssid, from,
179 to_id0, to_ssid, to); 179 to_id0, to_ssid, to);
180 continue; 180 continue;
181 } 181 }
182 pr_debug("blacklist_setup: adding range "
183 "from %x.%x.%04x to %x.%x.%04x\n",
184 from_id0, from_ssid, from, to_id0, to_ssid, to);
185 blacklist_range (ra, from, to, to_ssid); 182 blacklist_range (ra, from, to, to_ssid);
186 } 183 }
187 } 184 }
@@ -239,7 +236,7 @@ blacklist_parse_proc_parameters (char *buf)
239 */ 236 */
240 blacklist_parse_parameters (buf + 4, add); 237 blacklist_parse_parameters (buf + 4, add);
241 } else { 238 } else {
242 printk (KERN_WARNING "cio_ignore: Parse error; \n" 239 printk (KERN_WARNING "cio: cio_ignore: Parse error; \n"
243 KERN_WARNING "try using 'free all|<devno-range>," 240 KERN_WARNING "try using 'free all|<devno-range>,"
244 "<devno-range>,...'\n" 241 "<devno-range>,...'\n"
245 KERN_WARNING "or 'add <devno-range>," 242 KERN_WARNING "or 'add <devno-range>,"
diff --git a/drivers/s390/cio/ccwgroup.c b/drivers/s390/cio/ccwgroup.c
index e5ccda63e883..b0a18f5176aa 100644
--- a/drivers/s390/cio/ccwgroup.c
+++ b/drivers/s390/cio/ccwgroup.c
@@ -359,7 +359,6 @@ ccwgroup_probe (struct device *dev)
359 if ((ret = device_create_file(dev, &dev_attr_online))) 359 if ((ret = device_create_file(dev, &dev_attr_online)))
360 return ret; 360 return ret;
361 361
362 pr_debug("%s: device %s\n", __func__, gdev->dev.bus_id);
363 ret = gdrv->probe ? gdrv->probe(gdev) : -ENODEV; 362 ret = gdrv->probe ? gdrv->probe(gdev) : -ENODEV;
364 if (ret) 363 if (ret)
365 device_remove_file(dev, &dev_attr_online); 364 device_remove_file(dev, &dev_attr_online);
@@ -376,8 +375,6 @@ ccwgroup_remove (struct device *dev)
376 gdev = to_ccwgroupdev(dev); 375 gdev = to_ccwgroupdev(dev);
377 gdrv = to_ccwgroupdrv(dev->driver); 376 gdrv = to_ccwgroupdrv(dev->driver);
378 377
379 pr_debug("%s: device %s\n", __func__, gdev->dev.bus_id);
380
381 device_remove_file(dev, &dev_attr_online); 378 device_remove_file(dev, &dev_attr_online);
382 379
383 if (gdrv && gdrv->remove) 380 if (gdrv && gdrv->remove)
diff --git a/drivers/s390/cio/chp.c b/drivers/s390/cio/chp.c
index b57d93d986c0..920dd71e6434 100644
--- a/drivers/s390/cio/chp.c
+++ b/drivers/s390/cio/chp.c
@@ -121,14 +121,8 @@ static int s390_vary_chpid(struct chp_id chpid, int on)
121 CIO_TRACE_EVENT( 2, dbf_text); 121 CIO_TRACE_EVENT( 2, dbf_text);
122 122
123 status = chp_get_status(chpid); 123 status = chp_get_status(chpid);
124 if (status < 0) {
125 printk(KERN_ERR "Can't vary unknown chpid %x.%02x\n",
126 chpid.cssid, chpid.id);
127 return -EINVAL;
128 }
129
130 if (!on && !status) { 124 if (!on && !status) {
131 printk(KERN_ERR "chpid %x.%02x is already offline\n", 125 printk(KERN_ERR "cio: chpid %x.%02x is already offline\n",
132 chpid.cssid, chpid.id); 126 chpid.cssid, chpid.id);
133 return -EINVAL; 127 return -EINVAL;
134 } 128 }
@@ -421,21 +415,14 @@ int chp_new(struct chp_id chpid)
421 if (ret) 415 if (ret)
422 goto out_free; 416 goto out_free;
423 } else { 417 } else {
424 static int msg_done;
425
426 if (!msg_done) {
427 printk(KERN_WARNING "cio: Channel measurements not "
428 "available, continuing.\n");
429 msg_done = 1;
430 }
431 chp->cmg = -1; 418 chp->cmg = -1;
432 } 419 }
433 420
434 /* make it known to the system */ 421 /* make it known to the system */
435 ret = device_register(&chp->dev); 422 ret = device_register(&chp->dev);
436 if (ret) { 423 if (ret) {
437 printk(KERN_WARNING "%s: could not register %x.%02x\n", 424 CIO_MSG_EVENT(0, "Could not register chp%x.%02x: %d\n",
438 __func__, chpid.cssid, chpid.id); 425 chpid.cssid, chpid.id, ret);
439 goto out_free; 426 goto out_free;
440 } 427 }
441 ret = sysfs_create_group(&chp->dev.kobj, &chp_attr_group); 428 ret = sysfs_create_group(&chp->dev.kobj, &chp_attr_group);
diff --git a/drivers/s390/cio/chsc.c b/drivers/s390/cio/chsc.c
index ea92ac4d6577..597c0c76a2ad 100644
--- a/drivers/s390/cio/chsc.c
+++ b/drivers/s390/cio/chsc.c
@@ -990,16 +990,20 @@ out:
990 return ret; 990 return ret;
991} 991}
992 992
993static int __init 993int __init chsc_alloc_sei_area(void)
994chsc_alloc_sei_area(void)
995{ 994{
996 sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA); 995 sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
997 if (!sei_page) 996 if (!sei_page)
998 printk(KERN_WARNING"Can't allocate page for processing of " \ 997 CIO_MSG_EVENT(0, "Can't allocate page for processing of "
999 "chsc machine checks!\n"); 998 "chsc machine checks!\n");
1000 return (sei_page ? 0 : -ENOMEM); 999 return (sei_page ? 0 : -ENOMEM);
1001} 1000}
1002 1001
1002void __init chsc_free_sei_area(void)
1003{
1004 kfree(sei_page);
1005}
1006
1003int __init 1007int __init
1004chsc_enable_facility(int operation_code) 1008chsc_enable_facility(int operation_code)
1005{ 1009{
@@ -1051,8 +1055,6 @@ chsc_enable_facility(int operation_code)
1051 return ret; 1055 return ret;
1052} 1056}
1053 1057
1054subsys_initcall(chsc_alloc_sei_area);
1055
1056struct css_general_char css_general_characteristics; 1058struct css_general_char css_general_characteristics;
1057struct css_chsc_char css_chsc_characteristics; 1059struct css_chsc_char css_chsc_characteristics;
1058 1060
@@ -1073,8 +1075,8 @@ chsc_determine_css_characteristics(void)
1073 1075
1074 scsc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA); 1076 scsc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1075 if (!scsc_area) { 1077 if (!scsc_area) {
1076 printk(KERN_WARNING"cio: Was not able to determine available" \ 1078 CIO_MSG_EVENT(0, "Was not able to determine available"
1077 "CHSCs due to no memory.\n"); 1079 "CHSCs due to no memory.\n");
1078 return -ENOMEM; 1080 return -ENOMEM;
1079 } 1081 }
1080 1082
@@ -1083,15 +1085,15 @@ chsc_determine_css_characteristics(void)
1083 1085
1084 result = chsc(scsc_area); 1086 result = chsc(scsc_area);
1085 if (result) { 1087 if (result) {
1086 printk(KERN_WARNING"cio: Was not able to determine " \ 1088 CIO_MSG_EVENT(0, "Was not able to determine available CHSCs, "
1087 "available CHSCs, cc=%i.\n", result); 1089 "cc=%i.\n", result);
1088 result = -EIO; 1090 result = -EIO;
1089 goto exit; 1091 goto exit;
1090 } 1092 }
1091 1093
1092 if (scsc_area->response.code != 1) { 1094 if (scsc_area->response.code != 1) {
1093 printk(KERN_WARNING"cio: Was not able to determine " \ 1095 CIO_MSG_EVENT(0, "Was not able to determine "
1094 "available CHSCs.\n"); 1096 "available CHSCs.\n");
1095 result = -EIO; 1097 result = -EIO;
1096 goto exit; 1098 goto exit;
1097 } 1099 }
diff --git a/drivers/s390/cio/chsc.h b/drivers/s390/cio/chsc.h
index 2ad81d11cf7b..d1f5db1e69b9 100644
--- a/drivers/s390/cio/chsc.h
+++ b/drivers/s390/cio/chsc.h
@@ -79,6 +79,8 @@ extern int chsc_get_ssd_info(struct subchannel_id schid,
79 struct chsc_ssd_info *ssd); 79 struct chsc_ssd_info *ssd);
80extern int chsc_determine_css_characteristics(void); 80extern int chsc_determine_css_characteristics(void);
81extern int css_characteristics_avail; 81extern int css_characteristics_avail;
82extern int chsc_alloc_sei_area(void);
83extern void chsc_free_sei_area(void);
82 84
83extern int chsc_enable_facility(int); 85extern int chsc_enable_facility(int);
84struct channel_subsystem; 86struct channel_subsystem;
diff --git a/drivers/s390/cio/cio.c b/drivers/s390/cio/cio.c
index ea1defba5693..f2708d65be5a 100644
--- a/drivers/s390/cio/cio.c
+++ b/drivers/s390/cio/cio.c
@@ -47,8 +47,8 @@ cio_setup (char *parm)
47 else if (!strcmp (parm, "no")) 47 else if (!strcmp (parm, "no"))
48 cio_show_msg = 0; 48 cio_show_msg = 0;
49 else 49 else
50 printk (KERN_ERR "cio_setup : invalid cio_msg parameter '%s'", 50 printk(KERN_ERR "cio: cio_setup: "
51 parm); 51 "invalid cio_msg parameter '%s'", parm);
52 return 1; 52 return 1;
53} 53}
54 54
@@ -80,7 +80,6 @@ cio_debug_init (void)
80 goto out_unregister; 80 goto out_unregister;
81 debug_register_view (cio_debug_crw_id, &debug_sprintf_view); 81 debug_register_view (cio_debug_crw_id, &debug_sprintf_view);
82 debug_set_level (cio_debug_crw_id, 2); 82 debug_set_level (cio_debug_crw_id, 2);
83 pr_debug("debugging initialized\n");
84 return 0; 83 return 0;
85 84
86out_unregister: 85out_unregister:
@@ -90,7 +89,7 @@ out_unregister:
90 debug_unregister (cio_debug_trace_id); 89 debug_unregister (cio_debug_trace_id);
91 if (cio_debug_crw_id) 90 if (cio_debug_crw_id)
92 debug_unregister (cio_debug_crw_id); 91 debug_unregister (cio_debug_crw_id);
93 pr_debug("could not initialize debugging\n"); 92 printk(KERN_WARNING"cio: could not initialize debugging\n");
94 return -1; 93 return -1;
95} 94}
96 95
@@ -568,7 +567,7 @@ cio_validate_subchannel (struct subchannel *sch, struct subchannel_id schid)
568 */ 567 */
569 if (sch->st != 0) { 568 if (sch->st != 0) {
570 CIO_DEBUG(KERN_INFO, 0, 569 CIO_DEBUG(KERN_INFO, 0,
571 "Subchannel 0.%x.%04x reports " 570 "cio: Subchannel 0.%x.%04x reports "
572 "non-I/O subchannel type %04X\n", 571 "non-I/O subchannel type %04X\n",
573 sch->schid.ssid, sch->schid.sch_no, sch->st); 572 sch->schid.ssid, sch->schid.sch_no, sch->st);
574 /* We stop here for non-io subchannels. */ 573 /* We stop here for non-io subchannels. */
@@ -601,7 +600,7 @@ cio_validate_subchannel (struct subchannel *sch, struct subchannel_id schid)
601 sch->lpm = sch->schib.pmcw.pam & sch->opm; 600 sch->lpm = sch->schib.pmcw.pam & sch->opm;
602 601
603 CIO_DEBUG(KERN_INFO, 0, 602 CIO_DEBUG(KERN_INFO, 0,
604 "Detected device %04x on subchannel 0.%x.%04X" 603 "cio: Detected device %04x on subchannel 0.%x.%04X"
605 " - PIM = %02X, PAM = %02X, POM = %02X\n", 604 " - PIM = %02X, PAM = %02X, POM = %02X\n",
606 sch->schib.pmcw.dev, sch->schid.ssid, 605 sch->schib.pmcw.dev, sch->schid.ssid,
607 sch->schid.sch_no, sch->schib.pmcw.pim, 606 sch->schid.sch_no, sch->schib.pmcw.pim,
@@ -766,7 +765,7 @@ cio_get_console_sch_no(void)
766 /* unlike in 2.4, we cannot autoprobe here, since 765 /* unlike in 2.4, we cannot autoprobe here, since
767 * the channel subsystem is not fully initialized. 766 * the channel subsystem is not fully initialized.
768 * With some luck, the HWC console can take over */ 767 * With some luck, the HWC console can take over */
769 printk(KERN_WARNING "No ccw console found!\n"); 768 printk(KERN_WARNING "cio: No ccw console found!\n");
770 return -1; 769 return -1;
771 } 770 }
772 return console_irq; 771 return console_irq;
diff --git a/drivers/s390/cio/cio_debug.h b/drivers/s390/cio/cio_debug.h
index f88844adae1b..c9bf8989930f 100644
--- a/drivers/s390/cio/cio_debug.h
+++ b/drivers/s390/cio/cio_debug.h
@@ -23,6 +23,8 @@ extern debug_info_t *cio_debug_crw_id;
23static inline void 23static inline void
24CIO_HEX_EVENT(int level, void *data, int length) 24CIO_HEX_EVENT(int level, void *data, int length)
25{ 25{
26 if (unlikely(!cio_debug_trace_id))
27 return;
26 while (length > 0) { 28 while (length > 0) {
27 debug_event(cio_debug_trace_id, level, data, length); 29 debug_event(cio_debug_trace_id, level, data, length);
28 length -= cio_debug_trace_id->buf_size; 30 length -= cio_debug_trace_id->buf_size;
diff --git a/drivers/s390/cio/cmf.c b/drivers/s390/cio/cmf.c
index 28abd697be1a..02fd00b55e1b 100644
--- a/drivers/s390/cio/cmf.c
+++ b/drivers/s390/cio/cmf.c
@@ -1185,12 +1185,12 @@ static ssize_t cmb_enable_store(struct device *dev, struct device_attribute *att
1185 case '0': 1185 case '0':
1186 ret = disable_cmf(cdev); 1186 ret = disable_cmf(cdev);
1187 if (ret) 1187 if (ret)
1188 printk(KERN_INFO "disable_cmf failed (%d)\n", ret); 1188 dev_info(&cdev->dev, "disable_cmf failed (%d)\n", ret);
1189 break; 1189 break;
1190 case '1': 1190 case '1':
1191 ret = enable_cmf(cdev); 1191 ret = enable_cmf(cdev);
1192 if (ret && ret != -EBUSY) 1192 if (ret && ret != -EBUSY)
1193 printk(KERN_INFO "enable_cmf failed (%d)\n", ret); 1193 dev_info(&cdev->dev, "enable_cmf failed (%d)\n", ret);
1194 break; 1194 break;
1195 } 1195 }
1196 1196
@@ -1280,10 +1280,10 @@ init_cmf(void)
1280 format_string = "basic"; 1280 format_string = "basic";
1281 cmbops = &cmbops_basic; 1281 cmbops = &cmbops_basic;
1282 if (cmb_area.num_channels > 4096 || cmb_area.num_channels < 1) { 1282 if (cmb_area.num_channels > 4096 || cmb_area.num_channels < 1) {
1283 printk(KERN_ERR "Basic channel measurement facility" 1283 printk(KERN_ERR "cio: Basic channel measurement "
1284 " can only use 1 to 4096 devices\n" 1284 "facility can only use 1 to 4096 devices\n"
1285 KERN_ERR "when the cmf driver is built" 1285 KERN_ERR "when the cmf driver is built"
1286 " as a loadable module\n"); 1286 " as a loadable module\n");
1287 return 1; 1287 return 1;
1288 } 1288 }
1289 break; 1289 break;
@@ -1292,13 +1292,13 @@ init_cmf(void)
1292 cmbops = &cmbops_extended; 1292 cmbops = &cmbops_extended;
1293 break; 1293 break;
1294 default: 1294 default:
1295 printk(KERN_ERR "Invalid format %d for channel " 1295 printk(KERN_ERR "cio: Invalid format %d for channel "
1296 "measurement facility\n", format); 1296 "measurement facility\n", format);
1297 return 1; 1297 return 1;
1298 } 1298 }
1299 1299
1300 printk(KERN_INFO "Channel measurement facility using %s format (%s)\n", 1300 printk(KERN_INFO "cio: Channel measurement facility using %s "
1301 format_string, detect_string); 1301 "format (%s)\n", format_string, detect_string);
1302 return 0; 1302 return 0;
1303} 1303}
1304 1304
diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c
index dfca0ef139fd..1c27a5a06b49 100644
--- a/drivers/s390/cio/css.c
+++ b/drivers/s390/cio/css.c
@@ -109,7 +109,7 @@ css_subchannel_release(struct device *dev)
109 } 109 }
110} 110}
111 111
112int css_sch_device_register(struct subchannel *sch) 112static int css_sch_device_register(struct subchannel *sch)
113{ 113{
114 int ret; 114 int ret;
115 115
@@ -184,8 +184,8 @@ static int css_register_subchannel(struct subchannel *sch)
184 /* make it known to the system */ 184 /* make it known to the system */
185 ret = css_sch_device_register(sch); 185 ret = css_sch_device_register(sch);
186 if (ret) { 186 if (ret) {
187 printk (KERN_WARNING "%s: could not register %s\n", 187 CIO_MSG_EVENT(0, "Could not register sch 0.%x.%04x: %d\n",
188 __func__, sch->dev.bus_id); 188 sch->schid.ssid, sch->schid.sch_no, ret);
189 return ret; 189 return ret;
190 } 190 }
191 return ret; 191 return ret;
@@ -371,15 +371,12 @@ static int __init slow_subchannel_init(void)
371 spin_lock_init(&slow_subchannel_lock); 371 spin_lock_init(&slow_subchannel_lock);
372 slow_subchannel_set = idset_sch_new(); 372 slow_subchannel_set = idset_sch_new();
373 if (!slow_subchannel_set) { 373 if (!slow_subchannel_set) {
374 printk(KERN_WARNING "cio: could not allocate slow subchannel " 374 CIO_MSG_EVENT(0, "could not allocate slow subchannel set\n");
375 "set\n");
376 return -ENOMEM; 375 return -ENOMEM;
377 } 376 }
378 return 0; 377 return 0;
379} 378}
380 379
381subsys_initcall(slow_subchannel_init);
382
383static void css_slow_path_func(struct work_struct *unused) 380static void css_slow_path_func(struct work_struct *unused)
384{ 381{
385 struct subchannel_id schid; 382 struct subchannel_id schid;
@@ -425,8 +422,8 @@ static int reprobe_subchannel(struct subchannel_id schid, void *data)
425 struct subchannel *sch; 422 struct subchannel *sch;
426 int ret; 423 int ret;
427 424
428 CIO_DEBUG(KERN_INFO, 6, "cio: reprobe 0.%x.%04x\n", 425 CIO_MSG_EVENT(6, "cio: reprobe 0.%x.%04x\n",
429 schid.ssid, schid.sch_no); 426 schid.ssid, schid.sch_no);
430 if (need_reprobe) 427 if (need_reprobe)
431 return -EAGAIN; 428 return -EAGAIN;
432 429
@@ -642,9 +639,20 @@ init_channel_subsystem (void)
642{ 639{
643 int ret, i; 640 int ret, i;
644 641
645 if (chsc_determine_css_characteristics() == 0) 642 ret = chsc_determine_css_characteristics();
643 if (ret == -ENOMEM)
644 goto out; /* No need to continue. */
645 if (ret == 0)
646 css_characteristics_avail = 1; 646 css_characteristics_avail = 1;
647 647
648 ret = chsc_alloc_sei_area();
649 if (ret)
650 goto out;
651
652 ret = slow_subchannel_init();
653 if (ret)
654 goto out;
655
648 if ((ret = bus_register(&css_bus_type))) 656 if ((ret = bus_register(&css_bus_type)))
649 goto out; 657 goto out;
650 658
@@ -710,6 +718,10 @@ out_unregister:
710out_bus: 718out_bus:
711 bus_unregister(&css_bus_type); 719 bus_unregister(&css_bus_type);
712out: 720out:
721 chsc_free_sei_area();
722 kfree(slow_subchannel_set);
723 printk(KERN_WARNING"cio: failed to initialize css driver (%d)!\n",
724 ret);
713 return ret; 725 return ret;
714} 726}
715 727
diff --git a/drivers/s390/cio/css.h b/drivers/s390/cio/css.h
index ed7977531c3f..5d65e83ca66e 100644
--- a/drivers/s390/cio/css.h
+++ b/drivers/s390/cio/css.h
@@ -139,7 +139,6 @@ struct css_driver {
139 */ 139 */
140extern struct bus_type css_bus_type; 140extern struct bus_type css_bus_type;
141 141
142extern int css_sch_device_register(struct subchannel *);
143extern void css_sch_device_unregister(struct subchannel *); 142extern void css_sch_device_unregister(struct subchannel *);
144extern struct subchannel * get_subchannel_by_schid(struct subchannel_id); 143extern struct subchannel * get_subchannel_by_schid(struct subchannel_id);
145extern int css_init_done; 144extern int css_init_done;
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index 001682e70f67..297659fa0e26 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -338,15 +338,20 @@ ccw_device_remove_disconnected(struct ccw_device *cdev)
338 rc = device_schedule_callback(&cdev->dev, 338 rc = device_schedule_callback(&cdev->dev,
339 ccw_device_remove_orphan_cb); 339 ccw_device_remove_orphan_cb);
340 if (rc) 340 if (rc)
341 dev_info(&cdev->dev, "Couldn't unregister orphan\n"); 341 CIO_MSG_EVENT(2, "Couldn't unregister orphan "
342 "0.%x.%04x\n",
343 cdev->private->dev_id.ssid,
344 cdev->private->dev_id.devno);
342 return; 345 return;
343 } 346 }
344 /* Deregister subchannel, which will kill the ccw device. */ 347 /* Deregister subchannel, which will kill the ccw device. */
345 rc = device_schedule_callback(cdev->dev.parent, 348 rc = device_schedule_callback(cdev->dev.parent,
346 ccw_device_remove_sch_cb); 349 ccw_device_remove_sch_cb);
347 if (rc) 350 if (rc)
348 dev_info(&cdev->dev, 351 CIO_MSG_EVENT(2, "Couldn't unregister disconnected device "
349 "Couldn't unregister disconnected device\n"); 352 "0.%x.%04x\n",
353 cdev->private->dev_id.ssid,
354 cdev->private->dev_id.devno);
350} 355}
351 356
352int 357int
@@ -379,8 +384,10 @@ ccw_device_set_offline(struct ccw_device *cdev)
379 if (ret == 0) 384 if (ret == 0)
380 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); 385 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
381 else { 386 else {
382 pr_debug("ccw_device_offline returned %d, device %s\n", 387 CIO_MSG_EVENT(2, "ccw_device_offline returned %d, "
383 ret, cdev->dev.bus_id); 388 "device 0.%x.%04x\n",
389 ret, cdev->private->dev_id.ssid,
390 cdev->private->dev_id.devno);
384 cdev->online = 1; 391 cdev->online = 1;
385 } 392 }
386 return ret; 393 return ret;
@@ -402,8 +409,10 @@ ccw_device_set_online(struct ccw_device *cdev)
402 if (ret == 0) 409 if (ret == 0)
403 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); 410 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
404 else { 411 else {
405 pr_debug("ccw_device_online returned %d, device %s\n", 412 CIO_MSG_EVENT(2, "ccw_device_online returned %d, "
406 ret, cdev->dev.bus_id); 413 "device 0.%x.%04x\n",
414 ret, cdev->private->dev_id.ssid,
415 cdev->private->dev_id.devno);
407 return ret; 416 return ret;
408 } 417 }
409 if (cdev->private->state != DEV_STATE_ONLINE) 418 if (cdev->private->state != DEV_STATE_ONLINE)
@@ -417,9 +426,11 @@ ccw_device_set_online(struct ccw_device *cdev)
417 spin_unlock_irq(cdev->ccwlock); 426 spin_unlock_irq(cdev->ccwlock);
418 if (ret == 0) 427 if (ret == 0)
419 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); 428 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
420 else 429 else
421 pr_debug("ccw_device_offline returned %d, device %s\n", 430 CIO_MSG_EVENT(2, "ccw_device_offline returned %d, "
422 ret, cdev->dev.bus_id); 431 "device 0.%x.%04x\n",
432 ret, cdev->private->dev_id.ssid,
433 cdev->private->dev_id.devno);
423 return (ret == 0) ? -ENODEV : ret; 434 return (ret == 0) ? -ENODEV : ret;
424} 435}
425 436
@@ -439,9 +450,10 @@ static int online_store_recog_and_online(struct ccw_device *cdev)
439 if (cdev->id.cu_type == 0) { 450 if (cdev->id.cu_type == 0) {
440 ret = ccw_device_recognition(cdev); 451 ret = ccw_device_recognition(cdev);
441 if (ret) { 452 if (ret) {
442 printk(KERN_WARNING"Couldn't start recognition " 453 CIO_MSG_EVENT(0, "Couldn't start recognition "
443 "for device %s (ret=%d)\n", 454 "for device 0.%x.%04x (ret=%d)\n",
444 cdev->dev.bus_id, ret); 455 cdev->private->dev_id.ssid,
456 cdev->private->dev_id.devno, ret);
445 return ret; 457 return ret;
446 } 458 }
447 wait_event(cdev->private->wait_q, 459 wait_event(cdev->private->wait_q,
@@ -461,8 +473,8 @@ static void online_store_handle_online(struct ccw_device *cdev, int force)
461 if (force && cdev->private->state == DEV_STATE_BOXED) { 473 if (force && cdev->private->state == DEV_STATE_BOXED) {
462 ret = ccw_device_stlck(cdev); 474 ret = ccw_device_stlck(cdev);
463 if (ret) { 475 if (ret) {
464 printk(KERN_WARNING"ccw_device_stlck for device %s " 476 dev_warn(&cdev->dev,
465 "returned %d!\n", cdev->dev.bus_id, ret); 477 "ccw_device_stlck returned %d!\n", ret);
466 return; 478 return;
467 } 479 }
468 if (cdev->id.cu_type == 0) 480 if (cdev->id.cu_type == 0)
@@ -893,8 +905,10 @@ io_subchannel_register(struct work_struct *work)
893 ret = device_reprobe(&cdev->dev); 905 ret = device_reprobe(&cdev->dev);
894 if (ret) 906 if (ret)
895 /* We can't do much here. */ 907 /* We can't do much here. */
896 dev_info(&cdev->dev, "device_reprobe() returned" 908 CIO_MSG_EVENT(2, "device_reprobe() returned"
897 " %d\n", ret); 909 " %d for 0.%x.%04x\n", ret,
910 cdev->private->dev_id.ssid,
911 cdev->private->dev_id.devno);
898 } 912 }
899 goto out; 913 goto out;
900 } 914 }
@@ -907,8 +921,9 @@ io_subchannel_register(struct work_struct *work)
907 /* make it known to the system */ 921 /* make it known to the system */
908 ret = ccw_device_register(cdev); 922 ret = ccw_device_register(cdev);
909 if (ret) { 923 if (ret) {
910 printk (KERN_WARNING "%s: could not register %s\n", 924 CIO_MSG_EVENT(0, "Could not register ccw dev 0.%x.%04x: %d\n",
911 __func__, cdev->dev.bus_id); 925 cdev->private->dev_id.ssid,
926 cdev->private->dev_id.devno, ret);
912 put_device(&cdev->dev); 927 put_device(&cdev->dev);
913 spin_lock_irqsave(sch->lock, flags); 928 spin_lock_irqsave(sch->lock, flags);
914 sch->dev.driver_data = NULL; 929 sch->dev.driver_data = NULL;
@@ -1361,7 +1376,6 @@ ccw_device_remove (struct device *dev)
1361 struct ccw_driver *cdrv = cdev->drv; 1376 struct ccw_driver *cdrv = cdev->drv;
1362 int ret; 1377 int ret;
1363 1378
1364 pr_debug("removing device %s\n", cdev->dev.bus_id);
1365 if (cdrv->remove) 1379 if (cdrv->remove)
1366 cdrv->remove(cdev); 1380 cdrv->remove(cdev);
1367 if (cdev->online) { 1381 if (cdev->online) {
@@ -1374,8 +1388,10 @@ ccw_device_remove (struct device *dev)
1374 dev_fsm_final_state(cdev)); 1388 dev_fsm_final_state(cdev));
1375 else 1389 else
1376 //FIXME: we can't fail! 1390 //FIXME: we can't fail!
1377 pr_debug("ccw_device_offline returned %d, device %s\n", 1391 CIO_MSG_EVENT(2, "ccw_device_offline returned %d, "
1378 ret, cdev->dev.bus_id); 1392 "device 0.%x.%04x\n",
1393 ret, cdev->private->dev_id.ssid,
1394 cdev->private->dev_id.devno);
1379 } 1395 }
1380 ccw_device_set_timeout(cdev, 0); 1396 ccw_device_set_timeout(cdev, 0);
1381 cdev->drv = NULL; 1397 cdev->drv = NULL;
diff --git a/drivers/s390/cio/device_fsm.c b/drivers/s390/cio/device_fsm.c
index 6bba80929577..8633dc537695 100644
--- a/drivers/s390/cio/device_fsm.c
+++ b/drivers/s390/cio/device_fsm.c
@@ -268,7 +268,7 @@ ccw_device_recog_done(struct ccw_device *cdev, int state)
268 switch (state) { 268 switch (state) {
269 case DEV_STATE_NOT_OPER: 269 case DEV_STATE_NOT_OPER:
270 CIO_DEBUG(KERN_WARNING, 2, 270 CIO_DEBUG(KERN_WARNING, 2,
271 "SenseID : unknown device %04x on subchannel " 271 "cio: SenseID : unknown device %04x on subchannel "
272 "0.%x.%04x\n", cdev->private->dev_id.devno, 272 "0.%x.%04x\n", cdev->private->dev_id.devno,
273 sch->schid.ssid, sch->schid.sch_no); 273 sch->schid.ssid, sch->schid.sch_no);
274 break; 274 break;
@@ -293,7 +293,8 @@ ccw_device_recog_done(struct ccw_device *cdev, int state)
293 return; 293 return;
294 } 294 }
295 /* Issue device info message. */ 295 /* Issue device info message. */
296 CIO_DEBUG(KERN_INFO, 2, "SenseID : device 0.%x.%04x reports: " 296 CIO_DEBUG(KERN_INFO, 2,
297 "cio: SenseID : device 0.%x.%04x reports: "
297 "CU Type/Mod = %04X/%02X, Dev Type/Mod = " 298 "CU Type/Mod = %04X/%02X, Dev Type/Mod = "
298 "%04X/%02X\n", 299 "%04X/%02X\n",
299 cdev->private->dev_id.ssid, 300 cdev->private->dev_id.ssid,
@@ -303,7 +304,7 @@ ccw_device_recog_done(struct ccw_device *cdev, int state)
303 break; 304 break;
304 case DEV_STATE_BOXED: 305 case DEV_STATE_BOXED:
305 CIO_DEBUG(KERN_WARNING, 2, 306 CIO_DEBUG(KERN_WARNING, 2,
306 "SenseID : boxed device %04x on subchannel " 307 "cio: SenseID : boxed device %04x on subchannel "
307 "0.%x.%04x\n", cdev->private->dev_id.devno, 308 "0.%x.%04x\n", cdev->private->dev_id.devno,
308 sch->schid.ssid, sch->schid.sch_no); 309 sch->schid.ssid, sch->schid.sch_no);
309 break; 310 break;
@@ -388,7 +389,7 @@ ccw_device_done(struct ccw_device *cdev, int state)
388 389
389 if (state == DEV_STATE_BOXED) 390 if (state == DEV_STATE_BOXED)
390 CIO_DEBUG(KERN_WARNING, 2, 391 CIO_DEBUG(KERN_WARNING, 2,
391 "Boxed device %04x on subchannel %04x\n", 392 "cio: Boxed device %04x on subchannel %04x\n",
392 cdev->private->dev_id.devno, sch->schid.sch_no); 393 cdev->private->dev_id.devno, sch->schid.sch_no);
393 394
394 if (cdev->private->flags.donotify) { 395 if (cdev->private->flags.donotify) {
@@ -946,9 +947,10 @@ ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
946 /* Basic sense hasn't started. Try again. */ 947 /* Basic sense hasn't started. Try again. */
947 ccw_device_do_sense(cdev, irb); 948 ccw_device_do_sense(cdev, irb);
948 else { 949 else {
949 printk(KERN_INFO "Huh? %s(%s): unsolicited " 950 CIO_MSG_EVENT(2, "Huh? 0.%x.%04x: unsolicited "
950 "interrupt...\n", 951 "interrupt during w4sense...\n",
951 __FUNCTION__, cdev->dev.bus_id); 952 cdev->private->dev_id.ssid,
953 cdev->private->dev_id.devno);
952 if (cdev->handler) 954 if (cdev->handler)
953 cdev->handler (cdev, 0, irb); 955 cdev->handler (cdev, 0, irb);
954 } 956 }
@@ -1215,8 +1217,8 @@ ccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event)
1215static void 1217static void
1216ccw_device_bug(struct ccw_device *cdev, enum dev_event dev_event) 1218ccw_device_bug(struct ccw_device *cdev, enum dev_event dev_event)
1217{ 1219{
1218 printk(KERN_EMERG "dev_jumptable[%i][%i] == NULL\n", 1220 CIO_MSG_EVENT(0, "dev_jumptable[%i][%i] == NULL\n",
1219 cdev->private->state, dev_event); 1221 cdev->private->state, dev_event);
1220 BUG(); 1222 BUG();
1221} 1223}
1222 1224
diff --git a/drivers/s390/cio/device_ops.c b/drivers/s390/cio/device_ops.c
index a5d263fb55ae..14eba854b155 100644
--- a/drivers/s390/cio/device_ops.c
+++ b/drivers/s390/cio/device_ops.c
@@ -288,253 +288,6 @@ ccw_device_get_path_mask(struct ccw_device *cdev)
288 return sch->lpm; 288 return sch->lpm;
289} 289}
290 290
291static void
292ccw_device_wake_up(struct ccw_device *cdev, unsigned long ip, struct irb *irb)
293{
294 if (!ip)
295 /* unsolicited interrupt */
296 return;
297
298 /* Abuse intparm for error reporting. */
299 if (IS_ERR(irb))
300 cdev->private->intparm = -EIO;
301 else if (irb->scsw.cc == 1)
302 /* Retry for deferred condition code. */
303 cdev->private->intparm = -EAGAIN;
304 else if ((irb->scsw.dstat !=
305 (DEV_STAT_CHN_END|DEV_STAT_DEV_END)) ||
306 (irb->scsw.cstat != 0)) {
307 /*
308 * We didn't get channel end / device end. Check if path
309 * verification has been started; we can retry after it has
310 * finished. We also retry unit checks except for command reject
311 * or intervention required. Also check for long busy
312 * conditions.
313 */
314 if (cdev->private->flags.doverify ||
315 cdev->private->state == DEV_STATE_VERIFY)
316 cdev->private->intparm = -EAGAIN;
317 else if ((irb->scsw.dstat & DEV_STAT_UNIT_CHECK) &&
318 !(irb->ecw[0] &
319 (SNS0_CMD_REJECT | SNS0_INTERVENTION_REQ)))
320 cdev->private->intparm = -EAGAIN;
321 else if ((irb->scsw.dstat & DEV_STAT_ATTENTION) &&
322 (irb->scsw.dstat & DEV_STAT_DEV_END) &&
323 (irb->scsw.dstat & DEV_STAT_UNIT_EXCEP))
324 cdev->private->intparm = -EAGAIN;
325 else
326 cdev->private->intparm = -EIO;
327
328 } else
329 cdev->private->intparm = 0;
330 wake_up(&cdev->private->wait_q);
331}
332
333static int
334__ccw_device_retry_loop(struct ccw_device *cdev, struct ccw1 *ccw, long magic, __u8 lpm)
335{
336 int ret;
337 struct subchannel *sch;
338
339 sch = to_subchannel(cdev->dev.parent);
340 do {
341 ccw_device_set_timeout(cdev, 60 * HZ);
342 ret = cio_start (sch, ccw, lpm);
343 if (ret != 0)
344 ccw_device_set_timeout(cdev, 0);
345 if (ret == -EBUSY) {
346 /* Try again later. */
347 spin_unlock_irq(sch->lock);
348 msleep(10);
349 spin_lock_irq(sch->lock);
350 continue;
351 }
352 if (ret != 0)
353 /* Non-retryable error. */
354 break;
355 /* Wait for end of request. */
356 cdev->private->intparm = magic;
357 spin_unlock_irq(sch->lock);
358 wait_event(cdev->private->wait_q,
359 (cdev->private->intparm == -EIO) ||
360 (cdev->private->intparm == -EAGAIN) ||
361 (cdev->private->intparm == 0));
362 spin_lock_irq(sch->lock);
363 /* Check at least for channel end / device end */
364 if (cdev->private->intparm == -EIO) {
365 /* Non-retryable error. */
366 ret = -EIO;
367 break;
368 }
369 if (cdev->private->intparm == 0)
370 /* Success. */
371 break;
372 /* Try again later. */
373 spin_unlock_irq(sch->lock);
374 msleep(10);
375 spin_lock_irq(sch->lock);
376 } while (1);
377
378 return ret;
379}
380
381/**
382 * read_dev_chars() - read device characteristics
383 * @param cdev target ccw device
384 * @param buffer pointer to buffer for rdc data
385 * @param length size of rdc data
386 * @returns 0 for success, negative error value on failure
387 *
388 * Context:
389 * called for online device, lock not held
390 **/
391int
392read_dev_chars (struct ccw_device *cdev, void **buffer, int length)
393{
394 void (*handler)(struct ccw_device *, unsigned long, struct irb *);
395 struct subchannel *sch;
396 int ret;
397 struct ccw1 *rdc_ccw;
398
399 if (!cdev)
400 return -ENODEV;
401 if (!buffer || !length)
402 return -EINVAL;
403 sch = to_subchannel(cdev->dev.parent);
404
405 CIO_TRACE_EVENT (4, "rddevch");
406 CIO_TRACE_EVENT (4, sch->dev.bus_id);
407
408 rdc_ccw = kzalloc(sizeof(struct ccw1), GFP_KERNEL | GFP_DMA);
409 if (!rdc_ccw)
410 return -ENOMEM;
411 rdc_ccw->cmd_code = CCW_CMD_RDC;
412 rdc_ccw->count = length;
413 rdc_ccw->flags = CCW_FLAG_SLI;
414 ret = set_normalized_cda (rdc_ccw, (*buffer));
415 if (ret != 0) {
416 kfree(rdc_ccw);
417 return ret;
418 }
419
420 spin_lock_irq(sch->lock);
421 /* Save interrupt handler. */
422 handler = cdev->handler;
423 /* Temporarily install own handler. */
424 cdev->handler = ccw_device_wake_up;
425 if (cdev->private->state != DEV_STATE_ONLINE)
426 ret = -ENODEV;
427 else if (((sch->schib.scsw.stctl & SCSW_STCTL_PRIM_STATUS) &&
428 !(sch->schib.scsw.stctl & SCSW_STCTL_SEC_STATUS)) ||
429 cdev->private->flags.doverify)
430 ret = -EBUSY;
431 else
432 /* 0x00D9C4C3 == ebcdic "RDC" */
433 ret = __ccw_device_retry_loop(cdev, rdc_ccw, 0x00D9C4C3, 0);
434
435 /* Restore interrupt handler. */
436 cdev->handler = handler;
437 spin_unlock_irq(sch->lock);
438
439 clear_normalized_cda (rdc_ccw);
440 kfree(rdc_ccw);
441
442 return ret;
443}
444
445/*
446 * Read Configuration data using path mask
447 */
448int
449read_conf_data_lpm (struct ccw_device *cdev, void **buffer, int *length, __u8 lpm)
450{
451 void (*handler)(struct ccw_device *, unsigned long, struct irb *);
452 struct subchannel *sch;
453 struct ciw *ciw;
454 char *rcd_buf;
455 int ret;
456 struct ccw1 *rcd_ccw;
457
458 if (!cdev)
459 return -ENODEV;
460 if (!buffer || !length)
461 return -EINVAL;
462 sch = to_subchannel(cdev->dev.parent);
463
464 CIO_TRACE_EVENT (4, "rdconf");
465 CIO_TRACE_EVENT (4, sch->dev.bus_id);
466
467 /*
468 * scan for RCD command in extended SenseID data
469 */
470 ciw = ccw_device_get_ciw(cdev, CIW_TYPE_RCD);
471 if (!ciw || ciw->cmd == 0)
472 return -EOPNOTSUPP;
473
474 /* Adjust requested path mask to excluded varied off paths. */
475 if (lpm) {
476 lpm &= sch->opm;
477 if (lpm == 0)
478 return -EACCES;
479 }
480
481 rcd_ccw = kzalloc(sizeof(struct ccw1), GFP_KERNEL | GFP_DMA);
482 if (!rcd_ccw)
483 return -ENOMEM;
484 rcd_buf = kzalloc(ciw->count, GFP_KERNEL | GFP_DMA);
485 if (!rcd_buf) {
486 kfree(rcd_ccw);
487 return -ENOMEM;
488 }
489 rcd_ccw->cmd_code = ciw->cmd;
490 rcd_ccw->cda = (__u32) __pa (rcd_buf);
491 rcd_ccw->count = ciw->count;
492 rcd_ccw->flags = CCW_FLAG_SLI;
493
494 spin_lock_irq(sch->lock);
495 /* Save interrupt handler. */
496 handler = cdev->handler;
497 /* Temporarily install own handler. */
498 cdev->handler = ccw_device_wake_up;
499 if (cdev->private->state != DEV_STATE_ONLINE)
500 ret = -ENODEV;
501 else if (((sch->schib.scsw.stctl & SCSW_STCTL_PRIM_STATUS) &&
502 !(sch->schib.scsw.stctl & SCSW_STCTL_SEC_STATUS)) ||
503 cdev->private->flags.doverify)
504 ret = -EBUSY;
505 else
506 /* 0x00D9C3C4 == ebcdic "RCD" */
507 ret = __ccw_device_retry_loop(cdev, rcd_ccw, 0x00D9C3C4, lpm);
508
509 /* Restore interrupt handler. */
510 cdev->handler = handler;
511 spin_unlock_irq(sch->lock);
512
513 /*
514 * on success we update the user input parms
515 */
516 if (ret) {
517 kfree (rcd_buf);
518 *buffer = NULL;
519 *length = 0;
520 } else {
521 *length = ciw->count;
522 *buffer = rcd_buf;
523 }
524 kfree(rcd_ccw);
525
526 return ret;
527}
528
529/*
530 * Read Configuration data
531 */
532int
533read_conf_data (struct ccw_device *cdev, void **buffer, int *length)
534{
535 return read_conf_data_lpm (cdev, buffer, length, 0);
536}
537
538/* 291/*
539 * Try to break the lock on a boxed device. 292 * Try to break the lock on a boxed device.
540 */ 293 */
@@ -635,12 +388,6 @@ _ccw_device_get_subchannel_number(struct ccw_device *cdev)
635 return cdev->private->schid.sch_no; 388 return cdev->private->schid.sch_no;
636} 389}
637 390
638int
639_ccw_device_get_device_number(struct ccw_device *cdev)
640{
641 return cdev->private->dev_id.devno;
642}
643
644 391
645MODULE_LICENSE("GPL"); 392MODULE_LICENSE("GPL");
646EXPORT_SYMBOL(ccw_device_set_options_mask); 393EXPORT_SYMBOL(ccw_device_set_options_mask);
@@ -655,9 +402,5 @@ EXPORT_SYMBOL(ccw_device_start_timeout_key);
655EXPORT_SYMBOL(ccw_device_start_key); 402EXPORT_SYMBOL(ccw_device_start_key);
656EXPORT_SYMBOL(ccw_device_get_ciw); 403EXPORT_SYMBOL(ccw_device_get_ciw);
657EXPORT_SYMBOL(ccw_device_get_path_mask); 404EXPORT_SYMBOL(ccw_device_get_path_mask);
658EXPORT_SYMBOL(read_conf_data);
659EXPORT_SYMBOL(read_dev_chars);
660EXPORT_SYMBOL(_ccw_device_get_subchannel_number); 405EXPORT_SYMBOL(_ccw_device_get_subchannel_number);
661EXPORT_SYMBOL(_ccw_device_get_device_number);
662EXPORT_SYMBOL_GPL(ccw_device_get_chp_desc); 406EXPORT_SYMBOL_GPL(ccw_device_get_chp_desc);
663EXPORT_SYMBOL_GPL(read_conf_data_lpm);
diff --git a/drivers/s390/net/ctcmain.c b/drivers/s390/net/ctcmain.c
index b20fd0681733..92e8a37b5022 100644
--- a/drivers/s390/net/ctcmain.c
+++ b/drivers/s390/net/ctcmain.c
@@ -674,7 +674,7 @@ ch_action_txdone(fsm_instance * fi, int event, void *arg)
674 int first = 1; 674 int first = 1;
675 int i; 675 int i;
676 unsigned long duration; 676 unsigned long duration;
677 struct timespec done_stamp = xtime; 677 struct timespec done_stamp = current_kernel_time();
678 678
679 DBF_TEXT(trace, 4, __FUNCTION__); 679 DBF_TEXT(trace, 4, __FUNCTION__);
680 680
@@ -730,7 +730,7 @@ ch_action_txdone(fsm_instance * fi, int event, void *arg)
730 spin_unlock(&ch->collect_lock); 730 spin_unlock(&ch->collect_lock);
731 ch->ccw[1].count = ch->trans_skb->len; 731 ch->ccw[1].count = ch->trans_skb->len;
732 fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch); 732 fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch);
733 ch->prof.send_stamp = xtime; 733 ch->prof.send_stamp = current_kernel_time();
734 rc = ccw_device_start(ch->cdev, &ch->ccw[0], 734 rc = ccw_device_start(ch->cdev, &ch->ccw[0],
735 (unsigned long) ch, 0xff, 0); 735 (unsigned long) ch, 0xff, 0);
736 ch->prof.doios_multi++; 736 ch->prof.doios_multi++;
@@ -2281,7 +2281,7 @@ transmit_skb(struct channel *ch, struct sk_buff *skb)
2281 fsm_newstate(ch->fsm, CH_STATE_TX); 2281 fsm_newstate(ch->fsm, CH_STATE_TX);
2282 fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch); 2282 fsm_addtimer(&ch->timer, CTC_TIMEOUT_5SEC, CH_EVENT_TIMER, ch);
2283 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags); 2283 spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags);
2284 ch->prof.send_stamp = xtime; 2284 ch->prof.send_stamp = current_kernel_time();
2285 rc = ccw_device_start(ch->cdev, &ch->ccw[ccw_idx], 2285 rc = ccw_device_start(ch->cdev, &ch->ccw[ccw_idx],
2286 (unsigned long) ch, 0xff, 0); 2286 (unsigned long) ch, 0xff, 0);
2287 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags); 2287 spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags);
diff --git a/drivers/s390/net/netiucv.c b/drivers/s390/net/netiucv.c
index 3d28e1a5bf79..268889474339 100644
--- a/drivers/s390/net/netiucv.c
+++ b/drivers/s390/net/netiucv.c
@@ -753,7 +753,7 @@ static void conn_action_txdone(fsm_instance *fi, int event, void *arg)
753 753
754 header.next = 0; 754 header.next = 0;
755 memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN); 755 memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN);
756 conn->prof.send_stamp = xtime; 756 conn->prof.send_stamp = current_kernel_time();
757 txmsg.class = 0; 757 txmsg.class = 0;
758 txmsg.tag = 0; 758 txmsg.tag = 0;
759 rc = iucv_message_send(conn->path, &txmsg, 0, 0, 759 rc = iucv_message_send(conn->path, &txmsg, 0, 0,
@@ -1185,7 +1185,7 @@ static int netiucv_transmit_skb(struct iucv_connection *conn,
1185 memcpy(skb_put(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN); 1185 memcpy(skb_put(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN);
1186 1186
1187 fsm_newstate(conn->fsm, CONN_STATE_TX); 1187 fsm_newstate(conn->fsm, CONN_STATE_TX);
1188 conn->prof.send_stamp = xtime; 1188 conn->prof.send_stamp = current_kernel_time();
1189 1189
1190 msg.tag = 1; 1190 msg.tag = 1;
1191 msg.class = 0; 1191 msg.class = 0;
diff --git a/drivers/sbus/char/Kconfig b/drivers/sbus/char/Kconfig
index 35a73168333f..400c65bfb8c7 100644
--- a/drivers/sbus/char/Kconfig
+++ b/drivers/sbus/char/Kconfig
@@ -15,6 +15,7 @@ config SUN_OPENPROMIO
15 15
16config SUN_MOSTEK_RTC 16config SUN_MOSTEK_RTC
17 tristate "Mostek real time clock support" 17 tristate "Mostek real time clock support"
18 depends on SPARC32
18 help 19 help
19 The Mostek RTC chip is used on all known Sun computers except 20 The Mostek RTC chip is used on all known Sun computers except
20 some JavaStations. For a JavaStation you need to say Y both here 21 some JavaStations. For a JavaStation you need to say Y both here
diff --git a/drivers/sbus/char/jsflash.c b/drivers/sbus/char/jsflash.c
index 5157a2abc58d..4b7079fdc10c 100644
--- a/drivers/sbus/char/jsflash.c
+++ b/drivers/sbus/char/jsflash.c
@@ -185,7 +185,7 @@ static void jsfd_read(char *buf, unsigned long p, size_t togo) {
185 } 185 }
186} 186}
187 187
188static void jsfd_do_request(request_queue_t *q) 188static void jsfd_do_request(struct request_queue *q)
189{ 189{
190 struct request *req; 190 struct request *req;
191 191
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index da63c544919b..21c075d44db1 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -654,7 +654,7 @@ void scsi_run_host_queues(struct Scsi_Host *shost)
654static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int uptodate, 654static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int uptodate,
655 int bytes, int requeue) 655 int bytes, int requeue)
656{ 656{
657 request_queue_t *q = cmd->device->request_queue; 657 struct request_queue *q = cmd->device->request_queue;
658 struct request *req = cmd->request; 658 struct request *req = cmd->request;
659 unsigned long flags; 659 unsigned long flags;
660 660
@@ -818,7 +818,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
818{ 818{
819 int result = cmd->result; 819 int result = cmd->result;
820 int this_count = cmd->request_bufflen; 820 int this_count = cmd->request_bufflen;
821 request_queue_t *q = cmd->device->request_queue; 821 struct request_queue *q = cmd->device->request_queue;
822 struct request *req = cmd->request; 822 struct request *req = cmd->request;
823 int clear_errors = 1; 823 int clear_errors = 1;
824 struct scsi_sense_hdr sshdr; 824 struct scsi_sense_hdr sshdr;
@@ -1038,7 +1038,7 @@ static int scsi_init_io(struct scsi_cmnd *cmd)
1038 return BLKPREP_KILL; 1038 return BLKPREP_KILL;
1039} 1039}
1040 1040
1041static int scsi_issue_flush_fn(request_queue_t *q, struct gendisk *disk, 1041static int scsi_issue_flush_fn(struct request_queue *q, struct gendisk *disk,
1042 sector_t *error_sector) 1042 sector_t *error_sector)
1043{ 1043{
1044 struct scsi_device *sdev = q->queuedata; 1044 struct scsi_device *sdev = q->queuedata;
@@ -1340,7 +1340,7 @@ static inline int scsi_host_queue_ready(struct request_queue *q,
1340/* 1340/*
1341 * Kill a request for a dead device 1341 * Kill a request for a dead device
1342 */ 1342 */
1343static void scsi_kill_request(struct request *req, request_queue_t *q) 1343static void scsi_kill_request(struct request *req, struct request_queue *q)
1344{ 1344{
1345 struct scsi_cmnd *cmd = req->special; 1345 struct scsi_cmnd *cmd = req->special;
1346 struct scsi_device *sdev = cmd->device; 1346 struct scsi_device *sdev = cmd->device;
@@ -2119,7 +2119,7 @@ EXPORT_SYMBOL(scsi_target_resume);
2119int 2119int
2120scsi_internal_device_block(struct scsi_device *sdev) 2120scsi_internal_device_block(struct scsi_device *sdev)
2121{ 2121{
2122 request_queue_t *q = sdev->request_queue; 2122 struct request_queue *q = sdev->request_queue;
2123 unsigned long flags; 2123 unsigned long flags;
2124 int err = 0; 2124 int err = 0;
2125 2125
@@ -2159,7 +2159,7 @@ EXPORT_SYMBOL_GPL(scsi_internal_device_block);
2159int 2159int
2160scsi_internal_device_unblock(struct scsi_device *sdev) 2160scsi_internal_device_unblock(struct scsi_device *sdev)
2161{ 2161{
2162 request_queue_t *q = sdev->request_queue; 2162 struct request_queue *q = sdev->request_queue;
2163 int err; 2163 int err;
2164 unsigned long flags; 2164 unsigned long flags;
2165 2165
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 424d557284a9..e21c7142a3ea 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -814,7 +814,7 @@ static int sd_issue_flush(struct device *dev, sector_t *error_sector)
814 return ret; 814 return ret;
815} 815}
816 816
817static void sd_prepare_flush(request_queue_t *q, struct request *rq) 817static void sd_prepare_flush(struct request_queue *q, struct request *rq)
818{ 818{
819 memset(rq->cmd, 0, sizeof(rq->cmd)); 819 memset(rq->cmd, 0, sizeof(rq->cmd));
820 rq->cmd_type = REQ_TYPE_BLOCK_PC; 820 rq->cmd_type = REQ_TYPE_BLOCK_PC;
@@ -1285,7 +1285,7 @@ got_data:
1285 */ 1285 */
1286 int hard_sector = sector_size; 1286 int hard_sector = sector_size;
1287 sector_t sz = (sdkp->capacity/2) * (hard_sector/256); 1287 sector_t sz = (sdkp->capacity/2) * (hard_sector/256);
1288 request_queue_t *queue = sdp->request_queue; 1288 struct request_queue *queue = sdp->request_queue;
1289 sector_t mb = sz; 1289 sector_t mb = sz;
1290 1290
1291 blk_queue_hardsect_size(queue, hard_sector); 1291 blk_queue_hardsect_size(queue, hard_sector);
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index e7b6a7fde1cb..902eb11ffe8a 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -624,7 +624,7 @@ static void get_sectorsize(struct scsi_cd *cd)
624 unsigned char *buffer; 624 unsigned char *buffer;
625 int the_result, retries = 3; 625 int the_result, retries = 3;
626 int sector_size; 626 int sector_size;
627 request_queue_t *queue; 627 struct request_queue *queue;
628 628
629 buffer = kmalloc(512, GFP_KERNEL | GFP_DMA); 629 buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
630 if (!buffer) 630 if (!buffer)
diff --git a/drivers/serial/68328serial.c b/drivers/serial/68328serial.c
index cad426c9711e..aad4012bbb30 100644
--- a/drivers/serial/68328serial.c
+++ b/drivers/serial/68328serial.c
@@ -33,7 +33,6 @@
33#include <linux/keyboard.h> 33#include <linux/keyboard.h>
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/pm.h> 35#include <linux/pm.h>
36#include <linux/pm_legacy.h>
37#include <linux/bitops.h> 36#include <linux/bitops.h>
38#include <linux/delay.h> 37#include <linux/delay.h>
39 38
@@ -401,9 +400,9 @@ irqreturn_t rs_interrupt(int irq, void *dev_id)
401 return IRQ_HANDLED; 400 return IRQ_HANDLED;
402} 401}
403 402
404static void do_softint(void *private) 403static void do_softint(struct work_struct *work)
405{ 404{
406 struct m68k_serial *info = (struct m68k_serial *) private; 405 struct m68k_serial *info = container_of(work, struct m68k_serial, tqueue);
407 struct tty_struct *tty; 406 struct tty_struct *tty;
408 407
409 tty = info->tty; 408 tty = info->tty;
@@ -425,9 +424,9 @@ static void do_softint(void *private)
425 * do_serial_hangup() -> tty->hangup() -> rs_hangup() 424 * do_serial_hangup() -> tty->hangup() -> rs_hangup()
426 * 425 *
427 */ 426 */
428static void do_serial_hangup(void *private) 427static void do_serial_hangup(struct work_struct *work)
429{ 428{
430 struct m68k_serial *info = (struct m68k_serial *) private; 429 struct m68k_serial *info = container_of(work, struct m68k_serial, tqueue_hangup);
431 struct tty_struct *tty; 430 struct tty_struct *tty;
432 431
433 tty = info->tty; 432 tty = info->tty;
@@ -1324,59 +1323,6 @@ static void show_serial_version(void)
1324 printk("MC68328 serial driver version 1.00\n"); 1323 printk("MC68328 serial driver version 1.00\n");
1325} 1324}
1326 1325
1327#ifdef CONFIG_PM_LEGACY
1328/* Serial Power management
1329 * The console (currently fixed at line 0) is a special case for power
1330 * management because the kernel is so chatty. The console will be
1331 * explicitly disabled my our power manager as the last minute, so we won't
1332 * mess with it here.
1333 */
1334static struct pm_dev *serial_pm[NR_PORTS];
1335
1336static int serial_pm_callback(struct pm_dev *dev, pm_request_t request, void *data)
1337{
1338 struct m68k_serial *info = (struct m68k_serial *)dev->data;
1339
1340 if(info == NULL)
1341 return -1;
1342
1343 /* special case for line 0 - pm restores it */
1344 if(info->line == 0)
1345 return 0;
1346
1347 switch (request) {
1348 case PM_SUSPEND:
1349 shutdown(info);
1350 break;
1351
1352 case PM_RESUME:
1353 startup(info);
1354 break;
1355 }
1356 return 0;
1357}
1358
1359void shutdown_console(void)
1360{
1361 struct m68k_serial *info = &m68k_soft[0];
1362
1363 /* HACK: wait a bit for any pending printk's to be dumped */
1364 {
1365 int i = 10000;
1366 while(i--);
1367 }
1368
1369 shutdown(info);
1370}
1371
1372void startup_console(void)
1373{
1374 struct m68k_serial *info = &m68k_soft[0];
1375 startup(info);
1376}
1377#endif /* CONFIG_PM_LEGACY */
1378
1379
1380static const struct tty_operations rs_ops = { 1326static const struct tty_operations rs_ops = {
1381 .open = rs_open, 1327 .open = rs_open,
1382 .close = rs_close, 1328 .close = rs_close,
@@ -1444,8 +1390,8 @@ rs68328_init(void)
1444 info->event = 0; 1390 info->event = 0;
1445 info->count = 0; 1391 info->count = 0;
1446 info->blocked_open = 0; 1392 info->blocked_open = 0;
1447 INIT_WORK(&info->tqueue, do_softint, info); 1393 INIT_WORK(&info->tqueue, do_softint);
1448 INIT_WORK(&info->tqueue_hangup, do_serial_hangup, info); 1394 INIT_WORK(&info->tqueue_hangup, do_serial_hangup);
1449 init_waitqueue_head(&info->open_wait); 1395 init_waitqueue_head(&info->open_wait);
1450 init_waitqueue_head(&info->close_wait); 1396 init_waitqueue_head(&info->close_wait);
1451 info->line = i; 1397 info->line = i;
@@ -1467,11 +1413,6 @@ rs68328_init(void)
1467 IRQ_FLG_STD, 1413 IRQ_FLG_STD,
1468 "M68328_UART", NULL)) 1414 "M68328_UART", NULL))
1469 panic("Unable to attach 68328 serial interrupt\n"); 1415 panic("Unable to attach 68328 serial interrupt\n");
1470#ifdef CONFIG_PM_LEGACY
1471 serial_pm[i] = pm_register(PM_SYS_DEV, PM_SYS_COM, serial_pm_callback);
1472 if (serial_pm[i])
1473 serial_pm[i]->data = info;
1474#endif
1475 } 1416 }
1476 local_irq_restore(flags); 1417 local_irq_restore(flags);
1477 return 0; 1418 return 0;
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index 0b3ec38ae614..2f5a5ac1b271 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -2650,8 +2650,9 @@ static int __devinit serial8250_probe(struct platform_device *dev)
2650 ret = serial8250_register_port(&port); 2650 ret = serial8250_register_port(&port);
2651 if (ret < 0) { 2651 if (ret < 0) {
2652 dev_err(&dev->dev, "unable to register port at index %d " 2652 dev_err(&dev->dev, "unable to register port at index %d "
2653 "(IO%lx MEM%lx IRQ%d): %d\n", i, 2653 "(IO%lx MEM%llx IRQ%d): %d\n", i,
2654 p->iobase, p->mapbase, p->irq, ret); 2654 p->iobase, (unsigned long long)p->mapbase,
2655 p->irq, ret);
2655 } 2656 }
2656 } 2657 }
2657 return 0; 2658 return 0;
diff --git a/drivers/serial/8250_early.c b/drivers/serial/8250_early.c
index 947c20507e1f..150cad5c2eba 100644
--- a/drivers/serial/8250_early.c
+++ b/drivers/serial/8250_early.c
@@ -151,8 +151,9 @@ static int __init parse_options(struct early_serial8250_device *device, char *op
151#else 151#else
152 port->membase = ioremap(port->mapbase, 64); 152 port->membase = ioremap(port->mapbase, 64);
153 if (!port->membase) { 153 if (!port->membase) {
154 printk(KERN_ERR "%s: Couldn't ioremap 0x%lx\n", 154 printk(KERN_ERR "%s: Couldn't ioremap 0x%llx\n",
155 __FUNCTION__, port->mapbase); 155 __FUNCTION__,
156 (unsigned long long)port->mapbase);
156 return -ENOMEM; 157 return -ENOMEM;
157 } 158 }
158#endif 159#endif
@@ -175,9 +176,10 @@ static int __init parse_options(struct early_serial8250_device *device, char *op
175 device->baud); 176 device->baud);
176 } 177 }
177 178
178 printk(KERN_INFO "Early serial console at %s 0x%lx (options '%s')\n", 179 printk(KERN_INFO "Early serial console at %s 0x%llx (options '%s')\n",
179 mmio ? "MMIO" : "I/O port", 180 mmio ? "MMIO" : "I/O port",
180 mmio ? port->mapbase : (unsigned long) port->iobase, 181 mmio ? (unsigned long long) port->mapbase
182 : (unsigned long long) port->iobase,
181 device->options); 183 device->options);
182 return 0; 184 return 0;
183} 185}
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index 9c57486c2e7f..030a6063541d 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -626,7 +626,7 @@ static int uart_get_info(struct uart_state *state,
626 tmp.hub6 = port->hub6; 626 tmp.hub6 = port->hub6;
627 tmp.io_type = port->iotype; 627 tmp.io_type = port->iotype;
628 tmp.iomem_reg_shift = port->regshift; 628 tmp.iomem_reg_shift = port->regshift;
629 tmp.iomem_base = (void *)port->mapbase; 629 tmp.iomem_base = (void *)(unsigned long)port->mapbase;
630 630
631 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 631 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
632 return -EFAULT; 632 return -EFAULT;
@@ -1666,10 +1666,11 @@ static int uart_line_info(char *buf, struct uart_driver *drv, int i)
1666 return 0; 1666 return 0;
1667 1667
1668 mmio = port->iotype >= UPIO_MEM; 1668 mmio = port->iotype >= UPIO_MEM;
1669 ret = sprintf(buf, "%d: uart:%s %s%08lX irq:%d", 1669 ret = sprintf(buf, "%d: uart:%s %s%08llX irq:%d",
1670 port->line, uart_type(port), 1670 port->line, uart_type(port),
1671 mmio ? "mmio:0x" : "port:", 1671 mmio ? "mmio:0x" : "port:",
1672 mmio ? port->mapbase : (unsigned long) port->iobase, 1672 mmio ? (unsigned long long)port->mapbase
1673 : (unsigned long long) port->iobase,
1673 port->irq); 1674 port->irq);
1674 1675
1675 if (port->type == PORT_UNKNOWN) { 1676 if (port->type == PORT_UNKNOWN) {
@@ -2069,7 +2070,7 @@ uart_report_port(struct uart_driver *drv, struct uart_port *port)
2069 case UPIO_TSI: 2070 case UPIO_TSI:
2070 case UPIO_DWAPB: 2071 case UPIO_DWAPB:
2071 snprintf(address, sizeof(address), 2072 snprintf(address, sizeof(address),
2072 "MMIO 0x%lx", port->mapbase); 2073 "MMIO 0x%llx", (unsigned long long)port->mapbase);
2073 break; 2074 break;
2074 default: 2075 default:
2075 strlcpy(address, "*unknown*", sizeof(address)); 2076 strlcpy(address, "*unknown*", sizeof(address));
diff --git a/drivers/spi/spi_s3c24xx.c b/drivers/spi/spi_s3c24xx.c
index 7071ff8da63e..5cf48123e0ef 100644
--- a/drivers/spi/spi_s3c24xx.c
+++ b/drivers/spi/spi_s3c24xx.c
@@ -28,7 +28,7 @@
28#include <asm/hardware.h> 28#include <asm/hardware.h>
29 29
30#include <asm/arch/regs-gpio.h> 30#include <asm/arch/regs-gpio.h>
31#include <asm/arch/regs-spi.h> 31#include <asm/plat-s3c24xx/regs-spi.h>
32#include <asm/arch/spi.h> 32#include <asm/arch/spi.h>
33 33
34struct s3c24xx_spi { 34struct s3c24xx_spi {
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 564cc9b51822..a7231d171bd5 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -1571,7 +1571,14 @@ config FB_PM3
1571 1571
1572config FB_AU1100 1572config FB_AU1100
1573 bool "Au1100 LCD Driver" 1573 bool "Au1100 LCD Driver"
1574 depends on (FB = y) && EXPERIMENTAL && PCI && MIPS && MIPS_PB1100=y 1574 depends on (FB = y) && MIPS && SOC_AU1100
1575 select FB_CFB_FILLRECT
1576 select FB_CFB_COPYAREA
1577 select FB_CFB_IMAGEBLIT
1578 help
1579 This is the framebuffer driver for the AMD Au1100 SOC. It can drive
1580 various panels and CRTs by passing in kernel cmd line option
1581 au1100fb:panel=<name>.
1575 1582
1576config FB_AU1200 1583config FB_AU1200
1577 bool "Au1200 LCD Driver" 1584 bool "Au1200 LCD Driver"
diff --git a/drivers/video/chipsfb.c b/drivers/video/chipsfb.c
index f48e8c534c87..6796ba62c3c6 100644
--- a/drivers/video/chipsfb.c
+++ b/drivers/video/chipsfb.c
@@ -24,6 +24,7 @@
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/interrupt.h> 25#include <linux/interrupt.h>
26#include <linux/fb.h> 26#include <linux/fb.h>
27#include <linux/pm.h>
27#include <linux/init.h> 28#include <linux/init.h>
28#include <linux/pci.h> 29#include <linux/pci.h>
29#include <linux/console.h> 30#include <linux/console.h>
@@ -458,7 +459,7 @@ static int chipsfb_pci_suspend(struct pci_dev *pdev, pm_message_t state)
458 459
459 if (state.event == pdev->dev.power.power_state.event) 460 if (state.event == pdev->dev.power.power_state.event)
460 return 0; 461 return 0;
461 if (state.event != PM_SUSPEND_MEM) 462 if (state.event != PM_EVENT_SUSPEND)
462 goto done; 463 goto done;
463 464
464 acquire_console_sem(); 465 acquire_console_sem();
diff --git a/drivers/video/tgafb.c b/drivers/video/tgafb.c
index 89facb73edfc..d292a37ec7d6 100644
--- a/drivers/video/tgafb.c
+++ b/drivers/video/tgafb.c
@@ -849,7 +849,7 @@ tgafb_clut_imageblit(struct fb_info *info, const struct fb_image *image)
849 u32 *palette = ((u32 *)info->pseudo_palette); 849 u32 *palette = ((u32 *)info->pseudo_palette);
850 unsigned long pos, line_length, i, j; 850 unsigned long pos, line_length, i, j;
851 const unsigned char *data; 851 const unsigned char *data;
852 void *regs_base, *fb_base; 852 void __iomem *regs_base, *fb_base;
853 853
854 dx = image->dx; 854 dx = image->dx;
855 dy = image->dy; 855 dy = image->dy;
diff --git a/drivers/w1/masters/ds1wm.c b/drivers/w1/masters/ds1wm.c
index 763bc73e5070..4b696641ce33 100644
--- a/drivers/w1/masters/ds1wm.c
+++ b/drivers/w1/masters/ds1wm.c
@@ -85,7 +85,7 @@ static struct {
85}; 85};
86 86
87struct ds1wm_data { 87struct ds1wm_data {
88 void *map; 88 void __iomem *map;
89 int bus_shift; /* # of shifts to calc register offsets */ 89 int bus_shift; /* # of shifts to calc register offsets */
90 struct platform_device *pdev; 90 struct platform_device *pdev;
91 struct ds1wm_platform_data *pdata; 91 struct ds1wm_platform_data *pdata;
diff --git a/drivers/xen/xenbus/xenbus_xs.c b/drivers/xen/xenbus/xenbus_xs.c
index 9e943fbce81b..227d53b12a5c 100644
--- a/drivers/xen/xenbus/xenbus_xs.c
+++ b/drivers/xen/xenbus/xenbus_xs.c
@@ -782,8 +782,8 @@ static int process_msg(void)
782 msg->u.watch.vec = split(body, msg->hdr.len, 782 msg->u.watch.vec = split(body, msg->hdr.len,
783 &msg->u.watch.vec_size); 783 &msg->u.watch.vec_size);
784 if (IS_ERR(msg->u.watch.vec)) { 784 if (IS_ERR(msg->u.watch.vec)) {
785 kfree(msg);
786 err = PTR_ERR(msg->u.watch.vec); 785 err = PTR_ERR(msg->u.watch.vec);
786 kfree(msg);
787 goto out; 787 goto out;
788 } 788 }
789 789