Commit e3fbbc36f2d94f15d4d9bcd52d59d82d849a8e21

Authored by Heinrich Schuchardt
Committed by Alexander Graf
1 parent 3b8a489c9f

efi_loader: implement OpenProtocolInformation

efi_open_protocol_information provides the agent and controller
handles as well as the attributes and open count of an protocol
on a handle.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
[agraf: fix counting error]
Signed-off-by: Alexander Graf <agraf@suse.de>

Showing 1 changed file with 41 additions and 1 deletions Side-by-side Diff

lib/efi_loader/efi_boottime.c
... ... @@ -1742,9 +1742,49 @@
1742 1742 struct efi_open_protocol_info_entry **entry_buffer,
1743 1743 efi_uintn_t *entry_count)
1744 1744 {
  1745 + unsigned long buffer_size;
  1746 + unsigned long count;
  1747 + struct efi_handler *handler;
  1748 + struct efi_open_protocol_info_item *item;
  1749 + efi_status_t r;
  1750 +
1745 1751 EFI_ENTRY("%p, %pUl, %p, %p", handle, protocol, entry_buffer,
1746 1752 entry_count);
1747   - return EFI_EXIT(EFI_NOT_FOUND);
  1753 +
  1754 + /* Check parameters */
  1755 + if (!entry_buffer) {
  1756 + r = EFI_INVALID_PARAMETER;
  1757 + goto out;
  1758 + }
  1759 + r = efi_search_protocol(handle, protocol, &handler);
  1760 + if (r != EFI_SUCCESS)
  1761 + goto out;
  1762 +
  1763 + /* Count entries */
  1764 + count = 0;
  1765 + list_for_each_entry(item, &handler->open_infos, link) {
  1766 + if (item->info.open_count)
  1767 + ++count;
  1768 + }
  1769 + *entry_count = count;
  1770 + *entry_buffer = NULL;
  1771 + if (!count) {
  1772 + r = EFI_SUCCESS;
  1773 + goto out;
  1774 + }
  1775 +
  1776 + /* Copy entries */
  1777 + buffer_size = count * sizeof(struct efi_open_protocol_info_entry);
  1778 + r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size,
  1779 + (void **)entry_buffer);
  1780 + if (r != EFI_SUCCESS)
  1781 + goto out;
  1782 + list_for_each_entry_reverse(item, &handler->open_infos, link) {
  1783 + if (item->info.open_count)
  1784 + (*entry_buffer)[--count] = item->info;
  1785 + }
  1786 +out:
  1787 + return EFI_EXIT(r);
1748 1788 }
1749 1789  
1750 1790 /*