aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@g5.osdl.org>2006-09-26 14:49:46 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-09-26 14:49:46 -0400
commitdd77a4ee0f3981693d4229aa1d57cea9e526ff47 (patch)
treecb486be20b950201103a03636cbb1e1d180f0098
parente8216dee838c09776680a6f1a2e54d81f3cdfa14 (diff)
parent7e9f4b2d3e21e87c26025810413ef1592834e63b (diff)
Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6
* master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6: (47 commits) Driver core: Don't call put methods while holding a spinlock Driver core: Remove unneeded routines from driver core Driver core: Fix potential deadlock in driver core PCI: enable driver multi-threaded probe Driver Core: add ability for drivers to do a threaded probe sysfs: add proper sysfs_init() prototype drivers/base: check errors drivers/base: Platform notify needs to occur before drivers attach to the device v4l-dev2: handle __must_check add CONFIG_ENABLE_MUST_CHECK add __must_check to device management code Driver core: fixed add_bind_files() definition Driver core: fix comments in drivers/base/power/resume.c sysfs_remove_bin_file: no return value, dump_stack on error kobject: must_check fixes Driver core: add ability for devices to create and remove bin files Class: add support for class interfaces for devices Driver core: create devices/virtual/ tree Driver core: add device_rename function Driver core: add ability for classes to handle devices properly ...
-rw-r--r--Documentation/ABI/removed/devfs (renamed from Documentation/ABI/obsolete/devfs)5
-rw-r--r--Documentation/ABI/testing/sysfs-power88
-rw-r--r--Documentation/feature-removal-schedule.txt27
-rw-r--r--Documentation/power/devices.txt725
-rw-r--r--drivers/base/base.h2
-rw-r--r--drivers/base/bus.c133
-rw-r--r--drivers/base/class.c34
-rw-r--r--drivers/base/core.c230
-rw-r--r--drivers/base/dd.c147
-rw-r--r--drivers/base/driver.c16
-rw-r--r--drivers/base/platform.c30
-rw-r--r--drivers/base/power/resume.c37
-rw-r--r--drivers/base/power/suspend.c92
-rw-r--r--drivers/base/power/sysfs.c35
-rw-r--r--drivers/ide/ide.c6
-rw-r--r--drivers/ide/ppc/pmac.c14
-rw-r--r--drivers/media/dvb/cinergyT2/cinergyT2.c2
-rw-r--r--drivers/pci/Kconfig25
-rw-r--r--drivers/pci/hotplug/acpiphp_ibm.c4
-rw-r--r--drivers/pci/pci-driver.c38
-rw-r--r--drivers/pci/pci.c4
-rw-r--r--drivers/scsi/mesh.c15
-rw-r--r--drivers/usb/core/hcd-pci.c2
-rw-r--r--drivers/usb/host/ehci-pci.c6
-rw-r--r--drivers/usb/host/ohci-pci.c5
-rw-r--r--drivers/usb/host/sl811-hcd.c9
-rw-r--r--drivers/usb/host/uhci-hcd.c4
-rw-r--r--drivers/video/aty/radeon_pm.c15
-rw-r--r--drivers/video/i810/i810_main.c12
-rw-r--r--drivers/video/nvidia/nvidia.c13
-rw-r--r--drivers/video/savage/savagefb_driver.c14
-rw-r--r--fs/debugfs/file.c56
-rw-r--r--fs/debugfs/inode.c15
-rw-r--r--fs/namespace.c10
-rw-r--r--fs/sysfs/bin.c13
-rw-r--r--fs/sysfs/dir.c2
-rw-r--r--fs/sysfs/inode.c11
-rw-r--r--fs/sysfs/symlink.c14
-rw-r--r--fs/sysfs/sysfs.h2
-rw-r--r--include/linux/compiler.h5
-rw-r--r--include/linux/device.h99
-rw-r--r--include/linux/kobject.h16
-rw-r--r--include/linux/pci.h36
-rw-r--r--include/linux/platform_device.h2
-rw-r--r--include/linux/pm.h63
-rw-r--r--include/linux/sysfs.h28
-rw-r--r--include/media/v4l2-dev.h2
-rw-r--r--init/do_mounts.c5
-rw-r--r--kernel/power/Kconfig11
-rw-r--r--kernel/power/disk.c4
-rw-r--r--kernel/power/swsusp.c9
-rw-r--r--kernel/power/user.c2
-rw-r--r--lib/Kconfig.debug7
-rw-r--r--lib/klist.c26
-rw-r--r--lib/kobject.c9
55 files changed, 1659 insertions, 577 deletions
diff --git a/Documentation/ABI/obsolete/devfs b/Documentation/ABI/removed/devfs
index b8b87399bc8f..8195c4e0d0a1 100644
--- a/Documentation/ABI/obsolete/devfs
+++ b/Documentation/ABI/removed/devfs
@@ -1,13 +1,12 @@
1What: devfs 1What: devfs
2Date: July 2005 2Date: July 2005 (scheduled), finally removed in kernel v2.6.18
3Contact: Greg Kroah-Hartman <gregkh@suse.de> 3Contact: Greg Kroah-Hartman <gregkh@suse.de>
4Description: 4Description:
5 devfs has been unmaintained for a number of years, has unfixable 5 devfs has been unmaintained for a number of years, has unfixable
6 races, contains a naming policy within the kernel that is 6 races, contains a naming policy within the kernel that is
7 against the LSB, and can be replaced by using udev. 7 against the LSB, and can be replaced by using udev.
8 The files fs/devfs/*, include/linux/devfs_fs*.h will be removed, 8 The files fs/devfs/*, include/linux/devfs_fs*.h were removed,
9 along with the the assorted devfs function calls throughout the 9 along with the the assorted devfs function calls throughout the
10 kernel tree. 10 kernel tree.
11 11
12Users: 12Users:
13
diff --git a/Documentation/ABI/testing/sysfs-power b/Documentation/ABI/testing/sysfs-power
new file mode 100644
index 000000000000..d882f8093871
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-power
@@ -0,0 +1,88 @@
1What: /sys/power/
2Date: August 2006
3Contact: Rafael J. Wysocki <rjw@sisk.pl>
4Description:
5 The /sys/power directory will contain files that will
6 provide a unified interface to the power management
7 subsystem.
8
9What: /sys/power/state
10Date: August 2006
11Contact: Rafael J. Wysocki <rjw@sisk.pl>
12Description:
13 The /sys/power/state file controls the system power state.
14 Reading from this file returns what states are supported,
15 which is hard-coded to 'standby' (Power-On Suspend), 'mem'
16 (Suspend-to-RAM), and 'disk' (Suspend-to-Disk).
17
18 Writing to this file one of these strings causes the system to
19 transition into that state. Please see the file
20 Documentation/power/states.txt for a description of each of
21 these states.
22
23What: /sys/power/disk
24Date: August 2006
25Contact: Rafael J. Wysocki <rjw@sisk.pl>
26Description:
27 The /sys/power/disk file controls the operating mode of the
28 suspend-to-disk mechanism. Reading from this file returns
29 the name of the method by which the system will be put to
30 sleep on the next suspend. There are four methods supported:
31 'firmware' - means that the memory image will be saved to disk
32 by some firmware, in which case we also assume that the
33 firmware will handle the system suspend.
34 'platform' - the memory image will be saved by the kernel and
35 the system will be put to sleep by the platform driver (e.g.
36 ACPI or other PM registers).
37 'shutdown' - the memory image will be saved by the kernel and
38 the system will be powered off.
39 'reboot' - the memory image will be saved by the kernel and
40 the system will be rebooted.
41
42 The suspend-to-disk method may be chosen by writing to this
43 file one of the accepted strings:
44
45 'firmware'
46 'platform'
47 'shutdown'
48 'reboot'
49
50 It will only change to 'firmware' or 'platform' if the system
51 supports that.
52
53What: /sys/power/image_size
54Date: August 2006
55Contact: Rafael J. Wysocki <rjw@sisk.pl>
56Description:
57 The /sys/power/image_size file controls the size of the image
58 created by the suspend-to-disk mechanism. It can be written a
59 string representing a non-negative integer that will be used
60 as an upper limit of the image size, in bytes. The kernel's
61 suspend-to-disk code will do its best to ensure the image size
62 will not exceed this number. However, if it turns out to be
63 impossible, the kernel will try to suspend anyway using the
64 smallest image possible. In particular, if "0" is written to
65 this file, the suspend image will be as small as possible.
66
67 Reading from this file will display the current image size
68 limit, which is set to 500 MB by default.
69
70What: /sys/power/pm_trace
71Date: August 2006
72Contact: Rafael J. Wysocki <rjw@sisk.pl>
73Description:
74 The /sys/power/pm_trace file controls the code which saves the
75 last PM event point in the RTC across reboots, so that you can
76 debug a machine that just hangs during suspend (or more
77 commonly, during resume). Namely, the RTC is only used to save
78 the last PM event point if this file contains '1'. Initially
79 it contains '0' which may be changed to '1' by writing a
80 string representing a nonzero integer into it.
81
82 To use this debugging feature you should attempt to suspend
83 the machine, then reboot it and run
84
85 dmesg -s 1000000 | grep 'hash matches'
86
87 CAUTION: Using it will cause your machine's real-time (CMOS)
88 clock to be set to a random invalid time after a resume.
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index 552507fe9a7e..611acc32fdf5 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -6,6 +6,21 @@ be removed from this file.
6 6
7--------------------------- 7---------------------------
8 8
9What: /sys/devices/.../power/state
10 dev->power.power_state
11 dpm_runtime_{suspend,resume)()
12When: July 2007
13Why: Broken design for runtime control over driver power states, confusing
14 driver-internal runtime power management with: mechanisms to support
15 system-wide sleep state transitions; event codes that distinguish
16 different phases of swsusp "sleep" transitions; and userspace policy
17 inputs. This framework was never widely used, and most attempts to
18 use it were broken. Drivers should instead be exposing domain-specific
19 interfaces either to kernel or to userspace.
20Who: Pavel Machek <pavel@suse.cz>
21
22---------------------------
23
9What: RAW driver (CONFIG_RAW_DRIVER) 24What: RAW driver (CONFIG_RAW_DRIVER)
10When: December 2005 25When: December 2005
11Why: declared obsolete since kernel 2.6.3 26Why: declared obsolete since kernel 2.6.3
@@ -294,3 +309,15 @@ Why: The frame diverter is included in most distribution kernels, but is
294 It is not clear if anyone is still using it. 309 It is not clear if anyone is still using it.
295Who: Stephen Hemminger <shemminger@osdl.org> 310Who: Stephen Hemminger <shemminger@osdl.org>
296 311
312---------------------------
313
314
315What: PHYSDEVPATH, PHYSDEVBUS, PHYSDEVDRIVER in the uevent environment
316When: Oktober 2008
317Why: The stacking of class devices makes these values misleading and
318 inconsistent.
319 Class devices should not carry any of these properties, and bus
320 devices have SUBSYTEM and DRIVER as a replacement.
321Who: Kay Sievers <kay.sievers@suse.de>
322
323---------------------------
diff --git a/Documentation/power/devices.txt b/Documentation/power/devices.txt
index fba1e05c47c7..d0e79d5820a5 100644
--- a/Documentation/power/devices.txt
+++ b/Documentation/power/devices.txt
@@ -1,208 +1,553 @@
1Most of the code in Linux is device drivers, so most of the Linux power
2management code is also driver-specific. Most drivers will do very little;
3others, especially for platforms with small batteries (like cell phones),
4will do a lot.
5
6This writeup gives an overview of how drivers interact with system-wide
7power management goals, emphasizing the models and interfaces that are
8shared by everything that hooks up to the driver model core. Read it as
9background for the domain-specific work you'd do with any specific driver.
10
11
12Two Models for Device Power Management
13======================================
14Drivers will use one or both of these models to put devices into low-power
15states:
16
17 System Sleep model:
18 Drivers can enter low power states as part of entering system-wide
19 low-power states like "suspend-to-ram", or (mostly for systems with
20 disks) "hibernate" (suspend-to-disk).
21
22 This is something that device, bus, and class drivers collaborate on
23 by implementing various role-specific suspend and resume methods to
24 cleanly power down hardware and software subsystems, then reactivate
25 them without loss of data.
26
27 Some drivers can manage hardware wakeup events, which make the system
28 leave that low-power state. This feature may be disabled using the
29 relevant /sys/devices/.../power/wakeup file; enabling it may cost some
30 power usage, but let the whole system enter low power states more often.
31
32 Runtime Power Management model:
33 Drivers may also enter low power states while the system is running,
34 independently of other power management activity. Upstream drivers
35 will normally not know (or care) if the device is in some low power
36 state when issuing requests; the driver will auto-resume anything
37 that's needed when it gets a request.
38
39 This doesn't have, or need much infrastructure; it's just something you
40 should do when writing your drivers. For example, clk_disable() unused
41 clocks as part of minimizing power drain for currently-unused hardware.
42 Of course, sometimes clusters of drivers will collaborate with each
43 other, which could involve task-specific power management.
44
45There's not a lot to be said about those low power states except that they
46are very system-specific, and often device-specific. Also, that if enough
47drivers put themselves into low power states (at "runtime"), the effect may be
48the same as entering some system-wide low-power state (system sleep) ... and
49that synergies exist, so that several drivers using runtime pm might put the
50system into a state where even deeper power saving options are available.
51
52Most suspended devices will have quiesced all I/O: no more DMA or irqs, no
53more data read or written, and requests from upstream drivers are no longer
54accepted. A given bus or platform may have different requirements though.
55
56Examples of hardware wakeup events include an alarm from a real time clock,
57network wake-on-LAN packets, keyboard or mouse activity, and media insertion
58or removal (for PCMCIA, MMC/SD, USB, and so on).
59
60
61Interfaces for Entering System Sleep States
62===========================================
63Most of the programming interfaces a device driver needs to know about
64relate to that first model: entering a system-wide low power state,
65rather than just minimizing power consumption by one device.
66
67
68Bus Driver Methods
69------------------
70The core methods to suspend and resume devices reside in struct bus_type.
71These are mostly of interest to people writing infrastructure for busses
72like PCI or USB, or because they define the primitives that device drivers
73may need to apply in domain-specific ways to their devices:
1 74
2Device Power Management 75struct bus_type {
76 ...
77 int (*suspend)(struct device *dev, pm_message_t state);
78 int (*suspend_late)(struct device *dev, pm_message_t state);
3 79
80 int (*resume_early)(struct device *dev);
81 int (*resume)(struct device *dev);
82};
4 83
5Device power management encompasses two areas - the ability to save 84Bus drivers implement those methods as appropriate for the hardware and
6state and transition a device to a low-power state when the system is 85the drivers using it; PCI works differently from USB, and so on. Not many
7entering a low-power state; and the ability to transition a device to 86people write bus drivers; most driver code is a "device driver" that
8a low-power state while the system is running (and independently of 87builds on top of bus-specific framework code.
9any other power management activity). 88
89For more information on these driver calls, see the description later;
90they are called in phases for every device, respecting the parent-child
91sequencing in the driver model tree. Note that as this is being written,
92only the suspend() and resume() are widely available; not many bus drivers
93leverage all of those phases, or pass them down to lower driver levels.
94
95
96/sys/devices/.../power/wakeup files
97-----------------------------------
98All devices in the driver model have two flags to control handling of
99wakeup events, which are hardware signals that can force the device and/or
100system out of a low power state. These are initialized by bus or device
101driver code using device_init_wakeup(dev,can_wakeup).
102
103The "can_wakeup" flag just records whether the device (and its driver) can
104physically support wakeup events. When that flag is clear, the sysfs
105"wakeup" file is empty, and device_may_wakeup() returns false.
106
107For devices that can issue wakeup events, a separate flag controls whether
108that device should try to use its wakeup mechanism. The initial value of
109device_may_wakeup() will be true, so that the device's "wakeup" file holds
110the value "enabled". Userspace can change that to "disabled" so that
111device_may_wakeup() returns false; or change it back to "enabled" (so that
112it returns true again).
113
114
115EXAMPLE: PCI Device Driver Methods
116-----------------------------------
117PCI framework software calls these methods when the PCI device driver bound
118to a device device has provided them:
119
120struct pci_driver {
121 ...
122 int (*suspend)(struct pci_device *pdev, pm_message_t state);
123 int (*suspend_late)(struct pci_device *pdev, pm_message_t state);
124
125 int (*resume_early)(struct pci_device *pdev);
126 int (*resume)(struct pci_device *pdev);
127};
10 128
129Drivers will implement those methods, and call PCI-specific procedures
130like pci_set_power_state(), pci_enable_wake(), pci_save_state(), and
131pci_restore_state() to manage PCI-specific mechanisms. (PCI config space
132could be saved during driver probe, if it weren't for the fact that some
133systems rely on userspace tweaking using setpci.) Devices are suspended
134before their bridges enter low power states, and likewise bridges resume
135before their devices.
136
137
138Upper Layers of Driver Stacks
139-----------------------------
140Device drivers generally have at least two interfaces, and the methods
141sketched above are the ones which apply to the lower level (nearer PCI, USB,
142or other bus hardware). The network and block layers are examples of upper
143level interfaces, as is a character device talking to userspace.
144
145Power management requests normally need to flow through those upper levels,
146which often use domain-oriented requests like "blank that screen". In
147some cases those upper levels will have power management intelligence that
148relates to end-user activity, or other devices that work in cooperation.
149
150When those interfaces are structured using class interfaces, there is a
151standard way to have the upper layer stop issuing requests to a given
152class device (and restart later):
153
154struct class {
155 ...
156 int (*suspend)(struct device *dev, pm_message_t state);
157 int (*resume)(struct device *dev);
158};
11 159
12Methods 160Those calls are issued in specific phases of the process by which the
161system enters a low power "suspend" state, or resumes from it.
162
163
164Calling Drivers to Enter System Sleep States
165============================================
166When the system enters a low power state, each device's driver is asked
167to suspend the device by putting it into state compatible with the target
168system state. That's usually some version of "off", but the details are
169system-specific. Also, wakeup-enabled devices will usually stay partly
170functional in order to wake the system.
171
172When the system leaves that low power state, the device's driver is asked
173to resume it. The suspend and resume operations always go together, and
174both are multi-phase operations.
175
176For simple drivers, suspend might quiesce the device using the class code
177and then turn its hardware as "off" as possible with late_suspend. The
178matching resume calls would then completely reinitialize the hardware
179before reactivating its class I/O queues.
180
181More power-aware drivers drivers will use more than one device low power
182state, either at runtime or during system sleep states, and might trigger
183system wakeup events.
184
185
186Call Sequence Guarantees
187------------------------
188To ensure that bridges and similar links needed to talk to a device are
189available when the device is suspended or resumed, the device tree is
190walked in a bottom-up order to suspend devices. A top-down order is
191used to resume those devices.
192
193The ordering of the device tree is defined by the order in which devices
194get registered: a child can never be registered, probed or resumed before
195its parent; and can't be removed or suspended after that parent.
196
197The policy is that the device tree should match hardware bus topology.
198(Or at least the control bus, for devices which use multiple busses.)
199
200
201Suspending Devices
202------------------
203Suspending a given device is done in several phases. Suspending the
204system always includes every phase, executing calls for every device
205before the next phase begins. Not all busses or classes support all
206these callbacks; and not all drivers use all the callbacks.
207
208The phases are seen by driver notifications issued in this order:
209
210 1 class.suspend(dev, message) is called after tasks are frozen, for
211 devices associated with a class that has such a method. This
212 method may sleep.
213
214 Since I/O activity usually comes from such higher layers, this is
215 a good place to quiesce all drivers of a given type (and keep such
216 code out of those drivers).
217
218 2 bus.suspend(dev, message) is called next. This method may sleep,
219 and is often morphed into a device driver call with bus-specific
220 parameters and/or rules.
221
222 This call should handle parts of device suspend logic that require
223 sleeping. It probably does work to quiesce the device which hasn't
224 been abstracted into class.suspend() or bus.suspend_late().
225
226 3 bus.suspend_late(dev, message) is called with IRQs disabled, and
227 with only one CPU active. Until the bus.resume_early() phase
228 completes (see later), IRQs are not enabled again. This method
229 won't be exposed by all busses; for message based busses like USB,
230 I2C, or SPI, device interactions normally require IRQs. This bus
231 call may be morphed into a driver call with bus-specific parameters.
232
233 This call might save low level hardware state that might otherwise
234 be lost in the upcoming low power state, and actually put the
235 device into a low power state ... so that in some cases the device
236 may stay partly usable until this late. This "late" call may also
237 help when coping with hardware that behaves badly.
238
239The pm_message_t parameter is currently used to refine those semantics
240(described later).
241
242At the end of those phases, drivers should normally have stopped all I/O
243transactions (DMA, IRQs), saved enough state that they can re-initialize
244or restore previous state (as needed by the hardware), and placed the
245device into a low-power state. On many platforms they will also use
246clk_disable() to gate off one or more clock sources; sometimes they will
247also switch off power supplies, or reduce voltages. Drivers which have
248runtime PM support may already have performed some or all of the steps
249needed to prepare for the upcoming system sleep state.
250
251When any driver sees that its device_can_wakeup(dev), it should make sure
252to use the relevant hardware signals to trigger a system wakeup event.
253For example, enable_irq_wake() might identify GPIO signals hooked up to
254a switch or other external hardware, and pci_enable_wake() does something
255similar for PCI's PME# signal.
256
257If a driver (or bus, or class) fails it suspend method, the system won't
258enter the desired low power state; it will resume all the devices it's
259suspended so far.
260
261Note that drivers may need to perform different actions based on the target
262system lowpower/sleep state. At this writing, there are only platform
263specific APIs through which drivers could determine those target states.
264
265
266Device Low Power (suspend) States
267---------------------------------
268Device low-power states aren't very standard. One device might only handle
269"on" and "off, while another might support a dozen different versions of
270"on" (how many engines are active?), plus a state that gets back to "on"
271faster than from a full "off".
272
273Some busses define rules about what different suspend states mean. PCI
274gives one example: after the suspend sequence completes, a non-legacy
275PCI device may not perform DMA or issue IRQs, and any wakeup events it
276issues would be issued through the PME# bus signal. Plus, there are
277several PCI-standard device states, some of which are optional.
278
279In contrast, integrated system-on-chip processors often use irqs as the
280wakeup event sources (so drivers would call enable_irq_wake) and might
281be able to treat DMA completion as a wakeup event (sometimes DMA can stay
282active too, it'd only be the CPU and some peripherals that sleep).
283
284Some details here may be platform-specific. Systems may have devices that
285can be fully active in certain sleep states, such as an LCD display that's
286refreshed using DMA while most of the system is sleeping lightly ... and
287its frame buffer might even be updated by a DSP or other non-Linux CPU while
288the Linux control processor stays idle.
289
290Moreover, the specific actions taken may depend on the target system state.
291One target system state might allow a given device to be very operational;
292another might require a hard shut down with re-initialization on resume.
293And two different target systems might use the same device in different
294ways; the aforementioned LCD might be active in one product's "standby",
295but a different product using the same SOC might work differently.
296
297
298Meaning of pm_message_t.event
299-----------------------------
300Parameters to suspend calls include the device affected and a message of
301type pm_message_t, which has one field: the event. If driver does not
302recognize the event code, suspend calls may abort the request and return
303a negative errno. However, most drivers will be fine if they implement
304PM_EVENT_SUSPEND semantics for all messages.
305
306The event codes are used to refine the goal of suspending the device, and
307mostly matter when creating or resuming system memory image snapshots, as
308used with suspend-to-disk:
309
310 PM_EVENT_SUSPEND -- quiesce the driver and put hardware into a low-power
311 state. When used with system sleep states like "suspend-to-RAM" or
312 "standby", the upcoming resume() call will often be able to rely on
313 state kept in hardware, or issue system wakeup events. When used
314 instead with suspend-to-disk, few devices support this capability;
315 most are completely powered off.
316
317 PM_EVENT_FREEZE -- quiesce the driver, but don't necessarily change into
318 any low power mode. A system snapshot is about to be taken, often
319 followed by a call to the driver's resume() method. Neither wakeup
320 events nor DMA are allowed.
321
322 PM_EVENT_PRETHAW -- quiesce the driver, knowing that the upcoming resume()
323 will restore a suspend-to-disk snapshot from a different kernel image.
324 Drivers that are smart enough to look at their hardware state during
325 resume() processing need that state to be correct ... a PRETHAW could
326 be used to invalidate that state (by resetting the device), like a
327 shutdown() invocation would before a kexec() or system halt. Other
328 drivers might handle this the same way as PM_EVENT_FREEZE. Neither
329 wakeup events nor DMA are allowed.
330
331To enter "standby" (ACPI S1) or "Suspend to RAM" (STR, ACPI S3) states, or
332the similarly named APM states, only PM_EVENT_SUSPEND is used; for "Suspend
333to Disk" (STD, hibernate, ACPI S4), all of those event codes are used.
334
335There's also PM_EVENT_ON, a value which never appears as a suspend event
336but is sometimes used to record the "not suspended" device state.
337
338
339Resuming Devices
340----------------
341Resuming is done in multiple phases, much like suspending, with all
342devices processing each phase's calls before the next phase begins.
343
344The phases are seen by driver notifications issued in this order:
345
346 1 bus.resume_early(dev) is called with IRQs disabled, and with
347 only one CPU active. As with bus.suspend_late(), this method
348 won't be supported on busses that require IRQs in order to
349 interact with devices.
350
351 This reverses the effects of bus.suspend_late().
352
353 2 bus.resume(dev) is called next. This may be morphed into a device
354 driver call with bus-specific parameters; implementations may sleep.
355
356 This reverses the effects of bus.suspend().
357
358 3 class.resume(dev) is called for devices associated with a class
359 that has such a method. Implementations may sleep.
360
361 This reverses the effects of class.suspend(), and would usually
362 reactivate the device's I/O queue.
363
364At the end of those phases, drivers should normally be as functional as
365they were before suspending: I/O can be performed using DMA and IRQs, and
366the relevant clocks are gated on. The device need not be "fully on"; it
367might be in a runtime lowpower/suspend state that acts as if it were.
368
369However, the details here may again be platform-specific. For example,
370some systems support multiple "run" states, and the mode in effect at
371the end of resume() might not be the one which preceded suspension.
372That means availability of certain clocks or power supplies changed,
373which could easily affect how a driver works.
374
375
376Drivers need to be able to handle hardware which has been reset since the
377suspend methods were called, for example by complete reinitialization.
378This may be the hardest part, and the one most protected by NDA'd documents
379and chip errata. It's simplest if the hardware state hasn't changed since
380the suspend() was called, but that can't always be guaranteed.
381
382Drivers must also be prepared to notice that the device has been removed
383while the system was powered off, whenever that's physically possible.
384PCMCIA, MMC, USB, Firewire, SCSI, and even IDE are common examples of busses
385where common Linux platforms will see such removal. Details of how drivers
386will notice and handle such removals are currently bus-specific, and often
387involve a separate thread.
13 388
14The methods to suspend and resume devices reside in struct bus_type:
15 389
16struct bus_type { 390Note that the bus-specific runtime PM wakeup mechanism can exist, and might
17 ... 391be defined to share some of the same driver code as for system wakeup. For
18 int (*suspend)(struct device * dev, pm_message_t state); 392example, a bus-specific device driver's resume() method might be used there,
19 int (*resume)(struct device * dev); 393so it wouldn't only be called from bus.resume() during system-wide wakeup.
20}; 394See bus-specific information about how runtime wakeup events are handled.
21 395
22Each bus driver is responsible implementing these methods, translating
23the call into a bus-specific request and forwarding the call to the
24bus-specific drivers. For example, PCI drivers implement suspend() and
25resume() methods in struct pci_driver. The PCI core is simply
26responsible for translating the pointers to PCI-specific ones and
27calling the low-level driver.
28
29This is done to a) ease transition to the new power management methods
30and leverage the existing PM code in various bus drivers; b) allow
31buses to implement generic and default PM routines for devices, and c)
32make the flow of execution obvious to the reader.
33
34
35System Power Management
36
37When the system enters a low-power state, the device tree is walked in
38a depth-first fashion to transition each device into a low-power
39state. The ordering of the device tree is guaranteed by the order in
40which devices get registered - children are never registered before
41their ancestors, and devices are placed at the back of the list when
42registered. By walking the list in reverse order, we are guaranteed to
43suspend devices in the proper order.
44
45Devices are suspended once with interrupts enabled. Drivers are
46expected to stop I/O transactions, save device state, and place the
47device into a low-power state. Drivers may sleep, allocate memory,
48etc. at will.
49
50Some devices are broken and will inevitably have problems powering
51down or disabling themselves with interrupts enabled. For these
52special cases, they may return -EAGAIN. This will put the device on a
53list to be taken care of later. When interrupts are disabled, before
54we enter the low-power state, their drivers are called again to put
55their device to sleep.
56
57On resume, the devices that returned -EAGAIN will be called to power
58themselves back on with interrupts disabled. Once interrupts have been
59re-enabled, the rest of the drivers will be called to resume their
60devices. On resume, a driver is responsible for powering back on each
61device, restoring state, and re-enabling I/O transactions for that
62device.
63 396
397System Devices
398--------------
64System devices follow a slightly different API, which can be found in 399System devices follow a slightly different API, which can be found in
65 400
66 include/linux/sysdev.h 401 include/linux/sysdev.h
67 drivers/base/sys.c 402 drivers/base/sys.c
68 403
69System devices will only be suspended with interrupts disabled, and 404System devices will only be suspended with interrupts disabled, and after
70after all other devices have been suspended. On resume, they will be 405all other devices have been suspended. On resume, they will be resumed
71resumed before any other devices, and also with interrupts disabled. 406before any other devices, and also with interrupts disabled.
72 407
408That is, IRQs are disabled, the suspend_late() phase begins, then the
409sysdev_driver.suspend() phase, and the system enters a sleep state. Then
410the sysdev_driver.resume() phase begins, followed by the resume_early()
411phase, after which IRQs are enabled.
73 412
74Runtime Power Management 413Code to actually enter and exit the system-wide low power state sometimes
75 414involves hardware details that are only known to the boot firmware, and
76Many devices are able to dynamically power down while the system is 415may leave a CPU running software (from SRAM or flash memory) that monitors
77still running. This feature is useful for devices that are not being 416the system and manages its wakeup sequence.
78used, and can offer significant power savings on a running system.
79
80In each device's directory, there is a 'power' directory, which
81contains at least a 'state' file. Reading from this file displays what
82power state the device is currently in. Writing to this file initiates
83a transition to the specified power state, which must be a decimal in
84the range 1-3, inclusive; or 0 for 'On'.
85 417
86The PM core will call the ->suspend() method in the bus_type object
87that the device belongs to if the specified state is not 0, or
88->resume() if it is.
89 418
90Nothing will happen if the specified state is the same state the 419Runtime Power Management
91device is currently in. 420========================
92 421Many devices are able to dynamically power down while the system is still
93If the device is already in a low-power state, and the specified state 422running. This feature is useful for devices that are not being used, and
94is another, but different, low-power state, the ->resume() method will 423can offer significant power savings on a running system. These devices
95first be called to power the device back on, then ->suspend() will be 424often support a range of runtime power states, which might use names such
96called again with the new state. 425as "off", "sleep", "idle", "active", and so on. Those states will in some
97 426cases (like PCI) be partially constrained by a bus the device uses, and will
98The driver is responsible for saving the working state of the device 427usually include hardware states that are also used in system sleep states.
99and putting it into the low-power state specified. If this was 428
100successful, it returns 0, and the device's power_state field is 429However, note that if a driver puts a device into a runtime low power state
101updated. 430and the system then goes into a system-wide sleep state, it normally ought
102 431to resume into that runtime low power state rather than "full on". Such
103The driver must take care to know whether or not it is able to 432distinctions would be part of the driver-internal state machine for that
104properly resume the device, including all step of reinitialization 433hardware; the whole point of runtime power management is to be sure that
105necessary. (This is the hardest part, and the one most protected by 434drivers are decoupled in that way from the state machine governing phases
106NDA'd documents). 435of the system-wide power/sleep state transitions.
107 436
108The driver must also take care not to suspend a device that is 437
109currently in use. It is their responsibility to provide their own 438Power Saving Techniques
110exclusion mechanisms. 439-----------------------
111 440Normally runtime power management is handled by the drivers without specific
112The runtime power transition happens with interrupts enabled. If a 441userspace or kernel intervention, by device-aware use of techniques like:
113device cannot support being powered down with interrupts, it may 442
114return -EAGAIN (as it would during a system power management 443 Using information provided by other system layers
115transition), but it will _not_ be called again, and the transaction 444 - stay deeply "off" except between open() and close()
116will fail. 445 - if transceiver/PHY indicates "nobody connected", stay "off"
117 446 - application protocols may include power commands or hints
118There is currently no way to know what states a device or driver 447
119supports a priori. This will change in the future. 448 Using fewer CPU cycles
120 449 - using DMA instead of PIO
121pm_message_t meaning 450 - removing timers, or making them lower frequency
122 451 - shortening "hot" code paths
123pm_message_t has two fields. event ("major"), and flags. If driver 452 - eliminating cache misses
124does not know event code, it aborts the request, returning error. Some 453 - (sometimes) offloading work to device firmware
125drivers may need to deal with special cases based on the actual type 454
126of suspend operation being done at the system level. This is why 455 Reducing other resource costs
127there are flags. 456 - gating off unused clocks in software (or hardware)
128 457 - switching off unused power supplies
129Event codes are: 458 - eliminating (or delaying/merging) IRQs
130 459 - tuning DMA to use word and/or burst modes
131ON -- no need to do anything except special cases like broken 460
132HW. 461 Using device-specific low power states
133 462 - using lower voltages
134# NOTIFICATION -- pretty much same as ON? 463 - avoiding needless DMA transfers
135 464
136FREEZE -- stop DMA and interrupts, and be prepared to reinit HW from 465Read your hardware documentation carefully to see the opportunities that
137scratch. That probably means stop accepting upstream requests, the 466may be available. If you can, measure the actual power usage and check
138actual policy of what to do with them being specific to a given 467it against the budget established for your project.
139driver. It's acceptable for a network driver to just drop packets 468
140while a block driver is expected to block the queue so no request is 469
141lost. (Use IDE as an example on how to do that). FREEZE requires no 470Examples: USB hosts, system timer, system CPU
142power state change, and it's expected for drivers to be able to 471----------------------------------------------
143quickly transition back to operating state. 472USB host controllers make interesting, if complex, examples. In many cases
144 473these have no work to do: no USB devices are connected, or all of them are
145SUSPEND -- like FREEZE, but also put hardware into low-power state. If 474in the USB "suspend" state. Linux host controller drivers can then disable
146there's need to distinguish several levels of sleep, additional flag 475periodic DMA transfers that would otherwise be a constant power drain on the
147is probably best way to do that. 476memory subsystem, and enter a suspend state. In power-aware controllers,
148 477entering that suspend state may disable the clock used with USB signaling,
149Transitions are only from a resumed state to a suspended state, never 478saving a certain amount of power.
150between 2 suspended states. (ON -> FREEZE or ON -> SUSPEND can happen, 479
151FREEZE -> SUSPEND or SUSPEND -> FREEZE can not). 480The controller will be woken from that state (with an IRQ) by changes to the
152 481signal state on the data lines of a given port, for example by an existing
153All events are: 482peripheral requesting "remote wakeup" or by plugging a new peripheral. The
154 483same wakeup mechanism usually works from "standby" sleep states, and on some
155[NOTE NOTE NOTE: If you are driver author, you should not care; you 484systems also from "suspend to RAM" (or even "suspend to disk") states.
156should only look at event, and ignore flags.] 485(Except that ACPI may be involved instead of normal IRQs, on some hardware.)
157 486
158#Prepare for suspend -- userland is still running but we are going to 487System devices like timers and CPUs may have special roles in the platform
159#enter suspend state. This gives drivers chance to load firmware from 488power management scheme. For example, system timers using a "dynamic tick"
160#disk and store it in memory, or do other activities taht require 489approach don't just save CPU cycles (by eliminating needless timer IRQs),
161#operating userland, ability to kmalloc GFP_KERNEL, etc... All of these 490but they may also open the door to using lower power CPU "idle" states that
162#are forbiden once the suspend dance is started.. event = ON, flags = 491cost more than a jiffie to enter and exit. On x86 systems these are states
163#PREPARE_TO_SUSPEND 492like "C3"; note that periodic DMA transfers from a USB host controller will
164 493also prevent entry to a C3 state, much like a periodic timer IRQ.
165Apm standby -- prepare for APM event. Quiesce devices to make life 494
166easier for APM BIOS. event = FREEZE, flags = APM_STANDBY 495That kind of runtime mechanism interaction is common. "System On Chip" (SOC)
167 496processors often have low power idle modes that can't be entered unless
168Apm suspend -- same as APM_STANDBY, but it we should probably avoid 497certain medium-speed clocks (often 12 or 48 MHz) are gated off. When the
169spinning down disks. event = FREEZE, flags = APM_SUSPEND 498drivers gate those clocks effectively, then the system idle task may be able
170 499to use the lower power idle modes and thereby increase battery life.
171System halt, reboot -- quiesce devices to make life easier for BIOS. event 500
172= FREEZE, flags = SYSTEM_HALT or SYSTEM_REBOOT 501If the CPU can have a "cpufreq" driver, there also may be opportunities
173 502to shift to lower voltage settings and reduce the power cost of executing
174System shutdown -- at least disks need to be spun down, or data may be 503a given number of instructions. (Without voltage adjustment, it's rare
175lost. Quiesce devices, just to make life easier for BIOS. event = 504for cpufreq to save much power; the cost-per-instruction must go down.)
176FREEZE, flags = SYSTEM_SHUTDOWN 505
177 506
178Kexec -- turn off DMAs and put hardware into some state where new 507/sys/devices/.../power/state files
179kernel can take over. event = FREEZE, flags = KEXEC 508==================================
180 509For now you can also test some of this functionality using sysfs.
181Powerdown at end of swsusp -- very similar to SYSTEM_SHUTDOWN, except wake 510
182may need to be enabled on some devices. This actually has at least 3 511 DEPRECATED: USE "power/state" ONLY FOR DRIVER TESTING, AND
183subtypes, system can reboot, enter S4 and enter S5 at the end of 512 AVOID USING dev->power.power_state IN DRIVERS.
184swsusp. event = FREEZE, flags = SWSUSP and one of SYSTEM_REBOOT, 513
185SYSTEM_SHUTDOWN, SYSTEM_S4 514 THESE WILL BE REMOVED. IF THE "power/state" FILE GETS REPLACED,
186 515 IT WILL BECOME SOMETHING COUPLED TO THE BUS OR DRIVER.
187Suspend to ram -- put devices into low power state. event = SUSPEND, 516
188flags = SUSPEND_TO_RAM 517In each device's directory, there is a 'power' directory, which contains
189 518at least a 'state' file. The value of this field is effectively boolean,
190Freeze for swsusp snapshot -- stop DMA and interrupts. No need to put 519PM_EVENT_ON or PM_EVENT_SUSPEND.
191devices into low power mode, but you must be able to reinitialize 520
192device from scratch in resume method. This has two flavors, its done 521 * Reading from this file displays a value corresponding to
193once on suspending kernel, once on resuming kernel. event = FREEZE, 522 the power.power_state.event field. All nonzero values are
194flags = DURING_SUSPEND or DURING_RESUME 523 displayed as "2", corresponding to a low power state; zero
195 524 is displayed as "0", corresponding to normal operation.
196Device detach requested from /sys -- deinitialize device; proably same as 525
197SYSTEM_SHUTDOWN, I do not understand this one too much. probably event 526 * Writing to this file initiates a transition using the
198= FREEZE, flags = DEV_DETACH. 527 specified event code number; only '0', '2', and '3' are
199 528 accepted (without a newline); '2' and '3' are both
200#These are not really events sent: 529 mapped to PM_EVENT_SUSPEND.
201# 530
202#System fully on -- device is working normally; this is probably never 531On writes, the PM core relies on that recorded event code and the device/bus
203#passed to suspend() method... event = ON, flags = 0 532capabilities to determine whether it uses a partial suspend() or resume()
204# 533sequence to change things so that the recorded event corresponds to the
205#Ready after resume -- userland is now running, again. Time to free any 534numeric parameter.
206#memory you ate during prepare to suspend... event = ON, flags = 535
207#READY_AFTER_RESUME 536 - If the bus requires the irqs-disabled suspend_late()/resume_early()
208# 537 phases, writes fail because those operations are not supported here.
538
539 - If the recorded value is the expected value, nothing is done.
540
541 - If the recorded value is nonzero, the device is partially resumed,
542 using the bus.resume() and/or class.resume() methods.
543
544 - If the target value is nonzero, the device is partially suspended,
545 using the class.suspend() and/or bus.suspend() methods and the
546 PM_EVENT_SUSPEND message.
547
548Drivers have no way to tell whether their suspend() and resume() calls
549have come through the sysfs power/state file or as part of entering a
550system sleep state, except that when accessed through sysfs the normal
551parent/child sequencing rules are ignored. Drivers (such as bus, bridge,
552or hub drivers) which expose child devices may need to enforce those rules
553on their own.
diff --git a/drivers/base/base.h b/drivers/base/base.h
index c3b8dc98b8a7..d26644a59537 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -16,7 +16,7 @@ extern int cpu_dev_init(void);
16extern int attribute_container_init(void); 16extern int attribute_container_init(void);
17 17
18extern int bus_add_device(struct device * dev); 18extern int bus_add_device(struct device * dev);
19extern void bus_attach_device(struct device * dev); 19extern int bus_attach_device(struct device * dev);
20extern void bus_remove_device(struct device * dev); 20extern void bus_remove_device(struct device * dev);
21extern struct bus_type *get_bus(struct bus_type * bus); 21extern struct bus_type *get_bus(struct bus_type * bus);
22extern void put_bus(struct bus_type * bus); 22extern void put_bus(struct bus_type * bus);
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 2e954d07175a..12173d16bea7 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -371,12 +371,20 @@ int bus_add_device(struct device * dev)
371 if (bus) { 371 if (bus) {
372 pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id); 372 pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id);
373 error = device_add_attrs(bus, dev); 373 error = device_add_attrs(bus, dev);
374 if (!error) { 374 if (error)
375 sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id); 375 goto out;
376 sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "subsystem"); 376 error = sysfs_create_link(&bus->devices.kobj,
377 sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "bus"); 377 &dev->kobj, dev->bus_id);
378 } 378 if (error)
379 goto out;
380 error = sysfs_create_link(&dev->kobj,
381 &dev->bus->subsys.kset.kobj, "subsystem");
382 if (error)
383 goto out;
384 error = sysfs_create_link(&dev->kobj,
385 &dev->bus->subsys.kset.kobj, "bus");
379 } 386 }
387out:
380 return error; 388 return error;
381} 389}
382 390
@@ -384,16 +392,24 @@ int bus_add_device(struct device * dev)
384 * bus_attach_device - add device to bus 392 * bus_attach_device - add device to bus
385 * @dev: device tried to attach to a driver 393 * @dev: device tried to attach to a driver
386 * 394 *
395 * - Add device to bus's list of devices.
387 * - Try to attach to driver. 396 * - Try to attach to driver.
388 */ 397 */
389void bus_attach_device(struct device * dev) 398int bus_attach_device(struct device * dev)
390{ 399{
391 struct bus_type * bus = dev->bus; 400 struct bus_type *bus = dev->bus;
401 int ret = 0;
392 402
393 if (bus) { 403 if (bus) {
394 device_attach(dev); 404 dev->is_registered = 1;
395 klist_add_tail(&dev->knode_bus, &bus->klist_devices); 405 ret = device_attach(dev);
406 if (ret >= 0) {
407 klist_add_tail(&dev->knode_bus, &bus->klist_devices);
408 ret = 0;
409 } else
410 dev->is_registered = 0;
396 } 411 }
412 return ret;
397} 413}
398 414
399/** 415/**
@@ -412,7 +428,8 @@ void bus_remove_device(struct device * dev)
412 sysfs_remove_link(&dev->kobj, "bus"); 428 sysfs_remove_link(&dev->kobj, "bus");
413 sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id); 429 sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id);
414 device_remove_attrs(dev->bus, dev); 430 device_remove_attrs(dev->bus, dev);
415 klist_remove(&dev->knode_bus); 431 dev->is_registered = 0;
432 klist_del(&dev->knode_bus);
416 pr_debug("bus %s: remove device %s\n", dev->bus->name, dev->bus_id); 433 pr_debug("bus %s: remove device %s\n", dev->bus->name, dev->bus_id);
417 device_release_driver(dev); 434 device_release_driver(dev);
418 put_bus(dev->bus); 435 put_bus(dev->bus);
@@ -455,10 +472,17 @@ static void driver_remove_attrs(struct bus_type * bus, struct device_driver * dr
455 * Thanks to drivers making their tables __devinit, we can't allow manual 472 * Thanks to drivers making their tables __devinit, we can't allow manual
456 * bind and unbind from userspace unless CONFIG_HOTPLUG is enabled. 473 * bind and unbind from userspace unless CONFIG_HOTPLUG is enabled.
457 */ 474 */
458static void add_bind_files(struct device_driver *drv) 475static int __must_check add_bind_files(struct device_driver *drv)
459{ 476{
460 driver_create_file(drv, &driver_attr_unbind); 477 int ret;
461 driver_create_file(drv, &driver_attr_bind); 478
479 ret = driver_create_file(drv, &driver_attr_unbind);
480 if (ret == 0) {
481 ret = driver_create_file(drv, &driver_attr_bind);
482 if (ret)
483 driver_remove_file(drv, &driver_attr_unbind);
484 }
485 return ret;
462} 486}
463 487
464static void remove_bind_files(struct device_driver *drv) 488static void remove_bind_files(struct device_driver *drv)
@@ -467,7 +491,7 @@ static void remove_bind_files(struct device_driver *drv)
467 driver_remove_file(drv, &driver_attr_unbind); 491 driver_remove_file(drv, &driver_attr_unbind);
468} 492}
469#else 493#else
470static inline void add_bind_files(struct device_driver *drv) {} 494static inline int add_bind_files(struct device_driver *drv) { return 0; }
471static inline void remove_bind_files(struct device_driver *drv) {} 495static inline void remove_bind_files(struct device_driver *drv) {}
472#endif 496#endif
473 497
@@ -476,7 +500,7 @@ static inline void remove_bind_files(struct device_driver *drv) {}
476 * @drv: driver. 500 * @drv: driver.
477 * 501 *
478 */ 502 */
479int bus_add_driver(struct device_driver * drv) 503int bus_add_driver(struct device_driver *drv)
480{ 504{
481 struct bus_type * bus = get_bus(drv->bus); 505 struct bus_type * bus = get_bus(drv->bus);
482 int error = 0; 506 int error = 0;
@@ -484,27 +508,39 @@ int bus_add_driver(struct device_driver * drv)
484 if (bus) { 508 if (bus) {
485 pr_debug("bus %s: add driver %s\n", bus->name, drv->name); 509 pr_debug("bus %s: add driver %s\n", bus->name, drv->name);
486 error = kobject_set_name(&drv->kobj, "%s", drv->name); 510 error = kobject_set_name(&drv->kobj, "%s", drv->name);
487 if (error) { 511 if (error)
488 put_bus(bus); 512 goto out_put_bus;
489 return error;
490 }
491 drv->kobj.kset = &bus->drivers; 513 drv->kobj.kset = &bus->drivers;
492 if ((error = kobject_register(&drv->kobj))) { 514 if ((error = kobject_register(&drv->kobj)))
493 put_bus(bus); 515 goto out_put_bus;
494 return error;
495 }
496 516
497 driver_attach(drv); 517 error = driver_attach(drv);
518 if (error)
519 goto out_unregister;
498 klist_add_tail(&drv->knode_bus, &bus->klist_drivers); 520 klist_add_tail(&drv->knode_bus, &bus->klist_drivers);
499 module_add_driver(drv->owner, drv); 521 module_add_driver(drv->owner, drv);
500 522
501 driver_add_attrs(bus, drv); 523 error = driver_add_attrs(bus, drv);
502 add_bind_files(drv); 524 if (error) {
525 /* How the hell do we get out of this pickle? Give up */
526 printk(KERN_ERR "%s: driver_add_attrs(%s) failed\n",
527 __FUNCTION__, drv->name);
528 }
529 error = add_bind_files(drv);
530 if (error) {
531 /* Ditto */
532 printk(KERN_ERR "%s: add_bind_files(%s) failed\n",
533 __FUNCTION__, drv->name);
534 }
503 } 535 }
504 return error; 536 return error;
537out_unregister:
538 kobject_unregister(&drv->kobj);
539out_put_bus:
540 put_bus(bus);
541 return error;
505} 542}
506 543
507
508/** 544/**
509 * bus_remove_driver - delete driver from bus's knowledge. 545 * bus_remove_driver - delete driver from bus's knowledge.
510 * @drv: driver. 546 * @drv: driver.
@@ -530,16 +566,21 @@ void bus_remove_driver(struct device_driver * drv)
530 566
531 567
532/* Helper for bus_rescan_devices's iter */ 568/* Helper for bus_rescan_devices's iter */
533static int bus_rescan_devices_helper(struct device *dev, void *data) 569static int __must_check bus_rescan_devices_helper(struct device *dev,
570 void *data)
534{ 571{
572 int ret = 0;
573
535 if (!dev->driver) { 574 if (!dev->driver) {
536 if (dev->parent) /* Needed for USB */ 575 if (dev->parent) /* Needed for USB */
537 down(&dev->parent->sem); 576 down(&dev->parent->sem);
538 device_attach(dev); 577 ret = device_attach(dev);
539 if (dev->parent) 578 if (dev->parent)
540 up(&dev->parent->sem); 579 up(&dev->parent->sem);
580 if (ret > 0)
581 ret = 0;
541 } 582 }
542 return 0; 583 return ret < 0 ? ret : 0;
543} 584}
544 585
545/** 586/**
@@ -550,9 +591,9 @@ static int bus_rescan_devices_helper(struct device *dev, void *data)
550 * attached and rescan it against existing drivers to see if it matches 591 * attached and rescan it against existing drivers to see if it matches
551 * any by calling device_attach() for the unbound devices. 592 * any by calling device_attach() for the unbound devices.
552 */ 593 */
553void bus_rescan_devices(struct bus_type * bus) 594int bus_rescan_devices(struct bus_type * bus)
554{ 595{
555 bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper); 596 return bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper);
556} 597}
557 598
558/** 599/**
@@ -564,7 +605,7 @@ void bus_rescan_devices(struct bus_type * bus)
564 * to use if probing criteria changed during a devices lifetime and 605 * to use if probing criteria changed during a devices lifetime and
565 * driver attachment should change accordingly. 606 * driver attachment should change accordingly.
566 */ 607 */
567void device_reprobe(struct device *dev) 608int device_reprobe(struct device *dev)
568{ 609{
569 if (dev->driver) { 610 if (dev->driver) {
570 if (dev->parent) /* Needed for USB */ 611 if (dev->parent) /* Needed for USB */
@@ -573,14 +614,14 @@ void device_reprobe(struct device *dev)
573 if (dev->parent) 614 if (dev->parent)
574 up(&dev->parent->sem); 615 up(&dev->parent->sem);
575 } 616 }
576 617 return bus_rescan_devices_helper(dev, NULL);
577 bus_rescan_devices_helper(dev, NULL);
578} 618}
579EXPORT_SYMBOL_GPL(device_reprobe); 619EXPORT_SYMBOL_GPL(device_reprobe);
580 620
581struct bus_type * get_bus(struct bus_type * bus) 621struct bus_type *get_bus(struct bus_type *bus)
582{ 622{
583 return bus ? container_of(subsys_get(&bus->subsys), struct bus_type, subsys) : NULL; 623 return bus ? container_of(subsys_get(&bus->subsys),
624 struct bus_type, subsys) : NULL;
584} 625}
585 626
586void put_bus(struct bus_type * bus) 627void put_bus(struct bus_type * bus)
@@ -655,22 +696,6 @@ static void klist_devices_put(struct klist_node *n)
655 put_device(dev); 696 put_device(dev);
656} 697}
657 698
658static void klist_drivers_get(struct klist_node *n)
659{
660 struct device_driver *drv = container_of(n, struct device_driver,
661 knode_bus);
662
663 get_driver(drv);
664}
665
666static void klist_drivers_put(struct klist_node *n)
667{
668 struct device_driver *drv = container_of(n, struct device_driver,
669 knode_bus);
670
671 put_driver(drv);
672}
673
674/** 699/**
675 * bus_register - register a bus with the system. 700 * bus_register - register a bus with the system.
676 * @bus: bus. 701 * @bus: bus.
@@ -706,7 +731,7 @@ int bus_register(struct bus_type * bus)
706 goto bus_drivers_fail; 731 goto bus_drivers_fail;
707 732
708 klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put); 733 klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put);
709 klist_init(&bus->klist_drivers, klist_drivers_get, klist_drivers_put); 734 klist_init(&bus->klist_drivers, NULL, NULL);
710 bus_add_attrs(bus); 735 bus_add_attrs(bus);
711 736
712 pr_debug("bus type '%s' registered\n", bus->name); 737 pr_debug("bus type '%s' registered\n", bus->name);
diff --git a/drivers/base/class.c b/drivers/base/class.c
index de8908320f23..b06b0e2b9c62 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -19,6 +19,8 @@
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include "base.h" 20#include "base.h"
21 21
22extern struct subsystem devices_subsys;
23
22#define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr) 24#define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr)
23#define to_class(obj) container_of(obj, struct class, subsys.kset.kobj) 25#define to_class(obj) container_of(obj, struct class, subsys.kset.kobj)
24 26
@@ -197,7 +199,7 @@ static int class_device_create_uevent(struct class_device *class_dev,
197 * Note, the pointer created here is to be destroyed when finished by 199 * Note, the pointer created here is to be destroyed when finished by
198 * making a call to class_destroy(). 200 * making a call to class_destroy().
199 */ 201 */
200struct class *class_create(struct module *owner, char *name) 202struct class *class_create(struct module *owner, const char *name)
201{ 203{
202 struct class *cls; 204 struct class *cls;
203 int retval; 205 int retval;
@@ -361,7 +363,7 @@ static int class_uevent(struct kset *kset, struct kobject *kobj, char **envp,
361 pr_debug("%s - name = %s\n", __FUNCTION__, class_dev->class_id); 363 pr_debug("%s - name = %s\n", __FUNCTION__, class_dev->class_id);
362 364
363 if (class_dev->dev) { 365 if (class_dev->dev) {
364 /* add physical device, backing this device */ 366 /* add device, backing this class device (deprecated) */
365 struct device *dev = class_dev->dev; 367 struct device *dev = class_dev->dev;
366 char *path = kobject_get_path(&dev->kobj, GFP_KERNEL); 368 char *path = kobject_get_path(&dev->kobj, GFP_KERNEL);
367 369
@@ -679,7 +681,8 @@ int class_device_register(struct class_device *class_dev)
679struct class_device *class_device_create(struct class *cls, 681struct class_device *class_device_create(struct class *cls,
680 struct class_device *parent, 682 struct class_device *parent,
681 dev_t devt, 683 dev_t devt,
682 struct device *device, char *fmt, ...) 684 struct device *device,
685 const char *fmt, ...)
683{ 686{
684 va_list args; 687 va_list args;
685 struct class_device *class_dev = NULL; 688 struct class_device *class_dev = NULL;
@@ -839,6 +842,7 @@ int class_interface_register(struct class_interface *class_intf)
839{ 842{
840 struct class *parent; 843 struct class *parent;
841 struct class_device *class_dev; 844 struct class_device *class_dev;
845 struct device *dev;
842 846
843 if (!class_intf || !class_intf->class) 847 if (!class_intf || !class_intf->class)
844 return -ENODEV; 848 return -ENODEV;
@@ -853,6 +857,10 @@ int class_interface_register(struct class_interface *class_intf)
853 list_for_each_entry(class_dev, &parent->children, node) 857 list_for_each_entry(class_dev, &parent->children, node)
854 class_intf->add(class_dev, class_intf); 858 class_intf->add(class_dev, class_intf);
855 } 859 }
860 if (class_intf->add_dev) {
861 list_for_each_entry(dev, &parent->devices, node)
862 class_intf->add_dev(dev, class_intf);
863 }
856 up(&parent->sem); 864 up(&parent->sem);
857 865
858 return 0; 866 return 0;
@@ -862,6 +870,7 @@ void class_interface_unregister(struct class_interface *class_intf)
862{ 870{
863 struct class * parent = class_intf->class; 871 struct class * parent = class_intf->class;
864 struct class_device *class_dev; 872 struct class_device *class_dev;
873 struct device *dev;
865 874
866 if (!parent) 875 if (!parent)
867 return; 876 return;
@@ -872,12 +881,31 @@ void class_interface_unregister(struct class_interface *class_intf)
872 list_for_each_entry(class_dev, &parent->children, node) 881 list_for_each_entry(class_dev, &parent->children, node)
873 class_intf->remove(class_dev, class_intf); 882 class_intf->remove(class_dev, class_intf);
874 } 883 }
884 if (class_intf->remove_dev) {
885 list_for_each_entry(dev, &parent->devices, node)
886 class_intf->remove_dev(dev, class_intf);
887 }
875 up(&parent->sem); 888 up(&parent->sem);
876 889
877 class_put(parent); 890 class_put(parent);
878} 891}
879 892
893int virtual_device_parent(struct device *dev)
894{
895 if (!dev->class)
896 return -ENODEV;
897
898 if (!dev->class->virtual_dir) {
899 static struct kobject *virtual_dir = NULL;
900
901 if (!virtual_dir)
902 virtual_dir = kobject_add_dir(&devices_subsys.kset.kobj, "virtual");
903 dev->class->virtual_dir = kobject_add_dir(virtual_dir, dev->class->name);
904 }
880 905
906 dev->kobj.parent = dev->class->virtual_dir;
907 return 0;
908}
881 909
882int __init classes_init(void) 910int __init classes_init(void)
883{ 911{
diff --git a/drivers/base/core.c b/drivers/base/core.c
index be6b5bc0677d..b224bb43ff63 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3,6 +3,8 @@
3 * 3 *
4 * Copyright (c) 2002-3 Patrick Mochel 4 * Copyright (c) 2002-3 Patrick Mochel
5 * Copyright (c) 2002-3 Open Source Development Labs 5 * Copyright (c) 2002-3 Open Source Development Labs
6 * Copyright (c) 2006 Greg Kroah-Hartman <gregkh@suse.de>
7 * Copyright (c) 2006 Novell, Inc.
6 * 8 *
7 * This file is released under the GPLv2 9 * This file is released under the GPLv2
8 * 10 *
@@ -92,6 +94,8 @@ static void device_release(struct kobject * kobj)
92 94
93 if (dev->release) 95 if (dev->release)
94 dev->release(dev); 96 dev->release(dev);
97 else if (dev->class && dev->class->dev_release)
98 dev->class->dev_release(dev);
95 else { 99 else {
96 printk(KERN_ERR "Device '%s' does not have a release() function, " 100 printk(KERN_ERR "Device '%s' does not have a release() function, "
97 "it is broken and must be fixed.\n", 101 "it is broken and must be fixed.\n",
@@ -149,17 +153,21 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, char **envp,
149 "MINOR=%u", MINOR(dev->devt)); 153 "MINOR=%u", MINOR(dev->devt));
150 } 154 }
151 155
152 /* add bus name of physical device */ 156 /* add bus name (same as SUBSYSTEM, deprecated) */
153 if (dev->bus) 157 if (dev->bus)
154 add_uevent_var(envp, num_envp, &i, 158 add_uevent_var(envp, num_envp, &i,
155 buffer, buffer_size, &length, 159 buffer, buffer_size, &length,
156 "PHYSDEVBUS=%s", dev->bus->name); 160 "PHYSDEVBUS=%s", dev->bus->name);
157 161
158 /* add driver name of physical device */ 162 /* add driver name (PHYSDEV* values are deprecated)*/
159 if (dev->driver) 163 if (dev->driver) {
164 add_uevent_var(envp, num_envp, &i,
165 buffer, buffer_size, &length,
166 "DRIVER=%s", dev->driver->name);
160 add_uevent_var(envp, num_envp, &i, 167 add_uevent_var(envp, num_envp, &i,
161 buffer, buffer_size, &length, 168 buffer, buffer_size, &length,
162 "PHYSDEVDRIVER=%s", dev->driver->name); 169 "PHYSDEVDRIVER=%s", dev->driver->name);
170 }
163 171
164 /* terminate, set to next free slot, shrink available space */ 172 /* terminate, set to next free slot, shrink available space */
165 envp[i] = NULL; 173 envp[i] = NULL;
@@ -177,6 +185,15 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, char **envp,
177 } 185 }
178 } 186 }
179 187
188 if (dev->class && dev->class->dev_uevent) {
189 /* have the class specific function add its stuff */
190 retval = dev->class->dev_uevent(dev, envp, num_envp, buffer, buffer_size);
191 if (retval) {
192 pr_debug("%s - dev_uevent() returned %d\n",
193 __FUNCTION__, retval);
194 }
195 }
196
180 return retval; 197 return retval;
181} 198}
182 199
@@ -193,6 +210,72 @@ static ssize_t store_uevent(struct device *dev, struct device_attribute *attr,
193 return count; 210 return count;
194} 211}
195 212
213static int device_add_groups(struct device *dev)
214{
215 int i;
216 int error = 0;
217
218 if (dev->groups) {
219 for (i = 0; dev->groups[i]; i++) {
220 error = sysfs_create_group(&dev->kobj, dev->groups[i]);
221 if (error) {
222 while (--i >= 0)
223 sysfs_remove_group(&dev->kobj, dev->groups[i]);
224 goto out;
225 }
226 }
227 }
228out:
229 return error;
230}
231
232static void device_remove_groups(struct device *dev)
233{
234 int i;
235 if (dev->groups) {
236 for (i = 0; dev->groups[i]; i++) {
237 sysfs_remove_group(&dev->kobj, dev->groups[i]);
238 }
239 }
240}
241
242static int device_add_attrs(struct device *dev)
243{
244 struct class *class = dev->class;
245 int error = 0;
246 int i;
247
248 if (!class)
249 return 0;
250
251 if (class->dev_attrs) {
252 for (i = 0; attr_name(class->dev_attrs[i]); i++) {
253 error = device_create_file(dev, &class->dev_attrs[i]);
254 if (error)
255 break;
256 }
257 }
258 if (error)
259 while (--i >= 0)
260 device_remove_file(dev, &class->dev_attrs[i]);
261 return error;
262}
263
264static void device_remove_attrs(struct device *dev)
265{
266 struct class *class = dev->class;
267 int i;
268
269 if (!class)
270 return;
271
272 if (class->dev_attrs) {
273 for (i = 0; attr_name(class->dev_attrs[i]); i++)
274 device_remove_file(dev, &class->dev_attrs[i]);
275 }
276}
277
278
196static ssize_t show_dev(struct device *dev, struct device_attribute *attr, 279static ssize_t show_dev(struct device *dev, struct device_attribute *attr,
197 char *buf) 280 char *buf)
198{ 281{
@@ -236,6 +319,32 @@ void device_remove_file(struct device * dev, struct device_attribute * attr)
236 } 319 }
237} 320}
238 321
322/**
323 * device_create_bin_file - create sysfs binary attribute file for device.
324 * @dev: device.
325 * @attr: device binary attribute descriptor.
326 */
327int device_create_bin_file(struct device *dev, struct bin_attribute *attr)
328{
329 int error = -EINVAL;
330 if (dev)
331 error = sysfs_create_bin_file(&dev->kobj, attr);
332 return error;
333}
334EXPORT_SYMBOL_GPL(device_create_bin_file);
335
336/**
337 * device_remove_bin_file - remove sysfs binary attribute file
338 * @dev: device.
339 * @attr: device binary attribute descriptor.
340 */
341void device_remove_bin_file(struct device *dev, struct bin_attribute *attr)
342{
343 if (dev)
344 sysfs_remove_bin_file(&dev->kobj, attr);
345}
346EXPORT_SYMBOL_GPL(device_remove_bin_file);
347
239static void klist_children_get(struct klist_node *n) 348static void klist_children_get(struct klist_node *n)
240{ 349{
241 struct device *dev = container_of(n, struct device, knode_parent); 350 struct device *dev = container_of(n, struct device, knode_parent);
@@ -289,12 +398,20 @@ int device_add(struct device *dev)
289{ 398{
290 struct device *parent = NULL; 399 struct device *parent = NULL;
291 char *class_name = NULL; 400 char *class_name = NULL;
401 struct class_interface *class_intf;
292 int error = -EINVAL; 402 int error = -EINVAL;
293 403
294 dev = get_device(dev); 404 dev = get_device(dev);
295 if (!dev || !strlen(dev->bus_id)) 405 if (!dev || !strlen(dev->bus_id))
296 goto Error; 406 goto Error;
297 407
408 /* if this is a class device, and has no parent, create one */
409 if ((dev->class) && (dev->parent == NULL)) {
410 error = virtual_device_parent(dev);
411 if (error)
412 goto Error;
413 }
414
298 parent = get_device(dev->parent); 415 parent = get_device(dev->parent);
299 416
300 pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id); 417 pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id);
@@ -307,6 +424,10 @@ int device_add(struct device *dev)
307 if ((error = kobject_add(&dev->kobj))) 424 if ((error = kobject_add(&dev->kobj)))
308 goto Error; 425 goto Error;
309 426
427 /* notify platform of device entry */
428 if (platform_notify)
429 platform_notify(dev);
430
310 dev->uevent_attr.attr.name = "uevent"; 431 dev->uevent_attr.attr.name = "uevent";
311 dev->uevent_attr.attr.mode = S_IWUSR; 432 dev->uevent_attr.attr.mode = S_IWUSR;
312 if (dev->driver) 433 if (dev->driver)
@@ -340,12 +461,17 @@ int device_add(struct device *dev)
340 "subsystem"); 461 "subsystem");
341 sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj, 462 sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj,
342 dev->bus_id); 463 dev->bus_id);
343 464 if (parent) {
344 sysfs_create_link(&dev->kobj, &dev->parent->kobj, "device"); 465 sysfs_create_link(&dev->kobj, &dev->parent->kobj, "device");
345 class_name = make_class_name(dev->class->name, &dev->kobj); 466 class_name = make_class_name(dev->class->name, &dev->kobj);
346 sysfs_create_link(&dev->parent->kobj, &dev->kobj, class_name); 467 sysfs_create_link(&dev->parent->kobj, &dev->kobj, class_name);
468 }
347 } 469 }
348 470
471 if ((error = device_add_attrs(dev)))
472 goto AttrsError;
473 if ((error = device_add_groups(dev)))
474 goto GroupError;
349 if ((error = device_pm_add(dev))) 475 if ((error = device_pm_add(dev)))
350 goto PMError; 476 goto PMError;
351 if ((error = bus_add_device(dev))) 477 if ((error = bus_add_device(dev)))
@@ -356,15 +482,16 @@ int device_add(struct device *dev)
356 klist_add_tail(&dev->knode_parent, &parent->klist_children); 482 klist_add_tail(&dev->knode_parent, &parent->klist_children);
357 483
358 if (dev->class) { 484 if (dev->class) {
359 /* tie the class to the device */
360 down(&dev->class->sem); 485 down(&dev->class->sem);
486 /* tie the class to the device */
361 list_add_tail(&dev->node, &dev->class->devices); 487 list_add_tail(&dev->node, &dev->class->devices);
488
489 /* notify any interfaces that the device is here */
490 list_for_each_entry(class_intf, &dev->class->interfaces, node)
491 if (class_intf->add_dev)
492 class_intf->add_dev(dev, class_intf);
362 up(&dev->class->sem); 493 up(&dev->class->sem);
363 } 494 }
364
365 /* notify platform of device entry */
366 if (platform_notify)
367 platform_notify(dev);
368 Done: 495 Done:
369 kfree(class_name); 496 kfree(class_name);
370 put_device(dev); 497 put_device(dev);
@@ -372,6 +499,10 @@ int device_add(struct device *dev)
372 BusError: 499 BusError:
373 device_pm_remove(dev); 500 device_pm_remove(dev);
374 PMError: 501 PMError:
502 device_remove_groups(dev);
503 GroupError:
504 device_remove_attrs(dev);
505 AttrsError:
375 if (dev->devt_attr) { 506 if (dev->devt_attr) {
376 device_remove_file(dev, dev->devt_attr); 507 device_remove_file(dev, dev->devt_attr);
377 kfree(dev->devt_attr); 508 kfree(dev->devt_attr);
@@ -449,6 +580,7 @@ void device_del(struct device * dev)
449{ 580{
450 struct device * parent = dev->parent; 581 struct device * parent = dev->parent;
451 char *class_name = NULL; 582 char *class_name = NULL;
583 struct class_interface *class_intf;
452 584
453 if (parent) 585 if (parent)
454 klist_del(&dev->knode_parent); 586 klist_del(&dev->knode_parent);
@@ -458,14 +590,23 @@ void device_del(struct device * dev)
458 sysfs_remove_link(&dev->kobj, "subsystem"); 590 sysfs_remove_link(&dev->kobj, "subsystem");
459 sysfs_remove_link(&dev->class->subsys.kset.kobj, dev->bus_id); 591 sysfs_remove_link(&dev->class->subsys.kset.kobj, dev->bus_id);
460 class_name = make_class_name(dev->class->name, &dev->kobj); 592 class_name = make_class_name(dev->class->name, &dev->kobj);
461 sysfs_remove_link(&dev->kobj, "device"); 593 if (parent) {
462 sysfs_remove_link(&dev->parent->kobj, class_name); 594 sysfs_remove_link(&dev->kobj, "device");
595 sysfs_remove_link(&dev->parent->kobj, class_name);
596 }
463 kfree(class_name); 597 kfree(class_name);
464 down(&dev->class->sem); 598 down(&dev->class->sem);
599 /* notify any interfaces that the device is now gone */
600 list_for_each_entry(class_intf, &dev->class->interfaces, node)
601 if (class_intf->remove_dev)
602 class_intf->remove_dev(dev, class_intf);
603 /* remove the device from the class list */
465 list_del_init(&dev->node); 604 list_del_init(&dev->node);
466 up(&dev->class->sem); 605 up(&dev->class->sem);
467 } 606 }
468 device_remove_file(dev, &dev->uevent_attr); 607 device_remove_file(dev, &dev->uevent_attr);
608 device_remove_groups(dev);
609 device_remove_attrs(dev);
469 610
470 /* Notify the platform of the removal, in case they 611 /* Notify the platform of the removal, in case they
471 * need to do anything... 612 * need to do anything...
@@ -579,7 +720,7 @@ static void device_create_release(struct device *dev)
579 * been created with a call to class_create(). 720 * been created with a call to class_create().
580 */ 721 */
581struct device *device_create(struct class *class, struct device *parent, 722struct device *device_create(struct class *class, struct device *parent,
582 dev_t devt, char *fmt, ...) 723 dev_t devt, const char *fmt, ...)
583{ 724{
584 va_list args; 725 va_list args;
585 struct device *dev = NULL; 726 struct device *dev = NULL;
@@ -587,10 +728,6 @@ struct device *device_create(struct class *class, struct device *parent,
587 728
588 if (class == NULL || IS_ERR(class)) 729 if (class == NULL || IS_ERR(class))
589 goto error; 730 goto error;
590 if (parent == NULL) {
591 printk(KERN_WARNING "%s does not work yet for NULL parents\n", __FUNCTION__);
592 goto error;
593 }
594 731
595 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 732 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
596 if (!dev) { 733 if (!dev) {
@@ -644,3 +781,58 @@ void device_destroy(struct class *class, dev_t devt)
644 device_unregister(dev); 781 device_unregister(dev);
645} 782}
646EXPORT_SYMBOL_GPL(device_destroy); 783EXPORT_SYMBOL_GPL(device_destroy);
784
785/**
786 * device_rename - renames a device
787 * @dev: the pointer to the struct device to be renamed
788 * @new_name: the new name of the device
789 */
790int device_rename(struct device *dev, char *new_name)
791{
792 char *old_class_name = NULL;
793 char *new_class_name = NULL;
794 char *old_symlink_name = NULL;
795 int error;
796
797 dev = get_device(dev);
798 if (!dev)
799 return -EINVAL;
800
801 pr_debug("DEVICE: renaming '%s' to '%s'\n", dev->bus_id, new_name);
802
803 if ((dev->class) && (dev->parent))
804 old_class_name = make_class_name(dev->class->name, &dev->kobj);
805
806 if (dev->class) {
807 old_symlink_name = kmalloc(BUS_ID_SIZE, GFP_KERNEL);
808 if (!old_symlink_name)
809 return -ENOMEM;
810 strlcpy(old_symlink_name, dev->bus_id, BUS_ID_SIZE);
811 }
812
813 strlcpy(dev->bus_id, new_name, BUS_ID_SIZE);
814
815 error = kobject_rename(&dev->kobj, new_name);
816
817 if (old_class_name) {
818 new_class_name = make_class_name(dev->class->name, &dev->kobj);
819 if (new_class_name) {
820 sysfs_create_link(&dev->parent->kobj, &dev->kobj,
821 new_class_name);
822 sysfs_remove_link(&dev->parent->kobj, old_class_name);
823 }
824 }
825 if (dev->class) {
826 sysfs_remove_link(&dev->class->subsys.kset.kobj,
827 old_symlink_name);
828 sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj,
829 dev->bus_id);
830 }
831 put_device(dev);
832
833 kfree(old_class_name);
834 kfree(new_class_name);
835 kfree(old_symlink_name);
836
837 return error;
838}
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 889c71111239..b5f43c3e44fa 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -17,6 +17,7 @@
17 17
18#include <linux/device.h> 18#include <linux/device.h>
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/kthread.h>
20 21
21#include "base.h" 22#include "base.h"
22#include "power/power.h" 23#include "power/power.h"
@@ -38,66 +39,73 @@
38 * 39 *
39 * This function must be called with @dev->sem held. 40 * This function must be called with @dev->sem held.
40 */ 41 */
41void device_bind_driver(struct device * dev) 42int device_bind_driver(struct device *dev)
42{ 43{
43 if (klist_node_attached(&dev->knode_driver)) 44 int ret;
44 return; 45
46 if (klist_node_attached(&dev->knode_driver)) {
47 printk(KERN_WARNING "%s: device %s already bound\n",
48 __FUNCTION__, kobject_name(&dev->kobj));
49 return 0;
50 }
45 51
46 pr_debug("bound device '%s' to driver '%s'\n", 52 pr_debug("bound device '%s' to driver '%s'\n",
47 dev->bus_id, dev->driver->name); 53 dev->bus_id, dev->driver->name);
48 klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices); 54 klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices);
49 sysfs_create_link(&dev->driver->kobj, &dev->kobj, 55 ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj,
50 kobject_name(&dev->kobj)); 56 kobject_name(&dev->kobj));
51 sysfs_create_link(&dev->kobj, &dev->driver->kobj, "driver"); 57 if (ret == 0) {
58 ret = sysfs_create_link(&dev->kobj, &dev->driver->kobj,
59 "driver");
60 if (ret)
61 sysfs_remove_link(&dev->driver->kobj,
62 kobject_name(&dev->kobj));
63 }
64 return ret;
52} 65}
53 66
54/** 67struct stupid_thread_structure {
55 * driver_probe_device - attempt to bind device & driver. 68 struct device_driver *drv;
56 * @drv: driver. 69 struct device *dev;
57 * @dev: device. 70};
58 * 71
59 * First, we call the bus's match function, if one present, which 72static atomic_t probe_count = ATOMIC_INIT(0);
60 * should compare the device IDs the driver supports with the 73static int really_probe(void *void_data)
61 * device IDs of the device. Note we don't do this ourselves
62 * because we don't know the format of the ID structures, nor what
63 * is to be considered a match and what is not.
64 *
65 * This function returns 1 if a match is found, an error if one
66 * occurs (that is not -ENODEV or -ENXIO), and 0 otherwise.
67 *
68 * This function must be called with @dev->sem held. When called
69 * for a USB interface, @dev->parent->sem must be held as well.
70 */
71int driver_probe_device(struct device_driver * drv, struct device * dev)
72{ 74{
75 struct stupid_thread_structure *data = void_data;
76 struct device_driver *drv = data->drv;
77 struct device *dev = data->dev;
73 int ret = 0; 78 int ret = 0;
74 79
75 if (drv->bus->match && !drv->bus->match(dev, drv)) 80 atomic_inc(&probe_count);
76 goto Done; 81 pr_debug("%s: Probing driver %s with device %s\n",
82 drv->bus->name, drv->name, dev->bus_id);
77 83
78 pr_debug("%s: Matched Device %s with Driver %s\n",
79 drv->bus->name, dev->bus_id, drv->name);
80 dev->driver = drv; 84 dev->driver = drv;
81 if (dev->bus->probe) { 85 if (dev->bus->probe) {
82 ret = dev->bus->probe(dev); 86 ret = dev->bus->probe(dev);
83 if (ret) { 87 if (ret) {
84 dev->driver = NULL; 88 dev->driver = NULL;
85 goto ProbeFailed; 89 goto probe_failed;
86 } 90 }
87 } else if (drv->probe) { 91 } else if (drv->probe) {
88 ret = drv->probe(dev); 92 ret = drv->probe(dev);
89 if (ret) { 93 if (ret) {
90 dev->driver = NULL; 94 dev->driver = NULL;
91 goto ProbeFailed; 95 goto probe_failed;
92 } 96 }
93 } 97 }
94 device_bind_driver(dev); 98 if (device_bind_driver(dev)) {
99 printk(KERN_ERR "%s: device_bind_driver(%s) failed\n",
100 __FUNCTION__, dev->bus_id);
101 /* How does undo a ->probe? We're screwed. */
102 }
95 ret = 1; 103 ret = 1;
96 pr_debug("%s: Bound Device %s to Driver %s\n", 104 pr_debug("%s: Bound Device %s to Driver %s\n",
97 drv->bus->name, dev->bus_id, drv->name); 105 drv->bus->name, dev->bus_id, drv->name);
98 goto Done; 106 goto done;
99 107
100 ProbeFailed: 108probe_failed:
101 if (ret == -ENODEV || ret == -ENXIO) { 109 if (ret == -ENODEV || ret == -ENXIO) {
102 /* Driver matched, but didn't support device 110 /* Driver matched, but didn't support device
103 * or device not found. 111 * or device not found.
@@ -110,7 +118,71 @@ int driver_probe_device(struct device_driver * drv, struct device * dev)
110 "%s: probe of %s failed with error %d\n", 118 "%s: probe of %s failed with error %d\n",
111 drv->name, dev->bus_id, ret); 119 drv->name, dev->bus_id, ret);
112 } 120 }
113 Done: 121done:
122 kfree(data);
123 atomic_dec(&probe_count);
124 return ret;
125}
126
127/**
128 * driver_probe_done
129 * Determine if the probe sequence is finished or not.
130 *
131 * Should somehow figure out how to use a semaphore, not an atomic variable...
132 */
133int driver_probe_done(void)
134{
135 pr_debug("%s: probe_count = %d\n", __FUNCTION__,
136 atomic_read(&probe_count));
137 if (atomic_read(&probe_count))
138 return -EBUSY;
139 return 0;
140}
141
142/**
143 * driver_probe_device - attempt to bind device & driver together
144 * @drv: driver to bind a device to
145 * @dev: device to try to bind to the driver
146 *
147 * First, we call the bus's match function, if one present, which should
148 * compare the device IDs the driver supports with the device IDs of the
149 * device. Note we don't do this ourselves because we don't know the
150 * format of the ID structures, nor what is to be considered a match and
151 * what is not.
152 *
153 * This function returns 1 if a match is found, an error if one occurs
154 * (that is not -ENODEV or -ENXIO), and 0 otherwise.
155 *
156 * This function must be called with @dev->sem held. When called for a
157 * USB interface, @dev->parent->sem must be held as well.
158 */
159int driver_probe_device(struct device_driver * drv, struct device * dev)
160{
161 struct stupid_thread_structure *data;
162 struct task_struct *probe_task;
163 int ret = 0;
164
165 if (!device_is_registered(dev))
166 return -ENODEV;
167 if (drv->bus->match && !drv->bus->match(dev, drv))
168 goto done;
169
170 pr_debug("%s: Matched Device %s with Driver %s\n",
171 drv->bus->name, dev->bus_id, drv->name);
172
173 data = kmalloc(sizeof(*data), GFP_KERNEL);
174 data->drv = drv;
175 data->dev = dev;
176
177 if (drv->multithread_probe) {
178 probe_task = kthread_run(really_probe, data,
179 "probe-%s", dev->bus_id);
180 if (IS_ERR(probe_task))
181 ret = PTR_ERR(probe_task);
182 } else
183 ret = really_probe(data);
184
185done:
114 return ret; 186 return ret;
115} 187}
116 188
@@ -139,8 +211,9 @@ int device_attach(struct device * dev)
139 211
140 down(&dev->sem); 212 down(&dev->sem);
141 if (dev->driver) { 213 if (dev->driver) {
142 device_bind_driver(dev); 214 ret = device_bind_driver(dev);
143 ret = 1; 215 if (ret == 0)
216 ret = 1;
144 } else 217 } else
145 ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach); 218 ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach);
146 up(&dev->sem); 219 up(&dev->sem);
@@ -182,9 +255,9 @@ static int __driver_attach(struct device * dev, void * data)
182 * returns 0 and the @dev->driver is set, we've found a 255 * returns 0 and the @dev->driver is set, we've found a
183 * compatible pair. 256 * compatible pair.
184 */ 257 */
185void driver_attach(struct device_driver * drv) 258int driver_attach(struct device_driver * drv)
186{ 259{
187 bus_for_each_dev(drv->bus, NULL, drv, __driver_attach); 260 return bus_for_each_dev(drv->bus, NULL, drv, __driver_attach);
188} 261}
189 262
190/** 263/**
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 562600dd540a..1214cbd17d86 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -142,20 +142,6 @@ void put_driver(struct device_driver * drv)
142 kobject_put(&drv->kobj); 142 kobject_put(&drv->kobj);
143} 143}
144 144
145static void klist_devices_get(struct klist_node *n)
146{
147 struct device *dev = container_of(n, struct device, knode_driver);
148
149 get_device(dev);
150}
151
152static void klist_devices_put(struct klist_node *n)
153{
154 struct device *dev = container_of(n, struct device, knode_driver);
155
156 put_device(dev);
157}
158
159/** 145/**
160 * driver_register - register driver with bus 146 * driver_register - register driver with bus
161 * @drv: driver to register 147 * @drv: driver to register
@@ -175,7 +161,7 @@ int driver_register(struct device_driver * drv)
175 (drv->bus->shutdown && drv->shutdown)) { 161 (drv->bus->shutdown && drv->shutdown)) {
176 printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name); 162 printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name);
177 } 163 }
178 klist_init(&drv->klist_devices, klist_devices_get, klist_devices_put); 164 klist_init(&drv->klist_devices, NULL, NULL);
179 init_completion(&drv->unloaded); 165 init_completion(&drv->unloaded);
180 return bus_add_driver(drv); 166 return bus_add_driver(drv);
181} 167}
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 2b8755db76c6..940ce41f1887 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -505,12 +505,36 @@ static int platform_match(struct device * dev, struct device_driver * drv)
505 return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0); 505 return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0);
506} 506}
507 507
508static int platform_suspend(struct device * dev, pm_message_t state) 508static int platform_suspend(struct device *dev, pm_message_t mesg)
509{ 509{
510 int ret = 0; 510 int ret = 0;
511 511
512 if (dev->driver && dev->driver->suspend) 512 if (dev->driver && dev->driver->suspend)
513 ret = dev->driver->suspend(dev, state); 513 ret = dev->driver->suspend(dev, mesg);
514
515 return ret;
516}
517
518static int platform_suspend_late(struct device *dev, pm_message_t mesg)
519{
520 struct platform_driver *drv = to_platform_driver(dev->driver);
521 struct platform_device *pdev = container_of(dev, struct platform_device, dev);
522 int ret = 0;
523
524 if (dev->driver && drv->suspend_late)
525 ret = drv->suspend_late(pdev, mesg);
526
527 return ret;
528}
529
530static int platform_resume_early(struct device *dev)
531{
532 struct platform_driver *drv = to_platform_driver(dev->driver);
533 struct platform_device *pdev = container_of(dev, struct platform_device, dev);
534 int ret = 0;
535
536 if (dev->driver && drv->resume_early)
537 ret = drv->resume_early(pdev);
514 538
515 return ret; 539 return ret;
516} 540}
@@ -531,6 +555,8 @@ struct bus_type platform_bus_type = {
531 .match = platform_match, 555 .match = platform_match,
532 .uevent = platform_uevent, 556 .uevent = platform_uevent,
533 .suspend = platform_suspend, 557 .suspend = platform_suspend,
558 .suspend_late = platform_suspend_late,
559 .resume_early = platform_resume_early,
534 .resume = platform_resume, 560 .resume = platform_resume,
535}; 561};
536EXPORT_SYMBOL_GPL(platform_bus_type); 562EXPORT_SYMBOL_GPL(platform_bus_type);
diff --git a/drivers/base/power/resume.c b/drivers/base/power/resume.c
index 826093ef4c7e..020be36705a6 100644
--- a/drivers/base/power/resume.c
+++ b/drivers/base/power/resume.c
@@ -38,13 +38,35 @@ int resume_device(struct device * dev)
38 dev_dbg(dev,"resuming\n"); 38 dev_dbg(dev,"resuming\n");
39 error = dev->bus->resume(dev); 39 error = dev->bus->resume(dev);
40 } 40 }
41 if (dev->class && dev->class->resume) {
42 dev_dbg(dev,"class resume\n");
43 error = dev->class->resume(dev);
44 }
41 up(&dev->sem); 45 up(&dev->sem);
42 TRACE_RESUME(error); 46 TRACE_RESUME(error);
43 return error; 47 return error;
44} 48}
45 49
46 50
51static int resume_device_early(struct device * dev)
52{
53 int error = 0;
47 54
55 TRACE_DEVICE(dev);
56 TRACE_RESUME(0);
57 if (dev->bus && dev->bus->resume_early) {
58 dev_dbg(dev,"EARLY resume\n");
59 error = dev->bus->resume_early(dev);
60 }
61 TRACE_RESUME(error);
62 return error;
63}
64
65/*
66 * Resume the devices that have either not gone through
67 * the late suspend, or that did go through it but also
68 * went through the early resume
69 */
48void dpm_resume(void) 70void dpm_resume(void)
49{ 71{
50 down(&dpm_list_sem); 72 down(&dpm_list_sem);
@@ -74,6 +96,7 @@ void dpm_resume(void)
74 96
75void device_resume(void) 97void device_resume(void)
76{ 98{
99 might_sleep();
77 down(&dpm_sem); 100 down(&dpm_sem);
78 dpm_resume(); 101 dpm_resume();
79 up(&dpm_sem); 102 up(&dpm_sem);
@@ -83,12 +106,12 @@ EXPORT_SYMBOL_GPL(device_resume);
83 106
84 107
85/** 108/**
86 * device_power_up_irq - Power on some devices. 109 * dpm_power_up - Power on some devices.
87 * 110 *
88 * Walk the dpm_off_irq list and power each device up. This 111 * Walk the dpm_off_irq list and power each device up. This
89 * is used for devices that required they be powered down with 112 * is used for devices that required they be powered down with
90 * interrupts disabled. As devices are powered on, they are moved to 113 * interrupts disabled. As devices are powered on, they are moved
91 * the dpm_suspended list. 114 * to the dpm_active list.
92 * 115 *
93 * Interrupts must be disabled when calling this. 116 * Interrupts must be disabled when calling this.
94 */ 117 */
@@ -99,16 +122,14 @@ void dpm_power_up(void)
99 struct list_head * entry = dpm_off_irq.next; 122 struct list_head * entry = dpm_off_irq.next;
100 struct device * dev = to_device(entry); 123 struct device * dev = to_device(entry);
101 124
102 get_device(dev); 125 list_move_tail(entry, &dpm_off);
103 list_move_tail(entry, &dpm_active); 126 resume_device_early(dev);
104 resume_device(dev);
105 put_device(dev);
106 } 127 }
107} 128}
108 129
109 130
110/** 131/**
111 * device_pm_power_up - Turn on all devices that need special attention. 132 * device_power_up - Turn on all devices that need special attention.
112 * 133 *
113 * Power on system devices then devices that required we shut them down 134 * Power on system devices then devices that required we shut them down
114 * with interrupts disabled. 135 * with interrupts disabled.
diff --git a/drivers/base/power/suspend.c b/drivers/base/power/suspend.c
index 69509e02f703..ece136bf97e3 100644
--- a/drivers/base/power/suspend.c
+++ b/drivers/base/power/suspend.c
@@ -34,6 +34,7 @@ static inline char *suspend_verb(u32 event)
34 switch (event) { 34 switch (event) {
35 case PM_EVENT_SUSPEND: return "suspend"; 35 case PM_EVENT_SUSPEND: return "suspend";
36 case PM_EVENT_FREEZE: return "freeze"; 36 case PM_EVENT_FREEZE: return "freeze";
37 case PM_EVENT_PRETHAW: return "prethaw";
37 default: return "(unknown suspend event)"; 38 default: return "(unknown suspend event)";
38 } 39 }
39} 40}
@@ -65,7 +66,19 @@ int suspend_device(struct device * dev, pm_message_t state)
65 66
66 dev->power.prev_state = dev->power.power_state; 67 dev->power.prev_state = dev->power.power_state;
67 68
68 if (dev->bus && dev->bus->suspend && !dev->power.power_state.event) { 69 if (dev->class && dev->class->suspend && !dev->power.power_state.event) {
70 dev_dbg(dev, "class %s%s\n",
71 suspend_verb(state.event),
72 ((state.event == PM_EVENT_SUSPEND)
73 && device_may_wakeup(dev))
74 ? ", may wakeup"
75 : ""
76 );
77 error = dev->class->suspend(dev, state);
78 suspend_report_result(dev->class->suspend, error);
79 }
80
81 if (!error && dev->bus && dev->bus->suspend && !dev->power.power_state.event) {
69 dev_dbg(dev, "%s%s\n", 82 dev_dbg(dev, "%s%s\n",
70 suspend_verb(state.event), 83 suspend_verb(state.event),
71 ((state.event == PM_EVENT_SUSPEND) 84 ((state.event == PM_EVENT_SUSPEND)
@@ -81,15 +94,42 @@ int suspend_device(struct device * dev, pm_message_t state)
81} 94}
82 95
83 96
97/*
98 * This is called with interrupts off, only a single CPU
99 * running. We can't do down() on a semaphore (and we don't
100 * need the protection)
101 */
102static int suspend_device_late(struct device *dev, pm_message_t state)
103{
104 int error = 0;
105
106 if (dev->bus && dev->bus->suspend_late && !dev->power.power_state.event) {
107 dev_dbg(dev, "LATE %s%s\n",
108 suspend_verb(state.event),
109 ((state.event == PM_EVENT_SUSPEND)
110 && device_may_wakeup(dev))
111 ? ", may wakeup"
112 : ""
113 );
114 error = dev->bus->suspend_late(dev, state);
115 suspend_report_result(dev->bus->suspend_late, error);
116 }
117 return error;
118}
119
84/** 120/**
85 * device_suspend - Save state and stop all devices in system. 121 * device_suspend - Save state and stop all devices in system.
86 * @state: Power state to put each device in. 122 * @state: Power state to put each device in.
87 * 123 *
88 * Walk the dpm_active list, call ->suspend() for each device, and move 124 * Walk the dpm_active list, call ->suspend() for each device, and move
89 * it to dpm_off. 125 * it to the dpm_off list.
90 * Check the return value for each. If it returns 0, then we move the 126 *
91 * the device to the dpm_off list. If it returns -EAGAIN, we move it to 127 * (For historical reasons, if it returns -EAGAIN, that used to mean
92 * the dpm_off_irq list. If we get a different error, try and back out. 128 * that the device would be called again with interrupts disabled.
129 * These days, we use the "suspend_late()" callback for that, so we
130 * print a warning and consider it an error).
131 *
132 * If we get a different error, try and back out.
93 * 133 *
94 * If we hit a failure with any of the devices, call device_resume() 134 * If we hit a failure with any of the devices, call device_resume()
95 * above to bring the suspended devices back to life. 135 * above to bring the suspended devices back to life.
@@ -100,6 +140,7 @@ int device_suspend(pm_message_t state)
100{ 140{
101 int error = 0; 141 int error = 0;
102 142
143 might_sleep();
103 down(&dpm_sem); 144 down(&dpm_sem);
104 down(&dpm_list_sem); 145 down(&dpm_list_sem);
105 while (!list_empty(&dpm_active) && error == 0) { 146 while (!list_empty(&dpm_active) && error == 0) {
@@ -115,39 +156,27 @@ int device_suspend(pm_message_t state)
115 156
116 /* Check if the device got removed */ 157 /* Check if the device got removed */
117 if (!list_empty(&dev->power.entry)) { 158 if (!list_empty(&dev->power.entry)) {
118 /* Move it to the dpm_off or dpm_off_irq list */ 159 /* Move it to the dpm_off list */
119 if (!error) 160 if (!error)
120 list_move(&dev->power.entry, &dpm_off); 161 list_move(&dev->power.entry, &dpm_off);
121 else if (error == -EAGAIN) {
122 list_move(&dev->power.entry, &dpm_off_irq);
123 error = 0;
124 }
125 } 162 }
126 if (error) 163 if (error)
127 printk(KERN_ERR "Could not suspend device %s: " 164 printk(KERN_ERR "Could not suspend device %s: "
128 "error %d\n", kobject_name(&dev->kobj), error); 165 "error %d%s\n",
166 kobject_name(&dev->kobj), error,
167 error == -EAGAIN ? " (please convert to suspend_late)" : "");
129 put_device(dev); 168 put_device(dev);
130 } 169 }
131 up(&dpm_list_sem); 170 up(&dpm_list_sem);
132 if (error) { 171 if (error)
133 /* we failed... before resuming, bring back devices from
134 * dpm_off_irq list back to main dpm_off list, we do want
135 * to call resume() on them, in case they partially suspended
136 * despite returning -EAGAIN
137 */
138 while (!list_empty(&dpm_off_irq)) {
139 struct list_head * entry = dpm_off_irq.next;
140 list_move(entry, &dpm_off);
141 }
142 dpm_resume(); 172 dpm_resume();
143 } 173
144 up(&dpm_sem); 174 up(&dpm_sem);
145 return error; 175 return error;
146} 176}
147 177
148EXPORT_SYMBOL_GPL(device_suspend); 178EXPORT_SYMBOL_GPL(device_suspend);
149 179
150
151/** 180/**
152 * device_power_down - Shut down special devices. 181 * device_power_down - Shut down special devices.
153 * @state: Power state to enter. 182 * @state: Power state to enter.
@@ -162,14 +191,17 @@ int device_power_down(pm_message_t state)
162 int error = 0; 191 int error = 0;
163 struct device * dev; 192 struct device * dev;
164 193
165 list_for_each_entry_reverse(dev, &dpm_off_irq, power.entry) { 194 while (!list_empty(&dpm_off)) {
166 if ((error = suspend_device(dev, state))) 195 struct list_head * entry = dpm_off.prev;
167 break; 196
197 dev = to_device(entry);
198 error = suspend_device_late(dev, state);
199 if (error)
200 goto Error;
201 list_move(&dev->power.entry, &dpm_off_irq);
168 } 202 }
169 if (error) 203
170 goto Error; 204 error = sysdev_suspend(state);
171 if ((error = sysdev_suspend(state)))
172 goto Error;
173 Done: 205 Done:
174 return error; 206 return error;
175 Error: 207 Error:
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index 40d7242a07c1..2d47517dbe32 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -7,22 +7,29 @@
7#include "power.h" 7#include "power.h"
8 8
9 9
10#ifdef CONFIG_PM_SYSFS_DEPRECATED
11
10/** 12/**
11 * state - Control current power state of device 13 * state - Control current power state of device
12 * 14 *
13 * show() returns the current power state of the device. '0' indicates 15 * show() returns the current power state of the device. '0' indicates
14 * the device is on. Other values (1-3) indicate the device is in a low 16 * the device is on. Other values (2) indicate the device is in some low
15 * power state. 17 * power state.
16 * 18 *
17 * store() sets the current power state, which is an integer value 19 * store() sets the current power state, which is an integer valued
18 * between 0-3. If the device is on ('0'), and the value written is 20 * 0, 2, or 3. Devices with bus.suspend_late(), or bus.resume_early()
19 * greater than 0, then the device is placed directly into the low-power 21 * methods fail this operation; those methods couldn't be called.
20 * state (via its driver's ->suspend() method). 22 * Otherwise,
21 * If the device is currently in a low-power state, and the value is 0, 23 *
22 * the device is powered back on (via the ->resume() method). 24 * - If the recorded dev->power.power_state.event matches the
23 * If the device is in a low-power state, and a different low-power state 25 * target value, nothing is done.
24 * is requested, the device is first resumed, then suspended into the new 26 * - If the recorded event code is nonzero, the device is reactivated
25 * low-power state. 27 * by calling bus.resume() and/or class.resume().
28 * - If the target value is nonzero, the device is suspended by
29 * calling class.suspend() and/or bus.suspend() with event code
30 * PM_EVENT_SUSPEND.
31 *
32 * This mechanism is DEPRECATED and should only be used for testing.
26 */ 33 */
27 34
28static ssize_t state_show(struct device * dev, struct device_attribute *attr, char * buf) 35static ssize_t state_show(struct device * dev, struct device_attribute *attr, char * buf)
@@ -38,6 +45,10 @@ static ssize_t state_store(struct device * dev, struct device_attribute *attr, c
38 pm_message_t state; 45 pm_message_t state;
39 int error = -EINVAL; 46 int error = -EINVAL;
40 47
48 /* disallow incomplete suspend sequences */
49 if (dev->bus && (dev->bus->suspend_late || dev->bus->resume_early))
50 return error;
51
41 state.event = PM_EVENT_SUSPEND; 52 state.event = PM_EVENT_SUSPEND;
42 /* Older apps expected to write "3" here - confused with PCI D3 */ 53 /* Older apps expected to write "3" here - confused with PCI D3 */
43 if ((n == 1) && !strcmp(buf, "3")) 54 if ((n == 1) && !strcmp(buf, "3"))
@@ -57,6 +68,8 @@ static ssize_t state_store(struct device * dev, struct device_attribute *attr, c
57static DEVICE_ATTR(state, 0644, state_show, state_store); 68static DEVICE_ATTR(state, 0644, state_show, state_store);
58 69
59 70
71#endif /* CONFIG_PM_SYSFS_DEPRECATED */
72
60/* 73/*
61 * wakeup - Report/change current wakeup option for device 74 * wakeup - Report/change current wakeup option for device
62 * 75 *
@@ -130,7 +143,9 @@ static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store);
130 143
131 144
132static struct attribute * power_attrs[] = { 145static struct attribute * power_attrs[] = {
146#ifdef CONFIG_PM_SYSFS_DEPRECATED
133 &dev_attr_state.attr, 147 &dev_attr_state.attr,
148#endif
134 &dev_attr_wakeup.attr, 149 &dev_attr_wakeup.attr,
135 NULL, 150 NULL,
136}; 151};
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index defd4b4bd374..9c8468de1a75 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -1207,7 +1207,7 @@ int system_bus_clock (void)
1207 1207
1208EXPORT_SYMBOL(system_bus_clock); 1208EXPORT_SYMBOL(system_bus_clock);
1209 1209
1210static int generic_ide_suspend(struct device *dev, pm_message_t state) 1210static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
1211{ 1211{
1212 ide_drive_t *drive = dev->driver_data; 1212 ide_drive_t *drive = dev->driver_data;
1213 struct request rq; 1213 struct request rq;
@@ -1221,7 +1221,9 @@ static int generic_ide_suspend(struct device *dev, pm_message_t state)
1221 rq.special = &args; 1221 rq.special = &args;
1222 rq.end_io_data = &rqpm; 1222 rq.end_io_data = &rqpm;
1223 rqpm.pm_step = ide_pm_state_start_suspend; 1223 rqpm.pm_step = ide_pm_state_start_suspend;
1224 rqpm.pm_state = state.event; 1224 if (mesg.event == PM_EVENT_PRETHAW)
1225 mesg.event = PM_EVENT_FREEZE;
1226 rqpm.pm_state = mesg.event;
1225 1227
1226 return ide_do_drive_cmd(drive, &rq, ide_wait); 1228 return ide_do_drive_cmd(drive, &rq, ide_wait);
1227} 1229}
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c
index 996c694341bc..31ad79f52df7 100644
--- a/drivers/ide/ppc/pmac.c
+++ b/drivers/ide/ppc/pmac.c
@@ -1369,15 +1369,16 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
1369} 1369}
1370 1370
1371static int 1371static int
1372pmac_ide_macio_suspend(struct macio_dev *mdev, pm_message_t state) 1372pmac_ide_macio_suspend(struct macio_dev *mdev, pm_message_t mesg)
1373{ 1373{
1374 ide_hwif_t *hwif = (ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev); 1374 ide_hwif_t *hwif = (ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev);
1375 int rc = 0; 1375 int rc = 0;
1376 1376
1377 if (state.event != mdev->ofdev.dev.power.power_state.event && state.event >= PM_EVENT_SUSPEND) { 1377 if (mesg.event != mdev->ofdev.dev.power.power_state.event
1378 && mesg.event == PM_EVENT_SUSPEND) {
1378 rc = pmac_ide_do_suspend(hwif); 1379 rc = pmac_ide_do_suspend(hwif);
1379 if (rc == 0) 1380 if (rc == 0)
1380 mdev->ofdev.dev.power.power_state = state; 1381 mdev->ofdev.dev.power.power_state = mesg;
1381 } 1382 }
1382 1383
1383 return rc; 1384 return rc;
@@ -1473,15 +1474,16 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1473} 1474}
1474 1475
1475static int 1476static int
1476pmac_ide_pci_suspend(struct pci_dev *pdev, pm_message_t state) 1477pmac_ide_pci_suspend(struct pci_dev *pdev, pm_message_t mesg)
1477{ 1478{
1478 ide_hwif_t *hwif = (ide_hwif_t *)pci_get_drvdata(pdev); 1479 ide_hwif_t *hwif = (ide_hwif_t *)pci_get_drvdata(pdev);
1479 int rc = 0; 1480 int rc = 0;
1480 1481
1481 if (state.event != pdev->dev.power.power_state.event && state.event >= 2) { 1482 if (mesg.event != pdev->dev.power.power_state.event
1483 && mesg.event == PM_EVENT_SUSPEND) {
1482 rc = pmac_ide_do_suspend(hwif); 1484 rc = pmac_ide_do_suspend(hwif);
1483 if (rc == 0) 1485 if (rc == 0)
1484 pdev->dev.power.power_state = state; 1486 pdev->dev.power.power_state = mesg;
1485 } 1487 }
1486 1488
1487 return rc; 1489 return rc;
diff --git a/drivers/media/dvb/cinergyT2/cinergyT2.c b/drivers/media/dvb/cinergyT2/cinergyT2.c
index 001c71b6be61..410fa6d620ff 100644
--- a/drivers/media/dvb/cinergyT2/cinergyT2.c
+++ b/drivers/media/dvb/cinergyT2/cinergyT2.c
@@ -981,7 +981,7 @@ static int cinergyt2_suspend (struct usb_interface *intf, pm_message_t state)
981 if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->sem)) 981 if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->sem))
982 return -ERESTARTSYS; 982 return -ERESTARTSYS;
983 983
984 if (state.event > PM_EVENT_ON) { 984 if (1) {
985 struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf); 985 struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf);
986 986
987 cinergyt2_suspend_rc(cinergyt2); 987 cinergyt2_suspend_rc(cinergyt2);
diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index 4d762fc4878c..c27e782e6df9 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -17,6 +17,31 @@ config PCI_MSI
17 17
18 If you don't know what to do here, say N. 18 If you don't know what to do here, say N.
19 19
20config PCI_MULTITHREAD_PROBE
21 bool "PCI Multi-threaded probe (EXPERIMENTAL)"
22 depends on PCI && EXPERIMENTAL
23 help
24 Say Y here if you want the PCI core to spawn a new thread for
25 every PCI device that is probed. This can cause a huge
26 speedup in boot times on multiprocessor machines, and even a
27 smaller speedup on single processor machines.
28
29 But it can also cause lots of bad things to happen. A number
30 of PCI drivers can not properly handle running in this way,
31 some will just not work properly at all, while others might
32 decide to blow up power supplies with a huge load all at once,
33 so use this option at your own risk.
34
35 It is very unwise to use this option if you are not using a
36 boot process that can handle devices being created in any
37 order. A program that can create persistant block and network
38 device names (like udev) is a good idea if you wish to use
39 this option.
40
41 Again, use this option at your own risk, you have been warned!
42
43 When in doubt, say N.
44
20config PCI_DEBUG 45config PCI_DEBUG
21 bool "PCI Debugging" 46 bool "PCI Debugging"
22 depends on PCI && DEBUG_KERNEL 47 depends on PCI && DEBUG_KERNEL
diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
index 317457dd4014..d0a07d9ab30c 100644
--- a/drivers/pci/hotplug/acpiphp_ibm.c
+++ b/drivers/pci/hotplug/acpiphp_ibm.c
@@ -487,9 +487,7 @@ static void __exit ibm_acpiphp_exit(void)
487 if (ACPI_FAILURE(status)) 487 if (ACPI_FAILURE(status))
488 err("%s: Notification handler removal failed\n", __FUNCTION__); 488 err("%s: Notification handler removal failed\n", __FUNCTION__);
489 /* remove the /sys entries */ 489 /* remove the /sys entries */
490 if (sysfs_remove_bin_file(sysdir, &ibm_apci_table_attr)) 490 sysfs_remove_bin_file(sysdir, &ibm_apci_table_attr);
491 err("%s: removal of sysfs file apci_table failed\n",
492 __FUNCTION__);
493} 491}
494 492
495module_init(ibm_acpiphp_init); 493module_init(ibm_acpiphp_init);
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 474e9cd0e9e4..d8ace1f90dd2 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -17,6 +17,16 @@
17 * Registration of PCI drivers and handling of hot-pluggable devices. 17 * Registration of PCI drivers and handling of hot-pluggable devices.
18 */ 18 */
19 19
20/* multithreaded probe logic */
21static int pci_multithread_probe =
22#ifdef CONFIG_PCI_MULTITHREAD_PROBE
23 1;
24#else
25 0;
26#endif
27__module_param_call("", pci_multithread_probe, param_set_bool, param_get_bool, &pci_multithread_probe, 0644);
28
29
20/* 30/*
21 * Dynamic device IDs are disabled for !CONFIG_HOTPLUG 31 * Dynamic device IDs are disabled for !CONFIG_HOTPLUG
22 */ 32 */
@@ -279,6 +289,18 @@ static int pci_device_suspend(struct device * dev, pm_message_t state)
279 return i; 289 return i;
280} 290}
281 291
292static int pci_device_suspend_late(struct device * dev, pm_message_t state)
293{
294 struct pci_dev * pci_dev = to_pci_dev(dev);
295 struct pci_driver * drv = pci_dev->driver;
296 int i = 0;
297
298 if (drv && drv->suspend_late) {
299 i = drv->suspend_late(pci_dev, state);
300 suspend_report_result(drv->suspend_late, i);
301 }
302 return i;
303}
282 304
283/* 305/*
284 * Default resume method for devices that have no driver provided resume, 306 * Default resume method for devices that have no driver provided resume,
@@ -313,6 +335,17 @@ static int pci_device_resume(struct device * dev)
313 return error; 335 return error;
314} 336}
315 337
338static int pci_device_resume_early(struct device * dev)
339{
340 int error = 0;
341 struct pci_dev * pci_dev = to_pci_dev(dev);
342 struct pci_driver * drv = pci_dev->driver;
343
344 if (drv && drv->resume_early)
345 error = drv->resume_early(pci_dev);
346 return error;
347}
348
316static void pci_device_shutdown(struct device *dev) 349static void pci_device_shutdown(struct device *dev)
317{ 350{
318 struct pci_dev *pci_dev = to_pci_dev(dev); 351 struct pci_dev *pci_dev = to_pci_dev(dev);
@@ -385,6 +418,7 @@ int __pci_register_driver(struct pci_driver *drv, struct module *owner)
385 drv->driver.bus = &pci_bus_type; 418 drv->driver.bus = &pci_bus_type;
386 drv->driver.owner = owner; 419 drv->driver.owner = owner;
387 drv->driver.kobj.ktype = &pci_driver_kobj_type; 420 drv->driver.kobj.ktype = &pci_driver_kobj_type;
421 drv->driver.multithread_probe = pci_multithread_probe;
388 422
389 spin_lock_init(&drv->dynids.lock); 423 spin_lock_init(&drv->dynids.lock);
390 INIT_LIST_HEAD(&drv->dynids.list); 424 INIT_LIST_HEAD(&drv->dynids.list);
@@ -509,8 +543,10 @@ struct bus_type pci_bus_type = {
509 .probe = pci_device_probe, 543 .probe = pci_device_probe,
510 .remove = pci_device_remove, 544 .remove = pci_device_remove,
511 .suspend = pci_device_suspend, 545 .suspend = pci_device_suspend,
512 .shutdown = pci_device_shutdown, 546 .suspend_late = pci_device_suspend_late,
547 .resume_early = pci_device_resume_early,
513 .resume = pci_device_resume, 548 .resume = pci_device_resume,
549 .shutdown = pci_device_shutdown,
514 .dev_attrs = pci_dev_attrs, 550 .dev_attrs = pci_dev_attrs,
515}; 551};
516 552
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 9f79dd6d51ab..8ab027886034 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -432,10 +432,12 @@ pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state)
432 case PM_EVENT_ON: 432 case PM_EVENT_ON:
433 return PCI_D0; 433 return PCI_D0;
434 case PM_EVENT_FREEZE: 434 case PM_EVENT_FREEZE:
435 case PM_EVENT_PRETHAW:
436 /* REVISIT both freeze and pre-thaw "should" use D0 */
435 case PM_EVENT_SUSPEND: 437 case PM_EVENT_SUSPEND:
436 return PCI_D3hot; 438 return PCI_D3hot;
437 default: 439 default:
438 printk("They asked me for state %d\n", state.event); 440 printk("Unrecognized suspend event %d\n", state.event);
439 BUG(); 441 BUG();
440 } 442 }
441 return PCI_D0; 443 return PCI_D0;
diff --git a/drivers/scsi/mesh.c b/drivers/scsi/mesh.c
index 592b52afe658..683fc7ae4b8f 100644
--- a/drivers/scsi/mesh.c
+++ b/drivers/scsi/mesh.c
@@ -1756,16 +1756,23 @@ static void set_mesh_power(struct mesh_state *ms, int state)
1756 pmac_call_feature(PMAC_FTR_MESH_ENABLE, macio_get_of_node(ms->mdev), 0, 0); 1756 pmac_call_feature(PMAC_FTR_MESH_ENABLE, macio_get_of_node(ms->mdev), 0, 0);
1757 msleep(10); 1757 msleep(10);
1758 } 1758 }
1759} 1759}
1760 1760
1761 1761
1762#ifdef CONFIG_PM 1762#ifdef CONFIG_PM
1763static int mesh_suspend(struct macio_dev *mdev, pm_message_t state) 1763static int mesh_suspend(struct macio_dev *mdev, pm_message_t mesg)
1764{ 1764{
1765 struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev); 1765 struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev);
1766 unsigned long flags; 1766 unsigned long flags;
1767 1767
1768 if (state.event == mdev->ofdev.dev.power.power_state.event || state.event < 2) 1768 switch (mesg.event) {
1769 case PM_EVENT_SUSPEND:
1770 case PM_EVENT_FREEZE:
1771 break;
1772 default:
1773 return 0;
1774 }
1775 if (mesg.event == mdev->ofdev.dev.power.power_state.event)
1769 return 0; 1776 return 0;
1770 1777
1771 scsi_block_requests(ms->host); 1778 scsi_block_requests(ms->host);
@@ -1780,7 +1787,7 @@ static int mesh_suspend(struct macio_dev *mdev, pm_message_t state)
1780 disable_irq(ms->meshintr); 1787 disable_irq(ms->meshintr);
1781 set_mesh_power(ms, 0); 1788 set_mesh_power(ms, 0);
1782 1789
1783 mdev->ofdev.dev.power.power_state = state; 1790 mdev->ofdev.dev.power.power_state = mesg;
1784 1791
1785 return 0; 1792 return 0;
1786} 1793}
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index 5078fb3375e3..fa36391fedd3 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -281,7 +281,7 @@ int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message)
281 (void) usb_hcd_pci_resume (dev); 281 (void) usb_hcd_pci_resume (dev);
282 } 282 }
283 283
284 } else { 284 } else if (hcd->state != HC_STATE_HALT) {
285 dev_dbg (hcd->self.controller, "hcd state %d; not suspended\n", 285 dev_dbg (hcd->self.controller, "hcd state %d; not suspended\n",
286 hcd->state); 286 hcd->state);
287 WARN_ON(1); 287 WARN_ON(1);
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index cadffacd945b..6967ab71e282 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -238,6 +238,12 @@ static int ehci_pci_suspend(struct usb_hcd *hcd, pm_message_t message)
238 writel (0, &ehci->regs->intr_enable); 238 writel (0, &ehci->regs->intr_enable);
239 (void)readl(&ehci->regs->intr_enable); 239 (void)readl(&ehci->regs->intr_enable);
240 240
241 /* make sure snapshot being resumed re-enumerates everything */
242 if (message.event == PM_EVENT_PRETHAW) {
243 ehci_halt(ehci);
244 ehci_reset(ehci);
245 }
246
241 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 247 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
242 bail: 248 bail:
243 spin_unlock_irqrestore (&ehci->lock, flags); 249 spin_unlock_irqrestore (&ehci->lock, flags);
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c
index b268537e389e..37e122812b67 100644
--- a/drivers/usb/host/ohci-pci.c
+++ b/drivers/usb/host/ohci-pci.c
@@ -135,6 +135,11 @@ static int ohci_pci_suspend (struct usb_hcd *hcd, pm_message_t message)
135 } 135 }
136 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); 136 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
137 (void)ohci_readl(ohci, &ohci->regs->intrdisable); 137 (void)ohci_readl(ohci, &ohci->regs->intrdisable);
138
139 /* make sure snapshot being resumed re-enumerates everything */
140 if (message.event == PM_EVENT_PRETHAW)
141 ohci_usb_reset(ohci);
142
138 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 143 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
139 bail: 144 bail:
140 spin_unlock_irqrestore (&ohci->lock, flags); 145 spin_unlock_irqrestore (&ohci->lock, flags);
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index fa34092bbcde..9de115d9db27 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -1783,10 +1783,15 @@ sl811h_suspend(struct platform_device *dev, pm_message_t state)
1783 struct sl811 *sl811 = hcd_to_sl811(hcd); 1783 struct sl811 *sl811 = hcd_to_sl811(hcd);
1784 int retval = 0; 1784 int retval = 0;
1785 1785
1786 if (state.event == PM_EVENT_FREEZE) 1786 switch (state.event) {
1787 case PM_EVENT_FREEZE:
1787 retval = sl811h_bus_suspend(hcd); 1788 retval = sl811h_bus_suspend(hcd);
1788 else if (state.event == PM_EVENT_SUSPEND) 1789 break;
1790 case PM_EVENT_SUSPEND:
1791 case PM_EVENT_PRETHAW: /* explicitly discard hw state */
1789 port_power(sl811, 0); 1792 port_power(sl811, 0);
1793 break;
1794 }
1790 if (retval == 0) 1795 if (retval == 0)
1791 dev->dev.power.power_state = state; 1796 dev->dev.power.power_state = state;
1792 return retval; 1797 return retval;
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index 4151f618602d..b7402ceb3e93 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -734,6 +734,10 @@ static int uhci_suspend(struct usb_hcd *hcd, pm_message_t message)
734 734
735 /* FIXME: Enable non-PME# remote wakeup? */ 735 /* FIXME: Enable non-PME# remote wakeup? */
736 736
737 /* make sure snapshot being resumed re-enumerates everything */
738 if (message.event == PM_EVENT_PRETHAW)
739 uhci_hc_died(uhci);
740
737done_okay: 741done_okay:
738 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 742 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
739done: 743done:
diff --git a/drivers/video/aty/radeon_pm.c b/drivers/video/aty/radeon_pm.c
index e308ed2d249a..365de5dcc888 100644
--- a/drivers/video/aty/radeon_pm.c
+++ b/drivers/video/aty/radeon_pm.c
@@ -2621,25 +2621,28 @@ static int radeon_restore_pci_cfg(struct radeonfb_info *rinfo)
2621} 2621}
2622 2622
2623 2623
2624int radeonfb_pci_suspend(struct pci_dev *pdev, pm_message_t state) 2624int radeonfb_pci_suspend(struct pci_dev *pdev, pm_message_t mesg)
2625{ 2625{
2626 struct fb_info *info = pci_get_drvdata(pdev); 2626 struct fb_info *info = pci_get_drvdata(pdev);
2627 struct radeonfb_info *rinfo = info->par; 2627 struct radeonfb_info *rinfo = info->par;
2628 int i; 2628 int i;
2629 2629
2630 if (state.event == pdev->dev.power.power_state.event) 2630 if (mesg.event == pdev->dev.power.power_state.event)
2631 return 0; 2631 return 0;
2632 2632
2633 printk(KERN_DEBUG "radeonfb (%s): suspending to state: %d...\n", 2633 printk(KERN_DEBUG "radeonfb (%s): suspending for event: %d...\n",
2634 pci_name(pdev), state.event); 2634 pci_name(pdev), mesg.event);
2635 2635
2636 /* For suspend-to-disk, we cheat here. We don't suspend anything and 2636 /* For suspend-to-disk, we cheat here. We don't suspend anything and
2637 * let fbcon continue drawing until we are all set. That shouldn't 2637 * let fbcon continue drawing until we are all set. That shouldn't
2638 * really cause any problem at this point, provided that the wakeup 2638 * really cause any problem at this point, provided that the wakeup
2639 * code knows that any state in memory may not match the HW 2639 * code knows that any state in memory may not match the HW
2640 */ 2640 */
2641 if (state.event == PM_EVENT_FREEZE) 2641 switch (mesg.event) {
2642 case PM_EVENT_FREEZE: /* about to take snapshot */
2643 case PM_EVENT_PRETHAW: /* before restoring snapshot */
2642 goto done; 2644 goto done;
2645 }
2643 2646
2644 acquire_console_sem(); 2647 acquire_console_sem();
2645 2648
@@ -2706,7 +2709,7 @@ int radeonfb_pci_suspend(struct pci_dev *pdev, pm_message_t state)
2706 release_console_sem(); 2709 release_console_sem();
2707 2710
2708 done: 2711 done:
2709 pdev->dev.power.power_state = state; 2712 pdev->dev.power.power_state = mesg;
2710 2713
2711 return 0; 2714 return 0;
2712} 2715}
diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
index a6ca02f2156a..d42edaccb84c 100644
--- a/drivers/video/i810/i810_main.c
+++ b/drivers/video/i810/i810_main.c
@@ -1554,15 +1554,17 @@ static struct fb_ops i810fb_ops __devinitdata = {
1554/*********************************************************************** 1554/***********************************************************************
1555 * Power Management * 1555 * Power Management *
1556 ***********************************************************************/ 1556 ***********************************************************************/
1557static int i810fb_suspend(struct pci_dev *dev, pm_message_t state) 1557static int i810fb_suspend(struct pci_dev *dev, pm_message_t mesg)
1558{ 1558{
1559 struct fb_info *info = pci_get_drvdata(dev); 1559 struct fb_info *info = pci_get_drvdata(dev);
1560 struct i810fb_par *par = info->par; 1560 struct i810fb_par *par = info->par;
1561 1561
1562 par->cur_state = state.event; 1562 par->cur_state = mesg.event;
1563 1563
1564 if (state.event == PM_EVENT_FREEZE) { 1564 switch (mesg.event) {
1565 dev->dev.power.power_state = state; 1565 case PM_EVENT_FREEZE:
1566 case PM_EVENT_PRETHAW:
1567 dev->dev.power.power_state = mesg;
1566 return 0; 1568 return 0;
1567 } 1569 }
1568 1570
@@ -1578,7 +1580,7 @@ static int i810fb_suspend(struct pci_dev *dev, pm_message_t state)
1578 1580
1579 pci_save_state(dev); 1581 pci_save_state(dev);
1580 pci_disable_device(dev); 1582 pci_disable_device(dev);
1581 pci_set_power_state(dev, pci_choose_state(dev, state)); 1583 pci_set_power_state(dev, pci_choose_state(dev, mesg));
1582 release_console_sem(); 1584 release_console_sem();
1583 1585
1584 return 0; 1586 return 0;
diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
index d4f850117874..f8cd4c519aeb 100644
--- a/drivers/video/nvidia/nvidia.c
+++ b/drivers/video/nvidia/nvidia.c
@@ -950,24 +950,25 @@ static struct fb_ops nvidia_fb_ops = {
950}; 950};
951 951
952#ifdef CONFIG_PM 952#ifdef CONFIG_PM
953static int nvidiafb_suspend(struct pci_dev *dev, pm_message_t state) 953static int nvidiafb_suspend(struct pci_dev *dev, pm_message_t mesg)
954{ 954{
955 struct fb_info *info = pci_get_drvdata(dev); 955 struct fb_info *info = pci_get_drvdata(dev);
956 struct nvidia_par *par = info->par; 956 struct nvidia_par *par = info->par;
957 957
958 if (mesg.event == PM_EVENT_PRETHAW)
959 mesg.event = PM_EVENT_FREEZE;
958 acquire_console_sem(); 960 acquire_console_sem();
959 par->pm_state = state.event; 961 par->pm_state = mesg.event;
960 962
961 if (state.event == PM_EVENT_FREEZE) { 963 if (mesg.event == PM_EVENT_SUSPEND) {
962 dev->dev.power.power_state = state;
963 } else {
964 fb_set_suspend(info, 1); 964 fb_set_suspend(info, 1);
965 nvidiafb_blank(FB_BLANK_POWERDOWN, info); 965 nvidiafb_blank(FB_BLANK_POWERDOWN, info);
966 nvidia_write_regs(par, &par->SavedReg); 966 nvidia_write_regs(par, &par->SavedReg);
967 pci_save_state(dev); 967 pci_save_state(dev);
968 pci_disable_device(dev); 968 pci_disable_device(dev);
969 pci_set_power_state(dev, pci_choose_state(dev, state)); 969 pci_set_power_state(dev, pci_choose_state(dev, mesg));
970 } 970 }
971 dev->dev.power.power_state = mesg;
971 972
972 release_console_sem(); 973 release_console_sem();
973 return 0; 974 return 0;
diff --git a/drivers/video/savage/savagefb_driver.c b/drivers/video/savage/savagefb_driver.c
index 461e094e7b45..82b3deaae02d 100644
--- a/drivers/video/savage/savagefb_driver.c
+++ b/drivers/video/savage/savagefb_driver.c
@@ -2323,24 +2323,24 @@ static void __devexit savagefb_remove(struct pci_dev *dev)
2323 } 2323 }
2324} 2324}
2325 2325
2326static int savagefb_suspend(struct pci_dev* dev, pm_message_t state) 2326static int savagefb_suspend(struct pci_dev *dev, pm_message_t mesg)
2327{ 2327{
2328 struct fb_info *info = pci_get_drvdata(dev); 2328 struct fb_info *info = pci_get_drvdata(dev);
2329 struct savagefb_par *par = info->par; 2329 struct savagefb_par *par = info->par;
2330 2330
2331 DBG("savagefb_suspend"); 2331 DBG("savagefb_suspend");
2332 2332
2333 2333 if (mesg.event == PM_EVENT_PRETHAW)
2334 par->pm_state = state.event; 2334 mesg.event = PM_EVENT_FREEZE;
2335 par->pm_state = mesg.event;
2336 dev->dev.power.power_state = mesg;
2335 2337
2336 /* 2338 /*
2337 * For PM_EVENT_FREEZE, do not power down so the console 2339 * For PM_EVENT_FREEZE, do not power down so the console
2338 * can remain active. 2340 * can remain active.
2339 */ 2341 */
2340 if (state.event == PM_EVENT_FREEZE) { 2342 if (mesg.event == PM_EVENT_FREEZE)
2341 dev->dev.power.power_state = state;
2342 return 0; 2343 return 0;
2343 }
2344 2344
2345 acquire_console_sem(); 2345 acquire_console_sem();
2346 fb_set_suspend(info, 1); 2346 fb_set_suspend(info, 1);
@@ -2353,7 +2353,7 @@ static int savagefb_suspend(struct pci_dev* dev, pm_message_t state)
2353 savage_disable_mmio(par); 2353 savage_disable_mmio(par);
2354 pci_save_state(dev); 2354 pci_save_state(dev);
2355 pci_disable_device(dev); 2355 pci_disable_device(dev);
2356 pci_set_power_state(dev, pci_choose_state(dev, state)); 2356 pci_set_power_state(dev, pci_choose_state(dev, mesg));
2357 release_console_sem(); 2357 release_console_sem();
2358 2358
2359 return 0; 2359 return 0;
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index 39640fd03458..e4b430552c88 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -55,12 +55,11 @@ static u64 debugfs_u8_get(void *data)
55DEFINE_SIMPLE_ATTRIBUTE(fops_u8, debugfs_u8_get, debugfs_u8_set, "%llu\n"); 55DEFINE_SIMPLE_ATTRIBUTE(fops_u8, debugfs_u8_get, debugfs_u8_set, "%llu\n");
56 56
57/** 57/**
58 * debugfs_create_u8 - create a file in the debugfs filesystem that is used to read and write an unsigned 8 bit value. 58 * debugfs_create_u8 - create a debugfs file that is used to read and write an unsigned 8-bit value
59 *
60 * @name: a pointer to a string containing the name of the file to create. 59 * @name: a pointer to a string containing the name of the file to create.
61 * @mode: the permission that the file should have 60 * @mode: the permission that the file should have
62 * @parent: a pointer to the parent dentry for this file. This should be a 61 * @parent: a pointer to the parent dentry for this file. This should be a
63 * directory dentry if set. If this paramater is NULL, then the 62 * directory dentry if set. If this parameter is %NULL, then the
64 * file will be created in the root of the debugfs filesystem. 63 * file will be created in the root of the debugfs filesystem.
65 * @value: a pointer to the variable that the file should read to and write 64 * @value: a pointer to the variable that the file should read to and write
66 * from. 65 * from.
@@ -72,11 +71,11 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_u8, debugfs_u8_get, debugfs_u8_set, "%llu\n");
72 * This function will return a pointer to a dentry if it succeeds. This 71 * This function will return a pointer to a dentry if it succeeds. This
73 * pointer must be passed to the debugfs_remove() function when the file is 72 * pointer must be passed to the debugfs_remove() function when the file is
74 * to be removed (no automatic cleanup happens if your module is unloaded, 73 * to be removed (no automatic cleanup happens if your module is unloaded,
75 * you are responsible here.) If an error occurs, NULL will be returned. 74 * you are responsible here.) If an error occurs, %NULL will be returned.
76 * 75 *
77 * If debugfs is not enabled in the kernel, the value -ENODEV will be 76 * If debugfs is not enabled in the kernel, the value -%ENODEV will be
78 * returned. It is not wise to check for this value, but rather, check for 77 * returned. It is not wise to check for this value, but rather, check for
79 * NULL or !NULL instead as to eliminate the need for #ifdef in the calling 78 * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling
80 * code. 79 * code.
81 */ 80 */
82struct dentry *debugfs_create_u8(const char *name, mode_t mode, 81struct dentry *debugfs_create_u8(const char *name, mode_t mode,
@@ -97,12 +96,11 @@ static u64 debugfs_u16_get(void *data)
97DEFINE_SIMPLE_ATTRIBUTE(fops_u16, debugfs_u16_get, debugfs_u16_set, "%llu\n"); 96DEFINE_SIMPLE_ATTRIBUTE(fops_u16, debugfs_u16_get, debugfs_u16_set, "%llu\n");
98 97
99/** 98/**
100 * debugfs_create_u16 - create a file in the debugfs filesystem that is used to read and write an unsigned 16 bit value. 99 * debugfs_create_u16 - create a debugfs file that is used to read and write an unsigned 16-bit value
101 *
102 * @name: a pointer to a string containing the name of the file to create. 100 * @name: a pointer to a string containing the name of the file to create.
103 * @mode: the permission that the file should have 101 * @mode: the permission that the file should have
104 * @parent: a pointer to the parent dentry for this file. This should be a 102 * @parent: a pointer to the parent dentry for this file. This should be a
105 * directory dentry if set. If this paramater is NULL, then the 103 * directory dentry if set. If this parameter is %NULL, then the
106 * file will be created in the root of the debugfs filesystem. 104 * file will be created in the root of the debugfs filesystem.
107 * @value: a pointer to the variable that the file should read to and write 105 * @value: a pointer to the variable that the file should read to and write
108 * from. 106 * from.
@@ -114,11 +112,11 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_u16, debugfs_u16_get, debugfs_u16_set, "%llu\n");
114 * This function will return a pointer to a dentry if it succeeds. This 112 * This function will return a pointer to a dentry if it succeeds. This
115 * pointer must be passed to the debugfs_remove() function when the file is 113 * pointer must be passed to the debugfs_remove() function when the file is
116 * to be removed (no automatic cleanup happens if your module is unloaded, 114 * to be removed (no automatic cleanup happens if your module is unloaded,
117 * you are responsible here.) If an error occurs, NULL will be returned. 115 * you are responsible here.) If an error occurs, %NULL will be returned.
118 * 116 *
119 * If debugfs is not enabled in the kernel, the value -ENODEV will be 117 * If debugfs is not enabled in the kernel, the value -%ENODEV will be
120 * returned. It is not wise to check for this value, but rather, check for 118 * returned. It is not wise to check for this value, but rather, check for
121 * NULL or !NULL instead as to eliminate the need for #ifdef in the calling 119 * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling
122 * code. 120 * code.
123 */ 121 */
124struct dentry *debugfs_create_u16(const char *name, mode_t mode, 122struct dentry *debugfs_create_u16(const char *name, mode_t mode,
@@ -139,12 +137,11 @@ static u64 debugfs_u32_get(void *data)
139DEFINE_SIMPLE_ATTRIBUTE(fops_u32, debugfs_u32_get, debugfs_u32_set, "%llu\n"); 137DEFINE_SIMPLE_ATTRIBUTE(fops_u32, debugfs_u32_get, debugfs_u32_set, "%llu\n");
140 138
141/** 139/**
142 * debugfs_create_u32 - create a file in the debugfs filesystem that is used to read and write an unsigned 32 bit value. 140 * debugfs_create_u32 - create a debugfs file that is used to read and write an unsigned 32-bit value
143 *
144 * @name: a pointer to a string containing the name of the file to create. 141 * @name: a pointer to a string containing the name of the file to create.
145 * @mode: the permission that the file should have 142 * @mode: the permission that the file should have
146 * @parent: a pointer to the parent dentry for this file. This should be a 143 * @parent: a pointer to the parent dentry for this file. This should be a
147 * directory dentry if set. If this paramater is NULL, then the 144 * directory dentry if set. If this parameter is %NULL, then the
148 * file will be created in the root of the debugfs filesystem. 145 * file will be created in the root of the debugfs filesystem.
149 * @value: a pointer to the variable that the file should read to and write 146 * @value: a pointer to the variable that the file should read to and write
150 * from. 147 * from.
@@ -156,11 +153,11 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_u32, debugfs_u32_get, debugfs_u32_set, "%llu\n");
156 * This function will return a pointer to a dentry if it succeeds. This 153 * This function will return a pointer to a dentry if it succeeds. This
157 * pointer must be passed to the debugfs_remove() function when the file is 154 * pointer must be passed to the debugfs_remove() function when the file is
158 * to be removed (no automatic cleanup happens if your module is unloaded, 155 * to be removed (no automatic cleanup happens if your module is unloaded,
159 * you are responsible here.) If an error occurs, NULL will be returned. 156 * you are responsible here.) If an error occurs, %NULL will be returned.
160 * 157 *
161 * If debugfs is not enabled in the kernel, the value -ENODEV will be 158 * If debugfs is not enabled in the kernel, the value -%ENODEV will be
162 * returned. It is not wise to check for this value, but rather, check for 159 * returned. It is not wise to check for this value, but rather, check for
163 * NULL or !NULL instead as to eliminate the need for #ifdef in the calling 160 * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling
164 * code. 161 * code.
165 */ 162 */
166struct dentry *debugfs_create_u32(const char *name, mode_t mode, 163struct dentry *debugfs_create_u32(const char *name, mode_t mode,
@@ -219,12 +216,11 @@ static const struct file_operations fops_bool = {
219}; 216};
220 217
221/** 218/**
222 * debugfs_create_bool - create a file in the debugfs filesystem that is used to read and write a boolean value. 219 * debugfs_create_bool - create a debugfs file that is used to read and write a boolean value
223 *
224 * @name: a pointer to a string containing the name of the file to create. 220 * @name: a pointer to a string containing the name of the file to create.
225 * @mode: the permission that the file should have 221 * @mode: the permission that the file should have
226 * @parent: a pointer to the parent dentry for this file. This should be a 222 * @parent: a pointer to the parent dentry for this file. This should be a
227 * directory dentry if set. If this paramater is NULL, then the 223 * directory dentry if set. If this parameter is %NULL, then the
228 * file will be created in the root of the debugfs filesystem. 224 * file will be created in the root of the debugfs filesystem.
229 * @value: a pointer to the variable that the file should read to and write 225 * @value: a pointer to the variable that the file should read to and write
230 * from. 226 * from.
@@ -236,11 +232,11 @@ static const struct file_operations fops_bool = {
236 * This function will return a pointer to a dentry if it succeeds. This 232 * This function will return a pointer to a dentry if it succeeds. This
237 * pointer must be passed to the debugfs_remove() function when the file is 233 * pointer must be passed to the debugfs_remove() function when the file is
238 * to be removed (no automatic cleanup happens if your module is unloaded, 234 * to be removed (no automatic cleanup happens if your module is unloaded,
239 * you are responsible here.) If an error occurs, NULL will be returned. 235 * you are responsible here.) If an error occurs, %NULL will be returned.
240 * 236 *
241 * If debugfs is not enabled in the kernel, the value -ENODEV will be 237 * If debugfs is not enabled in the kernel, the value -%ENODEV will be
242 * returned. It is not wise to check for this value, but rather, check for 238 * returned. It is not wise to check for this value, but rather, check for
243 * NULL or !NULL instead as to eliminate the need for #ifdef in the calling 239 * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling
244 * code. 240 * code.
245 */ 241 */
246struct dentry *debugfs_create_bool(const char *name, mode_t mode, 242struct dentry *debugfs_create_bool(const char *name, mode_t mode,
@@ -264,13 +260,11 @@ static struct file_operations fops_blob = {
264}; 260};
265 261
266/** 262/**
267 * debugfs_create_blob - create a file in the debugfs filesystem that is 263 * debugfs_create_blob - create a debugfs file that is used to read and write a binary blob
268 * used to read and write a binary blob.
269 *
270 * @name: a pointer to a string containing the name of the file to create. 264 * @name: a pointer to a string containing the name of the file to create.
271 * @mode: the permission that the file should have 265 * @mode: the permission that the file should have
272 * @parent: a pointer to the parent dentry for this file. This should be a 266 * @parent: a pointer to the parent dentry for this file. This should be a
273 * directory dentry if set. If this paramater is NULL, then the 267 * directory dentry if set. If this parameter is %NULL, then the
274 * file will be created in the root of the debugfs filesystem. 268 * file will be created in the root of the debugfs filesystem.
275 * @blob: a pointer to a struct debugfs_blob_wrapper which contains a pointer 269 * @blob: a pointer to a struct debugfs_blob_wrapper which contains a pointer
276 * to the blob data and the size of the data. 270 * to the blob data and the size of the data.
@@ -282,11 +276,11 @@ static struct file_operations fops_blob = {
282 * This function will return a pointer to a dentry if it succeeds. This 276 * This function will return a pointer to a dentry if it succeeds. This
283 * pointer must be passed to the debugfs_remove() function when the file is 277 * pointer must be passed to the debugfs_remove() function when the file is
284 * to be removed (no automatic cleanup happens if your module is unloaded, 278 * to be removed (no automatic cleanup happens if your module is unloaded,
285 * you are responsible here.) If an error occurs, NULL will be returned. 279 * you are responsible here.) If an error occurs, %NULL will be returned.
286 * 280 *
287 * If debugfs is not enabled in the kernel, the value -ENODEV will be 281 * If debugfs is not enabled in the kernel, the value -%ENODEV will be
288 * returned. It is not wise to check for this value, but rather, check for 282 * returned. It is not wise to check for this value, but rather, check for
289 * NULL or !NULL instead as to eliminate the need for #ifdef in the calling 283 * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling
290 * code. 284 * code.
291 */ 285 */
292struct dentry *debugfs_create_blob(const char *name, mode_t mode, 286struct dentry *debugfs_create_blob(const char *name, mode_t mode,
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index e8ae3042b806..3ca268d2e5a2 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -162,7 +162,6 @@ static int debugfs_create_by_name(const char *name, mode_t mode,
162 162
163/** 163/**
164 * debugfs_create_file - create a file in the debugfs filesystem 164 * debugfs_create_file - create a file in the debugfs filesystem
165 *
166 * @name: a pointer to a string containing the name of the file to create. 165 * @name: a pointer to a string containing the name of the file to create.
167 * @mode: the permission that the file should have 166 * @mode: the permission that the file should have
168 * @parent: a pointer to the parent dentry for this file. This should be a 167 * @parent: a pointer to the parent dentry for this file. This should be a
@@ -182,11 +181,11 @@ static int debugfs_create_by_name(const char *name, mode_t mode,
182 * This function will return a pointer to a dentry if it succeeds. This 181 * This function will return a pointer to a dentry if it succeeds. This
183 * pointer must be passed to the debugfs_remove() function when the file is 182 * pointer must be passed to the debugfs_remove() function when the file is
184 * to be removed (no automatic cleanup happens if your module is unloaded, 183 * to be removed (no automatic cleanup happens if your module is unloaded,
185 * you are responsible here.) If an error occurs, NULL will be returned. 184 * you are responsible here.) If an error occurs, %NULL will be returned.
186 * 185 *
187 * If debugfs is not enabled in the kernel, the value -ENODEV will be 186 * If debugfs is not enabled in the kernel, the value -%ENODEV will be
188 * returned. It is not wise to check for this value, but rather, check for 187 * returned. It is not wise to check for this value, but rather, check for
189 * NULL or !NULL instead as to eliminate the need for #ifdef in the calling 188 * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling
190 * code. 189 * code.
191 */ 190 */
192struct dentry *debugfs_create_file(const char *name, mode_t mode, 191struct dentry *debugfs_create_file(const char *name, mode_t mode,
@@ -221,7 +220,6 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
221 220
222/** 221/**
223 * debugfs_create_dir - create a directory in the debugfs filesystem 222 * debugfs_create_dir - create a directory in the debugfs filesystem
224 *
225 * @name: a pointer to a string containing the name of the directory to 223 * @name: a pointer to a string containing the name of the directory to
226 * create. 224 * create.
227 * @parent: a pointer to the parent dentry for this file. This should be a 225 * @parent: a pointer to the parent dentry for this file. This should be a
@@ -233,11 +231,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
233 * This function will return a pointer to a dentry if it succeeds. This 231 * This function will return a pointer to a dentry if it succeeds. This
234 * pointer must be passed to the debugfs_remove() function when the file is 232 * pointer must be passed to the debugfs_remove() function when the file is
235 * to be removed (no automatic cleanup happens if your module is unloaded, 233 * to be removed (no automatic cleanup happens if your module is unloaded,
236 * you are responsible here.) If an error occurs, NULL will be returned. 234 * you are responsible here.) If an error occurs, %NULL will be returned.
237 * 235 *
238 * If debugfs is not enabled in the kernel, the value -ENODEV will be 236 * If debugfs is not enabled in the kernel, the value -%ENODEV will be
239 * returned. It is not wise to check for this value, but rather, check for 237 * returned. It is not wise to check for this value, but rather, check for
240 * NULL or !NULL instead as to eliminate the need for #ifdef in the calling 238 * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling
241 * code. 239 * code.
242 */ 240 */
243struct dentry *debugfs_create_dir(const char *name, struct dentry *parent) 241struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
@@ -250,7 +248,6 @@ EXPORT_SYMBOL_GPL(debugfs_create_dir);
250 248
251/** 249/**
252 * debugfs_remove - removes a file or directory from the debugfs filesystem 250 * debugfs_remove - removes a file or directory from the debugfs filesystem
253 *
254 * @dentry: a pointer to a the dentry of the file or directory to be 251 * @dentry: a pointer to a the dentry of the file or directory to be
255 * removed. 252 * removed.
256 * 253 *
diff --git a/fs/namespace.c b/fs/namespace.c
index fa7ed6a9fc2d..36d180858136 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -17,6 +17,7 @@
17#include <linux/acct.h> 17#include <linux/acct.h>
18#include <linux/capability.h> 18#include <linux/capability.h>
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/sysfs.h>
20#include <linux/seq_file.h> 21#include <linux/seq_file.h>
21#include <linux/namespace.h> 22#include <linux/namespace.h>
22#include <linux/namei.h> 23#include <linux/namei.h>
@@ -28,15 +29,6 @@
28 29
29extern int __init init_rootfs(void); 30extern int __init init_rootfs(void);
30 31
31#ifdef CONFIG_SYSFS
32extern int __init sysfs_init(void);
33#else
34static inline int sysfs_init(void)
35{
36 return 0;
37}
38#endif
39
40/* spinlock for vfsmount related operations, inplace of dcache_lock */ 32/* spinlock for vfsmount related operations, inplace of dcache_lock */
41__cacheline_aligned_in_smp DEFINE_SPINLOCK(vfsmount_lock); 33__cacheline_aligned_in_smp DEFINE_SPINLOCK(vfsmount_lock);
42 34
diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
index c16a93c353c0..98022e41cda1 100644
--- a/fs/sysfs/bin.c
+++ b/fs/sysfs/bin.c
@@ -10,6 +10,7 @@
10 10
11#include <linux/errno.h> 11#include <linux/errno.h>
12#include <linux/fs.h> 12#include <linux/fs.h>
13#include <linux/kernel.h>
13#include <linux/kobject.h> 14#include <linux/kobject.h>
14#include <linux/module.h> 15#include <linux/module.h>
15#include <linux/slab.h> 16#include <linux/slab.h>
@@ -176,7 +177,6 @@ const struct file_operations bin_fops = {
176 * sysfs_create_bin_file - create binary file for object. 177 * sysfs_create_bin_file - create binary file for object.
177 * @kobj: object. 178 * @kobj: object.
178 * @attr: attribute descriptor. 179 * @attr: attribute descriptor.
179 *
180 */ 180 */
181 181
182int sysfs_create_bin_file(struct kobject * kobj, struct bin_attribute * attr) 182int sysfs_create_bin_file(struct kobject * kobj, struct bin_attribute * attr)
@@ -191,13 +191,16 @@ int sysfs_create_bin_file(struct kobject * kobj, struct bin_attribute * attr)
191 * sysfs_remove_bin_file - remove binary file for object. 191 * sysfs_remove_bin_file - remove binary file for object.
192 * @kobj: object. 192 * @kobj: object.
193 * @attr: attribute descriptor. 193 * @attr: attribute descriptor.
194 *
195 */ 194 */
196 195
197int sysfs_remove_bin_file(struct kobject * kobj, struct bin_attribute * attr) 196void sysfs_remove_bin_file(struct kobject * kobj, struct bin_attribute * attr)
198{ 197{
199 sysfs_hash_and_remove(kobj->dentry,attr->attr.name); 198 if (sysfs_hash_and_remove(kobj->dentry, attr->attr.name) < 0) {
200 return 0; 199 printk(KERN_ERR "%s: "
200 "bad dentry or inode or no such file: \"%s\"\n",
201 __FUNCTION__, attr->attr.name);
202 dump_stack();
203 }
201} 204}
202 205
203EXPORT_SYMBOL_GPL(sysfs_create_bin_file); 206EXPORT_SYMBOL_GPL(sysfs_create_bin_file);
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 61c42430cba3..5f3d725d1125 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -43,7 +43,7 @@ static struct sysfs_dirent * sysfs_new_dirent(struct sysfs_dirent * parent_sd,
43 43
44 memset(sd, 0, sizeof(*sd)); 44 memset(sd, 0, sizeof(*sd));
45 atomic_set(&sd->s_count, 1); 45 atomic_set(&sd->s_count, 1);
46 atomic_set(&sd->s_event, 0); 46 atomic_set(&sd->s_event, 1);
47 INIT_LIST_HEAD(&sd->s_children); 47 INIT_LIST_HEAD(&sd->s_children);
48 list_add(&sd->s_sibling, &parent_sd->s_children); 48 list_add(&sd->s_sibling, &parent_sd->s_children);
49 sd->s_element = element; 49 sd->s_element = element;
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index 9889e54e1f13..fd7cd5f843d2 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -12,6 +12,7 @@
12#include <linux/namei.h> 12#include <linux/namei.h>
13#include <linux/backing-dev.h> 13#include <linux/backing-dev.h>
14#include <linux/capability.h> 14#include <linux/capability.h>
15#include <linux/errno.h>
15#include "sysfs.h" 16#include "sysfs.h"
16 17
17extern struct super_block * sysfs_sb; 18extern struct super_block * sysfs_sb;
@@ -234,17 +235,18 @@ void sysfs_drop_dentry(struct sysfs_dirent * sd, struct dentry * parent)
234 } 235 }
235} 236}
236 237
237void sysfs_hash_and_remove(struct dentry * dir, const char * name) 238int sysfs_hash_and_remove(struct dentry * dir, const char * name)
238{ 239{
239 struct sysfs_dirent * sd; 240 struct sysfs_dirent * sd;
240 struct sysfs_dirent * parent_sd; 241 struct sysfs_dirent * parent_sd;
242 int found = 0;
241 243
242 if (!dir) 244 if (!dir)
243 return; 245 return -ENOENT;
244 246
245 if (dir->d_inode == NULL) 247 if (dir->d_inode == NULL)
246 /* no inode means this hasn't been made visible yet */ 248 /* no inode means this hasn't been made visible yet */
247 return; 249 return -ENOENT;
248 250
249 parent_sd = dir->d_fsdata; 251 parent_sd = dir->d_fsdata;
250 mutex_lock(&dir->d_inode->i_mutex); 252 mutex_lock(&dir->d_inode->i_mutex);
@@ -255,8 +257,11 @@ void sysfs_hash_and_remove(struct dentry * dir, const char * name)
255 list_del_init(&sd->s_sibling); 257 list_del_init(&sd->s_sibling);
256 sysfs_drop_dentry(sd, dir); 258 sysfs_drop_dentry(sd, dir);
257 sysfs_put(sd); 259 sysfs_put(sd);
260 found = 1;
258 break; 261 break;
259 } 262 }
260 } 263 }
261 mutex_unlock(&dir->d_inode->i_mutex); 264 mutex_unlock(&dir->d_inode->i_mutex);
265
266 return found ? 0 : -ENOENT;
262} 267}
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index d2eac3ceed5f..f50e3cc2ded8 100644
--- a/fs/sysfs/symlink.c
+++ b/fs/sysfs/symlink.c
@@ -3,6 +3,7 @@
3 */ 3 */
4 4
5#include <linux/fs.h> 5#include <linux/fs.h>
6#include <linux/mount.h>
6#include <linux/module.h> 7#include <linux/module.h>
7#include <linux/kobject.h> 8#include <linux/kobject.h>
8#include <linux/namei.h> 9#include <linux/namei.h>
@@ -82,10 +83,19 @@ exit1:
82 */ 83 */
83int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char * name) 84int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char * name)
84{ 85{
85 struct dentry * dentry = kobj->dentry; 86 struct dentry *dentry = NULL;
86 int error = -EEXIST; 87 int error = -EEXIST;
87 88
88 BUG_ON(!kobj || !kobj->dentry || !name); 89 BUG_ON(!name);
90
91 if (!kobj) {
92 if (sysfs_mount && sysfs_mount->mnt_sb)
93 dentry = sysfs_mount->mnt_sb->s_root;
94 } else
95 dentry = kobj->dentry;
96
97 if (!dentry)
98 return -EFAULT;
89 99
90 mutex_lock(&dentry->d_inode->i_mutex); 100 mutex_lock(&dentry->d_inode->i_mutex);
91 if (!sysfs_dirent_exist(dentry->d_fsdata, name)) 101 if (!sysfs_dirent_exist(dentry->d_fsdata, name))
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index 3651ffb5ec09..6f3d6bd52887 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -10,7 +10,7 @@ extern int sysfs_make_dirent(struct sysfs_dirent *, struct dentry *, void *,
10 umode_t, int); 10 umode_t, int);
11 11
12extern int sysfs_add_file(struct dentry *, const struct attribute *, int); 12extern int sysfs_add_file(struct dentry *, const struct attribute *, int);
13extern void sysfs_hash_and_remove(struct dentry * dir, const char * name); 13extern int sysfs_hash_and_remove(struct dentry * dir, const char * name);
14extern struct sysfs_dirent *sysfs_find(struct sysfs_dirent *dir, const char * name); 14extern struct sysfs_dirent *sysfs_find(struct sysfs_dirent *dir, const char * name);
15 15
16extern int sysfs_create_subdir(struct kobject *, const char *, struct dentry **); 16extern int sysfs_create_subdir(struct kobject *, const char *, struct dentry **);
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 9b4f11094937..060b96112ec6 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -99,6 +99,11 @@ extern void __chk_io_ptr(void __iomem *);
99#define __must_check 99#define __must_check
100#endif 100#endif
101 101
102#ifndef CONFIG_ENABLE_MUST_CHECK
103#undef __must_check
104#define __must_check
105#endif
106
102/* 107/*
103 * Allow us to avoid 'defined but not used' warnings on functions and data, 108 * Allow us to avoid 'defined but not used' warnings on functions and data,
104 * as well as force them to be emitted to the assembly file. 109 * as well as force them to be emitted to the assembly file.
diff --git a/include/linux/device.h b/include/linux/device.h
index 1e5f30da98bc..662e6a10144e 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -15,6 +15,7 @@
15#include <linux/kobject.h> 15#include <linux/kobject.h>
16#include <linux/klist.h> 16#include <linux/klist.h>
17#include <linux/list.h> 17#include <linux/list.h>
18#include <linux/compiler.h>
18#include <linux/types.h> 19#include <linux/types.h>
19#include <linux/module.h> 20#include <linux/module.h>
20#include <linux/pm.h> 21#include <linux/pm.h>
@@ -51,14 +52,17 @@ struct bus_type {
51 int (*probe)(struct device * dev); 52 int (*probe)(struct device * dev);
52 int (*remove)(struct device * dev); 53 int (*remove)(struct device * dev);
53 void (*shutdown)(struct device * dev); 54 void (*shutdown)(struct device * dev);
54 int (*suspend)(struct device * dev, pm_message_t state); 55
55 int (*resume)(struct device * dev); 56 int (*suspend)(struct device * dev, pm_message_t state);
57 int (*suspend_late)(struct device * dev, pm_message_t state);
58 int (*resume_early)(struct device * dev);
59 int (*resume)(struct device * dev);
56}; 60};
57 61
58extern int bus_register(struct bus_type * bus); 62extern int __must_check bus_register(struct bus_type * bus);
59extern void bus_unregister(struct bus_type * bus); 63extern void bus_unregister(struct bus_type * bus);
60 64
61extern void bus_rescan_devices(struct bus_type * bus); 65extern int __must_check bus_rescan_devices(struct bus_type * bus);
62 66
63/* iterator helpers for buses */ 67/* iterator helpers for buses */
64 68
@@ -67,9 +71,9 @@ int bus_for_each_dev(struct bus_type * bus, struct device * start, void * data,
67struct device * bus_find_device(struct bus_type *bus, struct device *start, 71struct device * bus_find_device(struct bus_type *bus, struct device *start,
68 void *data, int (*match)(struct device *, void *)); 72 void *data, int (*match)(struct device *, void *));
69 73
70int bus_for_each_drv(struct bus_type * bus, struct device_driver * start, 74int __must_check bus_for_each_drv(struct bus_type *bus,
71 void * data, int (*fn)(struct device_driver *, void *)); 75 struct device_driver *start, void *data,
72 76 int (*fn)(struct device_driver *, void *));
73 77
74/* driverfs interface for exporting bus attributes */ 78/* driverfs interface for exporting bus attributes */
75 79
@@ -82,7 +86,8 @@ struct bus_attribute {
82#define BUS_ATTR(_name,_mode,_show,_store) \ 86#define BUS_ATTR(_name,_mode,_show,_store) \
83struct bus_attribute bus_attr_##_name = __ATTR(_name,_mode,_show,_store) 87struct bus_attribute bus_attr_##_name = __ATTR(_name,_mode,_show,_store)
84 88
85extern int bus_create_file(struct bus_type *, struct bus_attribute *); 89extern int __must_check bus_create_file(struct bus_type *,
90 struct bus_attribute *);
86extern void bus_remove_file(struct bus_type *, struct bus_attribute *); 91extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
87 92
88struct device_driver { 93struct device_driver {
@@ -101,16 +106,18 @@ struct device_driver {
101 void (*shutdown) (struct device * dev); 106 void (*shutdown) (struct device * dev);
102 int (*suspend) (struct device * dev, pm_message_t state); 107 int (*suspend) (struct device * dev, pm_message_t state);
103 int (*resume) (struct device * dev); 108 int (*resume) (struct device * dev);
109
110 unsigned int multithread_probe:1;
104}; 111};
105 112
106 113
107extern int driver_register(struct device_driver * drv); 114extern int __must_check driver_register(struct device_driver * drv);
108extern void driver_unregister(struct device_driver * drv); 115extern void driver_unregister(struct device_driver * drv);
109 116
110extern struct device_driver * get_driver(struct device_driver * drv); 117extern struct device_driver * get_driver(struct device_driver * drv);
111extern void put_driver(struct device_driver * drv); 118extern void put_driver(struct device_driver * drv);
112extern struct device_driver *driver_find(const char *name, struct bus_type *bus); 119extern struct device_driver *driver_find(const char *name, struct bus_type *bus);
113 120extern int driver_probe_done(void);
114 121
115/* driverfs interface for exporting driver attributes */ 122/* driverfs interface for exporting driver attributes */
116 123
@@ -123,16 +130,17 @@ struct driver_attribute {
123#define DRIVER_ATTR(_name,_mode,_show,_store) \ 130#define DRIVER_ATTR(_name,_mode,_show,_store) \
124struct driver_attribute driver_attr_##_name = __ATTR(_name,_mode,_show,_store) 131struct driver_attribute driver_attr_##_name = __ATTR(_name,_mode,_show,_store)
125 132
126extern int driver_create_file(struct device_driver *, struct driver_attribute *); 133extern int __must_check driver_create_file(struct device_driver *,
134 struct driver_attribute *);
127extern void driver_remove_file(struct device_driver *, struct driver_attribute *); 135extern void driver_remove_file(struct device_driver *, struct driver_attribute *);
128 136
129extern int driver_for_each_device(struct device_driver * drv, struct device * start, 137extern int __must_check driver_for_each_device(struct device_driver * drv,
130 void * data, int (*fn)(struct device *, void *)); 138 struct device *start, void *data,
139 int (*fn)(struct device *, void *));
131struct device * driver_find_device(struct device_driver *drv, 140struct device * driver_find_device(struct device_driver *drv,
132 struct device *start, void *data, 141 struct device *start, void *data,
133 int (*match)(struct device *, void *)); 142 int (*match)(struct device *, void *));
134 143
135
136/* 144/*
137 * device classes 145 * device classes
138 */ 146 */
@@ -146,17 +154,26 @@ struct class {
146 struct list_head interfaces; 154 struct list_head interfaces;
147 struct semaphore sem; /* locks both the children and interfaces lists */ 155 struct semaphore sem; /* locks both the children and interfaces lists */
148 156
157 struct kobject *virtual_dir;
158
149 struct class_attribute * class_attrs; 159 struct class_attribute * class_attrs;
150 struct class_device_attribute * class_dev_attrs; 160 struct class_device_attribute * class_dev_attrs;
161 struct device_attribute * dev_attrs;
151 162
152 int (*uevent)(struct class_device *dev, char **envp, 163 int (*uevent)(struct class_device *dev, char **envp,
153 int num_envp, char *buffer, int buffer_size); 164 int num_envp, char *buffer, int buffer_size);
165 int (*dev_uevent)(struct device *dev, char **envp, int num_envp,
166 char *buffer, int buffer_size);
154 167
155 void (*release)(struct class_device *dev); 168 void (*release)(struct class_device *dev);
156 void (*class_release)(struct class *class); 169 void (*class_release)(struct class *class);
170 void (*dev_release)(struct device *dev);
171
172 int (*suspend)(struct device *, pm_message_t state);
173 int (*resume)(struct device *);
157}; 174};
158 175
159extern int class_register(struct class *); 176extern int __must_check class_register(struct class *);
160extern void class_unregister(struct class *); 177extern void class_unregister(struct class *);
161 178
162 179
@@ -169,7 +186,8 @@ struct class_attribute {
169#define CLASS_ATTR(_name,_mode,_show,_store) \ 186#define CLASS_ATTR(_name,_mode,_show,_store) \
170struct class_attribute class_attr_##_name = __ATTR(_name,_mode,_show,_store) 187struct class_attribute class_attr_##_name = __ATTR(_name,_mode,_show,_store)
171 188
172extern int class_create_file(struct class *, const struct class_attribute *); 189extern int __must_check class_create_file(struct class *,
190 const struct class_attribute *);
173extern void class_remove_file(struct class *, const struct class_attribute *); 191extern void class_remove_file(struct class *, const struct class_attribute *);
174 192
175struct class_device_attribute { 193struct class_device_attribute {
@@ -182,7 +200,7 @@ struct class_device_attribute {
182struct class_device_attribute class_device_attr_##_name = \ 200struct class_device_attribute class_device_attr_##_name = \
183 __ATTR(_name,_mode,_show,_store) 201 __ATTR(_name,_mode,_show,_store)
184 202
185extern int class_device_create_file(struct class_device *, 203extern int __must_check class_device_create_file(struct class_device *,
186 const struct class_device_attribute *); 204 const struct class_device_attribute *);
187 205
188/** 206/**
@@ -242,10 +260,10 @@ class_set_devdata (struct class_device *dev, void *data)
242} 260}
243 261
244 262
245extern int class_device_register(struct class_device *); 263extern int __must_check class_device_register(struct class_device *);
246extern void class_device_unregister(struct class_device *); 264extern void class_device_unregister(struct class_device *);
247extern void class_device_initialize(struct class_device *); 265extern void class_device_initialize(struct class_device *);
248extern int class_device_add(struct class_device *); 266extern int __must_check class_device_add(struct class_device *);
249extern void class_device_del(struct class_device *); 267extern void class_device_del(struct class_device *);
250 268
251extern int class_device_rename(struct class_device *, char *); 269extern int class_device_rename(struct class_device *, char *);
@@ -255,7 +273,7 @@ extern void class_device_put(struct class_device *);
255 273
256extern void class_device_remove_file(struct class_device *, 274extern void class_device_remove_file(struct class_device *,
257 const struct class_device_attribute *); 275 const struct class_device_attribute *);
258extern int class_device_create_bin_file(struct class_device *, 276extern int __must_check class_device_create_bin_file(struct class_device *,
259 struct bin_attribute *); 277 struct bin_attribute *);
260extern void class_device_remove_bin_file(struct class_device *, 278extern void class_device_remove_bin_file(struct class_device *,
261 struct bin_attribute *); 279 struct bin_attribute *);
@@ -266,22 +284,23 @@ struct class_interface {
266 284
267 int (*add) (struct class_device *, struct class_interface *); 285 int (*add) (struct class_device *, struct class_interface *);
268 void (*remove) (struct class_device *, struct class_interface *); 286 void (*remove) (struct class_device *, struct class_interface *);
287 int (*add_dev) (struct device *, struct class_interface *);
288 void (*remove_dev) (struct device *, struct class_interface *);
269}; 289};
270 290
271extern int class_interface_register(struct class_interface *); 291extern int __must_check class_interface_register(struct class_interface *);
272extern void class_interface_unregister(struct class_interface *); 292extern void class_interface_unregister(struct class_interface *);
273 293
274extern struct class *class_create(struct module *owner, char *name); 294extern struct class *class_create(struct module *owner, const char *name);
275extern void class_destroy(struct class *cls); 295extern void class_destroy(struct class *cls);
276extern struct class_device *class_device_create(struct class *cls, 296extern struct class_device *class_device_create(struct class *cls,
277 struct class_device *parent, 297 struct class_device *parent,
278 dev_t devt, 298 dev_t devt,
279 struct device *device, 299 struct device *device,
280 char *fmt, ...) 300 const char *fmt, ...)
281 __attribute__((format(printf,5,6))); 301 __attribute__((format(printf,5,6)));
282extern void class_device_destroy(struct class *cls, dev_t devt); 302extern void class_device_destroy(struct class *cls, dev_t devt);
283 303
284
285/* interface for exporting device attributes */ 304/* interface for exporting device attributes */
286struct device_attribute { 305struct device_attribute {
287 struct attribute attr; 306 struct attribute attr;
@@ -294,8 +313,13 @@ struct device_attribute {
294#define DEVICE_ATTR(_name,_mode,_show,_store) \ 313#define DEVICE_ATTR(_name,_mode,_show,_store) \
295struct device_attribute dev_attr_##_name = __ATTR(_name,_mode,_show,_store) 314struct device_attribute dev_attr_##_name = __ATTR(_name,_mode,_show,_store)
296 315
297extern int device_create_file(struct device *device, struct device_attribute * entry); 316extern int __must_check device_create_file(struct device *device,
317 struct device_attribute * entry);
298extern void device_remove_file(struct device * dev, struct device_attribute * attr); 318extern void device_remove_file(struct device * dev, struct device_attribute * attr);
319extern int __must_check device_create_bin_file(struct device *dev,
320 struct bin_attribute *attr);
321extern void device_remove_bin_file(struct device *dev,
322 struct bin_attribute *attr);
299struct device { 323struct device {
300 struct klist klist_children; 324 struct klist klist_children;
301 struct klist_node knode_parent; /* node in sibling list */ 325 struct klist_node knode_parent; /* node in sibling list */
@@ -305,6 +329,7 @@ struct device {
305 329
306 struct kobject kobj; 330 struct kobject kobj;
307 char bus_id[BUS_ID_SIZE]; /* position on parent bus */ 331 char bus_id[BUS_ID_SIZE]; /* position on parent bus */
332 unsigned is_registered:1;
308 struct device_attribute uevent_attr; 333 struct device_attribute uevent_attr;
309 struct device_attribute *devt_attr; 334 struct device_attribute *devt_attr;
310 335
@@ -338,6 +363,7 @@ struct device {
338 struct list_head node; 363 struct list_head node;
339 struct class *class; /* optional*/ 364 struct class *class; /* optional*/
340 dev_t devt; /* dev_t, creates the sysfs "dev" */ 365 dev_t devt; /* dev_t, creates the sysfs "dev" */
366 struct attribute_group **groups; /* optional groups */
341 367
342 void (*release)(struct device * dev); 368 void (*release)(struct device * dev);
343}; 369};
@@ -356,38 +382,41 @@ dev_set_drvdata (struct device *dev, void *data)
356 382
357static inline int device_is_registered(struct device *dev) 383static inline int device_is_registered(struct device *dev)
358{ 384{
359 return klist_node_attached(&dev->knode_bus); 385 return dev->is_registered;
360} 386}
361 387
362/* 388/*
363 * High level routines for use by the bus drivers 389 * High level routines for use by the bus drivers
364 */ 390 */
365extern int device_register(struct device * dev); 391extern int __must_check device_register(struct device * dev);
366extern void device_unregister(struct device * dev); 392extern void device_unregister(struct device * dev);
367extern void device_initialize(struct device * dev); 393extern void device_initialize(struct device * dev);
368extern int device_add(struct device * dev); 394extern int __must_check device_add(struct device * dev);
369extern void device_del(struct device * dev); 395extern void device_del(struct device * dev);
370extern int device_for_each_child(struct device *, void *, 396extern int __must_check device_for_each_child(struct device *, void *,
371 int (*fn)(struct device *, void *)); 397 int (*fn)(struct device *, void *));
398extern int device_rename(struct device *dev, char *new_name);
372 399
373/* 400/*
374 * Manual binding of a device to driver. See drivers/base/bus.c 401 * Manual binding of a device to driver. See drivers/base/bus.c
375 * for information on use. 402 * for information on use.
376 */ 403 */
377extern void device_bind_driver(struct device * dev); 404extern int __must_check device_bind_driver(struct device *dev);
378extern void device_release_driver(struct device * dev); 405extern void device_release_driver(struct device * dev);
379extern int device_attach(struct device * dev); 406extern int __must_check device_attach(struct device * dev);
380extern void driver_attach(struct device_driver * drv); 407extern int __must_check driver_attach(struct device_driver *drv);
381extern void device_reprobe(struct device *dev); 408extern int __must_check device_reprobe(struct device *dev);
382 409
383/* 410/*
384 * Easy functions for dynamically creating devices on the fly 411 * Easy functions for dynamically creating devices on the fly
385 */ 412 */
386extern struct device *device_create(struct class *cls, struct device *parent, 413extern struct device *device_create(struct class *cls, struct device *parent,
387 dev_t devt, char *fmt, ...) 414 dev_t devt, const char *fmt, ...)
388 __attribute__((format(printf,4,5))); 415 __attribute__((format(printf,4,5)));
389extern void device_destroy(struct class *cls, dev_t devt); 416extern void device_destroy(struct class *cls, dev_t devt);
390 417
418extern int virtual_device_parent(struct device *dev);
419
391/* 420/*
392 * Platform "fixup" functions - allow the platform to have their say 421 * Platform "fixup" functions - allow the platform to have their say
393 * about devices and actions that the general device layer doesn't 422 * about devices and actions that the general device layer doesn't
@@ -412,7 +441,7 @@ extern void device_shutdown(void);
412 441
413 442
414/* drivers/base/firmware.c */ 443/* drivers/base/firmware.c */
415extern int firmware_register(struct subsystem *); 444extern int __must_check firmware_register(struct subsystem *);
416extern void firmware_unregister(struct subsystem *); 445extern void firmware_unregister(struct subsystem *);
417 446
418/* debugging and troubleshooting/diagnostic helpers. */ 447/* debugging and troubleshooting/diagnostic helpers. */
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 2d229327959e..bcd9cd173c2c 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -20,6 +20,7 @@
20#include <linux/types.h> 20#include <linux/types.h>
21#include <linux/list.h> 21#include <linux/list.h>
22#include <linux/sysfs.h> 22#include <linux/sysfs.h>
23#include <linux/compiler.h>
23#include <linux/spinlock.h> 24#include <linux/spinlock.h>
24#include <linux/rwsem.h> 25#include <linux/rwsem.h>
25#include <linux/kref.h> 26#include <linux/kref.h>
@@ -71,12 +72,12 @@ static inline const char * kobject_name(const struct kobject * kobj)
71extern void kobject_init(struct kobject *); 72extern void kobject_init(struct kobject *);
72extern void kobject_cleanup(struct kobject *); 73extern void kobject_cleanup(struct kobject *);
73 74
74extern int kobject_add(struct kobject *); 75extern int __must_check kobject_add(struct kobject *);
75extern void kobject_del(struct kobject *); 76extern void kobject_del(struct kobject *);
76 77
77extern int kobject_rename(struct kobject *, const char *new_name); 78extern int __must_check kobject_rename(struct kobject *, const char *new_name);
78 79
79extern int kobject_register(struct kobject *); 80extern int __must_check kobject_register(struct kobject *);
80extern void kobject_unregister(struct kobject *); 81extern void kobject_unregister(struct kobject *);
81 82
82extern struct kobject * kobject_get(struct kobject *); 83extern struct kobject * kobject_get(struct kobject *);
@@ -128,8 +129,8 @@ struct kset {
128 129
129 130
130extern void kset_init(struct kset * k); 131extern void kset_init(struct kset * k);
131extern int kset_add(struct kset * k); 132extern int __must_check kset_add(struct kset * k);
132extern int kset_register(struct kset * k); 133extern int __must_check kset_register(struct kset * k);
133extern void kset_unregister(struct kset * k); 134extern void kset_unregister(struct kset * k);
134 135
135static inline struct kset * to_kset(struct kobject * kobj) 136static inline struct kset * to_kset(struct kobject * kobj)
@@ -239,7 +240,7 @@ extern struct subsystem hypervisor_subsys;
239 (obj)->subsys.kset.kobj.kset = &(_subsys).kset 240 (obj)->subsys.kset.kobj.kset = &(_subsys).kset
240 241
241extern void subsystem_init(struct subsystem *); 242extern void subsystem_init(struct subsystem *);
242extern int subsystem_register(struct subsystem *); 243extern int __must_check subsystem_register(struct subsystem *);
243extern void subsystem_unregister(struct subsystem *); 244extern void subsystem_unregister(struct subsystem *);
244 245
245static inline struct subsystem * subsys_get(struct subsystem * s) 246static inline struct subsystem * subsys_get(struct subsystem * s)
@@ -258,7 +259,8 @@ struct subsys_attribute {
258 ssize_t (*store)(struct subsystem *, const char *, size_t); 259 ssize_t (*store)(struct subsystem *, const char *, size_t);
259}; 260};
260 261
261extern int subsys_create_file(struct subsystem * , struct subsys_attribute *); 262extern int __must_check subsys_create_file(struct subsystem * ,
263 struct subsys_attribute *);
262 264
263#if defined(CONFIG_HOTPLUG) 265#if defined(CONFIG_HOTPLUG)
264void kobject_uevent(struct kobject *kobj, enum kobject_action action); 266void kobject_uevent(struct kobject *kobj, enum kobject_action action);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 8565b81d7fbc..3ec72551ac31 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -49,6 +49,7 @@
49#include <linux/types.h> 49#include <linux/types.h>
50#include <linux/ioport.h> 50#include <linux/ioport.h>
51#include <linux/list.h> 51#include <linux/list.h>
52#include <linux/compiler.h>
52#include <linux/errno.h> 53#include <linux/errno.h>
53#include <linux/device.h> 54#include <linux/device.h>
54 55
@@ -346,6 +347,8 @@ struct pci_driver {
346 int (*probe) (struct pci_dev *dev, const struct pci_device_id *id); /* New device inserted */ 347 int (*probe) (struct pci_dev *dev, const struct pci_device_id *id); /* New device inserted */
347 void (*remove) (struct pci_dev *dev); /* Device removed (NULL if not a hot-plug capable driver) */ 348 void (*remove) (struct pci_dev *dev); /* Device removed (NULL if not a hot-plug capable driver) */
348 int (*suspend) (struct pci_dev *dev, pm_message_t state); /* Device suspended */ 349 int (*suspend) (struct pci_dev *dev, pm_message_t state); /* Device suspended */
350 int (*suspend_late) (struct pci_dev *dev, pm_message_t state);
351 int (*resume_early) (struct pci_dev *dev);
349 int (*resume) (struct pci_dev *dev); /* Device woken up */ 352 int (*resume) (struct pci_dev *dev); /* Device woken up */
350 int (*enable_wake) (struct pci_dev *dev, pci_power_t state, int enable); /* Enable wake event */ 353 int (*enable_wake) (struct pci_dev *dev, pci_power_t state, int enable); /* Enable wake event */
351 void (*shutdown) (struct pci_dev *dev); 354 void (*shutdown) (struct pci_dev *dev);
@@ -401,7 +404,7 @@ extern struct list_head pci_root_buses; /* list of all known PCI buses */
401extern struct list_head pci_devices; /* list of all devices */ 404extern struct list_head pci_devices; /* list of all devices */
402 405
403void pcibios_fixup_bus(struct pci_bus *); 406void pcibios_fixup_bus(struct pci_bus *);
404int pcibios_enable_device(struct pci_dev *, int mask); 407int __must_check pcibios_enable_device(struct pci_dev *, int mask);
405char *pcibios_setup (char *str); 408char *pcibios_setup (char *str);
406 409
407/* Used only when drivers/pci/setup.c is used */ 410/* Used only when drivers/pci/setup.c is used */
@@ -488,19 +491,19 @@ static inline int pci_write_config_dword(struct pci_dev *dev, int where, u32 val
488 return pci_bus_write_config_dword (dev->bus, dev->devfn, where, val); 491 return pci_bus_write_config_dword (dev->bus, dev->devfn, where, val);
489} 492}
490 493
491int pci_enable_device(struct pci_dev *dev); 494int __must_check pci_enable_device(struct pci_dev *dev);
492int pci_enable_device_bars(struct pci_dev *dev, int mask); 495int __must_check pci_enable_device_bars(struct pci_dev *dev, int mask);
493void pci_disable_device(struct pci_dev *dev); 496void pci_disable_device(struct pci_dev *dev);
494void pci_set_master(struct pci_dev *dev); 497void pci_set_master(struct pci_dev *dev);
495#define HAVE_PCI_SET_MWI 498#define HAVE_PCI_SET_MWI
496int pci_set_mwi(struct pci_dev *dev); 499int __must_check pci_set_mwi(struct pci_dev *dev);
497void pci_clear_mwi(struct pci_dev *dev); 500void pci_clear_mwi(struct pci_dev *dev);
498void pci_intx(struct pci_dev *dev, int enable); 501void pci_intx(struct pci_dev *dev, int enable);
499int pci_set_dma_mask(struct pci_dev *dev, u64 mask); 502int pci_set_dma_mask(struct pci_dev *dev, u64 mask);
500int pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask); 503int pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask);
501void pci_update_resource(struct pci_dev *dev, struct resource *res, int resno); 504void pci_update_resource(struct pci_dev *dev, struct resource *res, int resno);
502int pci_assign_resource(struct pci_dev *dev, int i); 505int __must_check pci_assign_resource(struct pci_dev *dev, int i);
503int pci_assign_resource_fixed(struct pci_dev *dev, int i); 506int __must_check pci_assign_resource_fixed(struct pci_dev *dev, int i);
504void pci_restore_bars(struct pci_dev *dev); 507void pci_restore_bars(struct pci_dev *dev);
505 508
506/* ROM control related routines */ 509/* ROM control related routines */
@@ -526,23 +529,24 @@ void pdev_sort_resources(struct pci_dev *, struct resource_list *);
526void pci_fixup_irqs(u8 (*)(struct pci_dev *, u8 *), 529void pci_fixup_irqs(u8 (*)(struct pci_dev *, u8 *),
527 int (*)(struct pci_dev *, u8, u8)); 530 int (*)(struct pci_dev *, u8, u8));
528#define HAVE_PCI_REQ_REGIONS 2 531#define HAVE_PCI_REQ_REGIONS 2
529int pci_request_regions(struct pci_dev *, const char *); 532int __must_check pci_request_regions(struct pci_dev *, const char *);
530void pci_release_regions(struct pci_dev *); 533void pci_release_regions(struct pci_dev *);
531int pci_request_region(struct pci_dev *, int, const char *); 534int __must_check pci_request_region(struct pci_dev *, int, const char *);
532void pci_release_region(struct pci_dev *, int); 535void pci_release_region(struct pci_dev *, int);
533 536
534/* drivers/pci/bus.c */ 537/* drivers/pci/bus.c */
535int pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res, 538int __must_check pci_bus_alloc_resource(struct pci_bus *bus,
536 resource_size_t size, resource_size_t align, 539 struct resource *res, resource_size_t size,
537 resource_size_t min, unsigned int type_mask, 540 resource_size_t align, resource_size_t min,
538 void (*alignf)(void *, struct resource *, 541 unsigned int type_mask,
539 resource_size_t, resource_size_t), 542 void (*alignf)(void *, struct resource *,
540 void *alignf_data); 543 resource_size_t, resource_size_t),
544 void *alignf_data);
541void pci_enable_bridges(struct pci_bus *bus); 545void pci_enable_bridges(struct pci_bus *bus);
542 546
543/* Proper probing supporting hot-pluggable devices */ 547/* Proper probing supporting hot-pluggable devices */
544int __pci_register_driver(struct pci_driver *, struct module *); 548int __must_check __pci_register_driver(struct pci_driver *, struct module *);
545static inline int pci_register_driver(struct pci_driver *driver) 549static inline int __must_check pci_register_driver(struct pci_driver *driver)
546{ 550{
547 return __pci_register_driver(driver, THIS_MODULE); 551 return __pci_register_driver(driver, THIS_MODULE);
548} 552}
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 782090c68932..29cd6dee13db 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -49,6 +49,8 @@ struct platform_driver {
49 int (*remove)(struct platform_device *); 49 int (*remove)(struct platform_device *);
50 void (*shutdown)(struct platform_device *); 50 void (*shutdown)(struct platform_device *);
51 int (*suspend)(struct platform_device *, pm_message_t state); 51 int (*suspend)(struct platform_device *, pm_message_t state);
52 int (*suspend_late)(struct platform_device *, pm_message_t state);
53 int (*resume_early)(struct platform_device *);
52 int (*resume)(struct platform_device *); 54 int (*resume)(struct platform_device *);
53 struct device_driver driver; 55 struct device_driver driver;
54}; 56};
diff --git a/include/linux/pm.h b/include/linux/pm.h
index 658c1b93d5bb..6b27e07aef19 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -142,29 +142,61 @@ typedef struct pm_message {
142} pm_message_t; 142} pm_message_t;
143 143
144/* 144/*
145 * There are 4 important states driver can be in: 145 * Several driver power state transitions are externally visible, affecting
146 * ON -- driver is working 146 * the state of pending I/O queues and (for drivers that touch hardware)
147 * FREEZE -- stop operations and apply whatever policy is applicable to a 147 * interrupts, wakeups, DMA, and other hardware state. There may also be
148 * suspended driver of that class, freeze queues for block like IDE 148 * internal transitions to various low power modes, which are transparent
149 * does, drop packets for ethernet, etc... stop DMA engine too etc... 149 * to the rest of the driver stack (such as a driver that's ON gating off
150 * so a consistent image can be saved; but do not power any hardware 150 * clocks which are not in active use).
151 * down.
152 * SUSPEND - like FREEZE, but hardware is doing as much powersaving as
153 * possible. Roughly pci D3.
154 * 151 *
155 * Unfortunately, current drivers only recognize numeric values 0 (ON) and 3 152 * One transition is triggered by resume(), after a suspend() call; the
156 * (SUSPEND). We'll need to fix the drivers. So yes, putting 3 to all different 153 * message is implicit:
157 * defines is intentional, and will go away as soon as drivers are fixed. Also 154 *
158 * note that typedef is neccessary, we'll probably want to switch to 155 * ON Driver starts working again, responding to hardware events
159 * typedef struct pm_message_t { int event; int flags; } pm_message_t 156 * and software requests. The hardware may have gone through
160 * or something similar soon. 157 * a power-off reset, or it may have maintained state from the
158 * previous suspend() which the driver will rely on while
159 * resuming. On most platforms, there are no restrictions on
160 * availability of resources like clocks during resume().
161 *
162 * Other transitions are triggered by messages sent using suspend(). All
163 * these transitions quiesce the driver, so that I/O queues are inactive.
164 * That commonly entails turning off IRQs and DMA; there may be rules
165 * about how to quiesce that are specific to the bus or the device's type.
166 * (For example, network drivers mark the link state.) Other details may
167 * differ according to the message:
168 *
169 * SUSPEND Quiesce, enter a low power device state appropriate for
170 * the upcoming system state (such as PCI_D3hot), and enable
171 * wakeup events as appropriate.
172 *
173 * FREEZE Quiesce operations so that a consistent image can be saved;
174 * but do NOT otherwise enter a low power device state, and do
175 * NOT emit system wakeup events.
176 *
177 * PRETHAW Quiesce as if for FREEZE; additionally, prepare for restoring
178 * the system from a snapshot taken after an earlier FREEZE.
179 * Some drivers will need to reset their hardware state instead
180 * of preserving it, to ensure that it's never mistaken for the
181 * state which that earlier snapshot had set up.
182 *
183 * A minimally power-aware driver treats all messages as SUSPEND, fully
184 * reinitializes its device during resume() -- whether or not it was reset
185 * during the suspend/resume cycle -- and can't issue wakeup events.
186 *
187 * More power-aware drivers may also use low power states at runtime as
188 * well as during system sleep states like PM_SUSPEND_STANDBY. They may
189 * be able to use wakeup events to exit from runtime low-power states,
190 * or from system low-power states such as standby or suspend-to-RAM.
161 */ 191 */
162 192
163#define PM_EVENT_ON 0 193#define PM_EVENT_ON 0
164#define PM_EVENT_FREEZE 1 194#define PM_EVENT_FREEZE 1
165#define PM_EVENT_SUSPEND 2 195#define PM_EVENT_SUSPEND 2
196#define PM_EVENT_PRETHAW 3
166 197
167#define PMSG_FREEZE ((struct pm_message){ .event = PM_EVENT_FREEZE, }) 198#define PMSG_FREEZE ((struct pm_message){ .event = PM_EVENT_FREEZE, })
199#define PMSG_PRETHAW ((struct pm_message){ .event = PM_EVENT_PRETHAW, })
168#define PMSG_SUSPEND ((struct pm_message){ .event = PM_EVENT_SUSPEND, }) 200#define PMSG_SUSPEND ((struct pm_message){ .event = PM_EVENT_SUSPEND, })
169#define PMSG_ON ((struct pm_message){ .event = PM_EVENT_ON, }) 201#define PMSG_ON ((struct pm_message){ .event = PM_EVENT_ON, })
170 202
@@ -190,6 +222,7 @@ extern void device_resume(void);
190extern suspend_disk_method_t pm_disk_mode; 222extern suspend_disk_method_t pm_disk_mode;
191 223
192extern int device_suspend(pm_message_t state); 224extern int device_suspend(pm_message_t state);
225extern int device_prepare_suspend(pm_message_t state);
193 226
194#define device_set_wakeup_enable(dev,val) \ 227#define device_set_wakeup_enable(dev,val) \
195 ((dev)->power.should_wakeup = !!(val)) 228 ((dev)->power.should_wakeup = !!(val))
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 1ea5d3cda6ae..6d5c43d31dec 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -10,6 +10,7 @@
10#ifndef _SYSFS_H_ 10#ifndef _SYSFS_H_
11#define _SYSFS_H_ 11#define _SYSFS_H_
12 12
13#include <linux/compiler.h>
13#include <asm/atomic.h> 14#include <asm/atomic.h>
14 15
15struct kobject; 16struct kobject;
@@ -86,40 +87,44 @@ struct sysfs_dirent {
86 87
87#ifdef CONFIG_SYSFS 88#ifdef CONFIG_SYSFS
88 89
89extern int 90extern int __must_check
90sysfs_create_dir(struct kobject *); 91sysfs_create_dir(struct kobject *);
91 92
92extern void 93extern void
93sysfs_remove_dir(struct kobject *); 94sysfs_remove_dir(struct kobject *);
94 95
95extern int 96extern int __must_check
96sysfs_rename_dir(struct kobject *, const char *new_name); 97sysfs_rename_dir(struct kobject *, const char *new_name);
97 98
98extern int 99extern int __must_check
99sysfs_create_file(struct kobject *, const struct attribute *); 100sysfs_create_file(struct kobject *, const struct attribute *);
100 101
101extern int 102extern int __must_check
102sysfs_update_file(struct kobject *, const struct attribute *); 103sysfs_update_file(struct kobject *, const struct attribute *);
103 104
104extern int 105extern int __must_check
105sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, mode_t mode); 106sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, mode_t mode);
106 107
107extern void 108extern void
108sysfs_remove_file(struct kobject *, const struct attribute *); 109sysfs_remove_file(struct kobject *, const struct attribute *);
109 110
110extern int 111extern int __must_check
111sysfs_create_link(struct kobject * kobj, struct kobject * target, const char * name); 112sysfs_create_link(struct kobject * kobj, struct kobject * target, const char * name);
112 113
113extern void 114extern void
114sysfs_remove_link(struct kobject *, const char * name); 115sysfs_remove_link(struct kobject *, const char * name);
115 116
116int sysfs_create_bin_file(struct kobject * kobj, struct bin_attribute * attr); 117int __must_check sysfs_create_bin_file(struct kobject *kobj,
117int sysfs_remove_bin_file(struct kobject * kobj, struct bin_attribute * attr); 118 struct bin_attribute *attr);
119void sysfs_remove_bin_file(struct kobject *kobj, struct bin_attribute *attr);
118 120
119int sysfs_create_group(struct kobject *, const struct attribute_group *); 121int __must_check sysfs_create_group(struct kobject *,
122 const struct attribute_group *);
120void sysfs_remove_group(struct kobject *, const struct attribute_group *); 123void sysfs_remove_group(struct kobject *, const struct attribute_group *);
121void sysfs_notify(struct kobject * k, char *dir, char *attr); 124void sysfs_notify(struct kobject * k, char *dir, char *attr);
122 125
126extern int __must_check sysfs_init(void);
127
123#else /* CONFIG_SYSFS */ 128#else /* CONFIG_SYSFS */
124 129
125static inline int sysfs_create_dir(struct kobject * k) 130static inline int sysfs_create_dir(struct kobject * k)
@@ -191,6 +196,11 @@ static inline void sysfs_notify(struct kobject * k, char *dir, char *attr)
191{ 196{
192} 197}
193 198
199static inline int __must_check sysfs_init(void)
200{
201 return 0;
202}
203
194#endif /* CONFIG_SYSFS */ 204#endif /* CONFIG_SYSFS */
195 205
196#endif /* _SYSFS_H_ */ 206#endif /* _SYSFS_H_ */
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index 810462f8a374..bb495b7f4680 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -341,7 +341,7 @@ extern int video_usercopy(struct inode *inode, struct file *file,
341extern struct video_device* video_devdata(struct file*); 341extern struct video_device* video_devdata(struct file*);
342 342
343#define to_video_device(cd) container_of(cd, struct video_device, class_dev) 343#define to_video_device(cd) container_of(cd, struct video_device, class_dev)
344static inline int 344static inline int __must_check
345video_device_create_file(struct video_device *vfd, 345video_device_create_file(struct video_device *vfd,
346 struct class_device_attribute *attr) 346 struct class_device_attribute *attr)
347{ 347{
diff --git a/init/do_mounts.c b/init/do_mounts.c
index 94aeec7aa917..b290aadb1d3f 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -8,6 +8,7 @@
8#include <linux/security.h> 8#include <linux/security.h>
9#include <linux/delay.h> 9#include <linux/delay.h>
10#include <linux/mount.h> 10#include <linux/mount.h>
11#include <linux/device.h>
11 12
12#include <linux/nfs_fs.h> 13#include <linux/nfs_fs.h>
13#include <linux/nfs_fs_sb.h> 14#include <linux/nfs_fs_sb.h>
@@ -403,6 +404,10 @@ void __init prepare_namespace(void)
403 ssleep(root_delay); 404 ssleep(root_delay);
404 } 405 }
405 406
407 /* wait for the known devices to complete their probing */
408 while (driver_probe_done() != 0)
409 msleep(100);
410
406 md_run_setup(); 411 md_run_setup();
407 412
408 if (saved_root_name[0]) { 413 if (saved_root_name[0]) {
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index 4b6e2f18e056..825068ca3479 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -64,6 +64,17 @@ config PM_TRACE
64 CAUTION: this option will cause your machine's real-time clock to be 64 CAUTION: this option will cause your machine's real-time clock to be
65 set to an invalid time after a resume. 65 set to an invalid time after a resume.
66 66
67config PM_SYSFS_DEPRECATED
68 bool "Driver model /sys/devices/.../power/state files (DEPRECATED)"
69 depends on PM && SYSFS
70 default n
71 help
72 The driver model started out with a sysfs file intended to provide
73 a userspace hook for device power management. This feature has never
74 worked very well, except for limited testing purposes, and so it will
75 be removed. It's not clear that a generic mechanism could really
76 handle the wide variability of device power states; any replacements
77 are likely to be bus or driver specific.
67 78
68config SOFTWARE_SUSPEND 79config SOFTWARE_SUSPEND
69 bool "Software Suspend" 80 bool "Software Suspend"
diff --git a/kernel/power/disk.c b/kernel/power/disk.c
index 7c7b9b65e365..d72234942798 100644
--- a/kernel/power/disk.c
+++ b/kernel/power/disk.c
@@ -103,7 +103,7 @@ static void unprepare_processes(void)
103} 103}
104 104
105/** 105/**
106 * pm_suspend_disk - The granpappy of power management. 106 * pm_suspend_disk - The granpappy of hibernation power management.
107 * 107 *
108 * If we're going through the firmware, then get it over with quickly. 108 * If we're going through the firmware, then get it over with quickly.
109 * 109 *
@@ -212,7 +212,7 @@ static int software_resume(void)
212 212
213 pr_debug("PM: Preparing devices for restore.\n"); 213 pr_debug("PM: Preparing devices for restore.\n");
214 214
215 if ((error = device_suspend(PMSG_FREEZE))) { 215 if ((error = device_suspend(PMSG_PRETHAW))) {
216 printk("Some devices failed to suspend\n"); 216 printk("Some devices failed to suspend\n");
217 swsusp_free(); 217 swsusp_free();
218 goto Thaw; 218 goto Thaw;
diff --git a/kernel/power/swsusp.c b/kernel/power/swsusp.c
index 8ef677ea0cea..0b66659dc516 100644
--- a/kernel/power/swsusp.c
+++ b/kernel/power/swsusp.c
@@ -247,6 +247,9 @@ int swsusp_suspend(void)
247 restore_processor_state(); 247 restore_processor_state();
248Restore_highmem: 248Restore_highmem:
249 restore_highmem(); 249 restore_highmem();
250 /* NOTE: device_power_up() is just a resume() for devices
251 * that suspended with irqs off ... no overall powerup.
252 */
250 device_power_up(); 253 device_power_up();
251Enable_irqs: 254Enable_irqs:
252 local_irq_enable(); 255 local_irq_enable();
@@ -256,8 +259,12 @@ Enable_irqs:
256int swsusp_resume(void) 259int swsusp_resume(void)
257{ 260{
258 int error; 261 int error;
262
259 local_irq_disable(); 263 local_irq_disable();
260 if (device_power_down(PMSG_FREEZE)) 264 /* NOTE: device_power_down() is just a suspend() with irqs off;
265 * it has no special "power things down" semantics
266 */
267 if (device_power_down(PMSG_PRETHAW))
261 printk(KERN_ERR "Some devices failed to power down, very bad\n"); 268 printk(KERN_ERR "Some devices failed to power down, very bad\n");
262 /* We'll ignore saved state, but this gets preempt count (etc) right */ 269 /* We'll ignore saved state, but this gets preempt count (etc) right */
263 save_processor_state(); 270 save_processor_state();
diff --git a/kernel/power/user.c b/kernel/power/user.c
index 2e4499f3e4d9..72825c853cd7 100644
--- a/kernel/power/user.c
+++ b/kernel/power/user.c
@@ -196,7 +196,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
196 snapshot_free_unused_memory(&data->handle); 196 snapshot_free_unused_memory(&data->handle);
197 down(&pm_sem); 197 down(&pm_sem);
198 pm_prepare_console(); 198 pm_prepare_console();
199 error = device_suspend(PMSG_FREEZE); 199 error = device_suspend(PMSG_PRETHAW);
200 if (!error) { 200 if (!error) {
201 error = swsusp_resume(); 201 error = swsusp_resume();
202 device_resume(); 202 device_resume();
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 3f21cc79a134..2869307ca3e4 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -8,6 +8,13 @@ config PRINTK_TIME
8 operations. This is useful for identifying long delays 8 operations. This is useful for identifying long delays
9 in kernel startup. 9 in kernel startup.
10 10
11config ENABLE_MUST_CHECK
12 bool "Enable __must_check logic"
13 default y
14 help
15 Enable the __must_check logic in the kernel build. Disable this to
16 suppress the "warning: ignoring return value of 'foo', declared with
17 attribute warn_unused_result" messages.
11 18
12config MAGIC_SYSRQ 19config MAGIC_SYSRQ
13 bool "Magic SysRq key" 20 bool "Magic SysRq key"
diff --git a/lib/klist.c b/lib/klist.c
index 9c94f0b163a1..120bd175aa78 100644
--- a/lib/klist.c
+++ b/lib/klist.c
@@ -123,12 +123,10 @@ EXPORT_SYMBOL_GPL(klist_add_tail);
123static void klist_release(struct kref * kref) 123static void klist_release(struct kref * kref)
124{ 124{
125 struct klist_node * n = container_of(kref, struct klist_node, n_ref); 125 struct klist_node * n = container_of(kref, struct klist_node, n_ref);
126 void (*put)(struct klist_node *) = n->n_klist->put; 126
127 list_del(&n->n_node); 127 list_del(&n->n_node);
128 complete(&n->n_removed); 128 complete(&n->n_removed);
129 n->n_klist = NULL; 129 n->n_klist = NULL;
130 if (put)
131 put(n);
132} 130}
133 131
134static int klist_dec_and_del(struct klist_node * n) 132static int klist_dec_and_del(struct klist_node * n)
@@ -145,10 +143,14 @@ static int klist_dec_and_del(struct klist_node * n)
145void klist_del(struct klist_node * n) 143void klist_del(struct klist_node * n)
146{ 144{
147 struct klist * k = n->n_klist; 145 struct klist * k = n->n_klist;
146 void (*put)(struct klist_node *) = k->put;
148 147
149 spin_lock(&k->k_lock); 148 spin_lock(&k->k_lock);
150 klist_dec_and_del(n); 149 if (!klist_dec_and_del(n))
150 put = NULL;
151 spin_unlock(&k->k_lock); 151 spin_unlock(&k->k_lock);
152 if (put)
153 put(n);
152} 154}
153 155
154EXPORT_SYMBOL_GPL(klist_del); 156EXPORT_SYMBOL_GPL(klist_del);
@@ -161,10 +163,7 @@ EXPORT_SYMBOL_GPL(klist_del);
161 163
162void klist_remove(struct klist_node * n) 164void klist_remove(struct klist_node * n)
163{ 165{
164 struct klist * k = n->n_klist; 166 klist_del(n);
165 spin_lock(&k->k_lock);
166 klist_dec_and_del(n);
167 spin_unlock(&k->k_lock);
168 wait_for_completion(&n->n_removed); 167 wait_for_completion(&n->n_removed);
169} 168}
170 169
@@ -260,12 +259,15 @@ static struct klist_node * to_klist_node(struct list_head * n)
260struct klist_node * klist_next(struct klist_iter * i) 259struct klist_node * klist_next(struct klist_iter * i)
261{ 260{
262 struct list_head * next; 261 struct list_head * next;
262 struct klist_node * lnode = i->i_cur;
263 struct klist_node * knode = NULL; 263 struct klist_node * knode = NULL;
264 void (*put)(struct klist_node *) = i->i_klist->put;
264 265
265 spin_lock(&i->i_klist->k_lock); 266 spin_lock(&i->i_klist->k_lock);
266 if (i->i_cur) { 267 if (lnode) {
267 next = i->i_cur->n_node.next; 268 next = lnode->n_node.next;
268 klist_dec_and_del(i->i_cur); 269 if (!klist_dec_and_del(lnode))
270 put = NULL;
269 } else 271 } else
270 next = i->i_head->next; 272 next = i->i_head->next;
271 273
@@ -275,6 +277,8 @@ struct klist_node * klist_next(struct klist_iter * i)
275 } 277 }
276 i->i_cur = knode; 278 i->i_cur = knode;
277 spin_unlock(&i->i_klist->k_lock); 279 spin_unlock(&i->i_klist->k_lock);
280 if (put && lnode)
281 put(lnode);
278 return knode; 282 return knode;
279} 283}
280 284
diff --git a/lib/kobject.c b/lib/kobject.c
index 8e7c71993487..1699eb9161f3 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -407,6 +407,7 @@ static struct kobj_type dir_ktype = {
407struct kobject *kobject_add_dir(struct kobject *parent, const char *name) 407struct kobject *kobject_add_dir(struct kobject *parent, const char *name)
408{ 408{
409 struct kobject *k; 409 struct kobject *k;
410 int ret;
410 411
411 if (!parent) 412 if (!parent)
412 return NULL; 413 return NULL;
@@ -418,7 +419,13 @@ struct kobject *kobject_add_dir(struct kobject *parent, const char *name)
418 k->parent = parent; 419 k->parent = parent;
419 k->ktype = &dir_ktype; 420 k->ktype = &dir_ktype;
420 kobject_set_name(k, name); 421 kobject_set_name(k, name);
421 kobject_register(k); 422 ret = kobject_register(k);
423 if (ret < 0) {
424 printk(KERN_WARNING "kobject_add_dir: "
425 "kobject_register error: %d\n", ret);
426 kobject_del(k);
427 return NULL;
428 }
422 429
423 return k; 430 return k;
424} 431}