arch/x86/power/cpu.c
Source file repositories/reference/linux-study-clean/arch/x86/power/cpu.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/power/cpu.c- Extension
.c- Size
- 13756 bytes
- Lines
- 524
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/suspend.hlinux/export.hlinux/smp.hlinux/perf_event.hlinux/tboot.hlinux/dmi.hlinux/pgtable.hasm/proto.hasm/mtrr.hasm/page.hasm/mce.hasm/suspend.hasm/fpu/api.hasm/debugreg.hasm/cpu.hasm/cacheinfo.hasm/mmu_context.hasm/cpu_device_id.hasm/microcode.hasm/msr.hasm/fred.h
Detected Declarations
struct msr_enumerationfunction msr_save_contextfunction msr_restore_contextfunction __save_processor_statefunction save_processor_statefunction do_fpu_endfunction fix_processor_contextfunction __restore_processor_statefunction pointerfunction restore_processor_statefunction resume_play_deadfunction hibernate_resume_nonboot_cpu_disablefunction bsp_checkfunction bsp_pm_callbackfunction bsp_pm_check_initfunction msr_build_contextfunction msr_initialize_bdwfunction msr_save_cpuid_featuresfunction pm_cpu_checkfunction pm_save_spec_msrfunction pm_check_save_msrmodule init bsp_pm_check_initmodule init pm_check_save_msrexport save_processor_stateexport restore_processor_state
Annotated Snippet
core_initcall(bsp_pm_check_init);
static int msr_build_context(const u32 *msr_id, const int num)
{
struct saved_msrs *saved_msrs = &saved_context.saved_msrs;
struct saved_msr *msr_array;
int total_num;
int i, j;
total_num = saved_msrs->num + num;
msr_array = kmalloc_objs(struct saved_msr, total_num);
if (!msr_array) {
pr_err("x86/pm: Can not allocate memory to save/restore MSRs during suspend.\n");
return -ENOMEM;
}
if (saved_msrs->array) {
/*
* Multiple callbacks can invoke this function, so copy any
* MSR save requests from previous invocations.
*/
memcpy(msr_array, saved_msrs->array,
sizeof(struct saved_msr) * saved_msrs->num);
kfree(saved_msrs->array);
}
for (i = saved_msrs->num, j = 0; i < total_num; i++, j++) {
u64 dummy;
msr_array[i].info.msr_no = msr_id[j];
msr_array[i].valid = !rdmsrq_safe(msr_id[j], &dummy);
msr_array[i].info.reg.q = 0;
}
saved_msrs->num = total_num;
saved_msrs->array = msr_array;
return 0;
}
/*
* The following sections are a quirk framework for problematic BIOSen:
* Sometimes MSRs are modified by the BIOSen after suspended to
* RAM, this might cause unexpected behavior after wakeup.
* Thus we save/restore these specified MSRs across suspend/resume
* in order to work around it.
*
* For any further problematic BIOSen/platforms,
* please add your own function similar to msr_initialize_bdw.
*/
static int msr_initialize_bdw(const struct dmi_system_id *d)
{
/* Add any extra MSR ids into this array. */
u32 bdw_msr_id[] = { MSR_IA32_THERM_CONTROL };
pr_info("x86/pm: %s detected, MSR saving is needed during suspending.\n", d->ident);
return msr_build_context(bdw_msr_id, ARRAY_SIZE(bdw_msr_id));
}
static const struct dmi_system_id msr_save_dmi_table[] = {
{
.callback = msr_initialize_bdw,
.ident = "BROADWELL BDX_EP",
.matches = {
DMI_MATCH(DMI_PRODUCT_NAME, "GRANTLEY"),
DMI_MATCH(DMI_PRODUCT_VERSION, "E63448-400"),
},
},
{}
};
static int msr_save_cpuid_features(const struct x86_cpu_id *c)
{
u32 cpuid_msr_id[] = {
MSR_AMD64_CPUID_FN_1,
};
pr_info("x86/pm: family %#hx cpu detected, MSR saving is needed during suspending.\n",
c->family);
return msr_build_context(cpuid_msr_id, ARRAY_SIZE(cpuid_msr_id));
}
static const struct x86_cpu_id msr_save_cpu_table[] = {
X86_MATCH_VENDOR_FAM(AMD, 0x15, &msr_save_cpuid_features),
X86_MATCH_VENDOR_FAM(AMD, 0x16, &msr_save_cpuid_features),
{}
};
Annotation
- Immediate include surface: `linux/suspend.h`, `linux/export.h`, `linux/smp.h`, `linux/perf_event.h`, `linux/tboot.h`, `linux/dmi.h`, `linux/pgtable.h`, `asm/proto.h`.
- Detected declarations: `struct msr_enumeration`, `function msr_save_context`, `function msr_restore_context`, `function __save_processor_state`, `function save_processor_state`, `function do_fpu_end`, `function fix_processor_context`, `function __restore_processor_state`, `function pointer`, `function restore_processor_state`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: integration 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.