drivers/power/reset/macsmc-reboot.c
Source file repositories/reference/linux-study-clean/drivers/power/reset/macsmc-reboot.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/reset/macsmc-reboot.c- Extension
.c- Size
- 8013 bytes
- Lines
- 291
- Domain
- Driver Families
- Bucket
- drivers/power
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- 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/delay.hlinux/mfd/core.hlinux/mfd/macsmc.hlinux/mod_devicetable.hlinux/module.hlinux/nvmem-consumer.hlinux/platform_device.hlinux/reboot.hlinux/slab.h
Detected Declarations
struct macsmc_reboot_nvmemstruct macsmc_rebootenum boot_stagefunction nvmem_cell_get_u8function nvmem_cell_set_u8function macsmc_prepare_atomicfunction macsmc_power_offfunction macsmc_restartfunction macsmc_reboot_notifyfunction macsmc_power_init_error_countsfunction macsmc_reboot_probe
Annotated Snippet
struct macsmc_reboot_nvmem {
struct nvmem_cell *shutdown_flag;
struct nvmem_cell *boot_stage;
struct nvmem_cell *boot_error_count;
struct nvmem_cell *panic_count;
};
static const char * const nvmem_names[] = {
"shutdown_flag",
"boot_stage",
"boot_error_count",
"panic_count",
};
enum boot_stage {
BOOT_STAGE_SHUTDOWN = 0x00, /* Clean shutdown */
BOOT_STAGE_IBOOT_DONE = 0x2f, /* Last stage of bootloader */
BOOT_STAGE_KERNEL_STARTED = 0x30, /* Normal OS booting */
};
struct macsmc_reboot {
struct device *dev;
struct apple_smc *smc;
struct notifier_block reboot_notify;
union {
struct macsmc_reboot_nvmem nvm;
struct nvmem_cell *nvm_cells[ARRAY_SIZE(nvmem_names)];
};
};
/* Helpers to read/write a u8 given a struct nvmem_cell */
static int nvmem_cell_get_u8(struct nvmem_cell *cell)
{
size_t len;
void *bfr;
u8 val;
bfr = nvmem_cell_read(cell, &len);
if (IS_ERR(bfr))
return PTR_ERR(bfr);
if (len < 1) {
kfree(bfr);
return -EINVAL;
}
val = *(u8 *)bfr;
kfree(bfr);
return val;
}
static int nvmem_cell_set_u8(struct nvmem_cell *cell, u8 val)
{
return nvmem_cell_write(cell, &val, sizeof(val));
}
/*
* SMC 'MBSE' key actions:
*
* 'offw' - shutdown warning
* 'slpw' - sleep warning
* 'rest' - restart warning
* 'off1' - shutdown (needs PMU bit set to stay on)
* 'susp' - suspend
* 'phra' - restart ("PE Halt Restart Action"?)
* 'panb' - panic beginning
* 'pane' - panic end
*/
static int macsmc_prepare_atomic(struct sys_off_data *data)
{
struct macsmc_reboot *reboot = data->cb_data;
dev_info(reboot->dev, "Preparing SMC for atomic mode\n");
apple_smc_enter_atomic(reboot->smc);
return NOTIFY_OK;
}
static int macsmc_power_off(struct sys_off_data *data)
{
struct macsmc_reboot *reboot = data->cb_data;
dev_info(reboot->dev, "Issuing power off (off1)\n");
if (apple_smc_write_u32_atomic(reboot->smc, SMC_KEY(MBSE), SMC_KEY(off1)) < 0) {
dev_err(reboot->dev, "Failed to issue MBSE = off1 (power_off)\n");
} else {
mdelay(100);
Annotation
- Immediate include surface: `linux/delay.h`, `linux/mfd/core.h`, `linux/mfd/macsmc.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/nvmem-consumer.h`, `linux/platform_device.h`, `linux/reboot.h`.
- Detected declarations: `struct macsmc_reboot_nvmem`, `struct macsmc_reboot`, `enum boot_stage`, `function nvmem_cell_get_u8`, `function nvmem_cell_set_u8`, `function macsmc_prepare_atomic`, `function macsmc_power_off`, `function macsmc_restart`, `function macsmc_reboot_notify`, `function macsmc_power_init_error_counts`.
- Atlas domain: Driver Families / drivers/power.
- 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.