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.

Dependency Surface

Detected Declarations

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

Implementation Notes