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
...

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