drivers/nvme/host/apple.c
Source file repositories/reference/linux-study-clean/drivers/nvme/host/apple.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/nvme/host/apple.c- Extension
.c- Size
- 46090 bytes
- Lines
- 1725
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/async.hlinux/blkdev.hlinux/blk-mq.hlinux/device.hlinux/dma-mapping.hlinux/dmapool.hlinux/interrupt.hlinux/io-64-nonatomic-lo-hi.hlinux/io.hlinux/iopoll.hlinux/jiffies.hlinux/mempool.hlinux/module.hlinux/of.hlinux/of_platform.hlinux/once.hlinux/platform_device.hlinux/pm_domain.hlinux/soc/apple/rtkit.hlinux/soc/apple/sart.hlinux/reset.hlinux/time64.hnvme.h
Detected Declarations
struct apple_nvmmu_tcbstruct apple_nvme_queuestruct apple_nvme_iodstruct apple_nvme_hwstruct apple_nvmefunction apple_nvme_queue_depthfunction apple_nvme_rtkit_crashedfunction apple_nvme_sart_dma_setupfunction apple_nvme_sart_dma_destroyfunction apple_nvmmu_invalfunction apple_nvme_submit_cmd_t8015function apple_nvme_submit_cmd_t8103function apple_nvme_iod_alloc_sizefunction apple_nvme_free_prpsfunction apple_nvme_unmap_datafunction apple_nvme_print_sglfunction for_each_sgfunction apple_nvme_setup_prpsfunction apple_nvme_setup_prp_simplefunction apple_nvme_map_datafunction apple_nvme_unmap_rqfunction apple_nvme_complete_rqfunction apple_nvme_complete_batchfunction apple_nvme_cqe_pendingfunction apple_nvme_queue_tagsetfunction apple_nvme_handle_cqefunction apple_nvme_update_cq_headfunction apple_nvme_poll_cqfunction apple_nvme_handle_cqfunction apple_nvme_irqfunction apple_nvme_create_cqfunction apple_nvme_remove_cqfunction apple_nvme_create_sqfunction apple_nvme_remove_sqfunction apple_nvme_queue_rqfunction apple_nvme_init_hctxfunction apple_nvme_init_requestfunction apple_nvme_disablefunction apple_nvme_timeoutfunction apple_nvme_pollfunction apple_nvme_init_queuefunction apple_nvme_reset_workfunction apple_nvme_remove_dead_ctrl_workfunction apple_nvme_reg_read32function apple_nvme_reg_write32function apple_nvme_reg_read64function apple_nvme_get_addressfunction apple_nvme_free_ctrl
Annotated Snippet
static const struct blk_mq_ops apple_nvme_mq_admin_ops = {
.queue_rq = apple_nvme_queue_rq,
.complete = apple_nvme_complete_rq,
.init_hctx = apple_nvme_init_hctx,
.init_request = apple_nvme_init_request,
.timeout = apple_nvme_timeout,
};
static const struct blk_mq_ops apple_nvme_mq_ops = {
.queue_rq = apple_nvme_queue_rq,
.complete = apple_nvme_complete_rq,
.init_hctx = apple_nvme_init_hctx,
.init_request = apple_nvme_init_request,
.timeout = apple_nvme_timeout,
.poll = apple_nvme_poll,
};
static void apple_nvme_init_queue(struct apple_nvme_queue *q)
{
unsigned int depth = apple_nvme_queue_depth(q);
struct apple_nvme *anv = queue_to_apple_nvme(q);
q->sq_tail = 0;
q->cq_head = 0;
q->cq_phase = 1;
if (anv->hw->has_lsq_nvmmu)
memset(q->tcbs, 0, anv->hw->max_queue_depth
* sizeof(struct apple_nvmmu_tcb));
memset(q->cqes, 0, depth * sizeof(struct nvme_completion));
WRITE_ONCE(q->enabled, true);
wmb(); /* ensure the first interrupt sees the initialization */
}
static void apple_nvme_reset_work(struct work_struct *work)
{
unsigned int nr_io_queues = 1;
int ret;
u32 boot_status, aqa;
struct apple_nvme *anv =
container_of(work, struct apple_nvme, ctrl.reset_work);
enum nvme_ctrl_state state = nvme_ctrl_state(&anv->ctrl);
if (state != NVME_CTRL_RESETTING) {
dev_warn(anv->dev, "ctrl state %d is not RESETTING\n", state);
ret = -ENODEV;
goto out;
}
/* there's unfortunately no known way to recover if RTKit crashed :( */
if (apple_rtkit_is_crashed(anv->rtk)) {
dev_err(anv->dev,
"RTKit has crashed without any way to recover.");
ret = -EIO;
goto out;
}
/* RTKit must be shut down cleanly for the (soft)-reset to work */
if (apple_rtkit_is_running(anv->rtk)) {
/* reset the controller if it is enabled */
if (anv->ctrl.ctrl_config & NVME_CC_ENABLE)
apple_nvme_disable(anv, false);
dev_dbg(anv->dev, "Trying to shut down RTKit before reset.");
ret = apple_rtkit_shutdown(anv->rtk);
if (ret)
goto out;
writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
}
/*
* Only do the soft-reset if the CPU is not running, which means either we
* or the previous stage shut it down cleanly.
*/
if (!(readl(anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL) &
APPLE_ANS_COPROC_CPU_CONTROL_RUN)) {
ret = reset_control_assert(anv->reset);
if (ret)
goto out;
ret = apple_rtkit_reinit(anv->rtk);
if (ret)
goto out;
ret = reset_control_deassert(anv->reset);
if (ret)
goto out;
writel(APPLE_ANS_COPROC_CPU_CONTROL_RUN,
anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL);
Annotation
- Immediate include surface: `linux/async.h`, `linux/blkdev.h`, `linux/blk-mq.h`, `linux/device.h`, `linux/dma-mapping.h`, `linux/dmapool.h`, `linux/interrupt.h`, `linux/io-64-nonatomic-lo-hi.h`.
- Detected declarations: `struct apple_nvmmu_tcb`, `struct apple_nvme_queue`, `struct apple_nvme_iod`, `struct apple_nvme_hw`, `struct apple_nvme`, `function apple_nvme_queue_depth`, `function apple_nvme_rtkit_crashed`, `function apple_nvme_sart_dma_setup`, `function apple_nvme_sart_dma_destroy`, `function apple_nvmmu_inval`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.