drivers/platform/chrome/cros_ec_proto_test.c
Source file repositories/reference/linux-study-clean/drivers/platform/chrome/cros_ec_proto_test.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/chrome/cros_ec_proto_test.c- Extension
.c- Size
- 84454 bytes
- Lines
- 2745
- Domain
- Driver Families
- Bucket
- drivers/platform
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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
kunit/test.hlinux/unaligned.hlinux/platform_data/cros_ec_commands.hlinux/platform_data/cros_ec_proto.hcros_ec.hcros_ec_proto_test_util.h
Detected Declarations
struct cros_ec_proto_test_privfunction cros_ec_proto_test_prepare_tx_legacy_normalfunction cros_ec_proto_test_prepare_tx_legacy_bad_msg_outsizefunction cros_ec_proto_test_prepare_tx_normalfunction cros_ec_proto_test_prepare_tx_bad_msg_outsizefunction cros_ec_proto_test_check_resultfunction cros_ec_proto_test_query_all_pretestfunction cros_ec_proto_test_query_all_normalfunction cros_ec_proto_test_query_all_no_pd_return_errorfunction cros_ec_proto_test_query_all_no_pd_return0function cros_ec_proto_test_query_all_legacy_normal_v3_return_errorfunction cros_ec_proto_test_query_all_legacy_normal_v3_return0function cros_ec_proto_test_query_all_legacy_xfer_errorfunction cros_ec_proto_test_query_all_legacy_return_errorfunction cros_ec_proto_test_query_all_legacy_data_errorfunction cros_ec_proto_test_query_all_legacy_return0function cros_ec_proto_test_query_all_no_mkbpfunction cros_ec_proto_test_query_all_no_mkbp_return_errorfunction cros_ec_proto_test_query_all_no_mkbp_return0function cros_ec_proto_test_query_all_no_host_sleepfunction cros_ec_proto_test_query_all_no_host_sleep_return0function cros_ec_proto_test_query_all_default_wake_mask_return_errorfunction cros_ec_proto_test_query_all_default_wake_mask_return0function cros_ec_proto_test_cmd_xfer_normalfunction cros_ec_proto_test_cmd_xfer_excess_msg_insizefunction cros_ec_proto_test_cmd_xfer_excess_msg_outsize_without_passthrufunction cros_ec_proto_test_cmd_xfer_excess_msg_outsize_with_passthrufunction cros_ec_proto_test_cmd_xfer_protocol_v3_normalfunction cros_ec_proto_test_cmd_xfer_protocol_v3_no_opfunction cros_ec_proto_test_cmd_xfer_protocol_v2_normalfunction cros_ec_proto_test_cmd_xfer_protocol_v2_no_opfunction cros_ec_proto_test_cmd_xfer_in_progress_normalfunction cros_ec_proto_test_cmd_xfer_in_progress_retries_eagainfunction cros_ec_proto_test_cmd_xfer_in_progress_retries_status_processingfunction cros_ec_proto_test_cmd_xfer_in_progress_xfer_errorfunction cros_ec_proto_test_cmd_xfer_in_progress_return_errorfunction cros_ec_proto_test_cmd_xfer_in_progress_return0function cros_ec_proto_test_cmd_xfer_status_normalfunction cros_ec_proto_test_cmd_xfer_status_xfer_errorfunction cros_ec_proto_test_cmd_xfer_status_return_errorfunction cros_ec_proto_test_get_next_event_no_mkbp_eventfunction cros_ec_proto_test_get_next_event_mkbp_event_ec_suspendedfunction cros_ec_proto_test_get_next_event_mkbp_event_version0function cros_ec_proto_test_get_next_event_mkbp_event_version2function cros_ec_proto_test_get_next_event_mkbp_event_host_event_rtcfunction cros_ec_proto_test_get_next_event_mkbp_event_host_event_maskedfunction cros_ec_proto_test_get_host_event_no_mkbp_eventfunction cros_ec_proto_test_get_host_event_not_host_event
Annotated Snippet
struct cros_ec_proto_test_priv {
struct cros_ec_device ec_dev;
u8 dout[BUFSIZE];
u8 din[BUFSIZE];
struct cros_ec_command *msg;
u8 _msg[BUFSIZE];
};
static void cros_ec_proto_test_prepare_tx_legacy_normal(struct kunit *test)
{
struct cros_ec_proto_test_priv *priv = test->priv;
struct cros_ec_device *ec_dev = &priv->ec_dev;
struct cros_ec_command *msg = priv->msg;
int ret, i;
u8 csum;
ec_dev->proto_version = 2;
msg->command = EC_CMD_HELLO;
msg->outsize = EC_PROTO2_MAX_PARAM_SIZE;
msg->data[0] = 0xde;
msg->data[1] = 0xad;
msg->data[2] = 0xbe;
msg->data[3] = 0xef;
ret = cros_ec_prepare_tx(ec_dev, msg);
KUNIT_EXPECT_EQ(test, ret, EC_MSG_TX_PROTO_BYTES + EC_PROTO2_MAX_PARAM_SIZE);
KUNIT_EXPECT_EQ(test, ec_dev->dout[0], EC_CMD_VERSION0);
KUNIT_EXPECT_EQ(test, ec_dev->dout[1], EC_CMD_HELLO);
KUNIT_EXPECT_EQ(test, ec_dev->dout[2], EC_PROTO2_MAX_PARAM_SIZE);
KUNIT_EXPECT_EQ(test, EC_MSG_TX_HEADER_BYTES, 3);
KUNIT_EXPECT_EQ(test, ec_dev->dout[EC_MSG_TX_HEADER_BYTES + 0], 0xde);
KUNIT_EXPECT_EQ(test, ec_dev->dout[EC_MSG_TX_HEADER_BYTES + 1], 0xad);
KUNIT_EXPECT_EQ(test, ec_dev->dout[EC_MSG_TX_HEADER_BYTES + 2], 0xbe);
KUNIT_EXPECT_EQ(test, ec_dev->dout[EC_MSG_TX_HEADER_BYTES + 3], 0xef);
for (i = 4; i < EC_PROTO2_MAX_PARAM_SIZE; ++i)
KUNIT_EXPECT_EQ(test, ec_dev->dout[EC_MSG_TX_HEADER_BYTES + i], 0);
csum = EC_CMD_VERSION0;
csum += EC_CMD_HELLO;
csum += EC_PROTO2_MAX_PARAM_SIZE;
csum += 0xde;
csum += 0xad;
csum += 0xbe;
csum += 0xef;
KUNIT_EXPECT_EQ(test,
ec_dev->dout[EC_MSG_TX_HEADER_BYTES + EC_PROTO2_MAX_PARAM_SIZE],
csum);
}
static void cros_ec_proto_test_prepare_tx_legacy_bad_msg_outsize(struct kunit *test)
{
struct cros_ec_proto_test_priv *priv = test->priv;
struct cros_ec_device *ec_dev = &priv->ec_dev;
struct cros_ec_command *msg = priv->msg;
int ret;
ec_dev->proto_version = 2;
msg->outsize = EC_PROTO2_MAX_PARAM_SIZE + 1;
ret = cros_ec_prepare_tx(ec_dev, msg);
KUNIT_EXPECT_EQ(test, ret, -EINVAL);
}
static void cros_ec_proto_test_prepare_tx_normal(struct kunit *test)
{
struct cros_ec_proto_test_priv *priv = test->priv;
struct cros_ec_device *ec_dev = &priv->ec_dev;
struct cros_ec_command *msg = priv->msg;
struct ec_host_request *request = (struct ec_host_request *)ec_dev->dout;
int ret, i;
u8 csum;
msg->command = EC_CMD_HELLO;
msg->outsize = 0x88;
msg->data[0] = 0xde;
msg->data[1] = 0xad;
msg->data[2] = 0xbe;
msg->data[3] = 0xef;
ret = cros_ec_prepare_tx(ec_dev, msg);
KUNIT_EXPECT_EQ(test, ret, sizeof(*request) + 0x88);
KUNIT_EXPECT_EQ(test, request->struct_version, EC_HOST_REQUEST_VERSION);
KUNIT_EXPECT_EQ(test, request->command, EC_CMD_HELLO);
KUNIT_EXPECT_EQ(test, request->command_version, 0);
KUNIT_EXPECT_EQ(test, request->data_len, 0x88);
Annotation
- Immediate include surface: `kunit/test.h`, `linux/unaligned.h`, `linux/platform_data/cros_ec_commands.h`, `linux/platform_data/cros_ec_proto.h`, `cros_ec.h`, `cros_ec_proto_test_util.h`.
- Detected declarations: `struct cros_ec_proto_test_priv`, `function cros_ec_proto_test_prepare_tx_legacy_normal`, `function cros_ec_proto_test_prepare_tx_legacy_bad_msg_outsize`, `function cros_ec_proto_test_prepare_tx_normal`, `function cros_ec_proto_test_prepare_tx_bad_msg_outsize`, `function cros_ec_proto_test_check_result`, `function cros_ec_proto_test_query_all_pretest`, `function cros_ec_proto_test_query_all_normal`, `function cros_ec_proto_test_query_all_no_pd_return_error`, `function cros_ec_proto_test_query_all_no_pd_return0`.
- Atlas domain: Driver Families / drivers/platform.
- Implementation status: source 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.