[PATCH] swsusp: separate swap-writing/reading code
[linux-2.6/linux-loongson.git] / kernel / power / power.h
blob089c84bed89577699447aa60b90ff2ea90b1d71b
1 #include <linux/suspend.h>
2 #include <linux/utsname.h>
4 struct swsusp_info {
5 struct new_utsname uts;
6 u32 version_code;
7 unsigned long num_physpages;
8 int cpus;
9 unsigned long image_pages;
10 unsigned long pages;
11 } __attribute__((aligned(PAGE_SIZE)));
15 #ifdef CONFIG_SOFTWARE_SUSPEND
16 extern int pm_suspend_disk(void);
18 #else
19 static inline int pm_suspend_disk(void)
21 return -EPERM;
23 #endif
24 extern struct semaphore pm_sem;
25 #define power_attr(_name) \
26 static struct subsys_attribute _name##_attr = { \
27 .attr = { \
28 .name = __stringify(_name), \
29 .mode = 0644, \
30 }, \
31 .show = _name##_show, \
32 .store = _name##_store, \
35 extern struct subsystem power_subsys;
37 /* References to section boundaries */
38 extern const void __nosave_begin, __nosave_end;
40 extern struct pbe *pagedir_nosave;
42 /* Preferred image size in bytes (default 500 MB) */
43 extern unsigned long image_size;
44 extern int in_suspend;
45 extern dev_t swsusp_resume_device;
47 extern asmlinkage int swsusp_arch_suspend(void);
48 extern asmlinkage int swsusp_arch_resume(void);
50 extern unsigned int count_data_pages(void);
51 extern void swsusp_free(void);
53 struct snapshot_handle {
54 loff_t offset;
55 unsigned int page;
56 unsigned int page_offset;
57 unsigned int prev;
58 struct pbe *pbe;
59 void *buffer;
60 unsigned int buf_offset;
63 #define data_of(handle) ((handle).buffer + (handle).buf_offset)
65 extern int snapshot_read_next(struct snapshot_handle *handle, size_t count);
66 extern int snapshot_write_next(struct snapshot_handle *handle, size_t count);
67 int snapshot_image_loaded(struct snapshot_handle *handle);
69 /**
70 * The bitmap is used for tracing allocated swap pages
72 * The entire bitmap consists of a number of bitmap_page
73 * structures linked with the help of the .next member.
74 * Thus each page can be allocated individually, so we only
75 * need to make 0-order memory allocations to create
76 * the bitmap.
79 #define BITMAP_PAGE_SIZE (PAGE_SIZE - sizeof(void *))
80 #define BITMAP_PAGE_CHUNKS (BITMAP_PAGE_SIZE / sizeof(long))
81 #define BITS_PER_CHUNK (sizeof(long) * 8)
82 #define BITMAP_PAGE_BITS (BITMAP_PAGE_CHUNKS * BITS_PER_CHUNK)
84 struct bitmap_page {
85 unsigned long chunks[BITMAP_PAGE_CHUNKS];
86 struct bitmap_page *next;
89 extern void free_bitmap(struct bitmap_page *bitmap);
90 extern struct bitmap_page *alloc_bitmap(unsigned int nr_bits);
91 extern unsigned long alloc_swap_page(int swap, struct bitmap_page *bitmap);
92 extern void free_all_swap_pages(int swap, struct bitmap_page *bitmap);
94 extern int swsusp_shrink_memory(void);
95 extern int swsusp_suspend(void);
96 extern int swsusp_resume(void);