Commit 542f96a5 authored by Pavel Machek's avatar Pavel Machek Committed by Linus Torvalds

[PATCH] suspend-to-{RAM,disk}

Here's suspend-to-{RAM,disk} combined patch for
2.5.17. Suspend-to-disk is pretty stable and was tested in
2.4-ac. Suspend-to-RAM is little more experimental, but works for me,
and is certainly better than disk-eating version currently in kernel.

Major parts are: process stopper, S3 specific code, S4 specific
code.
parent 79998dec
...@@ -52,7 +52,8 @@ appropriate callbacks that each device (or bridge) of that type share. ...@@ -52,7 +52,8 @@ appropriate callbacks that each device (or bridge) of that type share.
Each bus layer should implement the callbacks for these drivers. It then Each bus layer should implement the callbacks for these drivers. It then
forwards the calls on to the device-specific callbacks. This means that forwards the calls on to the device-specific callbacks. This means that
device-specific drivers must still implement callbacks for each operation. device-specific drivers must still implement callbacks for each operation.
But, they are not called from the top level driver layer. But, they are not called from the top level driver layer. [So for example
PCI devices will not call device_register but pci_device_register.]
This does add another layer of indirection for calling one of these functions, This does add another layer of indirection for calling one of these functions,
but there are benefits that are believed to outweigh this slowdown. but there are benefits that are believed to outweigh this slowdown.
...@@ -60,7 +61,7 @@ but there are benefits that are believed to outweigh this slowdown. ...@@ -60,7 +61,7 @@ but there are benefits that are believed to outweigh this slowdown.
First, it prevents device-specific drivers from having to know about the First, it prevents device-specific drivers from having to know about the
global device layer. This speeds up integration time incredibly. It also global device layer. This speeds up integration time incredibly. It also
allows drivers to be more portable across kernel versions. Note that the allows drivers to be more portable across kernel versions. Note that the
former was intentional, the latter is an added bonus. former was intentional, the latter is an added bonus.
Second, this added indirection allows the bus to perform any additional logic Second, this added indirection allows the bus to perform any additional logic
necessary for its child devices. A bus layer may add additional information to necessary for its child devices. A bus layer may add additional information to
...@@ -225,7 +226,6 @@ platform_data: ...@@ -225,7 +226,6 @@ platform_data:
It also allows the platform driver (e.g. ACPI) to a driver without the driver It also allows the platform driver (e.g. ACPI) to a driver without the driver
having to have explicit knowledge of (atrocities like) ACPI. having to have explicit knowledge of (atrocities like) ACPI.
current_state: current_state:
Current power state of the device. For PCI and other modern devices, this is Current power state of the device. For PCI and other modern devices, this is
0-3, though it's not necessarily limited to those values. 0-3, though it's not necessarily limited to those values.
...@@ -251,18 +251,24 @@ struct device_driver { ...@@ -251,18 +251,24 @@ struct device_driver {
} }
probe: probe:
Check for device existence and associate driver with it. Check for device existence and associate driver with it. In case of device
insertion, *all* drivers are called. Struct device has parent and bus_id
valid at this point. probe() may only be called from process context. Returns
0 if it handles that device, -ESRCH if this driver does not know how to handle
this device, valid error otherwise.
remove: remove:
Dissociate driver with device. Releases device so that it could be used by Dissociate driver with device. Releases device so that it could be used by
another driver. Also, if it is a hotplug device (hotplug PCI, Cardbus), an another driver. Also, if it is a hotplug device (hotplug PCI, Cardbus), an
ejection event could take place here. ejection event could take place here. remove() can be called from interrupt
context. [Fixme: Is that good?] Returns 0 on success. [Can we recover from
failed remove or should I define that remove() never fails?]
suspend: suspend:
Perform one step of the device suspend process. Perform one step of the device suspend process. Returns 0 on success.
resume: resume:
Perform one step of the device resume process. Perform one step of the device resume process. Returns 0 on success.
The probe() and remove() callbacks are intended to be much simpler than the The probe() and remove() callbacks are intended to be much simpler than the
current PCI correspondents. current PCI correspondents.
...@@ -275,7 +281,7 @@ probe() should do the following only: ...@@ -275,7 +281,7 @@ probe() should do the following only:
Some device initialisation was done in probe(). This should not be the case Some device initialisation was done in probe(). This should not be the case
anymore. All initialisation should take place in the open() call for the anymore. All initialisation should take place in the open() call for the
device. device. [FIXME: How do you "open" uhci?]
Breaking initialisation code out must also be done for the resume() callback, Breaking initialisation code out must also be done for the resume() callback,
as most devices will have to be completely reinitialised when coming back from as most devices will have to be completely reinitialised when coming back from
...@@ -324,6 +330,7 @@ the stage: ...@@ -324,6 +330,7 @@ the stage:
enum{ enum{
SUSPEND_NOTIFY, SUSPEND_NOTIFY,
SUSPEND_DISABLE,
SUSPEND_SAVE_STATE, SUSPEND_SAVE_STATE,
SUSPEND_POWER_DOWN, SUSPEND_POWER_DOWN,
}; };
...@@ -331,6 +338,7 @@ enum{ ...@@ -331,6 +338,7 @@ enum{
enum { enum {
RESUME_POWER_ON, RESUME_POWER_ON,
RESUME_RESTORE_STATE, RESUME_RESTORE_STATE,
RESUME_ENABLE,
}; };
...@@ -352,9 +360,9 @@ shutting down the device(s) you want to save state to. ...@@ -352,9 +360,9 @@ shutting down the device(s) you want to save state to.
Instead, the walking of the device tree has been moved to userspace. When a Instead, the walking of the device tree has been moved to userspace. When a
user requests the system to suspend, it will walk the device tree, as exported user requests the system to suspend, it will walk the device tree, as exported
via driverfs, and tell each device to go to sleep. It will do this multiple via driverfs, and tell each device to go to sleep. It will do this multiple
times based on what the system policy is. times based on what the system policy is. [Not possible. Take ACPI enabled
system, with battery critically low. In such state, you want to suspend-to-disk,
[ FIXME: URL pointer to the corresponding utility is missing here! ] *fast*. User maybe is not even running powerd (think system startup)!]
Device resume should happen in the same manner when the system awakens. Device resume should happen in the same manner when the system awakens.
...@@ -366,22 +374,25 @@ This level to notify the driver that it is going to sleep. If it knows that it ...@@ -366,22 +374,25 @@ This level to notify the driver that it is going to sleep. If it knows that it
cannot resume the hardware from the requested level, or it feels that it is cannot resume the hardware from the requested level, or it feels that it is
too important to be put to sleep, it should return an error from this function. too important to be put to sleep, it should return an error from this function.
It does not have to stop I/O requests or actually save state at this point. It does not have to stop I/O requests or actually save state at this point. Called
from process context.
SUSPEND_DISABLE: SUSPEND_DISABLE:
The driver should stop taking I/O requests at this stage. Because the save The driver should stop taking I/O requests at this stage. Because the save
state stage happens afterwards, the driver may not want to physically disable state stage happens afterwards, the driver may not want to physically disable
the device; only mark itself unavailable if possible. the device; only mark itself unavailable if possible. Called from process
context.
SUSPEND_SAVE_STATE: SUSPEND_SAVE_STATE:
The driver should allocate memory and save any device state that is relevant The driver should allocate memory and save any device state that is relevant
for the state it is going to enter. for the state it is going to enter. Called from process context.
SUSPEND_POWER_DOWN: SUSPEND_POWER_DOWN:
The driver should place the device in the power state requested. The driver should place the device in the power state requested. May be called
from interrupt context.
For resume, the stages are defined as follows: For resume, the stages are defined as follows:
...@@ -389,25 +400,27 @@ For resume, the stages are defined as follows: ...@@ -389,25 +400,27 @@ For resume, the stages are defined as follows:
RESUME_POWER_ON: RESUME_POWER_ON:
Devices should be powered on and reinitialised to some known working state. Devices should be powered on and reinitialised to some known working state.
Called from process context.
RESUME_RESTORE_STATE: RESUME_RESTORE_STATE:
The driver should restore device state to its pre-suspend state and free any The driver should restore device state to its pre-suspend state and free any
memory allocated for its saved state. memory allocated for its saved state. Called from process context.
RESUME_ENABLE: RESUME_ENABLE:
The device should start taking I/O requests again. The device should start taking I/O requests again. Called from process context.
Each driver does not have to implement each stage. But, it if it does Each driver does not have to implement each stage. But, it if it does
implemente a stage, it should do what is described above. It should not assume implement a stage, it should do what is described above. It should not assume
that it performed any stage previously, or that it will perform any stage that it performed any stage previously, or that it will perform any stage
later. later. [Really? It makes sense to support SAVE_STATE only after DISABLE].
It is quite possible that a driver can fail during the suspend process, for It is quite possible that a driver can fail during the suspend process, for
whatever reason. In this event, the calling process must gracefully recover whatever reason. In this event, the calling process must gracefully recover
and restore everything to their states before the suspend transition began. and restore everything to their states before the suspend transition began.
[Suspend may not fail, think battery low.]
If a driver knows that it cannot suspend or resume properly, it should fail If a driver knows that it cannot suspend or resume properly, it should fail
during the notify stage. Properly implemented power management schemes should during the notify stage. Properly implemented power management schemes should
......
From kernel/suspend.c:
* BIG FAT WARNING *********************************************************
*
* If you have unsupported (*) devices using DMA...
* ...say goodbye to your data.
*
* If you touch anything on disk between suspend and resume...
* ...kiss your data goodbye.
*
* If your disk driver does not support suspend... (IDE does)
* ...you'd better find out how to get along
* without your data.
*
* (*) pm interface support is needed to make it safe.
You need to append resume=/dev/your_swap_partition to kernel command
line. Then you suspend by echo 4 > /proc/acpi/sleep.
[Notice. Rest docs is pretty outdated (see date!) It should be safe to
use swsusp on ext3/reiserfs these days.]
Article about goals and implementation of Software Suspend for Linux
Author: G‚ábor Kuti
Last revised: 2002-04-08
Idea and goals to achieve
Nowadays it is common in several laptops that they have a suspend button. It
saves the state of the machine to a filesystem or to a partition and switches
to standby mode. Later resuming the machine the saved state is loaded back to
ram and the machine can continue its work. It has two real benefits. First we
save ourselves the time machine goes down and later boots up, energy costs
real high when running from batteries. The other gain is that we don't have to
interrupt our programs so processes that are calculating something for a long
time shouldn't need to be written interruptible.
On desk machines the power saving function isn't as important as it is in
laptops but we really may benefit from the second one. Nowadays the number of
desk machines supporting suspend function in their APM is going up but there
are (and there will still be for a long time) machines that don't even support
APM of any kind. On the other hand it is reported that using APM's suspend
some irqs (e.g. ATA disk irq) is lost and it is annoying for the user until
the Linux kernel resets the device.
So I started thinking about implementing Software Suspend which doesn't need
any APM support and - since it uses pretty near only high-level routines - is
supposed to be architecture independent code.
Using the code
The code is experimental right now - testers, extra eyes are welcome. To
compile this support into the kernel, you need CONFIG_EXPERIMENTAL,
and then CONFIG_SOFTWARE_SUSPEND in menu General Setup to be enabled. It
cannot be used as a module and I don't think it will ever be needed.
You have two ways to use this code. The first one is if you've compiled in
sysrq support then you may press Sysrq-D to request suspend. The other way
is with a patched SysVinit (my patch is against 2.76 and available at my
home page). You might call 'swsusp' or 'shutdown -z <time>'. Next way is to
echo 4 > /proc/acpi/sleep.
Either way it saves the state of the machine into active swaps and then
reboots. You must explicitly specify the swap partition to resume from with ``resume=''
kernel option. If signature is found it loads and restores saved state. If the
option ``noresume'' is specified as a boot parameter, it skips the resuming.
Warning! Look at section ``Things to implement'' to see what isn't yet
implemented. Also I strongly suggest you to list all active swaps in
/etc/fstab. Firstly because you don't have to specify anything to resume and
secondly if you have more than one swap area you can't decide which one has the
'root' signature.
In the meantime while the system is suspended you should not touch any of the
hardware!
About the code
Goals reached
The code can be downloaded from
http://falcon.sch.bme.hu/~seasons/linux/. It mainly works but there are still
some of XXXs, TODOs, FIXMEs in the code which seem not to be too important. It
should work all right except for the problems listed in ``Things to
implement''. Notes about the code are really welcome.
How the code works
When suspending is triggered it immediately wakes up process bdflush. Bdflush
checks whether we have anything in our run queue tq_bdflush. Since we queued up
function do_software_suspend, it is called. Here we shrink everything including
dcache, inodes, buffers and memory (here mainly processes are swapped out). We
count how many pages we need to duplicate (we have to be atomical!) then we
create an appropiate sized page directory. It will point to the original and
the new (copied) address of the page. We get the free pages by
__get_free_pages() but since it changes state we have to be able to track it
later so it also flips in a bit in page's flags (a new Nosave flag). We
duplicate pages and then mark them as used (so atomicity is ensured). After
this we write out the image to swaps, do another sync and the machine may
reboot. We also save registers to stack.
By resuming an ``inverse'' method is executed. The image if exists is loaded,
loadling is either triggered by ``resume='' kernel option. We
change our task to bdflush (it is needed because if we don't do this init does
an oops when it is waken up later) and then pages are copied back to their
original location. We restore registers, free previously allocated memory,
activate memory context and task information. Here we should restore hardware
state but even without this the machine is restored and processes are continued
to work. I think hardware state should be restored by some list (using
notify_chain) and probably by some userland program (run-parts?) for users'
pleasure. Check out my patch at the same location for the sysvinit patch.
WARNINGS!
- It does not like pcmcia cards. And this is logical: pcmcia cards need cardmgr to be
initialized. they are not initialized during singleuser boot, but "resumed" kernel does
expect them to be initialized. That leads to armagedon. You should eject any pcmcia cards
before suspending.
Things to implement
- SMP support. I've done an SMP support but since I don't have access to a kind
of this one I cannot test it. Please SMP people test it. .. Tested it,
doesn't work. Had no time to figure out why. There is some mess with
interrupts AFAIK..
- We should only make a copy of data related to kernel segment, since any
process data won't be changed.
- By copying pages back to their original position, copy_page caused General
Protection Fault. Why?
- Hardware state restoring. Now there's support for notifying via the notify
chain, event handlers are welcome. Some devices may have microcodes loaded
into them. We should have event handlers for them aswell.
- We should support other architectures (There are really only some arch
related functions..)
- We should also restore original state of swaps if the ``noresume'' kernel
option is specified.. Or do we need such a feature to save state for some
other time? Do we need some kind of ``several saved states''? (Linux-HA
people?). There's been some discussion about checkpointing on linux-future.
- Should make more sanity checks. Or are these enough?
Not so important ideas for implementing
- If a real time process is running then don't suspend the machine.
- Is there any sense in compressing the outwritten pages?
- Support for power.conf file as in Solaris, autoshutdown, special
devicetypes support, maybe in sysctl.
- Introduce timeout for SMP locking. But first locking ought to work :O
- Pre-detect if we don't have enough swap space or free it instead of
calling panic.
- Support for adding/removing hardware while suspended?
- We should not free pages at the beginning so aggressively, most of them
go there anyway..
- If X is active while suspending then by resuming calling svgatextmode
corrupts the virtual console of X.. (Maybe this has been fixed AFAIK).
Any other idea you might have tell me!
Contacting the author
If you have any question or any patch that solves the above or detected
problems please contact me at seasons@falcon.sch.bme.hu. I might delay
answering, sorry about that.
...@@ -1446,6 +1446,14 @@ M: neilb@cse.unsw.edu.au ...@@ -1446,6 +1446,14 @@ M: neilb@cse.unsw.edu.au
L: linux-raid@vger.kernel.org L: linux-raid@vger.kernel.org
S: Maintained S: Maintained
SOFTWARE SUSPEND:
P: Gabor Kuti
M: seasons@falcon.sch.bme.hu
M: seasons@makosteszta.sote.hu
L: http://lister.fornax.hu/mailman/listinfo/swsusp
W: http://falcon.sch.bme.hu/~seasons/linux
S: Maintained
SONIC NETWORK DRIVER SONIC NETWORK DRIVER
P: Thomas Bogendoerfer P: Thomas Bogendoerfer
M: tsbogend@alpha.franken.de M: tsbogend@alpha.franken.de
......
...@@ -940,3 +940,28 @@ CONFIG_DEBUG_BUGVERBOSE ...@@ -940,3 +940,28 @@ CONFIG_DEBUG_BUGVERBOSE
CONFIG_DEBUG_OBSOLETE CONFIG_DEBUG_OBSOLETE
Say Y here if you want to reduce the chances of the tree compiling, Say Y here if you want to reduce the chances of the tree compiling,
and are prepared to dig into driver internals to fix compile errors. and are prepared to dig into driver internals to fix compile errors.
Software Suspend
CONFIG_SOFTWARE_SUSPEND
Enable the possibilty of suspendig machine. It doesn't need APM.
You may suspend your machine by either pressing Sysrq-d or with
'swsusp' or 'shutdown -z <time>' (patch for sysvinit needed). It
creates an image which is saved in your active swaps. By the next
booting the kernel detects the saved image, restores the memory from
it and then it continues to run as before you've suspended.
If you don't want the previous state to continue use the 'noresume'
kernel option. However note that your partitions will be fsck'd and
you must re-mkswap your swap partitions/files.
Right now you may boot without resuming and then later resume but
in meantime you cannot use those swap partitions/files which were
involved in suspending. Also in this case there is a risk that buffers
on disk won't match with saved ones.
SMP is supported ``as-is''. There's a code for it but doesn't work.
There have been problems reported relating SCSI.
This option is about getting stable. However there is still some
absence of features.
For more information take a look at Documentation/swsusp.txt.
...@@ -438,6 +438,7 @@ setalias: ...@@ -438,6 +438,7 @@ setalias:
# Setting of user mode (AX=mode ID) => CF=success # Setting of user mode (AX=mode ID) => CF=success
mode_set: mode_set:
movw %ax, %fs:(0x01fa) # Store mode for use in acpi_wakeup.S
movw %ax, %bx movw %ax, %bx
cmpb $0xff, %ah cmpb $0xff, %ah
jz setalias jz setalias
......
...@@ -396,6 +396,9 @@ source net/bluetooth/Config.in ...@@ -396,6 +396,9 @@ source net/bluetooth/Config.in
mainmenu_option next_comment mainmenu_option next_comment
comment 'Kernel hacking' comment 'Kernel hacking'
if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
dep_bool 'Software Suspend' CONFIG_SOFTWARE_SUSPEND $CONFIG_PM
fi
bool 'Kernel debugging' CONFIG_DEBUG_KERNEL bool 'Kernel debugging' CONFIG_DEBUG_KERNEL
if [ "$CONFIG_DEBUG_KERNEL" != "n" ]; then if [ "$CONFIG_DEBUG_KERNEL" != "n" ]; then
......
...@@ -119,6 +119,7 @@ CONFIG_BINFMT_ELF=y ...@@ -119,6 +119,7 @@ CONFIG_BINFMT_ELF=y
CONFIG_BINFMT_MISC=y CONFIG_BINFMT_MISC=y
CONFIG_PM=y CONFIG_PM=y
# CONFIG_APM is not set # CONFIG_APM is not set
# CONFIG_SOFTWARE_SUSPEND is not set
# #
# Memory Technology Devices (MTD) # Memory Technology Devices (MTD)
......
...@@ -44,6 +44,8 @@ ...@@ -44,6 +44,8 @@
#include <asm/pgalloc.h> #include <asm/pgalloc.h>
#include <asm/io_apic.h> #include <asm/io_apic.h>
#include <asm/tlbflush.h> #include <asm/tlbflush.h>
#define ACPI_C
#include <asm/suspend.h>
#define PREFIX "ACPI: " #define PREFIX "ACPI: "
...@@ -623,5 +625,33 @@ void __init acpi_reserve_bootmem(void) ...@@ -623,5 +625,33 @@ void __init acpi_reserve_bootmem(void)
printk(KERN_DEBUG "ACPI: have wakeup address 0x%8.8lx\n", acpi_wakeup_address); printk(KERN_DEBUG "ACPI: have wakeup address 0x%8.8lx\n", acpi_wakeup_address);
} }
/*
* (KG): Since we affect stack here, we make this function as flat and easy
* as possible in order to not provoke gcc to use local variables on the stack.
* Note that on resume, all (expect nosave) variables will have the state from
* the time of writing (suspend_save_image) and the registers (including the
* stack pointer, but excluding the instruction pointer) will be loaded with
* the values saved at save_processor_context() time.
*/
void do_suspend_magic(int resume)
{
/* DANGER WILL ROBINSON!
*
* If this function is too difficult for gcc to optimize, it will crash and burn!
* see above.
*
* DO NOT TOUCH.
*/
if (!resume) {
save_processor_context();
acpi_save_register_state((unsigned long)&&acpi_sleep_done);
acpi_enter_sleep_state(3);
return;
}
acpi_sleep_done:
restore_processor_context();
printk("CPU context restored...\n");
}
#endif /*CONFIG_ACPI_SLEEP*/ #endif /*CONFIG_ACPI_SLEEP*/
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <linux/linkage.h> #include <linux/linkage.h>
#include <asm/segment.h> #include <asm/segment.h>
# Do we need to deal with A20?
ALIGN ALIGN
wakeup_start: wakeup_start:
...@@ -10,8 +11,16 @@ wakeup_code: ...@@ -10,8 +11,16 @@ wakeup_code:
wakeup_code_start = . wakeup_code_start = .
.code16 .code16
movw $0xb800, %ax
movw %ax,%fs
movw $0x0e00 + 'L', %fs:(0x10)
cli cli
cld cld
# setup video mode
# movw $0x4117, %bx # 0x4000 for linear framebuffer
# movw $0x4f02, %ax
# int $0x10
# setup data segment # setup data segment
movw %cs, %ax movw %cs, %ax
...@@ -20,6 +29,14 @@ wakeup_code: ...@@ -20,6 +29,14 @@ wakeup_code:
movw %ax, %ds movw %ax, %ds
movw %ax, %ss movw %ax, %ss
mov $(wakeup_stack - wakeup_data), %sp # Private stack is needed for ASUS board mov $(wakeup_stack - wakeup_data), %sp # Private stack is needed for ASUS board
movw $0x0e00 + 'S', %fs:(0x12)
movl real_magic - wakeup_data, %eax
cmpl $0x12345678, %eax
jne bogus_real_magic
mov video_mode - wakeup_data, %ax
call mode_set
# set up page table # set up page table
movl (real_save_cr3 - wakeup_data), %eax movl (real_save_cr3 - wakeup_data), %eax
...@@ -28,40 +45,114 @@ wakeup_code: ...@@ -28,40 +45,114 @@ wakeup_code:
# make sure %cr4 is set correctly (features, etc) # make sure %cr4 is set correctly (features, etc)
movl (real_save_cr4 - wakeup_data), %eax movl (real_save_cr4 - wakeup_data), %eax
movl %eax, %cr4 movl %eax, %cr4
movw $0xb800, %ax
movw %ax,%fs
movw $0x0e00 + 'i', %fs:(0x12)
# need a gdt # need a gdt
lgdt real_save_gdt - wakeup_data lgdt real_save_gdt - wakeup_data
movl %cr0, %eax movl (real_save_cr0 - wakeup_data), %eax
orl $0x80000001, %eax
movl %eax, %cr0 movl %eax, %cr0
movw $0x0e00 + 'n', %fs:(0x14)
movl real_magic - wakeup_data, %eax
cmpl $0x12345678, %eax
jne bogus_real_magic
ljmpl $__KERNEL_CS,$wakeup_pmode_return ljmpl $__KERNEL_CS,$wakeup_pmode_return
bogus_real_magic:
movw $0x0e00 + 'B', %fs:(0x12)
jmp bogus_real_magic
/* This code uses an extended set of video mode numbers. These include:
* Aliases for standard modes
* NORMAL_VGA (-1)
* EXTENDED_VGA (-2)
* ASK_VGA (-3)
* Video modes numbered by menu position -- NOT RECOMMENDED because of lack
* of compatibility when extending the table. These are between 0x00 and 0xff.
*/
#define VIDEO_FIRST_MENU 0x0000
/* Standard BIOS video modes (BIOS number + 0x0100) */
#define VIDEO_FIRST_BIOS 0x0100
/* VESA BIOS video modes (VESA number + 0x0200) */
#define VIDEO_FIRST_VESA 0x0200
/* Video7 special modes (BIOS number + 0x0900) */
#define VIDEO_FIRST_V7 0x0900
# Setting of user mode (AX=mode ID) => CF=success
mode_set:
movw %ax, %bx
#if 0
cmpb $0xff, %ah
jz setalias
testb $VIDEO_RECALC>>8, %ah
jnz _setrec
cmpb $VIDEO_FIRST_RESOLUTION>>8, %ah
jnc setres
cmpb $VIDEO_FIRST_SPECIAL>>8, %ah
jz setspc
cmpb $VIDEO_FIRST_V7>>8, %ah
jz setv7
#endif
cmpb $VIDEO_FIRST_VESA>>8, %ah
jnc check_vesa
#if 0
orb %ah, %ah
jz setmenu
#endif
decb %ah
# jz setbios Add bios modes later
setbad: clc
ret
check_vesa:
subb $VIDEO_FIRST_VESA>>8, %bh
orw $0x4000, %bx # Use linear frame buffer
movw $0x4f02, %ax # VESA BIOS mode set call
int $0x10
cmpw $0x004f, %ax # AL=4f if implemented
jnz _setbad # AH=0 if OK
stc
ret
_setbad: jmp setbad
.code32 .code32
ALIGN ALIGN
.org 0x100 .org 0x300
wakeup_data: wakeup_data:
.word 0 .word 0
real_save_gdt: .word 0 real_save_gdt: .word 0
.long 0 .long 0
real_save_cr0: .long 0
real_save_cr3: .long 0 real_save_cr3: .long 0
real_save_cr4: .long 0 real_save_cr4: .long 0
real_magic: .long 0
video_mode: .long 0
.org 0x300 .org 0x500
wakeup_stack: wakeup_stack:
wakeup_end: wakeup_end:
wakeup_pmode_return: wakeup_pmode_return:
# restore data segment
movl $__KERNEL_DS, %eax movl $__KERNEL_DS, %eax
movw %ax, %ds movl %eax, %ds
movw %ax, %es movw $0x0e00 + 'u', %ds:(0xb8016)
# and restore the stack
movw %ax, %ss
movl saved_esp, %esp
# restore other segment registers # restore other segment registers
xorl %eax, %eax xorl %eax, %eax
...@@ -72,6 +163,30 @@ wakeup_pmode_return: ...@@ -72,6 +163,30 @@ wakeup_pmode_return:
lgdt saved_gdt lgdt saved_gdt
lidt saved_idt lidt saved_idt
lldt saved_ldt lldt saved_ldt
ljmp $(__KERNEL_CS),$1f
1:
movl %cr3, %eax
movl %eax, %cr3
wbinvd
# and restore the stack ... but you need gdt for this to work
movl $__KERNEL_DS, %eax
movw %ax, %ss
movw %ax, %ds
movw %ax, %es
movw %ax, %fs
movw %ax, %gs
movl saved_esp, %esp
movw $0x0e00 + 'W', %ds:(0xb8018)
movl $(1024*1024*3), %ecx
movl $0, %esi
rep lodsb
movw $0x0e00 + 'O', %ds:(0xb8018)
movl %cs:saved_magic2, %eax
cmpl $0x12345678, %eax
jne bogus_magic
# restore the other general registers # restore the other general registers
movl saved_ebx, %ebx movl saved_ebx, %ebx
...@@ -81,8 +196,21 @@ wakeup_pmode_return: ...@@ -81,8 +196,21 @@ wakeup_pmode_return:
# jump to place where we left off # jump to place where we left off
movl saved_eip,%eax movl saved_eip,%eax
movw $0x0e00 + 'x', %ds:(0xb8018)
pushl %eax
popl %eax
movw $0x0e00 + '!', %ds:(0xb801a)
jmp *%eax jmp *%eax
bogus_magic:
movw $0x0e00 + 'B', %ds:(0xb8018)
jmp bogus_magic
bogus_magic2:
movw $0x0e00 + '2', %ds:(0xb8018)
jmp bogus_magic2
## ##
# acpi_copy_wakeup_routine # acpi_copy_wakeup_routine
# #
...@@ -113,23 +241,22 @@ ENTRY(acpi_copy_wakeup_routine) ...@@ -113,23 +241,22 @@ ENTRY(acpi_copy_wakeup_routine)
movl %edx, real_save_cr3 - wakeup_start (%eax) movl %edx, real_save_cr3 - wakeup_start (%eax)
movl %cr4, %edx movl %cr4, %edx
movl %edx, real_save_cr4 - wakeup_start (%eax) movl %edx, real_save_cr4 - wakeup_start (%eax)
movl %cr0, %edx
movl %edx, real_save_cr0 - wakeup_start (%eax)
sgdt real_save_gdt - wakeup_start (%eax) sgdt real_save_gdt - wakeup_start (%eax)
movl saved_videomode, %edx
movl %edx, video_mode - wakeup_start (%eax)
movl $0x12345678, real_magic - wakeup_start (%eax)
movl $0x12345678, saved_magic2
# restore the regs we used # restore the regs we used
popl %edi popl %edi
popl %esi popl %esi
ret ret
.data .data
ALIGN ALIGN
# saved registers
saved_gdt: .long 0,0
saved_idt: .long 0,0
saved_ldt: .long 0
saved_tss: .long 0
saved_cr0: .long 0
ENTRY(saved_ebp) .long 0 ENTRY(saved_ebp) .long 0
ENTRY(saved_esi) .long 0 ENTRY(saved_esi) .long 0
ENTRY(saved_edi) .long 0 ENTRY(saved_edi) .long 0
...@@ -137,3 +264,16 @@ ENTRY(saved_ebx) .long 0 ...@@ -137,3 +264,16 @@ ENTRY(saved_ebx) .long 0
ENTRY(saved_eip) .long 0 ENTRY(saved_eip) .long 0
ENTRY(saved_esp) .long 0 ENTRY(saved_esp) .long 0
ENTRY(saved_magic) .long 0
ENTRY(saved_magic2) .long 0
ENTRY(saved_videomode) .long 0
ALIGN
# saved registers
saved_gdt: .long 0,0
saved_idt: .long 0,0
saved_ldt: .long 0
saved_tss: .long 0
saved_cr0: .long 0
...@@ -1667,6 +1667,7 @@ static int apm(void *unused) ...@@ -1667,6 +1667,7 @@ static int apm(void *unused)
daemonize(); daemonize();
strcpy(current->comm, "kapmd"); strcpy(current->comm, "kapmd");
current->flags |= PF_IOTHREAD;
sigfillset(&current->blocked); sigfillset(&current->blocked);
if (apm_info.connection_version == 0) { if (apm_info.connection_version == 0) {
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/kernel_stat.h> #include <linux/kernel_stat.h>
#include <linux/device.h>
#include <asm/atomic.h> #include <asm/atomic.h>
#include <asm/system.h> #include <asm/system.h>
...@@ -237,7 +238,19 @@ void mask_and_ack_8259A(unsigned int irq) ...@@ -237,7 +238,19 @@ void mask_and_ack_8259A(unsigned int irq)
} }
} }
void __init init_8259A(int auto_eoi) static struct device device_i8259A = {
name: "i8259A",
bus_id: "0020",
};
static void __init init_8259A_devicefs(void)
{
register_sys_device(&device_i8259A);
}
__initcall(init_8259A_devicefs);
void init_8259A(int auto_eoi)
{ {
unsigned long flags; unsigned long flags;
......
...@@ -168,6 +168,8 @@ void __init visws_get_board_type_and_rev(void); ...@@ -168,6 +168,8 @@ void __init visws_get_board_type_and_rev(void);
static int disable_x86_serial_nr __initdata = 1; static int disable_x86_serial_nr __initdata = 1;
static int disable_x86_fxsr __initdata = 0; static int disable_x86_fxsr __initdata = 0;
extern unsigned long saved_videomode;
/* /*
* This is set up by the setup-routine at boot-time * This is set up by the setup-routine at boot-time
*/ */
...@@ -182,6 +184,7 @@ static int disable_x86_fxsr __initdata = 0; ...@@ -182,6 +184,7 @@ static int disable_x86_fxsr __initdata = 0;
#define SYS_DESC_TABLE (*(struct sys_desc_table_struct*)(PARAM+0xa0)) #define SYS_DESC_TABLE (*(struct sys_desc_table_struct*)(PARAM+0xa0))
#define MOUNT_ROOT_RDONLY (*(unsigned short *) (PARAM+0x1F2)) #define MOUNT_ROOT_RDONLY (*(unsigned short *) (PARAM+0x1F2))
#define RAMDISK_FLAGS (*(unsigned short *) (PARAM+0x1F8)) #define RAMDISK_FLAGS (*(unsigned short *) (PARAM+0x1F8))
#define VIDEO_MODE (*(unsigned short *) (PARAM+0x1FA))
#define ORIG_ROOT_DEV (*(unsigned short *) (PARAM+0x1FC)) #define ORIG_ROOT_DEV (*(unsigned short *) (PARAM+0x1FC))
#define AUX_DEVICE_INFO (*(unsigned char *) (PARAM+0x1FF)) #define AUX_DEVICE_INFO (*(unsigned char *) (PARAM+0x1FF))
#define LOADER_TYPE (*(unsigned char *) (PARAM+0x210)) #define LOADER_TYPE (*(unsigned char *) (PARAM+0x210))
...@@ -681,6 +684,8 @@ void __init setup_arch(char **cmdline_p) ...@@ -681,6 +684,8 @@ void __init setup_arch(char **cmdline_p)
drive_info = DRIVE_INFO; drive_info = DRIVE_INFO;
screen_info = SCREEN_INFO; screen_info = SCREEN_INFO;
apm_info.bios = APM_BIOS_INFO; apm_info.bios = APM_BIOS_INFO;
saved_videomode = VIDEO_MODE;
printk("Video mode to be used for restore is %lx\n", saved_videomode);
if( SYS_DESC_TABLE.length != 0 ) { if( SYS_DESC_TABLE.length != 0 ) {
MCA_bus = SYS_DESC_TABLE.table[3] &0x2; MCA_bus = SYS_DESC_TABLE.table[3] &0x2;
machine_id = SYS_DESC_TABLE.table[0]; machine_id = SYS_DESC_TABLE.table[0];
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <linux/tty.h> #include <linux/tty.h>
#include <linux/personality.h> #include <linux/personality.h>
#include <linux/binfmts.h> #include <linux/binfmts.h>
#include <linux/suspend.h>
#include <asm/ucontext.h> #include <asm/ucontext.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/i387.h> #include <asm/i387.h>
...@@ -594,6 +595,11 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset) ...@@ -594,6 +595,11 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset)
if ((regs->xcs & 3) != 3) if ((regs->xcs & 3) != 3)
return 1; return 1;
if (current->flags & PF_FREEZE) {
refrigerator(0);
goto no_signal;
}
if (!oldset) if (!oldset)
oldset = &current->blocked; oldset = &current->blocked;
...@@ -701,6 +707,7 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset) ...@@ -701,6 +707,7 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset)
return 1; return 1;
} }
no_signal:
/* Did we come from a system call? */ /* Did we come from a system call? */
if (regs->orig_eax >= 0) { if (regs->orig_eax >= 0) {
/* Restart the system call - no handlers present */ /* Restart the system call - no handlers present */
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/smp.h> #include <linux/smp.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/device.h>
#include <asm/io.h> #include <asm/io.h>
#include <asm/smp.h> #include <asm/smp.h>
...@@ -636,6 +637,17 @@ static unsigned long __init calibrate_tsc(void) ...@@ -636,6 +637,17 @@ static unsigned long __init calibrate_tsc(void)
return 0; return 0;
} }
static struct device device_i8253;
static void time_init_driverfs(void)
{
strcpy(device_i8253.name, "i8253");
strcpy(device_i8253.bus_id, "0040");
register_sys_device(&device_i8253);
}
__initcall(time_init_driverfs);
void __init time_init(void) void __init time_init(void)
{ {
extern int x86_udelay_tsc; extern int x86_udelay_tsc;
......
...@@ -65,6 +65,12 @@ SECTIONS ...@@ -65,6 +65,12 @@ SECTIONS
. = ALIGN(4096); . = ALIGN(4096);
__init_end = .; __init_end = .;
. = ALIGN(4096);
__nosave_begin = .;
.data_nosave : { *(.data.nosave) }
. = ALIGN(4096);
__nosave_end = .;
. = ALIGN(4096); . = ALIGN(4096);
.data.page_aligned : { *(.data.idt) } .data.page_aligned : { *(.data.idt) }
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/sysrq.h> #include <linux/sysrq.h>
#include <linux/pm.h> #include <linux/pm.h>
#include <linux/device.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/acpi.h> #include <asm/acpi.h>
#include "acpi_bus.h" #include "acpi_bus.h"
...@@ -128,6 +129,12 @@ acpi_system_restore_state ( ...@@ -128,6 +129,12 @@ acpi_system_restore_state (
/* restore device context */ /* restore device context */
device_resume(RESUME_RESTORE_STATE); device_resume(RESUME_RESTORE_STATE);
#endif #endif
if (dmi_broken & BROKEN_INIT_AFTER_S1) {
printk("Broken toshiba laptop -> kicking interrupts\n");
init_8259A(0);
}
return AE_OK; return AE_OK;
} }
...@@ -254,23 +261,21 @@ acpi_system_suspend( ...@@ -254,23 +261,21 @@ acpi_system_suspend(
switch (state) switch (state)
{ {
case ACPI_STATE_S1: case ACPI_STATE_S1:
/* do nothing */ barrier();
status = acpi_enter_sleep_state(state);
break; break;
case ACPI_STATE_S2: case ACPI_STATE_S2:
case ACPI_STATE_S3: case ACPI_STATE_S3:
acpi_save_register_state((unsigned long)&&acpi_sleep_done); do_suspend_magic(0);
break; break;
} }
barrier(); printk("acpi_restore_register_state...");
status = acpi_enter_sleep_state(state);
acpi_sleep_done:
acpi_restore_register_state(); acpi_restore_register_state();
restore_flags(flags); restore_flags(flags);
printk("acpi returning...");
return status; return status;
} }
...@@ -290,6 +295,8 @@ acpi_suspend ( ...@@ -290,6 +295,8 @@ acpi_suspend (
if (state < ACPI_STATE_S1 || state > ACPI_STATE_S5) if (state < ACPI_STATE_S1 || state > ACPI_STATE_S5)
return AE_ERROR; return AE_ERROR;
freeze_processes();
/* do we have a wakeup address for S2 and S3? */ /* do we have a wakeup address for S2 and S3? */
if (state == ACPI_STATE_S2 || state == ACPI_STATE_S3) { if (state == ACPI_STATE_S2 || state == ACPI_STATE_S3) {
if (!acpi_wakeup_address) if (!acpi_wakeup_address)
...@@ -315,7 +322,9 @@ acpi_suspend ( ...@@ -315,7 +322,9 @@ acpi_suspend (
* no matter what. * no matter what.
*/ */
acpi_system_restore_state(state); acpi_system_restore_state(state);
printk("acpi_leave_sleep_state...");
acpi_leave_sleep_state(state); acpi_leave_sleep_state(state);
printk("ook\n");
/* make sure interrupts are enabled */ /* make sure interrupts are enabled */
ACPI_ENABLE_IRQS(); ACPI_ENABLE_IRQS();
...@@ -323,6 +332,8 @@ acpi_suspend ( ...@@ -323,6 +332,8 @@ acpi_suspend (
/* reset firmware waking vector */ /* reset firmware waking vector */
acpi_set_firmware_waking_vector((ACPI_PHYSICAL_ADDRESS) 0); acpi_set_firmware_waking_vector((ACPI_PHYSICAL_ADDRESS) 0);
thaw_processes();
return status; return status;
} }
...@@ -700,8 +711,17 @@ acpi_system_write_sleep ( ...@@ -700,8 +711,17 @@ acpi_system_write_sleep (
if (!system->states[state]) if (!system->states[state])
return_VALUE(-ENODEV); return_VALUE(-ENODEV);
#ifdef CONFIG_SOFTWARE_SUSPEND
if (state == 4) {
/* We are working from process context, that's why we may call it directly. */
do_software_suspend();
return_VALUE(count);
}
#endif
status = acpi_suspend(state); status = acpi_suspend(state);
if (ACPI_FAILURE(status)) if (ACPI_FAILURE(status))
return_VALUE(-ENODEV); return_VALUE(-ENODEV);
...@@ -1180,6 +1200,10 @@ acpi_system_add ( ...@@ -1180,6 +1200,10 @@ acpi_system_add (
} }
} }
printk(")\n"); printk(")\n");
#ifdef CONFIG_SOFTWARE_SUSPEND
printk(KERN_INFO "Software suspend => we can do S4.");
system->states[4] = 1;
#endif
#ifdef CONFIG_PM #ifdef CONFIG_PM
/* Install the soft-off (S5) handler. */ /* Install the soft-off (S5) handler. */
......
...@@ -173,6 +173,7 @@ static int print_unex=1; ...@@ -173,6 +173,7 @@ static int print_unex=1;
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/devfs_fs_kernel.h> #include <linux/devfs_fs_kernel.h>
#include <linux/device.h>
/* /*
* PS/2 floppies have much slower step rates than regular floppies. * PS/2 floppies have much slower step rates than regular floppies.
...@@ -4178,11 +4179,15 @@ static int __init floppy_setup(char *str) ...@@ -4178,11 +4179,15 @@ static int __init floppy_setup(char *str)
static int have_no_fdc= -ENODEV; static int have_no_fdc= -ENODEV;
static struct device device_floppy;
int __init floppy_init(void) int __init floppy_init(void)
{ {
int i,unit,drive; int i,unit,drive;
strcpy(device_floppy.name, "floppy");
strcpy(device_floppy.bus_id, "03?0");
register_sys_device(&device_floppy);
raw_cmd = NULL; raw_cmd = NULL;
......
...@@ -1418,7 +1418,9 @@ static int __make_request(request_queue_t *q, struct bio *bio) ...@@ -1418,7 +1418,9 @@ static int __make_request(request_queue_t *q, struct bio *bio)
req->buffer = bio_data(bio); /* see ->buffer comment above */ req->buffer = bio_data(bio); /* see ->buffer comment above */
req->waiting = NULL; req->waiting = NULL;
req->bio = req->biotail = bio; req->bio = req->biotail = bio;
req->rq_dev = to_kdev_t(bio->bi_bdev->bd_dev); if (bio->bi_bdev)
req->rq_dev = to_kdev_t(bio->bi_bdev->bd_dev);
else req->rq_dev = NODEV;
add_request(q, req, insert_here); add_request(q, req, insert_here);
out: out:
if (freereq) if (freereq)
......
...@@ -71,11 +71,11 @@ ...@@ -71,11 +71,11 @@
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/swap.h> #include <linux/swap.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/loop.h>
#include <linux/suspend.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <linux/loop.h>
#define MAJOR_NR LOOP_MAJOR #define MAJOR_NR LOOP_MAJOR
static int max_loop = 8; static int max_loop = 8;
...@@ -534,6 +534,7 @@ static int loop_thread(void *data) ...@@ -534,6 +534,7 @@ static int loop_thread(void *data)
daemonize(); daemonize();
sprintf(current->comm, "loop%d", lo->lo_number); sprintf(current->comm, "loop%d", lo->lo_number);
current->flags |= PF_IOTHREAD;
spin_lock_irq(&current->sigmask_lock); spin_lock_irq(&current->sigmask_lock);
sigfillset(&current->blocked); sigfillset(&current->blocked);
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <linux/quotaops.h> #include <linux/quotaops.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/suspend.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
...@@ -317,6 +318,22 @@ static struct sysrq_key_op sysrq_kill_op = { ...@@ -317,6 +318,22 @@ static struct sysrq_key_op sysrq_kill_op = {
action_msg: "Kill All Tasks", action_msg: "Kill All Tasks",
}; };
#ifdef CONFIG_SOFTWARE_SUSPEND
static void sysrq_handle_swsusp(int key, struct pt_regs *pt_regs,
struct kbd_struct *kbd, struct tty_struct *tty) {
if(!software_suspend_enabled) {
printk("Software Suspend is not possible now\n");
return;
}
software_suspend();
}
static struct sysrq_key_op sysrq_swsusp_op = {
handler: sysrq_handle_swsusp,
help_msg: "suspenD",
action_msg: "Software suspend\n",
};
#endif
/* END SIGNAL SYSRQ HANDLERS BLOCK */ /* END SIGNAL SYSRQ HANDLERS BLOCK */
...@@ -339,7 +356,11 @@ static struct sysrq_key_op *sysrq_key_table[SYSRQ_KEY_TABLE_LENGTH] = { ...@@ -339,7 +356,11 @@ static struct sysrq_key_op *sysrq_key_table[SYSRQ_KEY_TABLE_LENGTH] = {
and will never arive */ and will never arive */
/* b */ &sysrq_reboot_op, /* b */ &sysrq_reboot_op,
/* c */ NULL, /* c */ NULL,
#ifdef CONFIG_SOFTWARE_SUSPEND
/* d */ &sysrq_swsusp_op,
#else
/* d */ NULL, /* d */ NULL,
#endif
/* e */ &sysrq_term_op, /* e */ &sysrq_term_op,
/* f */ NULL, /* f */ NULL,
/* g */ NULL, /* g */ NULL,
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/ide.h> #include <linux/ide.h>
#include <linux/suspend.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
#include <asm/irq.h> #include <asm/irq.h>
...@@ -562,6 +563,8 @@ static int idedisk_suspend(struct device *dev, u32 state, u32 level) ...@@ -562,6 +563,8 @@ static int idedisk_suspend(struct device *dev, u32 state, u32 level)
* already been done... * already been done...
*/ */
BUG_ON(in_interrupt());
if (level != SUSPEND_SAVE_STATE) if (level != SUSPEND_SAVE_STATE)
return 0; return 0;
......
...@@ -110,7 +110,7 @@ static int pci_pm_save_state(u32 state) ...@@ -110,7 +110,7 @@ static int pci_pm_save_state(u32 state)
return error; return error;
} }
static int pci_pm_suspend(u32 state) int pci_pm_suspend(u32 state)
{ {
struct list_head *list; struct list_head *list;
struct pci_bus *bus; struct pci_bus *bus;
...@@ -123,7 +123,7 @@ static int pci_pm_suspend(u32 state) ...@@ -123,7 +123,7 @@ static int pci_pm_suspend(u32 state)
return 0; return 0;
} }
static int pci_pm_resume(void) int pci_pm_resume(void)
{ {
struct list_head *list; struct list_head *list;
struct pci_bus *bus; struct pci_bus *bus;
......
...@@ -323,6 +323,7 @@ static int usb_stor_control_thread(void * __us) ...@@ -323,6 +323,7 @@ static int usb_stor_control_thread(void * __us)
/* avoid getting signals */ /* avoid getting signals */
spin_lock_irq(&current->sigmask_lock); spin_lock_irq(&current->sigmask_lock);
flush_signals(current); flush_signals(current);
current->flags |= PF_IOTHREAD;
sigfillset(&current->blocked); sigfillset(&current->blocked);
recalc_sigpending(); recalc_sigpending();
spin_unlock_irq(&current->sigmask_lock); spin_unlock_irq(&current->sigmask_lock);
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <linux/writeback.h> #include <linux/writeback.h>
#include <linux/mempool.h> #include <linux/mempool.h>
#include <linux/hash.h> #include <linux/hash.h>
#include <linux/suspend.h>
#include <asm/bitops.h> #include <asm/bitops.h>
#define BH_ENTRY(list) list_entry((list), struct buffer_head, b_assoc_buffers) #define BH_ENTRY(list) list_entry((list), struct buffer_head, b_assoc_buffers)
...@@ -120,6 +121,8 @@ void unlock_buffer(struct buffer_head *bh) ...@@ -120,6 +121,8 @@ void unlock_buffer(struct buffer_head *bh)
wake_up_buffer(bh); wake_up_buffer(bh);
} }
DECLARE_TASK_QUEUE(tq_bdflush);
/* /*
* Block until a buffer comes unlocked. This doesn't stop it * Block until a buffer comes unlocked. This doesn't stop it
* from becoming locked again - you have to lock it yourself * from becoming locked again - you have to lock it yourself
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/suspend.h>
#include <linux/pagemap.h> #include <linux/pagemap.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
...@@ -225,6 +226,7 @@ int kjournald(void *arg) ...@@ -225,6 +226,7 @@ int kjournald(void *arg)
journal->j_commit_interval / HZ); journal->j_commit_interval / HZ);
list_add(&journal->j_all_journals, &all_journals); list_add(&journal->j_all_journals, &all_journals);
current->flags |= PF_KERNTHREAD;
/* And now, wait forever for commit wakeup events. */ /* And now, wait forever for commit wakeup events. */
while (1) { while (1) {
if (journal->j_flags & JFS_UNMOUNT) if (journal->j_flags & JFS_UNMOUNT)
...@@ -245,7 +247,15 @@ int kjournald(void *arg) ...@@ -245,7 +247,15 @@ int kjournald(void *arg)
} }
wake_up(&journal->j_wait_done_commit); wake_up(&journal->j_wait_done_commit);
interruptible_sleep_on(&journal->j_wait_commit); if (current->flags & PF_FREEZE) { /* The simpler the better. Flushing journal isn't a
good idea, because that depends on threads that
may be already stopped. */
jbd_debug(1, "Now suspending kjournald\n");
refrigerator(PF_IOTHREAD);
jbd_debug(1, "Resuming kjournald\n");
} else /* we assume on resume that commits are already there,
so we don't sleep */
interruptible_sleep_on(&journal->j_wait_commit);
jbd_debug(1, "kjournald wakes\n"); jbd_debug(1, "kjournald wakes\n");
......
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
#include <linux/stat.h> #include <linux/stat.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/suspend.h>
/* the number of mounted filesystems. This is used to decide when to /* the number of mounted filesystems. This is used to decide when to
** start and kill the commit thread ** start and kill the commit thread
...@@ -1886,6 +1887,7 @@ static int reiserfs_journal_commit_thread(void *nullp) { ...@@ -1886,6 +1887,7 @@ static int reiserfs_journal_commit_thread(void *nullp) {
spin_unlock_irq(&current->sigmask_lock); spin_unlock_irq(&current->sigmask_lock);
sprintf(current->comm, "kreiserfsd") ; sprintf(current->comm, "kreiserfsd") ;
current->flags |= PF_KERNTHREAD;
lock_kernel() ; lock_kernel() ;
while(1) { while(1) {
...@@ -1899,7 +1901,12 @@ static int reiserfs_journal_commit_thread(void *nullp) { ...@@ -1899,7 +1901,12 @@ static int reiserfs_journal_commit_thread(void *nullp) {
break ; break ;
} }
wake_up(&reiserfs_commit_thread_done) ; wake_up(&reiserfs_commit_thread_done) ;
interruptible_sleep_on_timeout(&reiserfs_commit_thread_wait, 5 * HZ) ; #ifdef CONFIG_SOFTWARE_SUSPEND
if (current->flags & PF_FREEZE) {
refrigerator(PF_IOTHREAD);
} else
#endif
interruptible_sleep_on_timeout(&reiserfs_commit_thread_wait, 5 * HZ) ;
} }
unlock_kernel() ; unlock_kernel() ;
wake_up(&reiserfs_commit_thread_done) ; wake_up(&reiserfs_commit_thread_done) ;
......
...@@ -51,6 +51,12 @@ extern __inline__ int test_bit(int nr, long * addr) ...@@ -51,6 +51,12 @@ extern __inline__ int test_bit(int nr, long * addr)
return ((mask & *addr) != 0); return ((mask & *addr) != 0);
} }
/*
* fls: find last bit set.
*/
#define fls(x) generic_fls(x)
#ifdef __KERNEL__ #ifdef __KERNEL__
/* /*
......
...@@ -414,6 +414,12 @@ static __inline__ unsigned long __ffs(unsigned long word) ...@@ -414,6 +414,12 @@ static __inline__ unsigned long __ffs(unsigned long word)
return word; return word;
} }
/*
* fls: find last bit set.
*/
#define fls(x) generic_fls(x)
#ifdef __KERNEL__ #ifdef __KERNEL__
/* /*
......
#ifndef __ASM_I386_SUSPEND_H
#define __ASM_I386_SUSPEND_H
#endif
/*
* Copyright 2001-2002 Pavel Machek <pavel@suse.cz>
* Based on code
* Copyright 2001 Patrick Mochel <mochel@osdl.org>
*/
#if defined(SUSPEND_C) || defined(ACPI_C)
#include <asm/desc.h>
#include <asm/i387.h>
static inline void
arch_prepare_suspend(void)
{
if (!cpu_has_pse)
panic("pse required");
}
/* image of the saved processor state */
struct saved_context {
u32 eax, ebx, ecx, edx;
u32 esp, ebp, esi, edi;
u16 es, fs, gs, ss;
u32 cr0, cr2, cr3, cr4;
u16 gdt_pad;
u16 gdt_limit;
u32 gdt_base;
u16 idt_pad;
u16 idt_limit;
u32 idt_base;
u16 ldt;
u16 tss;
u32 tr;
u32 safety;
u32 return_address;
u32 eflags;
} __attribute__((packed));
static struct saved_context saved_context;
#define loaddebug(thread,register) \
__asm__("movl %0,%%db" #register \
: /* no output */ \
:"r" ((thread)->debugreg[register]))
/*
* save_processor_context
*
* Save the state of the processor before we go to sleep.
*
* return_stack is the value of the stack pointer (%esp) as the caller sees it.
* A good way could not be found to obtain it from here (don't want to make _too_
* many assumptions about the layout of the stack this far down.) Also, the
* handy little __builtin_frame_pointer(level) where level > 0, is blatantly
* buggy - it returns the value of the stack at the proper location, not the
* location, like it should (as of gcc 2.91.66)
*
* Note that the context and timing of this function is pretty critical.
* With a minimal amount of things going on in the caller and in here, gcc
* does a good job of being just a dumb compiler. Watch the assembly output
* if anything changes, though, and make sure everything is going in the right
* place.
*/
static inline void save_processor_context (void)
{
kernel_fpu_begin();
/*
* descriptor tables
*/
asm volatile ("sgdt (%0)" : "=m" (saved_context.gdt_limit));
asm volatile ("sidt (%0)" : "=m" (saved_context.idt_limit));
asm volatile ("sldt (%0)" : "=m" (saved_context.ldt));
asm volatile ("str (%0)" : "=m" (saved_context.tr));
/*
* save the general registers.
* note that gcc has constructs to specify output of certain registers,
* but they're not used here, because it assumes that you want to modify
* those registers, so it tries to be smart and save them beforehand.
* It's really not necessary, and kinda fishy (check the assembly output),
* so it's avoided.
*/
asm volatile ("movl %%esp, (%0)" : "=m" (saved_context.esp));
asm volatile ("movl %%eax, (%0)" : "=m" (saved_context.eax));
asm volatile ("movl %%ebx, (%0)" : "=m" (saved_context.ebx));
asm volatile ("movl %%ecx, (%0)" : "=m" (saved_context.ecx));
asm volatile ("movl %%edx, (%0)" : "=m" (saved_context.edx));
asm volatile ("movl %%ebp, (%0)" : "=m" (saved_context.ebp));
asm volatile ("movl %%esi, (%0)" : "=m" (saved_context.esi));
asm volatile ("movl %%edi, (%0)" : "=m" (saved_context.edi));
/*
* segment registers
*/
asm volatile ("movw %%es, %0" : "=r" (saved_context.es));
asm volatile ("movw %%fs, %0" : "=r" (saved_context.fs));
asm volatile ("movw %%gs, %0" : "=r" (saved_context.gs));
asm volatile ("movw %%ss, %0" : "=r" (saved_context.ss));
/*
* control registers
*/
asm volatile ("movl %%cr0, %0" : "=r" (saved_context.cr0));
asm volatile ("movl %%cr2, %0" : "=r" (saved_context.cr2));
asm volatile ("movl %%cr3, %0" : "=r" (saved_context.cr3));
asm volatile ("movl %%cr4, %0" : "=r" (saved_context.cr4));
/*
* eflags
*/
asm volatile ("pushfl ; popl (%0)" : "=m" (saved_context.eflags));
}
static void fix_processor_context(void)
{
int nr = smp_processor_id();
struct tss_struct * t = &init_tss[nr];
set_tss_desc(nr,t); /* This just modifies memory; should not be neccessary. But... This is neccessary, because 386 hardware has concept of busy tsc or some similar stupidity. */
gdt_table[__TSS(nr)].b &= 0xfffffdff;
load_TR(nr); /* This does ltr */
load_LDT(&current->mm->context); /* This does lldt */
/*
* Now maybe reload the debug registers
*/
if (current->thread.debugreg[7]){
loaddebug(&current->thread, 0);
loaddebug(&current->thread, 1);
loaddebug(&current->thread, 2);
loaddebug(&current->thread, 3);
/* no 4 and 5 */
loaddebug(&current->thread, 6);
loaddebug(&current->thread, 7);
}
}
static void
do_fpu_end(void)
{
/* restore FPU regs if necessary */
/* Do it out of line so that gcc does not move cr0 load to some stupid place */
kernel_fpu_end();
}
/*
* restore_processor_context
*
* Restore the processor context as it was before we went to sleep
* - descriptor tables
* - control registers
* - segment registers
* - flags
*
* Note that it is critical that this function is declared inline.
* It was separated out from restore_state to make that function
* a little clearer, but it needs to be inlined because we won't have a
* stack when we get here (so we can't push a return address).
*/
static inline void restore_processor_context (void)
{
/*
* first restore %ds, so we can access our data properly
*/
asm volatile (".align 4");
asm volatile ("movw %0, %%ds" :: "r" ((u16)__KERNEL_DS));
/*
* control registers
*/
asm volatile ("movl %0, %%cr4" :: "r" (saved_context.cr4));
asm volatile ("movl %0, %%cr3" :: "r" (saved_context.cr3));
asm volatile ("movl %0, %%cr2" :: "r" (saved_context.cr2));
asm volatile ("movl %0, %%cr0" :: "r" (saved_context.cr0));
/*
* segment registers
*/
asm volatile ("movw %0, %%es" :: "r" (saved_context.es));
asm volatile ("movw %0, %%fs" :: "r" (saved_context.fs));
asm volatile ("movw %0, %%gs" :: "r" (saved_context.gs));
asm volatile ("movw %0, %%ss" :: "r" (saved_context.ss));
/*
* the other general registers
*
* note that even though gcc has constructs to specify memory
* input into certain registers, it will try to be too smart
* and save them at the beginning of the function. This is esp.
* bad since we don't have a stack set up when we enter, and we
* want to preserve the values on exit. So, we set them manually.
*/
asm volatile ("movl %0, %%esp" :: "m" (saved_context.esp));
asm volatile ("movl %0, %%ebp" :: "m" (saved_context.ebp));
asm volatile ("movl %0, %%eax" :: "m" (saved_context.eax));
asm volatile ("movl %0, %%ebx" :: "m" (saved_context.ebx));
asm volatile ("movl %0, %%ecx" :: "m" (saved_context.ecx));
asm volatile ("movl %0, %%edx" :: "m" (saved_context.edx));
asm volatile ("movl %0, %%esi" :: "m" (saved_context.esi));
asm volatile ("movl %0, %%edi" :: "m" (saved_context.edi));
/*
* now restore the descriptor tables to their proper values
*/
asm volatile ("lgdt (%0)" :: "m" (saved_context.gdt_limit));
asm volatile ("lidt (%0)" :: "m" (saved_context.idt_limit));
asm volatile ("lldt (%0)" :: "m" (saved_context.ldt));
#if 0
asm volatile ("ltr (%0)" :: "m" (saved_context.tr));
#endif
fix_processor_context();
/*
* the flags
*/
asm volatile ("pushl %0 ; popfl" :: "m" (saved_context.eflags));
do_fpu_end();
}
#endif
#ifdef SUSPEND_C
#if 1
/* Local variables for do_magic */
static int loop __nosavedata = 0;
static int loop2 __nosavedata = 0;
/*
* (KG): Since we affect stack here, we make this function as flat and easy
* as possible in order to not provoke gcc to use local variables on the stack.
* Note that on resume, all (expect nosave) variables will have the state from
* the time of writing (suspend_save_image) and the registers (including the
* stack pointer, but excluding the instruction pointer) will be loaded with
* the values saved at save_processor_context() time.
*/
static void do_magic(int resume)
{
/* DANGER WILL ROBINSON!
*
* If this function is too difficult for gcc to optimize, it will crash and burn!
* see above.
*
* DO NOT TOUCH.
*/
if (!resume) {
do_magic_suspend_1();
save_processor_context(); /* We need to capture registers and memory at "same time" */
do_magic_suspend_2(); /* If everything goes okay, this function does not return */
return;
}
/* We want to run from swapper_pg_dir, since swapper_pg_dir is stored in constant
* place in memory
*/
__asm__( "movl %%ecx,%%cr3\n" ::"c"(__pa(swapper_pg_dir)));
/*
* Final function for resuming: after copying the pages to their original
* position, it restores the register state.
*/
do_magic_resume_1();
/* Critical section here: noone should touch memory from now */
/* This works, because nr_copy_pages, pagedir_nosave, loop and loop2 are nosavedata */
for (loop=0; loop < nr_copy_pages; loop++) {
/* You may not call something (like copy_page) here:
We may absolutely not use stack at this point */
for (loop2=0; loop2 < PAGE_SIZE; loop2++) {
*(((char *)((pagedir_nosave+loop)->orig_address))+loop2) =
*(((char *)((pagedir_nosave+loop)->address))+loop2);
__flush_tlb();
}
}
/* FIXME: What about page tables? Writing data pages may toggle
accessed/dirty bits in our page tables. That should be no problems
with 4MB page tables. That's why we require have_pse. */
/* Danger: previous loop probably destroyed our current stack. Better hope it did not use
any stack space, itself.
When this function is entered at resume time, we move stack to _old_ place.
This is means that this function must use no stack and no local variables in registers.
*/
restore_processor_context();
/* Ahah, we now run with our old stack, and with registers copied from suspend time */
do_magic_resume_2();
}
#endif
#endif
#ifndef _LINUX_BITOPS_H #ifndef _LINUX_BITOPS_H
#define _LINUX_BITOPS_H #define _LINUX_BITOPS_H
#include <asm/bitops.h>
/* /*
* ffs: find first bit set. This is defined the same way as * ffs: find first bit set. This is defined the same way as
...@@ -37,6 +37,47 @@ static inline int generic_ffs(int x) ...@@ -37,6 +37,47 @@ static inline int generic_ffs(int x)
return r; return r;
} }
/*
* fls: find last bit set.
*/
extern __inline__ int generic_fls(int x)
{
int r = 32;
if (!x)
return 0;
if (!(x & 0xffff0000)) {
x <<= 16;
r -= 16;
}
if (!(x & 0xff000000)) {
x <<= 8;
r -= 8;
}
if (!(x & 0xf0000000)) {
x <<= 4;
r -= 4;
}
if (!(x & 0xc0000000)) {
x <<= 2;
r -= 2;
}
if (!(x & 0x80000000)) {
x <<= 1;
r -= 1;
}
return r;
}
extern __inline__ int get_bitmask_order(unsigned int count)
{
int order;
order = fls(count);
return order; /* We could be slightly more clever with -1 here... */
}
/* /*
* hweightN: returns the hamming weight (i.e. the number * hweightN: returns the hamming weight (i.e. the number
* of bits set) of a N-bit word * of bits set) of a N-bit word
......
...@@ -169,6 +169,9 @@ typedef void (*__cleanup_module_func_t)(void); ...@@ -169,6 +169,9 @@ typedef void (*__cleanup_module_func_t)(void);
#endif #endif
/* Data marked not to be saved by software_suspend() */
#define __nosavedata __attribute__ ((__section__ (".data.nosave")))
#ifdef CONFIG_HOTPLUG #ifdef CONFIG_HOTPLUG
#define __devinit #define __devinit
#define __devinitdata #define __devinitdata
......
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
#define PG_private 12 /* Has something at ->private */ #define PG_private 12 /* Has something at ->private */
#define PG_writeback 13 /* Page is under writeback */ #define PG_writeback 13 /* Page is under writeback */
#define PG_nosave 15 /* Used for system suspend/resume */
/* /*
* Global page accounting. One instance per CPU. * Global page accounting. One instance per CPU.
...@@ -207,6 +208,12 @@ extern void get_page_state(struct page_state *ret); ...@@ -207,6 +208,12 @@ extern void get_page_state(struct page_state *ret);
ret; \ ret; \
}) })
#define PageNosave(page) test_bit(PG_nosave, &(page)->flags)
#define SetPageNosave(page) set_bit(PG_nosave, &(page)->flags)
#define TestSetPageNosave(page) test_and_set_bit(PG_nosave, &(page)->flags)
#define ClearPageNosave(page) clear_bit(PG_nosave, &(page)->flags)
#define TestClearPageNosave(page) test_and_clear_bit(PG_nosave, &(page)->flags)
/* /*
* The PageSwapCache predicate doesn't use a PG_flag at this time, * The PageSwapCache predicate doesn't use a PG_flag at this time,
* but it may again do so one day. * but it may again do so one day.
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
* CAD_OFF Ctrl-Alt-Del sequence sends SIGINT to init task. * CAD_OFF Ctrl-Alt-Del sequence sends SIGINT to init task.
* POWER_OFF Stop OS and remove all power from system, if possible. * POWER_OFF Stop OS and remove all power from system, if possible.
* RESTART2 Restart system using given command string. * RESTART2 Restart system using given command string.
* SW_SUSPEND Suspend system using Software Suspend if compiled in
*/ */
#define LINUX_REBOOT_CMD_RESTART 0x01234567 #define LINUX_REBOOT_CMD_RESTART 0x01234567
...@@ -28,6 +29,7 @@ ...@@ -28,6 +29,7 @@
#define LINUX_REBOOT_CMD_CAD_OFF 0x00000000 #define LINUX_REBOOT_CMD_CAD_OFF 0x00000000
#define LINUX_REBOOT_CMD_POWER_OFF 0x4321FEDC #define LINUX_REBOOT_CMD_POWER_OFF 0x4321FEDC
#define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4 #define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4
#define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2
#ifdef __KERNEL__ #ifdef __KERNEL__
...@@ -46,6 +48,13 @@ extern void machine_restart(char *cmd); ...@@ -46,6 +48,13 @@ extern void machine_restart(char *cmd);
extern void machine_halt(void); extern void machine_halt(void);
extern void machine_power_off(void); extern void machine_power_off(void);
/*
* Architecture-independent suspend facility
*/
extern void software_suspend(void);
extern unsigned char software_suspend_enabled;
#endif #endif
#endif /* _LINUX_REBOOT_H */ #endif /* _LINUX_REBOOT_H */
...@@ -388,6 +388,11 @@ do { if (atomic_dec_and_test(&(tsk)->usage)) __put_task_struct(tsk); } while(0) ...@@ -388,6 +388,11 @@ do { if (atomic_dec_and_test(&(tsk)->usage)) __put_task_struct(tsk); } while(0)
#define PF_FLUSHER 0x00004000 /* responsible for disk writeback */ #define PF_FLUSHER 0x00004000 /* responsible for disk writeback */
#define PF_RADIX_TREE 0x00008000 /* debug: performing radix tree alloc */ #define PF_RADIX_TREE 0x00008000 /* debug: performing radix tree alloc */
#define PF_FREEZE 0x00010000 /* this task should be frozen for suspend */
#define PF_IOTHREAD 0x00020000 /* this thread is needed for doing I/O to swap */
#define PF_KERNTHREAD 0x00040000 /* this thread is a kernel thread that cannot be sent signals to */
#define PF_FROZEN 0x00080000 /* frozen for system suspend */
/* /*
* Ptrace flags * Ptrace flags
*/ */
......
#ifndef _LINUX_SWSUSP_H
#define _LINUX_SWSUSP_H
#include <asm/suspend.h>
#include <linux/swap.h>
#include <linux/notifier.h>
#include <linux/config.h>
extern unsigned char software_suspend_enabled;
#define NORESUME 1
#define RESUME_SPECIFIED 2
#ifdef CONFIG_SOFTWARE_SUSPEND
/* page backup entry */
typedef struct pbe {
unsigned long address; /* address of the copy */
unsigned long orig_address; /* original address of page */
swp_entry_t swap_address;
swp_entry_t dummy; /* we need scratch space at
* end of page (see link, diskpage)
*/
} suspend_pagedir_t;
#define SWAP_FILENAME_MAXLENGTH 32
struct suspend_header {
__u32 version_code;
unsigned long num_physpages;
char machine[8];
char version[20];
int num_cpus;
int page_size;
unsigned long suspend_pagedir;
unsigned int num_pbes;
struct swap_location {
char filename[SWAP_FILENAME_MAXLENGTH];
} swap_location[MAX_SWAPFILES];
};
#define SUSPEND_PD_PAGES(x) (((x)*sizeof(struct pbe))/PAGE_SIZE+1)
extern struct tq_struct suspend_tq;
/* mm/vmscan.c */
extern int shrink_mem(void);
/* kernel/suspend.c */
extern void software_suspend(void);
extern void software_resume(void);
extern int resume_setup(char *str);
extern int register_suspend_notifier(struct notifier_block *);
extern int unregister_suspend_notifier(struct notifier_block *);
extern void refrigerator(unsigned long);
#else
#define software_suspend() do { } while(0)
#define software_resume() do { } while(0)
#define register_suspend_notifier(a) do { } while(0)
#define unregister_suspend_notifier(a) do { } while(0)
#define refrigerator(a) do { BUG(); } while(0)
#endif
#endif /* _LINUX_SWSUSP_H */
...@@ -66,7 +66,7 @@ typedef struct list_head task_queue; ...@@ -66,7 +66,7 @@ typedef struct list_head task_queue;
#define DECLARE_TASK_QUEUE(q) LIST_HEAD(q) #define DECLARE_TASK_QUEUE(q) LIST_HEAD(q)
#define TQ_ACTIVE(q) (!list_empty(&q)) #define TQ_ACTIVE(q) (!list_empty(&q))
extern task_queue tq_timer, tq_immediate, tq_disk; extern task_queue tq_timer, tq_immediate, tq_disk, tq_bdflush;
/* /*
* To implement your own list of active bottom halfs, use the following * To implement your own list of active bottom halfs, use the following
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <linux/fd.h> #include <linux/fd.h>
#include <linux/tty.h> #include <linux/tty.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/suspend.h>
#include <linux/nfs_fs.h> #include <linux/nfs_fs.h>
#include <linux/nfs_fs_sb.h> #include <linux/nfs_fs_sb.h>
...@@ -825,6 +826,11 @@ void prepare_namespace(void) ...@@ -825,6 +826,11 @@ void prepare_namespace(void)
#endif #endif
create_dev("/dev/root", ROOT_DEV, NULL); create_dev("/dev/root", ROOT_DEV, NULL);
/* This has to be before mounting root, because even readonly mount of reiserfs would replay
log corrupting stuff */
software_resume();
if (mount_initrd) { if (mount_initrd) {
if (initrd_load() && !kdev_same(ROOT_DEV, mk_kdev(RAMDISK_MAJOR, 0))) { if (initrd_load() && !kdev_same(ROOT_DEV, mk_kdev(RAMDISK_MAJOR, 0))) {
handle_initrd(); handle_initrd();
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
O_TARGET := kernel.o O_TARGET := kernel.o
export-objs = signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain.o \ export-objs = signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain.o \
printk.o platform.o printk.o platform.o suspend.o
obj-y = sched.o dma.o fork.o exec_domain.o panic.o printk.o \ obj-y = sched.o dma.o fork.o exec_domain.o panic.o printk.o \
module.o exit.o itimer.o info.o time.o softirq.o resource.o \ module.o exit.o itimer.o info.o time.o softirq.o resource.o \
...@@ -21,6 +21,7 @@ obj-$(CONFIG_UID16) += uid16.o ...@@ -21,6 +21,7 @@ obj-$(CONFIG_UID16) += uid16.o
obj-$(CONFIG_MODULES) += ksyms.o obj-$(CONFIG_MODULES) += ksyms.o
obj-$(CONFIG_PM) += pm.o obj-$(CONFIG_PM) += pm.o
obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o
obj-$(CONFIG_SOFTWARE_SUSPEND) += suspend.o
ifneq ($(CONFIG_IA64),y) ifneq ($(CONFIG_IA64),y)
# According to Alan Modra <alan@linuxcare.com.au>, the -fno-omit-frame-pointer is # According to Alan Modra <alan@linuxcare.com.au>, the -fno-omit-frame-pointer is
......
...@@ -72,6 +72,7 @@ static int context_thread(void *startup) ...@@ -72,6 +72,7 @@ static int context_thread(void *startup)
daemonize(); daemonize();
strcpy(curtask->comm, "keventd"); strcpy(curtask->comm, "keventd");
current->flags |= PF_IOTHREAD;
keventd_running = 1; keventd_running = 1;
keventd_task = curtask; keventd_task = curtask;
......
...@@ -493,7 +493,7 @@ static int send_signal(int sig, struct siginfo *info, struct sigpending *signals ...@@ -493,7 +493,7 @@ static int send_signal(int sig, struct siginfo *info, struct sigpending *signals
* No need to set need_resched since signal event passing * No need to set need_resched since signal event passing
* goes through ->blocked * goes through ->blocked
*/ */
static inline void signal_wake_up(struct task_struct *t) inline void signal_wake_up(struct task_struct *t)
{ {
set_tsk_thread_flag(t,TIF_SIGPENDING); set_tsk_thread_flag(t,TIF_SIGPENDING);
......
...@@ -366,6 +366,7 @@ static int ksoftirqd(void * __bind_cpu) ...@@ -366,6 +366,7 @@ static int ksoftirqd(void * __bind_cpu)
daemonize(); daemonize();
set_user_nice(current, 19); set_user_nice(current, 19);
current->flags |= PF_IOTHREAD;
sigfillset(&current->blocked); sigfillset(&current->blocked);
/* Migrate to the right CPU */ /* Migrate to the right CPU */
......
This diff is collapsed.
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
* Copyright (C) 1991, 1992 Linus Torvalds * Copyright (C) 1991, 1992 Linus Torvalds
*/ */
#include <linux/config.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/utsname.h> #include <linux/utsname.h>
...@@ -347,6 +348,16 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void * arg) ...@@ -347,6 +348,16 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void * arg)
machine_restart(buffer); machine_restart(buffer);
break; break;
#ifdef CONFIG_SOFTWARE_SUSPEND
case LINUX_REBOOT_CMD_SW_SUSPEND:
if(!software_suspend_enabled)
return -EAGAIN;
software_suspend();
do_exit(0);
break;
#endif
default: default:
unlock_kernel(); unlock_kernel();
return -EINVAL; return -EINVAL;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/compiler.h> #include <linux/compiler.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/suspend.h>
unsigned long totalram_pages; unsigned long totalram_pages;
unsigned long totalhigh_pages; unsigned long totalhigh_pages;
...@@ -247,6 +248,46 @@ static struct page * rmqueue(zone_t *zone, unsigned int order) ...@@ -247,6 +248,46 @@ static struct page * rmqueue(zone_t *zone, unsigned int order)
return NULL; return NULL;
} }
#ifdef CONFIG_SOFTWARE_SUSPEND
int is_head_of_free_region(struct page *p)
{
pg_data_t *pgdat = pgdat_list;
unsigned type;
unsigned long flags;
for (type=0;type < MAX_NR_ZONES; type++) {
zone_t *zone = pgdat->node_zones + type;
int order = MAX_ORDER - 1;
free_area_t *area;
struct list_head *head, *curr;
spin_lock_irqsave(&zone->lock, flags); /* Should not matter as we need quiescent system for suspend anyway, but... */
do {
area = zone->free_area + order;
head = &area->free_list;
curr = head;
for(;;) {
if(!curr) {
// printk("FIXME: this should not happen but it does!!!");
break;
}
if(p != memlist_entry(curr, struct page, list)) {
curr = memlist_next(curr);
if (curr == head)
break;
continue;
}
return 1 << order;
}
} while(order--);
spin_unlock_irqrestore(&zone->lock, flags);
}
return 0;
}
#endif /* CONFIG_SOFTWARE_SUSPEND */
#ifndef CONFIG_DISCONTIGMEM #ifndef CONFIG_DISCONTIGMEM
struct page *_alloc_pages(unsigned int gfp_mask, unsigned int order) struct page *_alloc_pages(unsigned int gfp_mask, unsigned int order)
{ {
......
...@@ -86,12 +86,16 @@ static int rw_swap_page_base(int rw, swp_entry_t entry, struct page *page) ...@@ -86,12 +86,16 @@ static int rw_swap_page_base(int rw, swp_entry_t entry, struct page *page)
* - it's marked as being swap-cache * - it's marked as being swap-cache
* - it's associated with the swap inode * - it's associated with the swap inode
*/ */
extern long suspend_device;
void rw_swap_page(int rw, struct page *page) void rw_swap_page(int rw, struct page *page)
{ {
swp_entry_t entry; swp_entry_t entry;
entry.val = page->index; entry.val = page->index;
if (suspend_device)
panic("I refuse to corrupt memory/swap.");
if (!PageLocked(page)) if (!PageLocked(page))
PAGE_BUG(page); PAGE_BUG(page);
if (!PageSwapCache(page)) if (!PageSwapCache(page))
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <linux/gfp.h> #include <linux/gfp.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/suspend.h>
/* /*
...@@ -96,7 +97,7 @@ static int __pdflush(struct pdflush_work *my_work) ...@@ -96,7 +97,7 @@ static int __pdflush(struct pdflush_work *my_work)
recalc_sigpending(); recalc_sigpending();
spin_unlock_irq(&current->sigmask_lock); spin_unlock_irq(&current->sigmask_lock);
current->flags |= PF_FLUSHER; current->flags |= PF_FLUSHER | PF_KERNTHREAD;
my_work->fn = NULL; my_work->fn = NULL;
my_work->who = current; my_work->who = current;
...@@ -107,15 +108,21 @@ static int __pdflush(struct pdflush_work *my_work) ...@@ -107,15 +108,21 @@ static int __pdflush(struct pdflush_work *my_work)
for ( ; ; ) { for ( ; ; ) {
struct pdflush_work *pdf; struct pdflush_work *pdf;
#ifdef CONFIG_SOFTWARE_SUSPEND
run_task_queue(&tq_bdflush);
#endif
list_add(&my_work->list, &pdflush_list); list_add(&my_work->list, &pdflush_list);
my_work->when_i_went_to_sleep = jiffies; my_work->when_i_went_to_sleep = jiffies;
set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
spin_unlock_irq(&pdflush_lock); spin_unlock_irq(&pdflush_lock);
if (current->flags & PF_FREEZE)
refrigerator(PF_IOTHREAD);
schedule(); schedule();
preempt_enable(); preempt_enable();
(*my_work->fn)(my_work->arg0); if (my_work->fn)
(*my_work->fn)(my_work->arg0);
preempt_disable(); preempt_disable();
/* /*
...@@ -146,6 +153,7 @@ static int __pdflush(struct pdflush_work *my_work) ...@@ -146,6 +153,7 @@ static int __pdflush(struct pdflush_work *my_work)
pdf->when_i_went_to_sleep = jiffies; /* Limit exit rate */ pdf->when_i_went_to_sleep = jiffies; /* Limit exit rate */
break; /* exeunt */ break; /* exeunt */
} }
my_work->fn = NULL;
} }
nr_pdflush_threads--; nr_pdflush_threads--;
// printk("pdflush %d [%d] ends\n", nr_pdflush_threads, current->pid); // printk("pdflush %d [%d] ends\n", nr_pdflush_threads, current->pid);
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <linux/file.h> #include <linux/file.h>
#include <linux/writeback.h> #include <linux/writeback.h>
#include <linux/compiler.h> #include <linux/compiler.h>
#include <linux/suspend.h>
#include <asm/pgalloc.h> #include <asm/pgalloc.h>
#include <asm/tlbflush.h> #include <asm/tlbflush.h>
...@@ -781,18 +782,22 @@ int kswapd(void *unused) ...@@ -781,18 +782,22 @@ int kswapd(void *unused)
* us from recursively trying to free more memory as we're * us from recursively trying to free more memory as we're
* trying to free the first piece of memory in the first place). * trying to free the first piece of memory in the first place).
*/ */
tsk->flags |= PF_MEMALLOC; tsk->flags |= PF_MEMALLOC | PF_KERNTHREAD;
/* /*
* Kswapd main loop. * Kswapd main loop.
*/ */
for (;;) { for (;;) {
if (current->flags & PF_FREEZE)
refrigerator(PF_IOTHREAD);
__set_current_state(TASK_INTERRUPTIBLE); __set_current_state(TASK_INTERRUPTIBLE);
add_wait_queue(&kswapd_wait, &wait); add_wait_queue(&kswapd_wait, &wait);
mb(); mb();
if (kswapd_can_sleep()) if (kswapd_can_sleep()) {
schedule(); schedule();
}
__set_current_state(TASK_RUNNING); __set_current_state(TASK_RUNNING);
remove_wait_queue(&kswapd_wait, &wait); remove_wait_queue(&kswapd_wait, &wait);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment