drivers/cxl/core/features.c
Source file repositories/reference/linux-study-clean/drivers/cxl/core/features.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/cxl/core/features.c- Extension
.c- Size
- 18887 bytes
- Lines
- 707
- Domain
- Driver Families
- Bucket
- drivers/cxl
- 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/fwctl.hlinux/device.hcxl/mailbox.hcxl/features.huapi/fwctl/cxl.hcxl.hcore.hcxlmem.h
Detected Declarations
function is_cxl_feature_exclusive_by_uuidfunction is_cxl_feature_exclusivefunction cxl_get_supported_features_countfunction get_supported_featuresfunction free_cxlfsfunction devm_cxl_setup_featuresfunction cxl_get_featurefunction cxl_set_featurefunction cxlctl_open_uctxfunction cxlctl_close_uctxfunction cxlctl_validate_set_featuresfunction cxlctl_validate_hw_commandfunction free_memdev_fwctlfunction devm_cxl_setup_fwctl
Annotated Snippet
if (remain_feats > max_feats) {
alloc_size = struct_size(mbox_out, ents, max_feats);
remain_feats = remain_feats - max_feats;
copy_feats = max_feats;
} else {
alloc_size = struct_size(mbox_out, ents, remain_feats);
copy_feats = remain_feats;
remain_feats = 0;
}
memset(&mbox_in, 0, sizeof(mbox_in));
mbox_in.count = cpu_to_le32(alloc_size);
mbox_in.start_idx = cpu_to_le16(start);
memset(mbox_out, 0, alloc_size);
mbox_cmd = (struct cxl_mbox_cmd) {
.opcode = CXL_MBOX_OP_GET_SUPPORTED_FEATURES,
.size_in = sizeof(mbox_in),
.payload_in = &mbox_in,
.size_out = alloc_size,
.payload_out = mbox_out,
.min_out = hdr_size,
};
rc = cxl_internal_send_cmd(cxl_mbox, &mbox_cmd);
if (rc < 0)
return NULL;
if (mbox_cmd.size_out <= hdr_size)
return NULL;
/*
* Make sure retrieved out buffer is multiple of feature
* entries.
*/
retrieved = mbox_cmd.size_out - hdr_size;
if (retrieved % feat_size)
return NULL;
num_entries = le16_to_cpu(mbox_out->num_entries);
/*
* If the reported output entries * defined entry size !=
* retrieved output bytes, then the output package is incorrect.
*/
if (num_entries * feat_size != retrieved)
return NULL;
memcpy(entry, mbox_out->ents, retrieved);
for (int i = 0; i < num_entries; i++) {
if (!is_cxl_feature_exclusive(entry + i))
user_feats++;
}
entry += num_entries;
/*
* If the number of output entries is less than expected, add the
* remaining entries to the next batch.
*/
remain_feats += copy_feats - num_entries;
start += num_entries;
} while (remain_feats);
entries->num_features = count;
entries->num_user_features = user_feats;
return no_free_ptr(entries);
}
static void free_cxlfs(void *_cxlfs)
{
struct cxl_features_state *cxlfs = _cxlfs;
struct cxl_dev_state *cxlds = cxlfs->cxlds;
cxlds->cxlfs = NULL;
kvfree(cxlfs->entries);
kfree(cxlfs);
}
/**
* devm_cxl_setup_features() - Allocate and initialize features context
* @cxlds: CXL device context
*
* Return 0 on success or -errno on failure.
*/
int devm_cxl_setup_features(struct cxl_dev_state *cxlds)
{
struct cxl_mailbox *cxl_mbox = &cxlds->cxl_mbox;
if (cxl_mbox->feat_cap < CXL_FEATURES_RO)
return -ENODEV;
struct cxl_features_state *cxlfs __free(kfree) =
kzalloc_obj(*cxlfs);
Annotation
- Immediate include surface: `linux/fwctl.h`, `linux/device.h`, `cxl/mailbox.h`, `cxl/features.h`, `uapi/fwctl/cxl.h`, `cxl.h`, `core.h`, `cxlmem.h`.
- Detected declarations: `function is_cxl_feature_exclusive_by_uuid`, `function is_cxl_feature_exclusive`, `function cxl_get_supported_features_count`, `function get_supported_features`, `function free_cxlfs`, `function devm_cxl_setup_features`, `function cxl_get_feature`, `function cxl_set_feature`, `function cxlctl_open_uctx`, `function cxlctl_close_uctx`.
- Atlas domain: Driver Families / drivers/cxl.
- 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.