drivers/ata/libata-core.c
Source file repositories/reference/linux-study-clean/drivers/ata/libata-core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/ata/libata-core.c- Extension
.c- Size
- 180613 bytes
- Lines
- 6937
- Domain
- Driver Families
- Bucket
- drivers/ata
- 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.
- 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/kernel.hlinux/module.hlinux/pci.hlinux/init.hlinux/list.hlinux/mm.hlinux/spinlock.hlinux/blkdev.hlinux/delay.hlinux/timer.hlinux/time.hlinux/interrupt.hlinux/completion.hlinux/suspend.hlinux/workqueue.hlinux/scatterlist.hlinux/io.hlinux/log2.hlinux/slab.hlinux/glob.hscsi/scsi.hscsi/scsi_cmnd.hscsi/scsi_host.hlinux/libata.hasm/byteorder.hlinux/unaligned.hlinux/cdrom.hlinux/ratelimit.hlinux/leds.hlinux/pm_runtime.hlinux/platform_device.hasm/setup.h
Detected Declarations
struct ata_force_paramstruct ata_force_entstruct ata_dev_quirk_valuestruct ata_dev_quirks_entryfunction ata_dev_print_infofunction ata_force_cblfunction ata_force_pflagsfunction ata_force_link_limitsfunction ata_force_xfermaskfunction ata_force_get_fe_for_devfunction ata_force_quirksfunction ata_force_pflagsfunction ata_set_rwcmd_protocolfunction ata_tf_read_blockfunction ata_set_tf_cdlfunction ata_build_rw_tffunction ata_pack_xfermaskfunction ata_unpack_xfermaskfunction ata_xfer_mask2modefunction ata_xfer_mode2maskfunction ata_xfer_mode2shiftfunction ata_dev_classifyfunction ata_id_stringfunction ata_id_c_stringfunction ata_id_n_sectorsfunction ata_tf_to_lba48function ata_tf_to_lbafunction ata_read_native_max_addressfunction ata_set_max_sectorsfunction ata_hpa_resizefunction ata_dump_idfunction ata_id_xfermaskfunction ata_qc_complete_internalfunction ata_exec_internalfunction ata_pio_need_iordyfunction ata_pio_mask_no_iordyfunction ata_do_dev_read_idfunction contextfunction ata_dev_power_init_tffunction ata_dev_power_is_activefunction contextfunction contextfunction contextfunction ata_clear_log_directoryfunction ata_read_log_directoryfunction ata_log_supportedfunction ata_identify_page_supportedfunction ata_do_link_spd_quirk
Annotated Snippet
subsys_initcall(ata_init);
module_exit(ata_exit);
static DEFINE_RATELIMIT_STATE(ratelimit, HZ / 5, 1);
int ata_ratelimit(void)
{
return __ratelimit(&ratelimit);
}
EXPORT_SYMBOL_GPL(ata_ratelimit);
/**
* ata_msleep - ATA EH owner aware msleep
* @ap: ATA port to attribute the sleep to
* @msecs: duration to sleep in milliseconds
*
* Sleeps @msecs. If the current task is owner of @ap's EH, the
* ownership is released before going to sleep and reacquired
* after the sleep is complete. IOW, other ports sharing the
* @ap->host will be allowed to own the EH while this task is
* sleeping.
*
* LOCKING:
* Might sleep.
*/
void ata_msleep(struct ata_port *ap, unsigned int msecs)
__context_unsafe(conditional locking)
{
bool owns_eh = ap && ap->host->eh_owner == current;
if (owns_eh)
ata_eh_release(ap);
if (msecs < 20) {
unsigned long usecs = msecs * USEC_PER_MSEC;
usleep_range(usecs, usecs + 50);
} else {
msleep(msecs);
}
if (owns_eh)
ata_eh_acquire(ap);
}
EXPORT_SYMBOL_GPL(ata_msleep);
/**
* ata_wait_register - wait until register value changes
* @ap: ATA port to wait register for, can be NULL
* @reg: IO-mapped register
* @mask: Mask to apply to read register value
* @val: Wait condition
* @interval: polling interval in milliseconds
* @timeout: timeout in milliseconds
*
* Waiting for some bits of register to change is a common
* operation for ATA controllers. This function reads 32bit LE
* IO-mapped register @reg and tests for the following condition.
*
* (*@reg & mask) != val
*
* If the condition is met, it returns; otherwise, the process is
* repeated after @interval_msec until timeout.
*
* LOCKING:
* Kernel thread context (may sleep)
*
* RETURNS:
* The final register value.
*/
u32 ata_wait_register(struct ata_port *ap, void __iomem *reg, u32 mask, u32 val,
unsigned int interval, unsigned int timeout)
{
unsigned long deadline;
u32 tmp;
tmp = ioread32(reg);
/* Calculate timeout _after_ the first read to make sure
* preceding writes reach the controller before starting to
* eat away the timeout.
*/
deadline = ata_deadline(jiffies, timeout);
while ((tmp & mask) == val && time_before(jiffies, deadline)) {
ata_msleep(ap, interval);
tmp = ioread32(reg);
}
return tmp;
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/pci.h`, `linux/init.h`, `linux/list.h`, `linux/mm.h`, `linux/spinlock.h`, `linux/blkdev.h`.
- Detected declarations: `struct ata_force_param`, `struct ata_force_ent`, `struct ata_dev_quirk_value`, `struct ata_dev_quirks_entry`, `function ata_dev_print_info`, `function ata_force_cbl`, `function ata_force_pflags`, `function ata_force_link_limits`, `function ata_force_xfermask`, `function ata_force_get_fe_for_dev`.
- Atlas domain: Driver Families / drivers/ata.
- Implementation status: integration 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.