drivers/mmc/core/sd_ops.c
Source file repositories/reference/linux-study-clean/drivers/mmc/core/sd_ops.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mmc/core/sd_ops.c- Extension
.c- Size
- 8620 bytes
- Lines
- 420
- Domain
- Driver Families
- Bucket
- drivers/mmc
- 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.
- 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/slab.hlinux/types.hlinux/export.hlinux/scatterlist.hlinux/mmc/host.hlinux/mmc/card.hlinux/mmc/mmc.hlinux/mmc/sd.hcore.hcard.hsd_ops.hmmc_ops.h
Detected Declarations
struct sd_app_op_cond_busy_datafunction mmc_app_cmdfunction mmc_wait_for_app_cmdfunction mmc_app_set_bus_widthfunction sd_app_op_cond_cbfunction mmc_send_app_op_condfunction mmc_send_ext_addrfunction __mmc_send_if_condfunction mmc_send_if_condfunction mmc_send_if_cond_pciefunction mmc_send_relative_addrfunction mmc_app_send_scrfunction mmc_sd_switchfunction mmc_app_sd_statusexport mmc_app_cmdexport mmc_sd_switch
Annotated Snippet
struct sd_app_op_cond_busy_data {
struct mmc_host *host;
u32 ocr;
struct mmc_command *cmd;
};
int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card)
{
int err;
struct mmc_command cmd = {};
if (WARN_ON(card && card->host != host))
return -EINVAL;
/*
* UHS2 packet has APP bit so only set APP_CMD flag here.
* Will set the APP bit when assembling UHS2 packet.
*/
if (host->uhs2_sd_tran) {
host->uhs2_app_cmd = true;
return 0;
}
cmd.opcode = MMC_APP_CMD;
if (card) {
cmd.arg = card->rca << 16;
cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
} else {
cmd.arg = 0;
cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_BCR;
}
err = mmc_wait_for_cmd(host, &cmd, 0);
if (err)
return err;
/* Check that card supported application commands */
if (!mmc_host_is_spi(host) && !(cmd.resp[0] & R1_APP_CMD))
return -EOPNOTSUPP;
return 0;
}
EXPORT_SYMBOL_GPL(mmc_app_cmd);
static int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card,
struct mmc_command *cmd)
{
struct mmc_request mrq = {};
int i, err = -EIO;
/*
* We have to resend MMC_APP_CMD for each attempt so
* we cannot use the retries field in mmc_command.
*/
for (i = 0; i <= MMC_CMD_RETRIES; i++) {
err = mmc_app_cmd(host, card);
if (err) {
/* no point in retrying; no APP commands allowed */
if (mmc_host_is_spi(host)) {
if (cmd->resp[0] & R1_SPI_ILLEGAL_COMMAND)
break;
}
continue;
}
memset(&mrq, 0, sizeof(struct mmc_request));
memset(cmd->resp, 0, sizeof(cmd->resp));
cmd->retries = 0;
mrq.cmd = cmd;
cmd->data = NULL;
mmc_wait_for_req(host, &mrq);
err = cmd->error;
if (!cmd->error)
break;
/* no point in retrying illegal APP commands */
if (mmc_host_is_spi(host)) {
if (cmd->resp[0] & R1_SPI_ILLEGAL_COMMAND)
break;
}
}
return err;
}
Annotation
- Immediate include surface: `linux/slab.h`, `linux/types.h`, `linux/export.h`, `linux/scatterlist.h`, `linux/mmc/host.h`, `linux/mmc/card.h`, `linux/mmc/mmc.h`, `linux/mmc/sd.h`.
- Detected declarations: `struct sd_app_op_cond_busy_data`, `function mmc_app_cmd`, `function mmc_wait_for_app_cmd`, `function mmc_app_set_bus_width`, `function sd_app_op_cond_cb`, `function mmc_send_app_op_cond`, `function mmc_send_ext_addr`, `function __mmc_send_if_cond`, `function mmc_send_if_cond`, `function mmc_send_if_cond_pcie`.
- Atlas domain: Driver Families / drivers/mmc.
- 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.