.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * This module provides an interface to trigger and test firmware loading. |
---|
3 | 4 | * |
---|
.. | .. |
---|
17 | 18 | #include <linux/device.h> |
---|
18 | 19 | #include <linux/fs.h> |
---|
19 | 20 | #include <linux/miscdevice.h> |
---|
| 21 | +#include <linux/sizes.h> |
---|
20 | 22 | #include <linux/slab.h> |
---|
21 | 23 | #include <linux/uaccess.h> |
---|
22 | 24 | #include <linux/delay.h> |
---|
| 25 | +#include <linux/kstrtox.h> |
---|
23 | 26 | #include <linux/kthread.h> |
---|
24 | 27 | #include <linux/vmalloc.h> |
---|
| 28 | +#include <linux/efi_embedded_fw.h> |
---|
| 29 | + |
---|
| 30 | +MODULE_IMPORT_NS(TEST_FIRMWARE); |
---|
25 | 31 | |
---|
26 | 32 | #define TEST_FIRMWARE_NAME "test-firmware.bin" |
---|
27 | 33 | #define TEST_FIRMWARE_NUM_REQS 4 |
---|
| 34 | +#define TEST_FIRMWARE_BUF_SIZE SZ_1K |
---|
28 | 35 | |
---|
29 | 36 | static DEFINE_MUTEX(test_fw_mutex); |
---|
30 | 37 | static const struct firmware *test_firmware; |
---|
.. | .. |
---|
35 | 42 | bool sent; |
---|
36 | 43 | const struct firmware *fw; |
---|
37 | 44 | const char *name; |
---|
| 45 | + const char *fw_buf; |
---|
38 | 46 | struct completion completion; |
---|
39 | 47 | struct task_struct *task; |
---|
40 | 48 | struct device *dev; |
---|
.. | .. |
---|
44 | 52 | * test_config - represents configuration for the test for different triggers |
---|
45 | 53 | * |
---|
46 | 54 | * @name: the name of the firmware file to look for |
---|
| 55 | + * @into_buf: when the into_buf is used if this is true |
---|
| 56 | + * request_firmware_into_buf() will be used instead. |
---|
| 57 | + * @buf_size: size of buf to allocate when into_buf is true |
---|
| 58 | + * @file_offset: file offset to request when calling request_firmware_into_buf |
---|
| 59 | + * @partial: partial read opt when calling request_firmware_into_buf |
---|
47 | 60 | * @sync_direct: when the sync trigger is used if this is true |
---|
48 | 61 | * request_firmware_direct() will be used instead. |
---|
49 | 62 | * @send_uevent: whether or not to send a uevent for async requests |
---|
.. | .. |
---|
82 | 95 | */ |
---|
83 | 96 | struct test_config { |
---|
84 | 97 | char *name; |
---|
| 98 | + bool into_buf; |
---|
| 99 | + size_t buf_size; |
---|
| 100 | + size_t file_offset; |
---|
| 101 | + bool partial; |
---|
85 | 102 | bool sync_direct; |
---|
86 | 103 | bool send_uevent; |
---|
87 | 104 | u8 num_requests; |
---|
.. | .. |
---|
128 | 145 | |
---|
129 | 146 | for (i = 0; i < test_fw_config->num_requests; i++) { |
---|
130 | 147 | req = &test_fw_config->reqs[i]; |
---|
131 | | - if (req->fw) |
---|
| 148 | + if (req->fw) { |
---|
| 149 | + if (req->fw_buf) { |
---|
| 150 | + kfree_const(req->fw_buf); |
---|
| 151 | + req->fw_buf = NULL; |
---|
| 152 | + } |
---|
132 | 153 | release_firmware(req->fw); |
---|
| 154 | + req->fw = NULL; |
---|
| 155 | + } |
---|
133 | 156 | } |
---|
134 | 157 | |
---|
135 | 158 | vfree(test_fw_config->reqs); |
---|
.. | .. |
---|
160 | 183 | { |
---|
161 | 184 | *dst = kstrndup(name, count, gfp); |
---|
162 | 185 | if (!*dst) |
---|
163 | | - return -ENOSPC; |
---|
| 186 | + return -ENOMEM; |
---|
164 | 187 | return count; |
---|
165 | 188 | } |
---|
166 | 189 | |
---|
.. | .. |
---|
175 | 198 | |
---|
176 | 199 | test_fw_config->num_requests = TEST_FIRMWARE_NUM_REQS; |
---|
177 | 200 | test_fw_config->send_uevent = true; |
---|
| 201 | + test_fw_config->into_buf = false; |
---|
| 202 | + test_fw_config->buf_size = TEST_FIRMWARE_BUF_SIZE; |
---|
| 203 | + test_fw_config->file_offset = 0; |
---|
| 204 | + test_fw_config->partial = false; |
---|
178 | 205 | test_fw_config->sync_direct = false; |
---|
179 | 206 | test_fw_config->req_firmware = request_firmware; |
---|
180 | 207 | test_fw_config->test_result = 0; |
---|
.. | .. |
---|
228 | 255 | dev_name(dev)); |
---|
229 | 256 | |
---|
230 | 257 | if (test_fw_config->name) |
---|
231 | | - len += scnprintf(buf+len, PAGE_SIZE - len, |
---|
| 258 | + len += scnprintf(buf + len, PAGE_SIZE - len, |
---|
232 | 259 | "name:\t%s\n", |
---|
233 | 260 | test_fw_config->name); |
---|
234 | 261 | else |
---|
235 | | - len += scnprintf(buf+len, PAGE_SIZE - len, |
---|
| 262 | + len += scnprintf(buf + len, PAGE_SIZE - len, |
---|
236 | 263 | "name:\tEMTPY\n"); |
---|
237 | 264 | |
---|
238 | | - len += scnprintf(buf+len, PAGE_SIZE - len, |
---|
| 265 | + len += scnprintf(buf + len, PAGE_SIZE - len, |
---|
239 | 266 | "num_requests:\t%u\n", test_fw_config->num_requests); |
---|
240 | 267 | |
---|
241 | | - len += scnprintf(buf+len, PAGE_SIZE - len, |
---|
| 268 | + len += scnprintf(buf + len, PAGE_SIZE - len, |
---|
242 | 269 | "send_uevent:\t\t%s\n", |
---|
243 | 270 | test_fw_config->send_uevent ? |
---|
244 | 271 | "FW_ACTION_HOTPLUG" : |
---|
245 | 272 | "FW_ACTION_NOHOTPLUG"); |
---|
246 | | - len += scnprintf(buf+len, PAGE_SIZE - len, |
---|
| 273 | + len += scnprintf(buf + len, PAGE_SIZE - len, |
---|
| 274 | + "into_buf:\t\t%s\n", |
---|
| 275 | + test_fw_config->into_buf ? "true" : "false"); |
---|
| 276 | + len += scnprintf(buf + len, PAGE_SIZE - len, |
---|
| 277 | + "buf_size:\t%zu\n", test_fw_config->buf_size); |
---|
| 278 | + len += scnprintf(buf + len, PAGE_SIZE - len, |
---|
| 279 | + "file_offset:\t%zu\n", test_fw_config->file_offset); |
---|
| 280 | + len += scnprintf(buf + len, PAGE_SIZE - len, |
---|
| 281 | + "partial:\t\t%s\n", |
---|
| 282 | + test_fw_config->partial ? "true" : "false"); |
---|
| 283 | + len += scnprintf(buf + len, PAGE_SIZE - len, |
---|
247 | 284 | "sync_direct:\t\t%s\n", |
---|
248 | 285 | test_fw_config->sync_direct ? "true" : "false"); |
---|
249 | | - len += scnprintf(buf+len, PAGE_SIZE - len, |
---|
| 286 | + len += scnprintf(buf + len, PAGE_SIZE - len, |
---|
250 | 287 | "read_fw_idx:\t%u\n", test_fw_config->read_fw_idx); |
---|
251 | 288 | |
---|
252 | 289 | mutex_unlock(&test_fw_mutex); |
---|
.. | .. |
---|
284 | 321 | return len; |
---|
285 | 322 | } |
---|
286 | 323 | |
---|
| 324 | +static inline int __test_dev_config_update_bool(const char *buf, size_t size, |
---|
| 325 | + bool *cfg) |
---|
| 326 | +{ |
---|
| 327 | + int ret; |
---|
| 328 | + |
---|
| 329 | + if (kstrtobool(buf, cfg) < 0) |
---|
| 330 | + ret = -EINVAL; |
---|
| 331 | + else |
---|
| 332 | + ret = size; |
---|
| 333 | + |
---|
| 334 | + return ret; |
---|
| 335 | +} |
---|
| 336 | + |
---|
287 | 337 | static int test_dev_config_update_bool(const char *buf, size_t size, |
---|
288 | 338 | bool *cfg) |
---|
289 | 339 | { |
---|
290 | 340 | int ret; |
---|
291 | 341 | |
---|
292 | 342 | mutex_lock(&test_fw_mutex); |
---|
293 | | - if (strtobool(buf, cfg) < 0) |
---|
294 | | - ret = -EINVAL; |
---|
295 | | - else |
---|
296 | | - ret = size; |
---|
| 343 | + ret = __test_dev_config_update_bool(buf, size, cfg); |
---|
297 | 344 | mutex_unlock(&test_fw_mutex); |
---|
298 | 345 | |
---|
299 | 346 | return ret; |
---|
300 | 347 | } |
---|
301 | 348 | |
---|
302 | | -static ssize_t |
---|
303 | | -test_dev_config_show_bool(char *buf, |
---|
304 | | - bool config) |
---|
| 349 | +static ssize_t test_dev_config_show_bool(char *buf, bool val) |
---|
305 | 350 | { |
---|
306 | | - bool val; |
---|
307 | | - |
---|
308 | | - mutex_lock(&test_fw_mutex); |
---|
309 | | - val = config; |
---|
310 | | - mutex_unlock(&test_fw_mutex); |
---|
311 | | - |
---|
312 | 351 | return snprintf(buf, PAGE_SIZE, "%d\n", val); |
---|
313 | 352 | } |
---|
314 | 353 | |
---|
315 | | -static ssize_t test_dev_config_show_int(char *buf, int cfg) |
---|
316 | | -{ |
---|
317 | | - int val; |
---|
318 | | - |
---|
319 | | - mutex_lock(&test_fw_mutex); |
---|
320 | | - val = cfg; |
---|
321 | | - mutex_unlock(&test_fw_mutex); |
---|
322 | | - |
---|
323 | | - return snprintf(buf, PAGE_SIZE, "%d\n", val); |
---|
324 | | -} |
---|
325 | | - |
---|
326 | | -static int test_dev_config_update_u8(const char *buf, size_t size, u8 *cfg) |
---|
| 354 | +static int __test_dev_config_update_size_t( |
---|
| 355 | + const char *buf, |
---|
| 356 | + size_t size, |
---|
| 357 | + size_t *cfg) |
---|
327 | 358 | { |
---|
328 | 359 | int ret; |
---|
329 | 360 | long new; |
---|
.. | .. |
---|
332 | 363 | if (ret) |
---|
333 | 364 | return ret; |
---|
334 | 365 | |
---|
335 | | - if (new > U8_MAX) |
---|
336 | | - return -EINVAL; |
---|
337 | | - |
---|
338 | | - mutex_lock(&test_fw_mutex); |
---|
339 | | - *(u8 *)cfg = new; |
---|
340 | | - mutex_unlock(&test_fw_mutex); |
---|
| 366 | + *(size_t *)cfg = new; |
---|
341 | 367 | |
---|
342 | 368 | /* Always return full write size even if we didn't consume all */ |
---|
343 | 369 | return size; |
---|
344 | 370 | } |
---|
345 | 371 | |
---|
346 | | -static ssize_t test_dev_config_show_u8(char *buf, u8 cfg) |
---|
| 372 | +static ssize_t test_dev_config_show_size_t(char *buf, size_t val) |
---|
| 373 | +{ |
---|
| 374 | + return snprintf(buf, PAGE_SIZE, "%zu\n", val); |
---|
| 375 | +} |
---|
| 376 | + |
---|
| 377 | +static ssize_t test_dev_config_show_int(char *buf, int val) |
---|
| 378 | +{ |
---|
| 379 | + return snprintf(buf, PAGE_SIZE, "%d\n", val); |
---|
| 380 | +} |
---|
| 381 | + |
---|
| 382 | +static int __test_dev_config_update_u8(const char *buf, size_t size, u8 *cfg) |
---|
347 | 383 | { |
---|
348 | 384 | u8 val; |
---|
| 385 | + int ret; |
---|
| 386 | + |
---|
| 387 | + ret = kstrtou8(buf, 10, &val); |
---|
| 388 | + if (ret) |
---|
| 389 | + return ret; |
---|
| 390 | + |
---|
| 391 | + *(u8 *)cfg = val; |
---|
| 392 | + |
---|
| 393 | + /* Always return full write size even if we didn't consume all */ |
---|
| 394 | + return size; |
---|
| 395 | +} |
---|
| 396 | + |
---|
| 397 | +static int test_dev_config_update_u8(const char *buf, size_t size, u8 *cfg) |
---|
| 398 | +{ |
---|
| 399 | + int ret; |
---|
349 | 400 | |
---|
350 | 401 | mutex_lock(&test_fw_mutex); |
---|
351 | | - val = cfg; |
---|
| 402 | + ret = __test_dev_config_update_u8(buf, size, cfg); |
---|
352 | 403 | mutex_unlock(&test_fw_mutex); |
---|
353 | 404 | |
---|
| 405 | + return ret; |
---|
| 406 | +} |
---|
| 407 | + |
---|
| 408 | +static ssize_t test_dev_config_show_u8(char *buf, u8 val) |
---|
| 409 | +{ |
---|
354 | 410 | return snprintf(buf, PAGE_SIZE, "%u\n", val); |
---|
355 | 411 | } |
---|
356 | 412 | |
---|
.. | .. |
---|
375 | 431 | mutex_unlock(&test_fw_mutex); |
---|
376 | 432 | goto out; |
---|
377 | 433 | } |
---|
378 | | - mutex_unlock(&test_fw_mutex); |
---|
379 | 434 | |
---|
380 | | - rc = test_dev_config_update_u8(buf, count, |
---|
381 | | - &test_fw_config->num_requests); |
---|
| 435 | + rc = __test_dev_config_update_u8(buf, count, |
---|
| 436 | + &test_fw_config->num_requests); |
---|
| 437 | + mutex_unlock(&test_fw_mutex); |
---|
382 | 438 | |
---|
383 | 439 | out: |
---|
384 | 440 | return rc; |
---|
.. | .. |
---|
391 | 447 | return test_dev_config_show_u8(buf, test_fw_config->num_requests); |
---|
392 | 448 | } |
---|
393 | 449 | static DEVICE_ATTR_RW(config_num_requests); |
---|
| 450 | + |
---|
| 451 | +static ssize_t config_into_buf_store(struct device *dev, |
---|
| 452 | + struct device_attribute *attr, |
---|
| 453 | + const char *buf, size_t count) |
---|
| 454 | +{ |
---|
| 455 | + return test_dev_config_update_bool(buf, |
---|
| 456 | + count, |
---|
| 457 | + &test_fw_config->into_buf); |
---|
| 458 | +} |
---|
| 459 | + |
---|
| 460 | +static ssize_t config_into_buf_show(struct device *dev, |
---|
| 461 | + struct device_attribute *attr, |
---|
| 462 | + char *buf) |
---|
| 463 | +{ |
---|
| 464 | + return test_dev_config_show_bool(buf, test_fw_config->into_buf); |
---|
| 465 | +} |
---|
| 466 | +static DEVICE_ATTR_RW(config_into_buf); |
---|
| 467 | + |
---|
| 468 | +static ssize_t config_buf_size_store(struct device *dev, |
---|
| 469 | + struct device_attribute *attr, |
---|
| 470 | + const char *buf, size_t count) |
---|
| 471 | +{ |
---|
| 472 | + int rc; |
---|
| 473 | + |
---|
| 474 | + mutex_lock(&test_fw_mutex); |
---|
| 475 | + if (test_fw_config->reqs) { |
---|
| 476 | + pr_err("Must call release_all_firmware prior to changing config\n"); |
---|
| 477 | + rc = -EINVAL; |
---|
| 478 | + mutex_unlock(&test_fw_mutex); |
---|
| 479 | + goto out; |
---|
| 480 | + } |
---|
| 481 | + |
---|
| 482 | + rc = __test_dev_config_update_size_t(buf, count, |
---|
| 483 | + &test_fw_config->buf_size); |
---|
| 484 | + mutex_unlock(&test_fw_mutex); |
---|
| 485 | + |
---|
| 486 | +out: |
---|
| 487 | + return rc; |
---|
| 488 | +} |
---|
| 489 | + |
---|
| 490 | +static ssize_t config_buf_size_show(struct device *dev, |
---|
| 491 | + struct device_attribute *attr, |
---|
| 492 | + char *buf) |
---|
| 493 | +{ |
---|
| 494 | + return test_dev_config_show_size_t(buf, test_fw_config->buf_size); |
---|
| 495 | +} |
---|
| 496 | +static DEVICE_ATTR_RW(config_buf_size); |
---|
| 497 | + |
---|
| 498 | +static ssize_t config_file_offset_store(struct device *dev, |
---|
| 499 | + struct device_attribute *attr, |
---|
| 500 | + const char *buf, size_t count) |
---|
| 501 | +{ |
---|
| 502 | + int rc; |
---|
| 503 | + |
---|
| 504 | + mutex_lock(&test_fw_mutex); |
---|
| 505 | + if (test_fw_config->reqs) { |
---|
| 506 | + pr_err("Must call release_all_firmware prior to changing config\n"); |
---|
| 507 | + rc = -EINVAL; |
---|
| 508 | + mutex_unlock(&test_fw_mutex); |
---|
| 509 | + goto out; |
---|
| 510 | + } |
---|
| 511 | + |
---|
| 512 | + rc = __test_dev_config_update_size_t(buf, count, |
---|
| 513 | + &test_fw_config->file_offset); |
---|
| 514 | + mutex_unlock(&test_fw_mutex); |
---|
| 515 | + |
---|
| 516 | +out: |
---|
| 517 | + return rc; |
---|
| 518 | +} |
---|
| 519 | + |
---|
| 520 | +static ssize_t config_file_offset_show(struct device *dev, |
---|
| 521 | + struct device_attribute *attr, |
---|
| 522 | + char *buf) |
---|
| 523 | +{ |
---|
| 524 | + return test_dev_config_show_size_t(buf, test_fw_config->file_offset); |
---|
| 525 | +} |
---|
| 526 | +static DEVICE_ATTR_RW(config_file_offset); |
---|
| 527 | + |
---|
| 528 | +static ssize_t config_partial_store(struct device *dev, |
---|
| 529 | + struct device_attribute *attr, |
---|
| 530 | + const char *buf, size_t count) |
---|
| 531 | +{ |
---|
| 532 | + return test_dev_config_update_bool(buf, |
---|
| 533 | + count, |
---|
| 534 | + &test_fw_config->partial); |
---|
| 535 | +} |
---|
| 536 | + |
---|
| 537 | +static ssize_t config_partial_show(struct device *dev, |
---|
| 538 | + struct device_attribute *attr, |
---|
| 539 | + char *buf) |
---|
| 540 | +{ |
---|
| 541 | + return test_dev_config_show_bool(buf, test_fw_config->partial); |
---|
| 542 | +} |
---|
| 543 | +static DEVICE_ATTR_RW(config_partial); |
---|
394 | 544 | |
---|
395 | 545 | static ssize_t config_sync_direct_store(struct device *dev, |
---|
396 | 546 | struct device_attribute *attr, |
---|
.. | .. |
---|
456 | 606 | |
---|
457 | 607 | name = kstrndup(buf, count, GFP_KERNEL); |
---|
458 | 608 | if (!name) |
---|
459 | | - return -ENOSPC; |
---|
| 609 | + return -ENOMEM; |
---|
460 | 610 | |
---|
461 | 611 | pr_info("loading '%s'\n", name); |
---|
462 | 612 | |
---|
463 | 613 | mutex_lock(&test_fw_mutex); |
---|
464 | 614 | release_firmware(test_firmware); |
---|
| 615 | + if (test_fw_config->reqs) |
---|
| 616 | + __test_release_all_firmware(); |
---|
465 | 617 | test_firmware = NULL; |
---|
466 | 618 | rc = request_firmware(&test_firmware, name, dev); |
---|
467 | 619 | if (rc) { |
---|
.. | .. |
---|
480 | 632 | } |
---|
481 | 633 | static DEVICE_ATTR_WO(trigger_request); |
---|
482 | 634 | |
---|
| 635 | +#ifdef CONFIG_EFI_EMBEDDED_FIRMWARE |
---|
| 636 | +extern struct list_head efi_embedded_fw_list; |
---|
| 637 | +extern bool efi_embedded_fw_checked; |
---|
| 638 | + |
---|
| 639 | +static ssize_t trigger_request_platform_store(struct device *dev, |
---|
| 640 | + struct device_attribute *attr, |
---|
| 641 | + const char *buf, size_t count) |
---|
| 642 | +{ |
---|
| 643 | + static const u8 test_data[] = { |
---|
| 644 | + 0x55, 0xaa, 0x55, 0xaa, 0x01, 0x02, 0x03, 0x04, |
---|
| 645 | + 0x55, 0xaa, 0x55, 0xaa, 0x05, 0x06, 0x07, 0x08, |
---|
| 646 | + 0x55, 0xaa, 0x55, 0xaa, 0x10, 0x20, 0x30, 0x40, |
---|
| 647 | + 0x55, 0xaa, 0x55, 0xaa, 0x50, 0x60, 0x70, 0x80 |
---|
| 648 | + }; |
---|
| 649 | + struct efi_embedded_fw efi_embedded_fw; |
---|
| 650 | + const struct firmware *firmware = NULL; |
---|
| 651 | + bool saved_efi_embedded_fw_checked; |
---|
| 652 | + char *name; |
---|
| 653 | + int rc; |
---|
| 654 | + |
---|
| 655 | + name = kstrndup(buf, count, GFP_KERNEL); |
---|
| 656 | + if (!name) |
---|
| 657 | + return -ENOMEM; |
---|
| 658 | + |
---|
| 659 | + pr_info("inserting test platform fw '%s'\n", name); |
---|
| 660 | + efi_embedded_fw.name = name; |
---|
| 661 | + efi_embedded_fw.data = (void *)test_data; |
---|
| 662 | + efi_embedded_fw.length = sizeof(test_data); |
---|
| 663 | + list_add(&efi_embedded_fw.list, &efi_embedded_fw_list); |
---|
| 664 | + saved_efi_embedded_fw_checked = efi_embedded_fw_checked; |
---|
| 665 | + efi_embedded_fw_checked = true; |
---|
| 666 | + |
---|
| 667 | + pr_info("loading '%s'\n", name); |
---|
| 668 | + rc = firmware_request_platform(&firmware, name, dev); |
---|
| 669 | + if (rc) { |
---|
| 670 | + pr_info("load of '%s' failed: %d\n", name, rc); |
---|
| 671 | + goto out; |
---|
| 672 | + } |
---|
| 673 | + if (firmware->size != sizeof(test_data) || |
---|
| 674 | + memcmp(firmware->data, test_data, sizeof(test_data)) != 0) { |
---|
| 675 | + pr_info("firmware contents mismatch for '%s'\n", name); |
---|
| 676 | + rc = -EINVAL; |
---|
| 677 | + goto out; |
---|
| 678 | + } |
---|
| 679 | + pr_info("loaded: %zu\n", firmware->size); |
---|
| 680 | + rc = count; |
---|
| 681 | + |
---|
| 682 | +out: |
---|
| 683 | + efi_embedded_fw_checked = saved_efi_embedded_fw_checked; |
---|
| 684 | + release_firmware(firmware); |
---|
| 685 | + list_del(&efi_embedded_fw.list); |
---|
| 686 | + kfree(name); |
---|
| 687 | + |
---|
| 688 | + return rc; |
---|
| 689 | +} |
---|
| 690 | +static DEVICE_ATTR_WO(trigger_request_platform); |
---|
| 691 | +#endif |
---|
| 692 | + |
---|
483 | 693 | static DECLARE_COMPLETION(async_fw_done); |
---|
484 | 694 | |
---|
485 | 695 | static void trigger_async_request_cb(const struct firmware *fw, void *context) |
---|
.. | .. |
---|
497 | 707 | |
---|
498 | 708 | name = kstrndup(buf, count, GFP_KERNEL); |
---|
499 | 709 | if (!name) |
---|
500 | | - return -ENOSPC; |
---|
| 710 | + return -ENOMEM; |
---|
501 | 711 | |
---|
502 | 712 | pr_info("loading '%s'\n", name); |
---|
503 | 713 | |
---|
504 | 714 | mutex_lock(&test_fw_mutex); |
---|
505 | 715 | release_firmware(test_firmware); |
---|
506 | 716 | test_firmware = NULL; |
---|
| 717 | + if (test_fw_config->reqs) |
---|
| 718 | + __test_release_all_firmware(); |
---|
507 | 719 | rc = request_firmware_nowait(THIS_MODULE, 1, name, dev, GFP_KERNEL, |
---|
508 | 720 | NULL, trigger_async_request_cb); |
---|
509 | 721 | if (rc) { |
---|
.. | .. |
---|
521 | 733 | rc = count; |
---|
522 | 734 | } else { |
---|
523 | 735 | pr_err("failed to async load firmware\n"); |
---|
524 | | - rc = -ENODEV; |
---|
| 736 | + rc = -ENOMEM; |
---|
525 | 737 | } |
---|
526 | 738 | |
---|
527 | 739 | out: |
---|
.. | .. |
---|
540 | 752 | |
---|
541 | 753 | name = kstrndup(buf, count, GFP_KERNEL); |
---|
542 | 754 | if (!name) |
---|
543 | | - return -ENOSPC; |
---|
| 755 | + return -ENOMEM; |
---|
544 | 756 | |
---|
545 | 757 | pr_info("loading '%s' using custom fallback mechanism\n", name); |
---|
546 | 758 | |
---|
547 | 759 | mutex_lock(&test_fw_mutex); |
---|
548 | 760 | release_firmware(test_firmware); |
---|
| 761 | + if (test_fw_config->reqs) |
---|
| 762 | + __test_release_all_firmware(); |
---|
549 | 763 | test_firmware = NULL; |
---|
550 | 764 | rc = request_firmware_nowait(THIS_MODULE, FW_ACTION_NOHOTPLUG, name, |
---|
551 | 765 | dev, GFP_KERNEL, NULL, |
---|
.. | .. |
---|
584 | 798 | return -EINVAL; |
---|
585 | 799 | } |
---|
586 | 800 | |
---|
587 | | - req->rc = test_fw_config->req_firmware(&req->fw, req->name, req->dev); |
---|
| 801 | + if (test_fw_config->into_buf) { |
---|
| 802 | + void *test_buf; |
---|
| 803 | + |
---|
| 804 | + test_buf = kzalloc(TEST_FIRMWARE_BUF_SIZE, GFP_KERNEL); |
---|
| 805 | + if (!test_buf) |
---|
| 806 | + return -ENOMEM; |
---|
| 807 | + |
---|
| 808 | + if (test_fw_config->partial) |
---|
| 809 | + req->rc = request_partial_firmware_into_buf |
---|
| 810 | + (&req->fw, |
---|
| 811 | + req->name, |
---|
| 812 | + req->dev, |
---|
| 813 | + test_buf, |
---|
| 814 | + test_fw_config->buf_size, |
---|
| 815 | + test_fw_config->file_offset); |
---|
| 816 | + else |
---|
| 817 | + req->rc = request_firmware_into_buf |
---|
| 818 | + (&req->fw, |
---|
| 819 | + req->name, |
---|
| 820 | + req->dev, |
---|
| 821 | + test_buf, |
---|
| 822 | + test_fw_config->buf_size); |
---|
| 823 | + if (!req->fw) |
---|
| 824 | + kfree(test_buf); |
---|
| 825 | + else |
---|
| 826 | + req->fw_buf = test_buf; |
---|
| 827 | + } else { |
---|
| 828 | + req->rc = test_fw_config->req_firmware(&req->fw, |
---|
| 829 | + req->name, |
---|
| 830 | + req->dev); |
---|
| 831 | + } |
---|
| 832 | + |
---|
588 | 833 | if (req->rc) { |
---|
589 | 834 | pr_info("#%u: batched sync load failed: %d\n", |
---|
590 | 835 | req->idx, req->rc); |
---|
.. | .. |
---|
618 | 863 | |
---|
619 | 864 | mutex_lock(&test_fw_mutex); |
---|
620 | 865 | |
---|
| 866 | + if (test_fw_config->reqs) { |
---|
| 867 | + rc = -EBUSY; |
---|
| 868 | + goto out_bail; |
---|
| 869 | + } |
---|
| 870 | + |
---|
621 | 871 | test_fw_config->reqs = |
---|
622 | 872 | vzalloc(array3_size(sizeof(struct test_batched_req), |
---|
623 | 873 | test_fw_config->num_requests, 2)); |
---|
.. | .. |
---|
631 | 881 | |
---|
632 | 882 | for (i = 0; i < test_fw_config->num_requests; i++) { |
---|
633 | 883 | req = &test_fw_config->reqs[i]; |
---|
634 | | - if (!req) { |
---|
635 | | - WARN_ON(1); |
---|
636 | | - rc = -ENOMEM; |
---|
637 | | - goto out_bail; |
---|
638 | | - } |
---|
639 | 884 | req->fw = NULL; |
---|
640 | 885 | req->idx = i; |
---|
641 | 886 | req->name = test_fw_config->name; |
---|
| 887 | + req->fw_buf = NULL; |
---|
642 | 888 | req->dev = dev; |
---|
643 | 889 | init_completion(&req->completion); |
---|
644 | 890 | req->task = kthread_run(test_fw_run_batch_request, req, |
---|
.. | .. |
---|
721 | 967 | |
---|
722 | 968 | mutex_lock(&test_fw_mutex); |
---|
723 | 969 | |
---|
| 970 | + if (test_fw_config->reqs) { |
---|
| 971 | + rc = -EBUSY; |
---|
| 972 | + goto out_bail; |
---|
| 973 | + } |
---|
| 974 | + |
---|
724 | 975 | test_fw_config->reqs = |
---|
725 | 976 | vzalloc(array3_size(sizeof(struct test_batched_req), |
---|
726 | 977 | test_fw_config->num_requests, 2)); |
---|
.. | .. |
---|
737 | 988 | |
---|
738 | 989 | for (i = 0; i < test_fw_config->num_requests; i++) { |
---|
739 | 990 | req = &test_fw_config->reqs[i]; |
---|
740 | | - if (!req) { |
---|
741 | | - WARN_ON(1); |
---|
742 | | - goto out_bail; |
---|
743 | | - } |
---|
744 | 991 | req->name = test_fw_config->name; |
---|
| 992 | + req->fw_buf = NULL; |
---|
745 | 993 | req->fw = NULL; |
---|
746 | 994 | req->idx = i; |
---|
747 | 995 | init_completion(&req->completion); |
---|
.. | .. |
---|
857 | 1105 | TEST_FW_DEV_ATTR(config), |
---|
858 | 1106 | TEST_FW_DEV_ATTR(config_name), |
---|
859 | 1107 | TEST_FW_DEV_ATTR(config_num_requests), |
---|
| 1108 | + TEST_FW_DEV_ATTR(config_into_buf), |
---|
| 1109 | + TEST_FW_DEV_ATTR(config_buf_size), |
---|
| 1110 | + TEST_FW_DEV_ATTR(config_file_offset), |
---|
| 1111 | + TEST_FW_DEV_ATTR(config_partial), |
---|
860 | 1112 | TEST_FW_DEV_ATTR(config_sync_direct), |
---|
861 | 1113 | TEST_FW_DEV_ATTR(config_send_uevent), |
---|
862 | 1114 | TEST_FW_DEV_ATTR(config_read_fw_idx), |
---|
.. | .. |
---|
865 | 1117 | TEST_FW_DEV_ATTR(trigger_request), |
---|
866 | 1118 | TEST_FW_DEV_ATTR(trigger_async_request), |
---|
867 | 1119 | TEST_FW_DEV_ATTR(trigger_custom_fallback), |
---|
| 1120 | +#ifdef CONFIG_EFI_EMBEDDED_FIRMWARE |
---|
| 1121 | + TEST_FW_DEV_ATTR(trigger_request_platform), |
---|
| 1122 | +#endif |
---|
868 | 1123 | |
---|
869 | 1124 | /* These use the config and can use the test_result */ |
---|
870 | 1125 | TEST_FW_DEV_ATTR(trigger_batched_requests), |
---|
.. | .. |
---|
902 | 1157 | |
---|
903 | 1158 | rc = misc_register(&test_fw_misc_device); |
---|
904 | 1159 | if (rc) { |
---|
| 1160 | + __test_firmware_config_free(); |
---|
905 | 1161 | kfree(test_fw_config); |
---|
906 | 1162 | pr_err("could not register misc device: %d\n", rc); |
---|
907 | 1163 | return rc; |
---|