Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

test_firmware: add support for firmware_request_platform

Add support for testing firmware_request_platform through a new
trigger_request_platform trigger.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Luis Chamberlain <mcgrof@kernel.org>
Link: https://lore.kernel.org/r/20200115163554.101315-6-hdegoede@redhat.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Hans de Goede and committed by
Greg Kroah-Hartman
548193cb e4c2c0ff

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