|
24 | 24 | #include <linux/delay.h>
|
25 | 25 | #include <linux/kthread.h>
|
26 | 26 | #include <linux/vmalloc.h>
|
| 27 | +#include <linux/efi_embedded_fw.h> |
27 | 28 |
|
28 | 29 | #define TEST_FIRMWARE_NAME "test-firmware.bin"
|
29 | 30 | #define TEST_FIRMWARE_NUM_REQS 4
|
@@ -507,6 +508,57 @@ static ssize_t trigger_request_store(struct device *dev,
|
507 | 508 | }
|
508 | 509 | static DEVICE_ATTR_WO(trigger_request);
|
509 | 510 |
|
| 511 | +#ifdef CONFIG_EFI_EMBEDDED_FIRMWARE |
| 512 | +static ssize_t trigger_request_platform_store(struct device *dev, |
| 513 | + struct device_attribute *attr, |
| 514 | + const char *buf, size_t count) |
| 515 | +{ |
| 516 | + static const u8 test_data[] = { |
| 517 | + 0x55, 0xaa, 0x55, 0xaa, 0x01, 0x02, 0x03, 0x04, |
| 518 | + 0x55, 0xaa, 0x55, 0xaa, 0x05, 0x06, 0x07, 0x08, |
| 519 | + 0x55, 0xaa, 0x55, 0xaa, 0x10, 0x20, 0x30, 0x40, |
| 520 | + 0x55, 0xaa, 0x55, 0xaa, 0x50, 0x60, 0x70, 0x80 |
| 521 | + }; |
| 522 | + struct efi_embedded_fw efi_embedded_fw; |
| 523 | + const struct firmware *firmware = NULL; |
| 524 | + char *name; |
| 525 | + int rc; |
| 526 | + |
| 527 | + name = kstrndup(buf, count, GFP_KERNEL); |
| 528 | + if (!name) |
| 529 | + return -ENOSPC; |
| 530 | + |
| 531 | + pr_info("inserting test platform fw '%s'\n", name); |
| 532 | + efi_embedded_fw.name = name; |
| 533 | + efi_embedded_fw.data = (void *)test_data; |
| 534 | + efi_embedded_fw.length = sizeof(test_data); |
| 535 | + list_add(&efi_embedded_fw.list, &efi_embedded_fw_list); |
| 536 | + |
| 537 | + pr_info("loading '%s'\n", name); |
| 538 | + rc = firmware_request_platform(&firmware, name, dev); |
| 539 | + if (rc) { |
| 540 | + pr_info("load of '%s' failed: %d\n", name, rc); |
| 541 | + goto out; |
| 542 | + } |
| 543 | + if (firmware->size != sizeof(test_data) || |
| 544 | + memcmp(firmware->data, test_data, sizeof(test_data)) != 0) { |
| 545 | + pr_info("firmware contents mismatch for '%s'\n", name); |
| 546 | + rc = -EINVAL; |
| 547 | + goto out; |
| 548 | + } |
| 549 | + pr_info("loaded: %zu\n", firmware->size); |
| 550 | + rc = count; |
| 551 | + |
| 552 | +out: |
| 553 | + release_firmware(firmware); |
| 554 | + list_del(&efi_embedded_fw.list); |
| 555 | + kfree(name); |
| 556 | + |
| 557 | + return rc; |
| 558 | +} |
| 559 | +static DEVICE_ATTR_WO(trigger_request_platform); |
| 560 | +#endif |
| 561 | + |
510 | 562 | static DECLARE_COMPLETION(async_fw_done);
|
511 | 563 |
|
512 | 564 | static void trigger_async_request_cb(const struct firmware *fw, void *context)
|
@@ -903,6 +955,9 @@ static struct attribute *test_dev_attrs[] = {
|
903 | 955 | TEST_FW_DEV_ATTR(trigger_request),
|
904 | 956 | TEST_FW_DEV_ATTR(trigger_async_request),
|
905 | 957 | TEST_FW_DEV_ATTR(trigger_custom_fallback),
|
| 958 | +#ifdef CONFIG_EFI_EMBEDDED_FIRMWARE |
| 959 | + TEST_FW_DEV_ATTR(trigger_request_platform), |
| 960 | +#endif |
906 | 961 |
|
907 | 962 | /* These use the config and can use the test_result */
|
908 | 963 | TEST_FW_DEV_ATTR(trigger_batched_requests),
|
|
0 commit comments