mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-23 22:18:17 +00:00
UEFI: cleanup functions in boot.c file
Remove the useless function named get_path(). Remove the useless function named print_ch(). Remove the useless function named isspace(). Move the function memory_map() from boot.c to malloc.c Signed-off-by: Zheng, Gen <gen.zheng@intel.com>
This commit is contained in:
parent
edde39b368
commit
0762798543
@ -41,84 +41,6 @@ EFI_SYSTEM_TABLE *sys_table;
|
||||
EFI_BOOT_SERVICES *boot;
|
||||
EFI_RUNTIME_SERVICES *runtime;
|
||||
|
||||
/**
|
||||
* memory_map - Allocate and fill out an array of memory descriptors
|
||||
* @map_buf: buffer containing the memory map
|
||||
* @map_size: size of the buffer containing the memory map
|
||||
* @map_key: key for the current memory map
|
||||
* @desc_size: size of the desc
|
||||
* @desc_version: memory descriptor version
|
||||
*
|
||||
* On success, @map_size contains the size of the memory map pointed
|
||||
* to by @map_buf and @map_key, @desc_size and @desc_version are
|
||||
* updated.
|
||||
*/
|
||||
EFI_STATUS
|
||||
memory_map(EFI_MEMORY_DESCRIPTOR **map_buf, UINTN *map_size,
|
||||
UINTN *map_key, UINTN *desc_size, UINT32 *desc_version)
|
||||
{
|
||||
EFI_STATUS err;
|
||||
|
||||
*map_size = sizeof(**map_buf) * 31;
|
||||
get_map:
|
||||
|
||||
/*
|
||||
* Because we're about to allocate memory, we may
|
||||
* potentially create a new memory descriptor, thereby
|
||||
* increasing the size of the memory map. So increase
|
||||
* the buffer size by the size of one memory
|
||||
* descriptor, just in case.
|
||||
*/
|
||||
*map_size += sizeof(**map_buf);
|
||||
|
||||
err = allocate_pool(EfiLoaderData, *map_size,
|
||||
(void **)map_buf);
|
||||
if (err != EFI_SUCCESS) {
|
||||
Print(L"Failed to allocate pool for memory map");
|
||||
goto failed;
|
||||
}
|
||||
|
||||
err = get_memory_map(map_size, *map_buf, map_key,
|
||||
desc_size, desc_version);
|
||||
if (err != EFI_SUCCESS) {
|
||||
if (err == EFI_BUFFER_TOO_SMALL) {
|
||||
/*
|
||||
* 'map_size' has been updated to reflect the
|
||||
* required size of a map buffer.
|
||||
*/
|
||||
free_pool((void *)*map_buf);
|
||||
goto get_map;
|
||||
}
|
||||
|
||||
Print(L"Failed to get memory map");
|
||||
goto failed;
|
||||
}
|
||||
|
||||
failed:
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline BOOLEAN isspace(CHAR8 ch)
|
||||
{
|
||||
return ((unsigned char)ch <= ' ');
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void print_ch(char *str)
|
||||
{
|
||||
int j;
|
||||
CHAR16 *buf;
|
||||
int len = strlen(str);
|
||||
|
||||
buf = malloc((strlen(str) + 1)* 2);
|
||||
for (j=0; j<len; j++)
|
||||
buf[j] = str[j];
|
||||
buf[j] = 0;
|
||||
Print(L"CHAR16::: %s\n", buf);
|
||||
free(buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void hv_jump(EFI_PHYSICAL_ADDRESS hv_start,
|
||||
struct multiboot_info *mbi, struct efi_ctx *efi_ctx)
|
||||
{
|
||||
@ -141,56 +63,6 @@ static inline void hv_jump(EFI_PHYSICAL_ADDRESS hv_start,
|
||||
hf(MULTIBOOT_INFO_MAGIC, mbi);
|
||||
}
|
||||
|
||||
EFI_STATUS get_path(CHAR16* name, EFI_LOADED_IMAGE *info, EFI_DEVICE_PATH **path)
|
||||
{
|
||||
unsigned int pathlen;
|
||||
EFI_STATUS efi_status = EFI_SUCCESS;
|
||||
CHAR16 *pathstr, *pathname;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < StrLen(name); i++) {
|
||||
if (name[i] == '/')
|
||||
name[i] = '\\';
|
||||
}
|
||||
|
||||
pathstr = DevicePathToStr(info->FilePath);
|
||||
for (i = 0; i < StrLen(pathstr); i++) {
|
||||
if (pathstr[i] == '/')
|
||||
pathstr[i] = '\\';
|
||||
}
|
||||
|
||||
pathlen = StrLen(pathstr);
|
||||
|
||||
if (name[0] == '\\') {
|
||||
*path = FileDevicePath(info->DeviceHandle, name);
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (i=pathlen - 1; i > 0; i--) {
|
||||
if (pathstr[i] == '\\') break;
|
||||
}
|
||||
pathstr[i] = '\0';
|
||||
|
||||
pathlen = StrLen(pathstr);
|
||||
|
||||
pathlen++;
|
||||
pathname = AllocatePool((pathlen + 1 + StrLen(name))*sizeof(CHAR16));
|
||||
if (!pathname) {
|
||||
Print(L"Failed to allocate memory for pathname\n");
|
||||
efi_status = EFI_OUT_OF_RESOURCES;
|
||||
goto out;
|
||||
}
|
||||
StrCpy(pathname, pathstr);
|
||||
StrCat(pathname, L"\\");
|
||||
StrCat(pathname, name);
|
||||
|
||||
*path = FileDevicePath(info->DeviceHandle, pathname);
|
||||
|
||||
out:
|
||||
FreePool(pathstr);
|
||||
return efi_status;
|
||||
}
|
||||
|
||||
static EFI_STATUS
|
||||
switch_to_guest_mode(EFI_HANDLE image)
|
||||
{
|
||||
|
@ -36,6 +36,63 @@
|
||||
#include "efilinux.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
/**
|
||||
* memory_map - Allocate and fill out an array of memory descriptors
|
||||
* @map_buf: buffer containing the memory map
|
||||
* @map_size: size of the buffer containing the memory map
|
||||
* @map_key: key for the current memory map
|
||||
* @desc_size: size of the desc
|
||||
* @desc_version: memory descriptor version
|
||||
*
|
||||
* On success, @map_size contains the size of the memory map pointed
|
||||
* to by @map_buf and @map_key, @desc_size and @desc_version are
|
||||
* updated.
|
||||
*/
|
||||
EFI_STATUS
|
||||
memory_map(EFI_MEMORY_DESCRIPTOR **map_buf, UINTN *map_size,
|
||||
UINTN *map_key, UINTN *desc_size, UINT32 *desc_version)
|
||||
{
|
||||
EFI_STATUS err;
|
||||
|
||||
*map_size = sizeof(**map_buf) * 31;
|
||||
get_map:
|
||||
|
||||
/*
|
||||
* Because we're about to allocate memory, we may
|
||||
* potentially create a new memory descriptor, thereby
|
||||
* increasing the size of the memory map. So increase
|
||||
* the buffer size by the size of one memory
|
||||
* descriptor, just in case.
|
||||
*/
|
||||
*map_size += sizeof(**map_buf);
|
||||
|
||||
err = allocate_pool(EfiLoaderData, *map_size,
|
||||
(void **)map_buf);
|
||||
if (err != EFI_SUCCESS) {
|
||||
Print(L"Failed to allocate pool for memory map");
|
||||
goto failed;
|
||||
}
|
||||
|
||||
err = get_memory_map(map_size, *map_buf, map_key,
|
||||
desc_size, desc_version);
|
||||
if (err != EFI_SUCCESS) {
|
||||
if (err == EFI_BUFFER_TOO_SMALL) {
|
||||
/*
|
||||
* 'map_size' has been updated to reflect the
|
||||
* required size of a map buffer.
|
||||
*/
|
||||
free_pool((void *)*map_buf);
|
||||
goto get_map;
|
||||
}
|
||||
|
||||
Print(L"Failed to get memory map");
|
||||
goto failed;
|
||||
}
|
||||
|
||||
failed:
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* emalloc - Allocate memory with a strict alignment requirement
|
||||
* @size: size in bytes of the requested allocation
|
||||
|
Loading…
Reference in New Issue
Block a user