* Event log main entry point */
| 737 | * Event log main entry point |
| 738 | */ |
| 739 | int elog_init(void) |
| 740 | { |
| 741 | void *mirror_buffer; |
| 742 | size_t elog_size; |
| 743 | switch (elog_state.elog_initialized) { |
| 744 | case ELOG_UNINITIALIZED: |
| 745 | break; |
| 746 | case ELOG_INITIALIZED: |
| 747 | return 0; |
| 748 | case ELOG_BROKEN: |
| 749 | return -1; |
| 750 | } |
| 751 | elog_state.elog_initialized = ELOG_BROKEN; |
| 752 | |
| 753 | if (!ENV_SMM) |
| 754 | timestamp_add_now(TS_ELOG_INIT_START); |
| 755 | |
| 756 | elog_debug("%s()\n", __func__); |
| 757 | |
| 758 | /* Set up the backing store */ |
| 759 | if (elog_find_flash() < 0) |
| 760 | return -1; |
| 761 | |
| 762 | elog_size = region_device_sz(&elog_state.nv_dev); |
| 763 | mirror_buffer = elog_mirror_buf; |
| 764 | rdev_chain_mem_rw(&elog_state.mirror_dev, mirror_buffer, elog_size); |
| 765 | |
| 766 | /* |
| 767 | * Mark as initialized to allow elog_init() to be called and deemed |
| 768 | * successful in the prepare/shrink path which adds events. |
| 769 | */ |
| 770 | elog_state.elog_initialized = ELOG_INITIALIZED; |
| 771 | |
| 772 | /* Load the log from flash and prepare the flash if necessary. */ |
| 773 | if (elog_scan_flash() < 0 && elog_prepare_empty() < 0) { |
| 774 | printk(BIOS_ERR, "ELOG: Unable to prepare flash\n"); |
| 775 | return -1; |
| 776 | } |
| 777 | |
| 778 | printk(BIOS_INFO, "ELOG: area is %zu bytes, full threshold %d," |
| 779 | " shrink size %d\n", region_device_sz(&elog_state.nv_dev), |
| 780 | elog_state.full_threshold, elog_state.shrink_size); |
| 781 | |
| 782 | if (ENV_PAYLOAD_LOADER) |
| 783 | elog_add_boot_count(); |
| 784 | |
| 785 | if (!ENV_SMM) |
| 786 | timestamp_add_now(TS_ELOG_INIT_END); |
| 787 | |
| 788 | return 0; |
| 789 | } |
| 790 | |
| 791 | /* |
| 792 | * Add an event to the log |
no test coverage detected