drivers/mmc/core/block.c
Source file repositories/reference/linux-study-clean/drivers/mmc/core/block.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mmc/core/block.c- Extension
.c- Size
- 86446 bytes
- Lines
- 3389
- Domain
- Driver Families
- Bucket
- drivers/mmc
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/moduleparam.hlinux/module.hlinux/init.hlinux/kernel.hlinux/fs.hlinux/slab.hlinux/errno.hlinux/hdreg.hlinux/kdev_t.hlinux/kref.hlinux/blkdev.hlinux/cdev.hlinux/mutex.hlinux/scatterlist.hlinux/string.hlinux/string_helpers.hlinux/delay.hlinux/capability.hlinux/compat.hlinux/pm_runtime.hlinux/idr.hlinux/debugfs.hlinux/rpmb.hlinux/mmc/ioctl.hlinux/mmc/card.hlinux/mmc/host.hlinux/mmc/mmc.hlinux/mmc/sd.hlinux/uaccess.hlinux/unaligned.hqueue.hblock.h
Detected Declarations
struct mmc_blk_busy_datastruct mmc_blk_datastruct mmc_rpmb_datastruct mmc_blk_ioc_datafunction mmc_get_devidxfunction mmc_blk_kref_releasefunction mmc_blk_putfunction power_ro_lock_showfunction power_ro_lock_storefunction list_for_each_entryfunction force_ro_showfunction force_ro_storefunction mmc_disk_attrs_is_visiblefunction mmc_blk_openfunction mmc_blk_releasefunction mmc_blk_getgeofunction mmc_blk_ioctl_copy_to_userfunction __mmc_blk_ioctl_cmdfunction ioctlfunction mmc_blk_ioctl_cmdfunction mmc_blk_ioctl_multi_cmdfunction mmc_blk_check_blkdevfunction mmc_blk_ioctlfunction mmc_blk_compat_ioctlfunction mmc_blk_alternative_gpt_sectorfunction mmc_blk_part_switch_prefunction mmc_blk_part_switch_postfunction mmc_blk_part_switchfunction mmc_sd_num_wr_blocksfunction mmc_blk_clock_khzfunction mmc_blk_data_timeout_msfunction mmc_blk_resetfunction mmc_blk_reset_successfunction mmc_blk_check_sbcfunction mmc_blk_issue_drv_opfunction mmc_blk_issue_erase_rqfunction mmc_blk_issue_trim_rqfunction mmc_blk_issue_discard_rqfunction mmc_blk_issue_secdiscard_rqfunction mmc_blk_issue_flushfunction mmc_apply_rel_rwfunction mmc_blk_eval_resp_errorfunction specificationfunction mmc_blk_data_prepfunction for_each_sgfunction mmc_blk_cqe_complete_rqfunction mmc_blk_cqe_recoveryfunction mmc_blk_cqe_req_done
Annotated Snippet
static const struct bus_type mmc_rpmb_bus_type = {
.name = "mmc_rpmb",
};
/**
* struct mmc_rpmb_data - special RPMB device type for these areas
* @dev: the device for the RPMB area
* @chrdev: character device for the RPMB area
* @id: unique device ID number
* @part_index: partition index (0 on first)
* @md: parent MMC block device
* @rdev: registered RPMB device
* @node: list item, so we can put this device on a list
*/
struct mmc_rpmb_data {
struct device dev;
struct cdev chrdev;
int id;
unsigned int part_index;
struct mmc_blk_data *md;
struct rpmb_dev *rdev;
struct list_head node;
};
static DEFINE_MUTEX(open_lock);
module_param(perdev_minors, int, 0444);
MODULE_PARM_DESC(perdev_minors, "Minors numbers to allocate per device");
static inline int mmc_blk_part_switch(struct mmc_card *card,
unsigned int part_type);
static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
struct mmc_card *card,
int recovery_mode,
struct mmc_queue *mq);
static void mmc_blk_hsq_req_done(struct mmc_request *mrq);
static int mmc_spi_err_check(struct mmc_card *card);
static int mmc_blk_busy_cb(void *cb_data, bool *busy);
static struct mmc_blk_data *mmc_blk_get(struct gendisk *disk)
{
struct mmc_blk_data *md;
mutex_lock(&open_lock);
md = disk->private_data;
if (md && !kref_get_unless_zero(&md->kref))
md = NULL;
mutex_unlock(&open_lock);
return md;
}
static inline int mmc_get_devidx(struct gendisk *disk)
{
int devidx = disk->first_minor / perdev_minors;
return devidx;
}
static void mmc_blk_kref_release(struct kref *ref)
{
struct mmc_blk_data *md = container_of(ref, struct mmc_blk_data, kref);
int devidx;
devidx = mmc_get_devidx(md->disk);
ida_free(&mmc_blk_ida, devidx);
mutex_lock(&open_lock);
md->disk->private_data = NULL;
mutex_unlock(&open_lock);
put_disk(md->disk);
kfree(md);
}
static void mmc_blk_put(struct mmc_blk_data *md)
{
kref_put(&md->kref, mmc_blk_kref_release);
}
static ssize_t power_ro_lock_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int ret;
struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev));
struct mmc_card *card = md->queue.card;
int locked = 0;
if (card->ext_csd.boot_ro_lock & EXT_CSD_BOOT_WP_B_PERM_WP_EN)
locked = 2;
else if (card->ext_csd.boot_ro_lock & EXT_CSD_BOOT_WP_B_PWR_WP_EN)
Annotation
- Immediate include surface: `linux/moduleparam.h`, `linux/module.h`, `linux/init.h`, `linux/kernel.h`, `linux/fs.h`, `linux/slab.h`, `linux/errno.h`, `linux/hdreg.h`.
- Detected declarations: `struct mmc_blk_busy_data`, `struct mmc_blk_data`, `struct mmc_rpmb_data`, `struct mmc_blk_ioc_data`, `function mmc_get_devidx`, `function mmc_blk_kref_release`, `function mmc_blk_put`, `function power_ro_lock_show`, `function power_ro_lock_store`, `function list_for_each_entry`.
- Atlas domain: Driver Families / drivers/mmc.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.