^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include <linux/suspend.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <linux/suspend_ioctls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/utsname.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/freezer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) struct swsusp_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) struct new_utsname uts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) u32 version_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) unsigned long num_physpages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) int cpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) unsigned long image_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) unsigned long pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) unsigned long size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) } __aligned(PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #ifdef CONFIG_HIBERNATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /* kernel/power/snapshot.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) extern void __init hibernate_reserved_size_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) extern void __init hibernate_image_size_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #ifdef CONFIG_ARCH_HIBERNATION_HEADER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /* Maximum size of architecture specific data in a hibernation header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define MAX_ARCH_HEADER_SIZE (sizeof(struct new_utsname) + 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) extern int arch_hibernation_header_save(void *addr, unsigned int max_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) extern int arch_hibernation_header_restore(void *addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static inline int init_header_complete(struct swsusp_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) return arch_hibernation_header_save(info, MAX_ARCH_HEADER_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static inline const char *check_image_kernel(struct swsusp_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) return arch_hibernation_header_restore(info) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) "architecture specific data" : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #endif /* CONFIG_ARCH_HIBERNATION_HEADER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) extern int hibernate_resume_nonboot_cpu_disable(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * Keep some memory free so that I/O operations can succeed without paging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * [Might this be more than 4 MB?]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define PAGES_FOR_IO ((4096 * 1024) >> PAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * Keep 1 MB of memory free so that device drivers can allocate some pages in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * their .suspend() routines without breaking the suspend to disk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define SPARE_PAGES ((1024 * 1024) >> PAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) asmlinkage int swsusp_save(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /* kernel/power/hibernate.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) extern bool freezer_test_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) extern int hibernation_snapshot(int platform_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) extern int hibernation_restore(int platform_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) extern int hibernation_platform_enter(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #ifdef CONFIG_STRICT_KERNEL_RWX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /* kernel/power/snapshot.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) extern void enable_restore_image_protection(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static inline void enable_restore_image_protection(void) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #endif /* CONFIG_STRICT_KERNEL_RWX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #else /* !CONFIG_HIBERNATION */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static inline void hibernate_reserved_size_init(void) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static inline void hibernate_image_size_init(void) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #endif /* !CONFIG_HIBERNATION */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define power_attr(_name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static struct kobj_attribute _name##_attr = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) .attr = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .name = __stringify(_name), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .mode = 0644, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) .show = _name##_show, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) .store = _name##_store, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define power_attr_ro(_name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) static struct kobj_attribute _name##_attr = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) .attr = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) .name = __stringify(_name), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) .mode = S_IRUGO, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) .show = _name##_show, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /* Preferred image size in bytes (default 500 MB) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) extern unsigned long image_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /* Size of memory reserved for drivers (default SPARE_PAGES x PAGE_SIZE) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) extern unsigned long reserved_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) extern int in_suspend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) extern dev_t swsusp_resume_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) extern sector_t swsusp_resume_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) extern int create_basic_memory_bitmaps(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) extern void free_basic_memory_bitmaps(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) extern int hibernate_preallocate_memory(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) extern void clear_or_poison_free_pages(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * Auxiliary structure used for reading the snapshot image data and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * metadata from and writing them to the list of page backup entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * (PBEs) which is the main data structure of swsusp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * Using struct snapshot_handle we can transfer the image, including its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * metadata, as a continuous sequence of bytes with the help of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * snapshot_read_next() and snapshot_write_next().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * The code that writes the image to a storage or transfers it to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * the user land is required to use snapshot_read_next() for this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * purpose and it should not make any assumptions regarding the internal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * structure of the image. Similarly, the code that reads the image from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * a storage or transfers it from the user land is required to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * snapshot_write_next().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * This may allow us to change the internal structure of the image
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * in the future with considerably less effort.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct snapshot_handle {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) unsigned int cur; /* number of the block of PAGE_SIZE bytes the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * next operation will refer to (ie. current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) void *buffer; /* address of the block to read from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * or write to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int sync_read; /* Set to one to notify the caller of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * snapshot_write_next() that it may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * need to call wait_on_bio_chain()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /* This macro returns the address from/to which the caller of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * snapshot_read_next()/snapshot_write_next() is allowed to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * read/write data after the function returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #define data_of(handle) ((handle).buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) extern unsigned int snapshot_additional_pages(struct zone *zone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) extern unsigned long snapshot_get_image_size(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) extern int snapshot_read_next(struct snapshot_handle *handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) extern int snapshot_write_next(struct snapshot_handle *handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) extern void snapshot_write_finalize(struct snapshot_handle *handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) extern int snapshot_image_loaded(struct snapshot_handle *handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) extern bool hibernate_acquire(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) extern void hibernate_release(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) extern sector_t alloc_swapdev_block(int swap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) extern void free_all_swap_pages(int swap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) extern int swsusp_swap_in_use(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * Flags that can be passed from the hibernatig hernel to the "boot" kernel in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * the image header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) #define SF_PLATFORM_MODE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) #define SF_NOCOMPRESS_MODE 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) #define SF_CRC32_MODE 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /* kernel/power/hibernate.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) extern int swsusp_check(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) extern void swsusp_free(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) extern int swsusp_read(unsigned int *flags_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) extern int swsusp_write(unsigned int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) extern void swsusp_close(fmode_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) #ifdef CONFIG_SUSPEND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) extern int swsusp_unmark(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) struct __kernel_old_timeval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /* kernel/power/swsusp.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) extern void swsusp_show_speed(ktime_t, ktime_t, unsigned int, char *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) #ifdef CONFIG_SUSPEND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /* kernel/power/suspend.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) extern const char * const pm_labels[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) extern const char *pm_states[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) extern const char *mem_sleep_states[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) extern int suspend_devices_and_enter(suspend_state_t state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) #else /* !CONFIG_SUSPEND */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) #define mem_sleep_current PM_SUSPEND_ON
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static inline int suspend_devices_and_enter(suspend_state_t state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #endif /* !CONFIG_SUSPEND */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #ifdef CONFIG_PM_TEST_SUSPEND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /* kernel/power/suspend_test.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) extern void suspend_test_start(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) extern void suspend_test_finish(const char *label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) #else /* !CONFIG_PM_TEST_SUSPEND */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static inline void suspend_test_start(void) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static inline void suspend_test_finish(const char *label) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) #endif /* !CONFIG_PM_TEST_SUSPEND */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /* kernel/power/main.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) extern int pm_notifier_call_chain_robust(unsigned long val_up, unsigned long val_down);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) extern int pm_notifier_call_chain(unsigned long val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) int restore_highmem(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static inline unsigned int count_highmem_pages(void) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static inline int restore_highmem(void) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * Suspend test levels
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /* keep first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) TEST_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) TEST_CORE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) TEST_CPUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) TEST_PLATFORM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) TEST_DEVICES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) TEST_FREEZER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) /* keep last */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) __TEST_AFTER_LAST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) #define TEST_FIRST TEST_NONE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) #define TEST_MAX (__TEST_AFTER_LAST - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) #ifdef CONFIG_PM_SLEEP_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) extern int pm_test_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) #define pm_test_level (TEST_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) #ifdef CONFIG_SUSPEND_FREEZER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static inline int suspend_freeze_processes(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) error = freeze_processes();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * freeze_processes() automatically thaws every task if freezing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * fails. So we need not do anything extra upon error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) error = freeze_kernel_threads();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * freeze_kernel_threads() thaws only kernel threads upon freezing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * failure. So we have to thaw the userspace tasks ourselves.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) thaw_processes();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static inline void suspend_thaw_processes(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) thaw_processes();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static inline int suspend_freeze_processes(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static inline void suspend_thaw_processes(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) #ifdef CONFIG_PM_AUTOSLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) /* kernel/power/autosleep.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) extern int pm_autosleep_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) extern int pm_autosleep_lock(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) extern void pm_autosleep_unlock(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) extern suspend_state_t pm_autosleep_state(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) extern int pm_autosleep_set_state(suspend_state_t state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) #else /* !CONFIG_PM_AUTOSLEEP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static inline int pm_autosleep_init(void) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static inline int pm_autosleep_lock(void) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) static inline void pm_autosleep_unlock(void) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static inline suspend_state_t pm_autosleep_state(void) { return PM_SUSPEND_ON; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) #endif /* !CONFIG_PM_AUTOSLEEP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) #ifdef CONFIG_PM_WAKELOCKS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) /* kernel/power/wakelock.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) extern ssize_t pm_show_wakelocks(char *buf, bool show_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) extern int pm_wake_lock(const char *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) extern int pm_wake_unlock(const char *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) #endif /* !CONFIG_PM_WAKELOCKS */