diff options
author | Scott Branden <scott.branden@broadcom.com> | 2019-08-22 14:40:04 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-09-04 07:31:28 -0400 |
commit | 7feebfa487b929b3e085f4f11ae7ac9e2e92e848 (patch) | |
tree | 64735746c4249c148d93eb9bd47a0fd2d4ac7aaf /lib/test_firmware.c | |
parent | 4b708b7b1a2c09fbdfff6b942ebe3a160213aacd (diff) |
test_firmware: add support for request_firmware_into_buf
Add test config into_buf to allow request_firmware_into_buf to be
called instead of request_firmware/request_firmware_direct. The number
of parameters differ calling request_firmware_into_buf and support
has not been added to test such api in test_firmware until now.
Signed-off-by: Scott Branden <scott.branden@broadcom.com>
Acked-by: Luis Chamberlain <mcgrof@kernel.org>
Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Link: https://lore.kernel.org/r/20190822184005.901-2-scott.branden@broadcom.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'lib/test_firmware.c')
-rw-r--r-- | lib/test_firmware.c | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/lib/test_firmware.c b/lib/test_firmware.c index 6ca97a63b3d6..251213c872b5 100644 --- a/lib/test_firmware.c +++ b/lib/test_firmware.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/device.h> | 18 | #include <linux/device.h> |
19 | #include <linux/fs.h> | 19 | #include <linux/fs.h> |
20 | #include <linux/miscdevice.h> | 20 | #include <linux/miscdevice.h> |
21 | #include <linux/sizes.h> | ||
21 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
22 | #include <linux/uaccess.h> | 23 | #include <linux/uaccess.h> |
23 | #include <linux/delay.h> | 24 | #include <linux/delay.h> |
@@ -26,6 +27,7 @@ | |||
26 | 27 | ||
27 | #define TEST_FIRMWARE_NAME "test-firmware.bin" | 28 | #define TEST_FIRMWARE_NAME "test-firmware.bin" |
28 | #define TEST_FIRMWARE_NUM_REQS 4 | 29 | #define TEST_FIRMWARE_NUM_REQS 4 |
30 | #define TEST_FIRMWARE_BUF_SIZE SZ_1K | ||
29 | 31 | ||
30 | static DEFINE_MUTEX(test_fw_mutex); | 32 | static DEFINE_MUTEX(test_fw_mutex); |
31 | static const struct firmware *test_firmware; | 33 | static const struct firmware *test_firmware; |
@@ -45,6 +47,8 @@ struct test_batched_req { | |||
45 | * test_config - represents configuration for the test for different triggers | 47 | * test_config - represents configuration for the test for different triggers |
46 | * | 48 | * |
47 | * @name: the name of the firmware file to look for | 49 | * @name: the name of the firmware file to look for |
50 | * @into_buf: when the into_buf is used if this is true | ||
51 | * request_firmware_into_buf() will be used instead. | ||
48 | * @sync_direct: when the sync trigger is used if this is true | 52 | * @sync_direct: when the sync trigger is used if this is true |
49 | * request_firmware_direct() will be used instead. | 53 | * request_firmware_direct() will be used instead. |
50 | * @send_uevent: whether or not to send a uevent for async requests | 54 | * @send_uevent: whether or not to send a uevent for async requests |
@@ -83,6 +87,7 @@ struct test_batched_req { | |||
83 | */ | 87 | */ |
84 | struct test_config { | 88 | struct test_config { |
85 | char *name; | 89 | char *name; |
90 | bool into_buf; | ||
86 | bool sync_direct; | 91 | bool sync_direct; |
87 | bool send_uevent; | 92 | bool send_uevent; |
88 | u8 num_requests; | 93 | u8 num_requests; |
@@ -176,6 +181,7 @@ static int __test_firmware_config_init(void) | |||
176 | 181 | ||
177 | test_fw_config->num_requests = TEST_FIRMWARE_NUM_REQS; | 182 | test_fw_config->num_requests = TEST_FIRMWARE_NUM_REQS; |
178 | test_fw_config->send_uevent = true; | 183 | test_fw_config->send_uevent = true; |
184 | test_fw_config->into_buf = false; | ||
179 | test_fw_config->sync_direct = false; | 185 | test_fw_config->sync_direct = false; |
180 | test_fw_config->req_firmware = request_firmware; | 186 | test_fw_config->req_firmware = request_firmware; |
181 | test_fw_config->test_result = 0; | 187 | test_fw_config->test_result = 0; |
@@ -245,6 +251,9 @@ static ssize_t config_show(struct device *dev, | |||
245 | "FW_ACTION_HOTPLUG" : | 251 | "FW_ACTION_HOTPLUG" : |
246 | "FW_ACTION_NOHOTPLUG"); | 252 | "FW_ACTION_NOHOTPLUG"); |
247 | len += scnprintf(buf+len, PAGE_SIZE - len, | 253 | len += scnprintf(buf+len, PAGE_SIZE - len, |
254 | "into_buf:\t\t%s\n", | ||
255 | test_fw_config->into_buf ? "true" : "false"); | ||
256 | len += scnprintf(buf+len, PAGE_SIZE - len, | ||
248 | "sync_direct:\t\t%s\n", | 257 | "sync_direct:\t\t%s\n", |
249 | test_fw_config->sync_direct ? "true" : "false"); | 258 | test_fw_config->sync_direct ? "true" : "false"); |
250 | len += scnprintf(buf+len, PAGE_SIZE - len, | 259 | len += scnprintf(buf+len, PAGE_SIZE - len, |
@@ -393,6 +402,23 @@ static ssize_t config_num_requests_show(struct device *dev, | |||
393 | } | 402 | } |
394 | static DEVICE_ATTR_RW(config_num_requests); | 403 | static DEVICE_ATTR_RW(config_num_requests); |
395 | 404 | ||
405 | static ssize_t config_into_buf_store(struct device *dev, | ||
406 | struct device_attribute *attr, | ||
407 | const char *buf, size_t count) | ||
408 | { | ||
409 | return test_dev_config_update_bool(buf, | ||
410 | count, | ||
411 | &test_fw_config->into_buf); | ||
412 | } | ||
413 | |||
414 | static ssize_t config_into_buf_show(struct device *dev, | ||
415 | struct device_attribute *attr, | ||
416 | char *buf) | ||
417 | { | ||
418 | return test_dev_config_show_bool(buf, test_fw_config->into_buf); | ||
419 | } | ||
420 | static DEVICE_ATTR_RW(config_into_buf); | ||
421 | |||
396 | static ssize_t config_sync_direct_store(struct device *dev, | 422 | static ssize_t config_sync_direct_store(struct device *dev, |
397 | struct device_attribute *attr, | 423 | struct device_attribute *attr, |
398 | const char *buf, size_t count) | 424 | const char *buf, size_t count) |
@@ -522,7 +548,7 @@ static ssize_t trigger_async_request_store(struct device *dev, | |||
522 | rc = count; | 548 | rc = count; |
523 | } else { | 549 | } else { |
524 | pr_err("failed to async load firmware\n"); | 550 | pr_err("failed to async load firmware\n"); |
525 | rc = -ENODEV; | 551 | rc = -ENOMEM; |
526 | } | 552 | } |
527 | 553 | ||
528 | out: | 554 | out: |
@@ -585,7 +611,26 @@ static int test_fw_run_batch_request(void *data) | |||
585 | return -EINVAL; | 611 | return -EINVAL; |
586 | } | 612 | } |
587 | 613 | ||
588 | req->rc = test_fw_config->req_firmware(&req->fw, req->name, req->dev); | 614 | if (test_fw_config->into_buf) { |
615 | void *test_buf; | ||
616 | |||
617 | test_buf = kzalloc(TEST_FIRMWARE_BUF_SIZE, GFP_KERNEL); | ||
618 | if (!test_buf) | ||
619 | return -ENOSPC; | ||
620 | |||
621 | req->rc = request_firmware_into_buf(&req->fw, | ||
622 | req->name, | ||
623 | req->dev, | ||
624 | test_buf, | ||
625 | TEST_FIRMWARE_BUF_SIZE); | ||
626 | if (!req->fw) | ||
627 | kfree(test_buf); | ||
628 | } else { | ||
629 | req->rc = test_fw_config->req_firmware(&req->fw, | ||
630 | req->name, | ||
631 | req->dev); | ||
632 | } | ||
633 | |||
589 | if (req->rc) { | 634 | if (req->rc) { |
590 | pr_info("#%u: batched sync load failed: %d\n", | 635 | pr_info("#%u: batched sync load failed: %d\n", |
591 | req->idx, req->rc); | 636 | req->idx, req->rc); |
@@ -849,6 +894,7 @@ static struct attribute *test_dev_attrs[] = { | |||
849 | TEST_FW_DEV_ATTR(config), | 894 | TEST_FW_DEV_ATTR(config), |
850 | TEST_FW_DEV_ATTR(config_name), | 895 | TEST_FW_DEV_ATTR(config_name), |
851 | TEST_FW_DEV_ATTR(config_num_requests), | 896 | TEST_FW_DEV_ATTR(config_num_requests), |
897 | TEST_FW_DEV_ATTR(config_into_buf), | ||
852 | TEST_FW_DEV_ATTR(config_sync_direct), | 898 | TEST_FW_DEV_ATTR(config_sync_direct), |
853 | TEST_FW_DEV_ATTR(config_send_uevent), | 899 | TEST_FW_DEV_ATTR(config_send_uevent), |
854 | TEST_FW_DEV_ATTR(config_read_fw_idx), | 900 | TEST_FW_DEV_ATTR(config_read_fw_idx), |