drivers/bus/fsl-mc/mc-sys.c
Source file repositories/reference/linux-study-clean/drivers/bus/fsl-mc/mc-sys.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/bus/fsl-mc/mc-sys.c- Extension
.c- Size
- 8614 bytes
- Lines
- 298
- Domain
- Driver Families
- Bucket
- drivers/bus
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/delay.hlinux/slab.hlinux/ioport.hlinux/device.hlinux/io.hlinux/io-64-nonatomic-hi-lo.hlinux/fsl/mc.hfsl-mc-private.h
Detected Declarations
function usleep_rangefunction mc_cmd_hdr_read_cmdidfunction mc_status_to_errorfunction mc_write_commandfunction mc_read_responsefunction mc_polling_wait_preemptiblefunction mc_polling_wait_atomicfunction mc_send_commandexport mc_send_command
Annotated Snippet
if (time_after_eq(jiffies, jiffies_until_timeout)) {
dev_dbg(mc_io->dev,
"MC command timed out (portal: %pa, dprc handle: %#x, command: %#x)\n",
&mc_io->portal_phys_addr,
(unsigned int)mc_cmd_hdr_read_token(cmd),
(unsigned int)mc_cmd_hdr_read_cmdid(cmd));
return -ETIMEDOUT;
}
}
*mc_status = status;
return 0;
}
/**
* mc_polling_wait_atomic() - Waits for the completion of an MC command
* doing atomic polling. udelay() is called
* between polling iterations.
* @mc_io: MC I/O object to be used
* @cmd: command buffer to receive MC response
* @mc_status: MC command completion status
*/
static int mc_polling_wait_atomic(struct fsl_mc_io *mc_io,
struct fsl_mc_command *cmd,
enum mc_cmd_status *mc_status)
{
enum mc_cmd_status status;
unsigned long timeout_usecs = MC_CMD_COMPLETION_TIMEOUT_MS * 1000;
BUILD_BUG_ON((MC_CMD_COMPLETION_TIMEOUT_MS * 1000) %
MC_CMD_COMPLETION_POLLING_MAX_SLEEP_USECS != 0);
for (;;) {
status = mc_read_response(mc_io->portal_virt_addr, cmd);
if (status != MC_CMD_STATUS_READY)
break;
udelay(MC_CMD_COMPLETION_POLLING_MAX_SLEEP_USECS);
timeout_usecs -= MC_CMD_COMPLETION_POLLING_MAX_SLEEP_USECS;
if (timeout_usecs == 0) {
dev_dbg(mc_io->dev,
"MC command timed out (portal: %pa, dprc handle: %#x, command: %#x)\n",
&mc_io->portal_phys_addr,
(unsigned int)mc_cmd_hdr_read_token(cmd),
(unsigned int)mc_cmd_hdr_read_cmdid(cmd));
return -ETIMEDOUT;
}
}
*mc_status = status;
return 0;
}
/**
* mc_send_command() - Sends a command to the MC device using the given
* MC I/O object
* @mc_io: MC I/O object to be used
* @cmd: command to be sent
*
* Returns '0' on Success; Error code otherwise.
*/
int mc_send_command(struct fsl_mc_io *mc_io, struct fsl_mc_command *cmd)
{
int error;
enum mc_cmd_status status;
unsigned long irq_flags = 0;
if (in_hardirq() && !(mc_io->flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL))
return -EINVAL;
if (mc_io->flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL)
raw_spin_lock_irqsave(&mc_io->spinlock, irq_flags);
else
mutex_lock(&mc_io->mutex);
/*
* Send command to the MC hardware:
*/
mc_write_command(mc_io->portal_virt_addr, cmd);
/*
* Wait for response from the MC hardware:
*/
if (!(mc_io->flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL))
error = mc_polling_wait_preemptible(mc_io, cmd, &status);
else
error = mc_polling_wait_atomic(mc_io, cmd, &status);
Annotation
- Immediate include surface: `linux/delay.h`, `linux/slab.h`, `linux/ioport.h`, `linux/device.h`, `linux/io.h`, `linux/io-64-nonatomic-hi-lo.h`, `linux/fsl/mc.h`, `fsl-mc-private.h`.
- Detected declarations: `function usleep_range`, `function mc_cmd_hdr_read_cmdid`, `function mc_status_to_error`, `function mc_write_command`, `function mc_read_response`, `function mc_polling_wait_preemptible`, `function mc_polling_wait_atomic`, `function mc_send_command`, `export mc_send_command`.
- Atlas domain: Driver Families / drivers/bus.
- 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.