drivers/mfd/macsmc.c
Source file repositories/reference/linux-study-clean/drivers/mfd/macsmc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mfd/macsmc.c- Extension
.c- Size
- 13443 bytes
- Lines
- 505
- Domain
- Driver Families
- Bucket
- drivers/mfd
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/bitfield.hlinux/delay.hlinux/device.hlinux/io.hlinux/ioport.hlinux/math.hlinux/mfd/core.hlinux/mfd/macsmc.hlinux/notifier.hlinux/of.hlinux/of_platform.hlinux/overflow.hlinux/platform_device.hlinux/soc/apple/rtkit.hlinux/unaligned.h
Detected Declarations
function apple_smc_cmd_lockedfunction apple_smc_cmdfunction apple_smc_rw_lockedfunction apple_smc_readfunction apple_smc_writefunction apple_smc_rwfunction apple_smc_get_key_by_indexfunction apple_smc_get_key_infofunction apple_smc_enter_atomicfunction apple_smc_write_atomicfunction apple_smc_rtkit_crashedfunction apple_smc_rtkit_shmem_setupfunction apple_smc_rtkit_recv_earlyfunction apple_smc_rtkit_recvfunction apple_smc_rtkit_shutdownfunction apple_smc_disable_notificationsfunction apple_smc_probeexport apple_smc_readexport apple_smc_writeexport apple_smc_rwexport apple_smc_get_key_by_indexexport apple_smc_get_key_infoexport apple_smc_enter_atomicexport apple_smc_write_atomic
Annotated Snippet
if (ret < 0) {
dev_err(smc->dev, "RTKit poll failed (%llx)", msg);
return ret;
}
udelay(100);
}
if (FIELD_GET(SMC_ID, smc->cmd_ret) != smc->msg_id) {
dev_err(smc->dev, "Command sequence mismatch (expected %d, got %d)\n",
smc->msg_id, (unsigned int)FIELD_GET(SMC_ID, smc->cmd_ret));
return -EIO;
}
result = FIELD_GET(SMC_RESULT, smc->cmd_ret);
if (result)
return -EIO;
return FIELD_GET(SMC_SIZE, smc->cmd_ret);
}
EXPORT_SYMBOL(apple_smc_write_atomic);
static void apple_smc_rtkit_crashed(void *cookie, const void *bfr, size_t bfr_len)
{
struct apple_smc *smc = cookie;
smc->boot_stage = APPLE_SMC_ERROR_CRASHED;
dev_err(smc->dev, "SMC crashed! Your system will reboot in a few seconds...\n");
}
static int apple_smc_rtkit_shmem_setup(void *cookie, struct apple_rtkit_shmem *bfr)
{
struct apple_smc *smc = cookie;
size_t bfr_end;
if (!bfr->iova) {
dev_err(smc->dev, "RTKit wants a RAM buffer\n");
return -EIO;
}
if (check_add_overflow(bfr->iova, bfr->size - 1, &bfr_end))
return -EFAULT;
if (bfr->iova < smc->sram->start || bfr->iova > smc->sram->end ||
bfr_end > smc->sram->end) {
dev_err(smc->dev, "RTKit buffer request outside SRAM region: [0x%llx, 0x%llx]\n",
(unsigned long long)bfr->iova,
(unsigned long long)bfr_end);
return -EFAULT;
}
bfr->iomem = smc->sram_base + (bfr->iova - smc->sram->start);
bfr->is_mapped = true;
return 0;
}
static bool apple_smc_rtkit_recv_early(void *cookie, u8 endpoint, u64 message)
{
struct apple_smc *smc = cookie;
if (endpoint != SMC_ENDPOINT) {
dev_warn(smc->dev, "Received message for unknown endpoint 0x%x\n", endpoint);
return false;
}
if (smc->boot_stage == APPLE_SMC_BOOTING) {
int ret;
smc->shmem.iova = message;
smc->shmem.size = SMC_SHMEM_SIZE;
ret = apple_smc_rtkit_shmem_setup(smc, &smc->shmem);
if (ret < 0) {
smc->boot_stage = APPLE_SMC_ERROR_NO_SHMEM;
dev_err(smc->dev, "Failed to initialize shared memory (%d)\n", ret);
} else {
smc->boot_stage = APPLE_SMC_INITIALIZED;
}
complete(&smc->init_done);
} else if (FIELD_GET(SMC_MSG, message) == SMC_MSG_NOTIFICATION) {
/* Handle these in the RTKit worker thread */
return false;
} else {
smc->cmd_ret = message;
if (smc->atomic_pending)
smc->atomic_pending = false;
else
complete(&smc->cmd_done);
}
return true;
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/delay.h`, `linux/device.h`, `linux/io.h`, `linux/ioport.h`, `linux/math.h`, `linux/mfd/core.h`, `linux/mfd/macsmc.h`.
- Detected declarations: `function apple_smc_cmd_locked`, `function apple_smc_cmd`, `function apple_smc_rw_locked`, `function apple_smc_read`, `function apple_smc_write`, `function apple_smc_rw`, `function apple_smc_get_key_by_index`, `function apple_smc_get_key_info`, `function apple_smc_enter_atomic`, `function apple_smc_write_atomic`.
- Atlas domain: Driver Families / drivers/mfd.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.