arch/x86/power/hibernate.c
Source file repositories/reference/linux-study-clean/arch/x86/power/hibernate.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/power/hibernate.c- Extension
.c- Size
- 5788 bytes
- Lines
- 217
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/gfp.hlinux/smp.hlinux/suspend.hlinux/scatterlist.hlinux/kdebug.hlinux/cpu.hlinux/pgtable.hlinux/types.hlinux/crc32.hasm/e820/api.hasm/init.hasm/proto.hasm/page.hasm/mtrr.hasm/sections.hasm/suspend.hasm/tlbflush.h
Detected Declarations
struct restore_data_recordfunction pfn_is_nosavefunction compute_e820_crc32function arch_hibernation_header_savefunction arch_hibernation_header_restorefunction relocate_restore_codefunction arch_resume_nosmt
Annotated Snippet
struct restore_data_record {
unsigned long jump_address;
unsigned long jump_address_phys;
unsigned long cr3;
unsigned long magic;
unsigned long e820_checksum;
};
/**
* compute_e820_crc32 - calculate crc32 of a given e820 table
*
* @table: the e820 table to be calculated
*
* Return: the resulting checksum
*/
static inline u32 compute_e820_crc32(struct e820_table *table)
{
int size = offsetof(struct e820_table, entries) +
sizeof(struct e820_entry) * table->nr_entries;
return ~crc32_le(~0, (unsigned char const *)table, size);
}
#ifdef CONFIG_X86_64
#define RESTORE_MAGIC 0x23456789ABCDEF02UL
#else
#define RESTORE_MAGIC 0x12345679UL
#endif
/**
* arch_hibernation_header_save - populate the architecture specific part
* of a hibernation image header
* @addr: address where architecture specific header data will be saved.
* @max_size: maximum size of architecture specific data in hibernation header.
*
* Return: 0 on success, -EOVERFLOW if max_size is insufficient.
*/
int arch_hibernation_header_save(void *addr, unsigned int max_size)
{
struct restore_data_record *rdr = addr;
if (max_size < sizeof(struct restore_data_record))
return -EOVERFLOW;
rdr->magic = RESTORE_MAGIC;
rdr->jump_address = (unsigned long)restore_registers;
rdr->jump_address_phys = __pa_symbol(restore_registers);
/*
* The restore code fixes up CR3 and CR4 in the following sequence:
*
* [in hibernation asm]
* 1. CR3 <= temporary page tables
* 2. CR4 <= mmu_cr4_features (from the kernel that restores us)
* 3. CR3 <= rdr->cr3
* 4. CR4 <= mmu_cr4_features (from us, i.e. the image kernel)
* [in restore_processor_state()]
* 5. CR4 <= saved CR4
* 6. CR3 <= saved CR3
*
* Our mmu_cr4_features has CR4.PCIDE=0, and toggling
* CR4.PCIDE while CR3's PCID bits are nonzero is illegal, so
* rdr->cr3 needs to point to valid page tables but must not
* have any of the PCID bits set.
*/
rdr->cr3 = restore_cr3 & ~CR3_PCID_MASK;
rdr->e820_checksum = compute_e820_crc32(e820_table_firmware);
return 0;
}
/**
* arch_hibernation_header_restore - read the architecture specific data
* from the hibernation image header
* @addr: address to read the data from
*/
int arch_hibernation_header_restore(void *addr)
{
struct restore_data_record *rdr = addr;
if (rdr->magic != RESTORE_MAGIC) {
pr_crit("Unrecognized hibernate image header format!\n");
return -EINVAL;
}
restore_jump_address = rdr->jump_address;
jump_address_phys = rdr->jump_address_phys;
restore_cr3 = rdr->cr3;
if (rdr->e820_checksum != compute_e820_crc32(e820_table_firmware)) {
pr_crit("Hibernate inconsistent memory map detected!\n");
Annotation
- Immediate include surface: `linux/gfp.h`, `linux/smp.h`, `linux/suspend.h`, `linux/scatterlist.h`, `linux/kdebug.h`, `linux/cpu.h`, `linux/pgtable.h`, `linux/types.h`.
- Detected declarations: `struct restore_data_record`, `function pfn_is_nosave`, `function compute_e820_crc32`, `function arch_hibernation_header_save`, `function arch_hibernation_header_restore`, `function relocate_restore_code`, `function arch_resume_nosmt`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.