|
67 | 67 | #include <linux/acpi.h> |
68 | 68 | #include <linux/init.h> |
69 | 69 | #include <linux/sfi.h> |
| 70 | +#include <linux/slab.h> |
70 | 71 |
|
71 | 72 | #include "sfi_core.h" |
72 | 73 |
|
@@ -382,6 +383,102 @@ static __init int sfi_find_syst(void) |
382 | 383 | return -1; |
383 | 384 | } |
384 | 385 |
|
| 386 | +static struct kobject *sfi_kobj; |
| 387 | +static struct kobject *tables_kobj; |
| 388 | + |
| 389 | +static ssize_t sfi_table_show(struct file *filp, struct kobject *kobj, |
| 390 | + struct bin_attribute *bin_attr, char *buf, |
| 391 | + loff_t offset, size_t count) |
| 392 | +{ |
| 393 | + struct sfi_table_attr *tbl_attr = |
| 394 | + container_of(bin_attr, struct sfi_table_attr, attr); |
| 395 | + struct sfi_table_header *th = NULL; |
| 396 | + struct sfi_table_key key; |
| 397 | + ssize_t cnt; |
| 398 | + |
| 399 | + key.sig = tbl_attr->name; |
| 400 | + key.oem_id = NULL; |
| 401 | + key.oem_table_id = NULL; |
| 402 | + |
| 403 | + if (strncmp(SFI_SIG_SYST, tbl_attr->name, SFI_SIGNATURE_SIZE)) { |
| 404 | + th = sfi_get_table(&key); |
| 405 | + if (!th) |
| 406 | + return 0; |
| 407 | + |
| 408 | + cnt = memory_read_from_buffer(buf, count, &offset, |
| 409 | + th, th->len); |
| 410 | + sfi_put_table(th); |
| 411 | + } else |
| 412 | + cnt = memory_read_from_buffer(buf, count, &offset, |
| 413 | + syst_va, syst_va->header.len); |
| 414 | + |
| 415 | + return cnt; |
| 416 | +} |
| 417 | + |
| 418 | +struct sfi_table_attr __init *sfi_sysfs_install_table(u64 pa) |
| 419 | +{ |
| 420 | + struct sfi_table_attr *tbl_attr; |
| 421 | + struct sfi_table_header *th; |
| 422 | + int ret; |
| 423 | + |
| 424 | + tbl_attr = kzalloc(sizeof(struct sfi_table_attr), GFP_KERNEL); |
| 425 | + if (!tbl_attr) |
| 426 | + return NULL; |
| 427 | + |
| 428 | + th = sfi_map_table(pa); |
| 429 | + if (!th || !th->sig[0]) { |
| 430 | + kfree(tbl_attr); |
| 431 | + return NULL; |
| 432 | + } |
| 433 | + |
| 434 | + sysfs_attr_init(&tbl_attr->attr.attr); |
| 435 | + memcpy(tbl_attr->name, th->sig, SFI_SIGNATURE_SIZE); |
| 436 | + |
| 437 | + tbl_attr->attr.size = 0; |
| 438 | + tbl_attr->attr.read = sfi_table_show; |
| 439 | + tbl_attr->attr.attr.name = tbl_attr->name; |
| 440 | + tbl_attr->attr.attr.mode = 0400; |
| 441 | + |
| 442 | + ret = sysfs_create_bin_file(tables_kobj, |
| 443 | + &tbl_attr->attr); |
| 444 | + if (ret) |
| 445 | + kfree(tbl_attr); |
| 446 | + |
| 447 | + sfi_unmap_table(th); |
| 448 | + return tbl_attr; |
| 449 | +} |
| 450 | + |
| 451 | +static int __init sfi_sysfs_init(void) |
| 452 | +{ |
| 453 | + int tbl_cnt, i; |
| 454 | + |
| 455 | + if (sfi_disabled) |
| 456 | + return 0; |
| 457 | + |
| 458 | + sfi_kobj = kobject_create_and_add("sfi", firmware_kobj); |
| 459 | + if (!sfi_kobj) |
| 460 | + return 0; |
| 461 | + |
| 462 | + tables_kobj = kobject_create_and_add("tables", sfi_kobj); |
| 463 | + if (!tables_kobj) { |
| 464 | + kobject_put(sfi_kobj); |
| 465 | + return 0; |
| 466 | + } |
| 467 | + |
| 468 | + sfi_sysfs_install_table(syst_pa); |
| 469 | + |
| 470 | + tbl_cnt = SFI_GET_NUM_ENTRIES(syst_va, u64); |
| 471 | + |
| 472 | + for (i = 0; i < tbl_cnt; i++) |
| 473 | + sfi_sysfs_install_table(syst_va->pentry[i]); |
| 474 | + |
| 475 | + sfi_acpi_sysfs_init(); |
| 476 | + kobject_uevent(sfi_kobj, KOBJ_ADD); |
| 477 | + kobject_uevent(tables_kobj, KOBJ_ADD); |
| 478 | + pr_info("SFI sysfs interfaces init success\n"); |
| 479 | + return 0; |
| 480 | +} |
| 481 | + |
385 | 482 | void __init sfi_init(void) |
386 | 483 | { |
387 | 484 | if (!acpi_disabled) |
@@ -414,3 +511,9 @@ void __init sfi_init_late(void) |
414 | 511 |
|
415 | 512 | sfi_acpi_init(); |
416 | 513 | } |
| 514 | + |
| 515 | +/* |
| 516 | + * The reason we put it here becasue we need wait till the /sys/firmware |
| 517 | + * is setup, then our interface can be registered in /sys/firmware/sfi |
| 518 | + */ |
| 519 | +core_initcall(sfi_sysfs_init); |
0 commit comments