Merge tag 'v3.10.101' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / kernel / power / tuxonice_modules.h
1 /*
2 * kernel/power/tuxonice_modules.h
3 *
4 * Copyright (C) 2004-2010 Nigel Cunningham (nigel at tuxonice net)
5 *
6 * This file is released under the GPLv2.
7 *
8 * It contains declarations for modules. Modules are additions to
9 * TuxOnIce that provide facilities such as image compression or
10 * encryption, backends for storage of the image and user interfaces.
11 *
12 */
13
14 #ifndef TOI_MODULES_H
15 #define TOI_MODULES_H
16
17 /* This is the maximum size we store in the image header for a module name */
18 #define TOI_MAX_MODULE_NAME_LENGTH 30
19
20 struct toi_boot_kernel_data;
21
22 /* Per-module metadata */
23 struct toi_module_header {
24 char name[TOI_MAX_MODULE_NAME_LENGTH];
25 int enabled;
26 int type;
27 int index;
28 int data_length;
29 unsigned long signature;
30 };
31
32 enum {
33 FILTER_MODULE,
34 WRITER_MODULE,
35 BIO_ALLOCATOR_MODULE,
36 MISC_MODULE,
37 MISC_HIDDEN_MODULE,
38 };
39
40 enum {
41 TOI_ASYNC,
42 TOI_SYNC
43 };
44
45 enum {
46 TOI_VIRT,
47 TOI_PAGE,
48 };
49
50 #define TOI_MAP(type, addr) \
51 (type == TOI_PAGE ? kmap(addr) : addr)
52
53 #define TOI_UNMAP(type, addr) \
54 do { \
55 if (type == TOI_PAGE) \
56 kunmap(addr); \
57 } while (0)
58
59 struct toi_module_ops {
60 /* Functions common to all modules */
61 int type;
62 char *name;
63 char *directory;
64 char *shared_directory;
65 struct kobject *dir_kobj;
66 struct module *module;
67 int enabled, early, initialised;
68 struct list_head module_list;
69
70 /* List of filters or allocators */
71 struct list_head list, type_list;
72
73 /*
74 * Requirements for memory and storage in
75 * the image header..
76 */
77 int (*memory_needed) (void);
78 int (*storage_needed) (void);
79
80 int header_requested, header_used;
81
82 int (*expected_compression) (void);
83 #ifdef CONFIG_TOI_ENHANCE
84 int (*actual_compression) (void);
85 #endif
86
87 /*
88 * Debug info
89 */
90 int (*print_debug_info) (char *buffer, int size);
91 int (*save_config_info) (char *buffer);
92 void (*load_config_info) (char *buffer, int len);
93
94 /*
95 * Initialise & cleanup - general routines called
96 * at the start and end of a cycle.
97 */
98 int (*initialise) (int starting_cycle);
99 void (*cleanup) (int finishing_cycle);
100
101 void (*pre_atomic_restore) (struct toi_boot_kernel_data *bkd);
102 void (*post_atomic_restore) (struct toi_boot_kernel_data *bkd);
103
104 /*
105 * Calls for allocating storage (allocators only).
106 *
107 * Header space is requested separately and cannot fail, but the
108 * reservation is only applied when main storage is allocated.
109 * The header space reservation is thus always set prior to
110 * requesting the allocation of storage - and prior to querying
111 * how much storage is available.
112 */
113
114 unsigned long (*storage_available) (void);
115 void (*reserve_header_space) (unsigned long space_requested);
116 int (*register_storage) (void);
117 int (*allocate_storage) (unsigned long space_requested);
118 unsigned long (*storage_allocated) (void);
119
120 /*
121 * Routines used in image I/O.
122 */
123 int (*rw_init) (int rw, int stream_number);
124 int (*rw_cleanup) (int rw);
125 int (*write_page) (unsigned long index, int buf_type, void *buf, unsigned int buf_size);
126 int (*read_page) (unsigned long *index, int buf_type, void *buf, unsigned int *buf_size);
127 int (*io_flusher) (int rw);
128
129 /* Reset module if image exists but reading aborted */
130 void (*noresume_reset) (void);
131
132 /* Read and write the metadata */
133 int (*write_header_init) (void);
134 int (*write_header_cleanup) (void);
135
136 int (*read_header_init) (void);
137 int (*read_header_cleanup) (void);
138
139 /* To be called after read_header_init */
140 int (*get_header_version) (void);
141
142 int (*rw_header_chunk) (int rw, struct toi_module_ops *owner,
143 char *buffer_start, int buffer_size);
144
145 int (*rw_header_chunk_noreadahead) (int rw,
146 struct toi_module_ops *owner, char *buffer_start,
147 int buffer_size);
148
149 /* Attempt to parse an image location */
150 int (*parse_sig_location) (char *buffer, int only_writer, int quiet);
151
152 /* Throttle I/O according to throughput */
153 void (*update_throughput_throttle) (int jif_index);
154
155 /* Flush outstanding I/O */
156 int (*finish_all_io) (void);
157
158 /* Determine whether image exists that we can restore */
159 int (*image_exists) (int quiet);
160
161 /* Mark the image as having tried to resume */
162 int (*mark_resume_attempted) (int);
163
164 /* Destroy image if one exists */
165 int (*remove_image) (void);
166
167 /* Sysfs Data */
168 struct toi_sysfs_data *sysfs_data;
169 int num_sysfs_entries;
170
171 /* Block I/O allocator */
172 struct toi_bio_allocator_ops *bio_allocator_ops;
173 };
174
175 extern int toi_num_modules, toiNumAllocators;
176
177 extern struct toi_module_ops *toiActiveAllocator;
178 extern struct list_head toi_filters, toiAllocators, toi_modules;
179
180 extern void toi_prepare_console_modules(void);
181 extern void toi_cleanup_console_modules(void);
182
183 extern struct toi_module_ops *toi_find_module_given_name(char *name);
184 extern struct toi_module_ops *toi_get_next_filter(struct toi_module_ops *);
185
186 extern int toi_register_module(struct toi_module_ops *module);
187 extern void toi_move_module_tail(struct toi_module_ops *module);
188
189 extern long toi_header_storage_for_modules(void);
190 extern long toi_memory_for_modules(int print_parts);
191 extern void print_toi_header_storage_for_modules(void);
192 extern int toi_expected_compression_ratio(void);
193 #ifdef CONFIG_TOI_ENHANCE
194 extern int toi_actual_compression_ratio(void);
195 #endif
196
197 extern int toi_print_module_debug_info(char *buffer, int buffer_size);
198 extern int toi_register_module(struct toi_module_ops *module);
199 extern void toi_unregister_module(struct toi_module_ops *module);
200
201 extern int toi_initialise_modules(int starting_cycle, int early);
202 #define toi_initialise_modules_early(starting) \
203 toi_initialise_modules(starting, 1)
204 #define toi_initialise_modules_late(starting) \
205 toi_initialise_modules(starting, 0)
206 extern void toi_cleanup_modules(int finishing_cycle);
207
208 extern void toi_post_atomic_restore_modules(struct toi_boot_kernel_data *bkd);
209 extern void toi_pre_atomic_restore_modules(struct toi_boot_kernel_data *bkd);
210
211 extern void toi_print_modules(void);
212
213 int toi_get_modules(void);
214 void toi_put_modules(void);
215 #endif