tools/testing/cxl/test/mem.c
Source file repositories/reference/linux-study-clean/tools/testing/cxl/test/mem.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/cxl/test/mem.c- Extension
.c- Size
- 48876 bytes
- Lines
- 1919
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/platform_device.hlinux/mod_devicetable.hlinux/vmalloc.hlinux/module.hlinux/delay.hlinux/sizes.hlinux/bits.hcxl/mailbox.hlinux/unaligned.hcrypto/sha2.hcxlmem.htrace.h
Detected Declarations
struct cxl_mbox_health_infostruct mock_event_logstruct mock_event_storestruct vendor_test_featstruct cxl_mockmem_datastruct cxl_test_gen_mediastruct cxl_test_dramstruct cxl_test_mem_moduleenum cxl_command_effectsfunction event_reset_logfunction event_get_clear_handlefunction event_get_cur_event_handlefunction event_log_emptyfunction mes_add_eventfunction mock_get_eventfunction mock_clear_eventfunction cxl_mock_event_triggerfunction mock_set_timestampfunction cxl_mock_add_event_logsfunction mock_gslfunction mock_get_logfunction mock_rcd_idfunction mock_idfunction mock_partition_infofunction cxl_mockmem_sanitize_workfunction mock_sanitizefunction msecs_to_jiffiesfunction mock_secure_erasefunction mock_get_security_statefunction master_plimit_checkfunction user_plimit_checkfunction mock_set_passphrasefunction mock_disable_passphrasefunction mock_freeze_securityfunction mock_unlock_securityfunction mock_passphrase_secure_erasefunction passphrasefunction mock_get_lsafunction mock_set_lsafunction mock_health_infofunction mock_set_shutdown_statefunction cxl_get_injected_pofunction mock_get_poisonfunction mock_poison_dev_max_injectedfunction mock_poison_addfunction mock_poison_foundfunction mock_inject_poisonfunction mock_poison_del
Annotated Snippet
static ssize_t poison_inject_max_show(struct device_driver *drv, char *buf)
{
return sysfs_emit(buf, "%u\n", poison_inject_dev_max);
}
static ssize_t poison_inject_max_store(struct device_driver *drv,
const char *buf, size_t len)
{
int val;
if (kstrtoint(buf, 0, &val) < 0)
return -EINVAL;
if (!mock_poison_list_empty())
return -EBUSY;
if (val <= MOCK_INJECT_TEST_MAX)
poison_inject_dev_max = val;
else
return -EINVAL;
return len;
}
static DRIVER_ATTR_RW(poison_inject_max);
static struct attribute *cxl_mock_mem_core_attrs[] = {
&driver_attr_poison_inject_max.attr,
NULL
};
ATTRIBUTE_GROUPS(cxl_mock_mem_core);
static int mock_fw_info(struct cxl_mockmem_data *mdata,
struct cxl_mbox_cmd *cmd)
{
struct cxl_mbox_get_fw_info fw_info = {
.num_slots = FW_SLOTS,
.slot_info = (mdata->fw_slot & 0x7) |
((mdata->fw_staged & 0x7) << 3),
.activation_cap = 0,
};
strcpy(fw_info.slot_1_revision, "cxl_test_fw_001");
strcpy(fw_info.slot_2_revision, "cxl_test_fw_002");
strcpy(fw_info.slot_3_revision, "cxl_test_fw_003");
strcpy(fw_info.slot_4_revision, "");
if (cmd->size_out < sizeof(fw_info))
return -EINVAL;
memcpy(cmd->payload_out, &fw_info, sizeof(fw_info));
return 0;
}
static int mock_transfer_fw(struct cxl_mockmem_data *mdata,
struct cxl_mbox_cmd *cmd)
{
struct cxl_mbox_transfer_fw *transfer;
void *fw = mdata->fw;
size_t offset, length;
if (cmd->size_in < sizeof(*transfer))
return -EINVAL;
transfer = cmd->payload_in;
offset = le32_to_cpu(transfer->offset) * CXL_FW_TRANSFER_ALIGNMENT;
length = cmd->size_in - sizeof(*transfer);
if (offset + length > FW_SIZE)
return -EINVAL;
switch (transfer->action) {
case CXL_FW_TRANSFER_ACTION_FULL:
if (offset != 0)
return -EINVAL;
fallthrough;
case CXL_FW_TRANSFER_ACTION_END:
if (transfer->slot == 0 || transfer->slot > FW_SLOTS)
return -EINVAL;
mdata->fw_size = offset + length;
break;
case CXL_FW_TRANSFER_ACTION_INITIATE:
case CXL_FW_TRANSFER_ACTION_CONTINUE:
break;
case CXL_FW_TRANSFER_ACTION_ABORT:
return 0;
default:
return -EINVAL;
}
memcpy(fw + offset, transfer->data, length);
Annotation
- Immediate include surface: `linux/platform_device.h`, `linux/mod_devicetable.h`, `linux/vmalloc.h`, `linux/module.h`, `linux/delay.h`, `linux/sizes.h`, `linux/bits.h`, `cxl/mailbox.h`.
- Detected declarations: `struct cxl_mbox_health_info`, `struct mock_event_log`, `struct mock_event_store`, `struct vendor_test_feat`, `struct cxl_mockmem_data`, `struct cxl_test_gen_media`, `struct cxl_test_dram`, `struct cxl_test_mem_module`, `enum cxl_command_effects`, `function event_reset_log`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: pattern 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.