drivers/mtd/nand/raw/nand_base.c
Source file repositories/reference/linux-study-clean/drivers/mtd/nand/raw/nand_base.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/nand/raw/nand_base.c- Extension
.c- Size
- 175661 bytes
- Lines
- 6610
- Domain
- Driver Families
- Bucket
- drivers/mtd
- 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.
- 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/module.hlinux/delay.hlinux/errno.hlinux/err.hlinux/sched.hlinux/slab.hlinux/mm.hlinux/types.hlinux/mtd/mtd.hlinux/mtd/nand.hlinux/mtd/nand-ecc-sw-hamming.hlinux/mtd/nand-ecc-sw-bch.hlinux/interrupt.hlinux/bitops.hlinux/io.hlinux/mtd/partitions.hlinux/of.hlinux/gpio/consumer.hlinux/cleanup.hinternals.h
Detected Declarations
struct nand_op_parser_ctxenum nand_ecc_legacy_modefunction Copyrightfunction nand_pairing_dist3_get_wunitfunction check_offs_lenfunction anotherfunction nand_select_targetfunction nand_deselect_targetfunction nand_release_devicefunction nand_bbm_get_next_pagefunction nand_block_badfunction nand_region_is_securedfunction nand_isbad_bbmfunction nand_get_devicefunction nand_check_wpfunction nand_do_write_oobfunction nand_default_block_markbadfunction nand_markbad_bbmfunction stepsfunction nand_block_isreservedfunction nand_block_checkbadfunction nand_soft_waitrdyfunction nand_gpio_waitrdyfunction panic_nand_waitfunction nand_supports_get_featuresfunction nand_supports_set_featuresfunction nand_reset_interfacefunction nand_setup_interfacefunction nand_choose_best_sdr_timingsfunction nand_choose_best_nvddr_timingsfunction nand_choose_best_timingsfunction nand_choose_interface_configfunction nand_fill_column_cyclesfunction nand_sp_exec_read_page_opfunction nand_lp_exec_read_page_opfunction rawnand_last_page_of_blockfunction rawnand_cap_cont_readsfunction nand_lp_exec_cont_read_page_opfunction rawnand_cont_read_ongoingfunction nand_read_page_opfunction nand_read_param_page_opfunction nand_change_read_column_opfunction nand_read_oob_opfunction nand_exec_prog_page_opfunction nand_prog_page_begin_opfunction nand_prog_page_end_opfunction nand_prog_page_opfunction nand_change_write_column_op
Annotated Snippet
struct nand_op_parser_ctx {
const struct nand_op_instr *instrs;
unsigned int ninstrs;
struct nand_subop subop;
};
/**
* nand_op_parser_must_split_instr - Checks if an instruction must be split
* @pat: the parser pattern element that matches @instr
* @instr: pointer to the instruction to check
* @start_offset: this is an in/out parameter. If @instr has already been
* split, then @start_offset is the offset from which to start
* (either an address cycle or an offset in the data buffer).
* Conversely, if the function returns true (ie. instr must be
* split), this parameter is updated to point to the first
* data/address cycle that has not been taken care of.
*
* Some NAND controllers are limited and cannot send X address cycles with a
* unique operation, or cannot read/write more than Y bytes at the same time.
* In this case, split the instruction that does not fit in a single
* controller-operation into two or more chunks.
*
* Returns true if the instruction must be split, false otherwise.
* The @start_offset parameter is also updated to the offset at which the next
* bundle of instruction must start (if an address or a data instruction).
*/
static bool
nand_op_parser_must_split_instr(const struct nand_op_parser_pattern_elem *pat,
const struct nand_op_instr *instr,
unsigned int *start_offset)
{
switch (pat->type) {
case NAND_OP_ADDR_INSTR:
if (!pat->ctx.addr.maxcycles)
break;
if (instr->ctx.addr.naddrs - *start_offset >
pat->ctx.addr.maxcycles) {
*start_offset += pat->ctx.addr.maxcycles;
return true;
}
break;
case NAND_OP_DATA_IN_INSTR:
case NAND_OP_DATA_OUT_INSTR:
if (!pat->ctx.data.maxlen)
break;
if (instr->ctx.data.len - *start_offset >
pat->ctx.data.maxlen) {
*start_offset += pat->ctx.data.maxlen;
return true;
}
break;
default:
break;
}
return false;
}
/**
* nand_op_parser_match_pat - Checks if a pattern matches the instructions
* remaining in the parser context
* @pat: the pattern to test
* @ctx: the parser context structure to match with the pattern @pat
*
* Check if @pat matches the set or a sub-set of instructions remaining in @ctx.
* Returns true if this is the case, false ortherwise. When true is returned,
* @ctx->subop is updated with the set of instructions to be passed to the
* controller driver.
*/
static bool
nand_op_parser_match_pat(const struct nand_op_parser_pattern *pat,
struct nand_op_parser_ctx *ctx)
{
unsigned int instr_offset = ctx->subop.first_instr_start_off;
const struct nand_op_instr *end = ctx->instrs + ctx->ninstrs;
const struct nand_op_instr *instr = ctx->subop.instrs;
unsigned int i, ninstrs;
for (i = 0, ninstrs = 0; i < pat->nelems && instr < end; i++) {
/*
* The pattern instruction does not match the operation
* instruction. If the instruction is marked optional in the
* pattern definition, we skip the pattern element and continue
* to the next one. If the element is mandatory, there's no
* match and we can return false directly.
*/
Annotation
- Immediate include surface: `linux/module.h`, `linux/delay.h`, `linux/errno.h`, `linux/err.h`, `linux/sched.h`, `linux/slab.h`, `linux/mm.h`, `linux/types.h`.
- Detected declarations: `struct nand_op_parser_ctx`, `enum nand_ecc_legacy_mode`, `function Copyright`, `function nand_pairing_dist3_get_wunit`, `function check_offs_len`, `function another`, `function nand_select_target`, `function nand_deselect_target`, `function nand_release_device`, `function nand_bbm_get_next_page`.
- Atlas domain: Driver Families / drivers/mtd.
- 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.