drivers/soc/qcom/qmi_encdec.c
Source file repositories/reference/linux-study-clean/drivers/soc/qcom/qmi_encdec.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/soc/qcom/qmi_encdec.c- Extension
.c- Size
- 27537 bytes
- Lines
- 946
- Domain
- Driver Families
- Bucket
- drivers/soc
- 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/slab.hlinux/uaccess.hlinux/module.hlinux/kernel.hlinux/errno.hlinux/string.hlinux/soc/qcom/qmi.h
Detected Declarations
function skip_to_next_elemfunction qmi_calc_min_msg_lenfunction qmi_encode_basic_elemfunction qmi_encode_struct_elemfunction qmi_encode_string_elemfunction qmi_encodefunction qmi_decode_basic_elemfunction qmi_decode_struct_elemfunction qmi_decode_string_elemfunction find_eifunction qmi_decodefunction qmi_encode_messagefunction qmi_decode_messageexport qmi_encode_messageexport qmi_decode_messageexport qmi_response_type_v01_ei
Annotated Snippet
if (temp_ei->data_type == QMI_OPT_FLAG) {
temp_ei = skip_to_next_elem(temp_ei, level);
continue;
}
if (temp_ei->data_type == QMI_DATA_LEN) {
min_msg_len += (temp_ei->elem_size == sizeof(u8) ?
sizeof(u8) : sizeof(u16));
temp_ei++;
continue;
} else if (temp_ei->data_type == QMI_STRUCT) {
min_msg_len += qmi_calc_min_msg_len(temp_ei->ei_array,
(level + 1));
temp_ei++;
} else if (temp_ei->data_type == QMI_STRING) {
if (level > 1)
min_msg_len += temp_ei->elem_len <= U8_MAX ?
sizeof(u8) : sizeof(u16);
min_msg_len += temp_ei->elem_len * temp_ei->elem_size;
temp_ei++;
} else {
min_msg_len += (temp_ei->elem_len * temp_ei->elem_size);
temp_ei++;
}
/*
* Type & Length info. not prepended for elements in the
* nested structure.
*/
if (level == 1)
min_msg_len += (TLV_TYPE_SIZE + TLV_LEN_SIZE);
}
return min_msg_len;
}
/**
* qmi_encode_basic_elem() - Encodes elements of basic/primary data type
* @buf_dst: Buffer to store the encoded information.
* @buf_src: Buffer containing the elements to be encoded.
* @elem_len: Number of elements, in the buf_src, to be encoded.
* @elem_size: Size of a single instance of the element to be encoded.
*
* This function encodes the "elem_len" number of data elements, each of
* size "elem_size" bytes from the source buffer "buf_src" and stores the
* encoded information in the destination buffer "buf_dst". The elements are
* of primary data type which include u8 - u64 or similar. This
* function returns the number of bytes of encoded information.
*
* Return: The number of bytes of encoded information on success or negative
* errno on error.
*/
static int qmi_encode_basic_elem(void *buf_dst, const void *buf_src,
u32 elem_len, u32 elem_size)
{
u32 i, rc = 0;
for (i = 0; i < elem_len; i++) {
switch (elem_size) {
case sizeof(u8):
QMI_ENCDEC_ENCODE_U8(buf_dst, buf_src);
break;
case sizeof(u16):
QMI_ENCDEC_ENCODE_U16(buf_dst, buf_src);
break;
case sizeof(u32):
QMI_ENCDEC_ENCODE_U32(buf_dst, buf_src);
break;
case sizeof(u64):
QMI_ENCDEC_ENCODE_U64(buf_dst, buf_src);
break;
default:
pr_err("%s: Unrecognized element size\n", __func__);
return -EINVAL;
}
rc += elem_size;
}
return rc;
}
/**
* qmi_encode_struct_elem() - Encodes elements of struct data type
* @ei_array: Struct info array descibing the struct element.
* @buf_dst: Buffer to store the encoded information.
* @buf_src: Buffer containing the elements to be encoded.
* @elem_len: Number of elements, in the buf_src, to be encoded.
* @out_buf_len: Available space in the encode buffer.
* @enc_level: Depth of the nested structure from the main structure.
Annotation
- Immediate include surface: `linux/slab.h`, `linux/uaccess.h`, `linux/module.h`, `linux/kernel.h`, `linux/errno.h`, `linux/string.h`, `linux/soc/qcom/qmi.h`.
- Detected declarations: `function skip_to_next_elem`, `function qmi_calc_min_msg_len`, `function qmi_encode_basic_elem`, `function qmi_encode_struct_elem`, `function qmi_encode_string_elem`, `function qmi_encode`, `function qmi_decode_basic_elem`, `function qmi_decode_struct_elem`, `function qmi_decode_string_elem`, `function find_ei`.
- Atlas domain: Driver Families / drivers/soc.
- 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.