tuxonice_modules.h 5.7 KB

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