diff mbox

[Xen-devel,RFC,07/19] move read_file() to efi-shared.c

Message ID 1403918735-30027-8-git-send-email-roy.franz@linaro.org
State New
Headers show

Commit Message

Roy Franz June 28, 2014, 1:25 a.m. UTC
The now refactored read_file() is shareable with the ARM code that will be
added, so move it to the shared C file.

Signed-off-by: Roy Franz <roy.franz@linaro.org>
---
 xen/arch/x86/efi/boot.c       | 77 ---------------------------------------
 xen/arch/x86/efi/efi-shared.c | 83 +++++++++++++++++++++++++++++++++++++++++++
 xen/include/efi/efi-shared.h  |  2 ++
 3 files changed, 85 insertions(+), 77 deletions(-)
diff mbox

Patch

diff --git a/xen/arch/x86/efi/boot.c b/xen/arch/x86/efi/boot.c
index 8904a4e..2e3d341 100644
--- a/xen/arch/x86/efi/boot.c
+++ b/xen/arch/x86/efi/boot.c
@@ -164,83 +164,6 @@  static unsigned int __init get_argv(unsigned int argc, CHAR16 **argv,
     return argc;
 }
 
-static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
-                               struct file *file)
-{
-    EFI_FILE_HANDLE FileHandle = NULL;
-    UINT64 size;
-    EFI_STATUS ret;
-    CHAR16 *what = NULL;
-
-    if ( !name )
-        PrintErrMesgExit(L"No Filename", EFI_OUT_OF_RESOURCES);
-
-    ret = dir_handle->Open(dir_handle, &FileHandle, name,
-                           EFI_FILE_MODE_READ, 0);
-
-    if ( EFI_ERROR(ret) )
-        what = L"Open";
-    else
-        ret = FileHandle->SetPosition(FileHandle, -1);
-    if ( EFI_ERROR(ret) )
-        what = what ?: L"Seek";
-    else
-        ret = FileHandle->GetPosition(FileHandle, &size);
-    if ( EFI_ERROR(ret) )
-        what = what ?: L"Get size";
-    else
-        ret = FileHandle->SetPosition(FileHandle, 0);
-    if ( EFI_ERROR(ret) )
-        what = what ?: L"Seek";
-    else
-    {
-        file->addr = min(1UL << (32 + PAGE_SHIFT),
-                         HYPERVISOR_VIRT_END - DIRECTMAP_VIRT_START);
-        ret = efi_bs->AllocatePages(AllocateMaxAddress, EfiLoaderData,
-                                    PFN_UP(size), &file->addr);
-    }
-    if ( EFI_ERROR(ret) )
-    {
-        file->addr = 0;
-        what = what ?: L"Allocation";
-    }
-    else
-    {
-
-        file->size = size;
-        ret = FileHandle->Read(FileHandle, &file->size, file->ptr);
-        if ( !EFI_ERROR(ret) && file->size != size )
-            ret = EFI_ABORTED;
-        if ( EFI_ERROR(ret) )
-        {
-            what = what ?: L"Read";
-            efi_bs->FreePages(file->addr, PFN_UP(file->size));
-            file->addr = 0;
-        }
-    }
-
-    if ( FileHandle )
-        FileHandle->Close(FileHandle);
-
-
-    if ( what )
-    {
-        PrintErrMesg(what, ret);
-        blexit(L"Unable to load file");
-    }
-    else
-    {
-        PrintStr(name);
-        PrintStr(L": ");
-        DisplayUint(file->addr, 2 * sizeof(file->addr));
-        PrintStr(L"-");
-        DisplayUint(file->addr + file->size, 2 * sizeof(file->addr));
-        PrintStr(newline);
-        return 1;
-    }
-
-}
-
 /* Only call with non-config files. */
 void __init load_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
                                struct file *file)
diff --git a/xen/arch/x86/efi/efi-shared.c b/xen/arch/x86/efi/efi-shared.c
index d997b5c..98ad5db 100644
--- a/xen/arch/x86/efi/efi-shared.c
+++ b/xen/arch/x86/efi/efi-shared.c
@@ -11,6 +11,12 @@ 
 #include <xen/init.h>
 #include <asm/processor.h>
 #include <xen/keyhandler.h>
+#include <xen/pfn.h>
+#include <xen/kernel.h>
+#if EFI_PAGE_SIZE != PAGE_SIZE
+# error Cannot use xen/pfn.h here!
+#endif
+
 
 SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdOut;
 SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdErr;
@@ -338,3 +344,80 @@  char *__init get_value(const struct file *cfg, const char *section,
     }
     return NULL;
 }
+
+bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
+                               struct file *file)
+{
+    EFI_FILE_HANDLE FileHandle = NULL;
+    UINT64 size;
+    EFI_STATUS ret;
+    CHAR16 *what = NULL;
+
+    if ( !name )
+        PrintErrMesgExit(L"No Filename", EFI_OUT_OF_RESOURCES);
+
+    ret = dir_handle->Open(dir_handle, &FileHandle, name,
+                           EFI_FILE_MODE_READ, 0);
+
+    if ( EFI_ERROR(ret) )
+        what = L"Open";
+    else
+        ret = FileHandle->SetPosition(FileHandle, -1);
+    if ( EFI_ERROR(ret) )
+        what = what ?: L"Seek";
+    else
+        ret = FileHandle->GetPosition(FileHandle, &size);
+    if ( EFI_ERROR(ret) )
+        what = what ?: L"Get size";
+    else
+        ret = FileHandle->SetPosition(FileHandle, 0);
+    if ( EFI_ERROR(ret) )
+        what = what ?: L"Seek";
+    else
+    {
+        file->addr = min(1UL << (32 + PAGE_SHIFT),
+                         HYPERVISOR_VIRT_END - DIRECTMAP_VIRT_START);
+        ret = efi_bs->AllocatePages(AllocateMaxAddress, EfiLoaderData,
+                                    PFN_UP(size), &file->addr);
+    }
+    if ( EFI_ERROR(ret) )
+    {
+        file->addr = 0;
+        what = what ?: L"Allocation";
+    }
+    else
+    {
+
+        file->size = size;
+        ret = FileHandle->Read(FileHandle, &file->size, file->ptr);
+        if ( !EFI_ERROR(ret) && file->size != size )
+            ret = EFI_ABORTED;
+        if ( EFI_ERROR(ret) )
+        {
+            what = what ?: L"Read";
+            efi_bs->FreePages(file->addr, PFN_UP(file->size));
+            file->addr = 0;
+        }
+    }
+
+    if ( FileHandle )
+        FileHandle->Close(FileHandle);
+
+
+    if ( what )
+    {
+        PrintErrMesg(what, ret);
+        blexit(L"Unable to load file");
+    }
+    else
+    {
+        PrintStr(name);
+        PrintStr(L": ");
+        DisplayUint(file->addr, 2 * sizeof(file->addr));
+        PrintStr(L"-");
+        DisplayUint(file->addr + file->size, 2 * sizeof(file->addr));
+        PrintStr(newline);
+        return 1;
+    }
+
+}
diff --git a/xen/include/efi/efi-shared.h b/xen/include/efi/efi-shared.h
index d4b6e13..168cf2a 100644
--- a/xen/include/efi/efi-shared.h
+++ b/xen/include/efi/efi-shared.h
@@ -54,4 +54,6 @@  char *__init get_value(const struct file *cfg, const char *section,
 /* These functions need to be provided by the architecture's EFI code */
 void __init noreturn blexit(const CHAR16 *str);
 
+bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
+                               struct file *file);
 #endif