2 * kernel/power/tuxonice_modules.h
4 * Copyright (C) 2004-2010 Nigel Cunningham (nigel at tuxonice net)
6 * This file is released under the GPLv2.
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.
17 /* This is the maximum size we store in the image header for a module name */
18 #define TOI_MAX_MODULE_NAME_LENGTH 30
20 struct toi_boot_kernel_data
;
22 /* Per-module metadata */
23 struct toi_module_header
{
24 char name
[TOI_MAX_MODULE_NAME_LENGTH
];
29 unsigned long signature
;
50 #define TOI_MAP(type, addr) \
51 (type == TOI_PAGE ? kmap(addr) : addr)
53 #define TOI_UNMAP(type, addr) \
55 if (type == TOI_PAGE) \
59 struct toi_module_ops
{
60 /* Functions common to all modules */
64 char *shared_directory
;
65 struct kobject
*dir_kobj
;
66 struct module
*module
;
67 int enabled
, early
, initialised
;
68 struct list_head module_list
;
70 /* List of filters or allocators */
71 struct list_head list
, type_list
;
74 * Requirements for memory and storage in
77 int (*memory_needed
) (void);
78 int (*storage_needed
) (void);
80 int header_requested
, header_used
;
82 int (*expected_compression
) (void);
83 #ifdef CONFIG_TOI_ENHANCE
84 int (*actual_compression
) (void);
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
);
95 * Initialise & cleanup - general routines called
96 * at the start and end of a cycle.
98 int (*initialise
) (int starting_cycle
);
99 void (*cleanup
) (int finishing_cycle
);
101 void (*pre_atomic_restore
) (struct toi_boot_kernel_data
*bkd
);
102 void (*post_atomic_restore
) (struct toi_boot_kernel_data
*bkd
);
105 * Calls for allocating storage (allocators only).
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.
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);
121 * Routines used in image I/O.
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
);
129 /* Reset module if image exists but reading aborted */
130 void (*noresume_reset
) (void);
132 /* Read and write the metadata */
133 int (*write_header_init
) (void);
134 int (*write_header_cleanup
) (void);
136 int (*read_header_init
) (void);
137 int (*read_header_cleanup
) (void);
139 /* To be called after read_header_init */
140 int (*get_header_version
) (void);
142 int (*rw_header_chunk
) (int rw
, struct toi_module_ops
*owner
,
143 char *buffer_start
, int buffer_size
);
145 int (*rw_header_chunk_noreadahead
) (int rw
,
146 struct toi_module_ops
*owner
, char *buffer_start
,
149 /* Attempt to parse an image location */
150 int (*parse_sig_location
) (char *buffer
, int only_writer
, int quiet
);
152 /* Throttle I/O according to throughput */
153 void (*update_throughput_throttle
) (int jif_index
);
155 /* Flush outstanding I/O */
156 int (*finish_all_io
) (void);
158 /* Determine whether image exists that we can restore */
159 int (*image_exists
) (int quiet
);
161 /* Mark the image as having tried to resume */
162 int (*mark_resume_attempted
) (int);
164 /* Destroy image if one exists */
165 int (*remove_image
) (void);
168 struct toi_sysfs_data
*sysfs_data
;
169 int num_sysfs_entries
;
171 /* Block I/O allocator */
172 struct toi_bio_allocator_ops
*bio_allocator_ops
;
175 extern int toi_num_modules
, toiNumAllocators
;
177 extern struct toi_module_ops
*toiActiveAllocator
;
178 extern struct list_head toi_filters
, toiAllocators
, toi_modules
;
180 extern void toi_prepare_console_modules(void);
181 extern void toi_cleanup_console_modules(void);
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
*);
186 extern int toi_register_module(struct toi_module_ops
*module
);
187 extern void toi_move_module_tail(struct toi_module_ops
*module
);
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);
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
);
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
);
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
);
211 extern void toi_print_modules(void);
213 int toi_get_modules(void);
214 void toi_put_modules(void);