svn commit: r346409 - in head/stand/efi: include libefi

Warner Losh imp at FreeBSD.org
Tue Sep 3 14:07:32 UTC 2019


Author: imp
Date: Fri Apr 19 19:45:19 2019
New Revision: 346409
URL: https://svnweb.freebsd.org/changeset/base/346409

Log:
  Add wrapper functions to convert strings to EFI_DEVICE_PATH
  
  In anticipation of new functionality, create routines to convert char *
  and a CHAR16 * to a EFI_DEVICE_PATH
  	EFI_DEVICE_PATH *efi_name_to_devpath(const char *path);
  	EFI_DEVICE_PATH *efi_name_to_devpath16(CHAR16 *path);
  	void efi_devpath_free(EFI_DEVICE_PATH *dp);
  The first two return an EFI_DEVICE_PATH for the passed in paths. The
  third frees up the storage the first two return when the caller is
  done with it.
  
  Differential Revision: https://reviews.freebsd.org/D19971

Modified:
  head/stand/efi/include/efilib.h
  head/stand/efi/libefi/devpath.c

Modified: head/stand/efi/include/efilib.h
==============================================================================
--- head/stand/efi/include/efilib.h	Fri Apr 19 19:45:15 2019	(r346408)
+++ head/stand/efi/include/efilib.h	Fri Apr 19 19:45:19 2019	(r346409)
@@ -92,6 +92,9 @@ CHAR16 *efi_devpath_name(EFI_DEVICE_PATH *);
 void efi_free_devpath_name(CHAR16 *);
 EFI_DEVICE_PATH *efi_devpath_to_media_path(EFI_DEVICE_PATH *);
 UINTN efi_devpath_length(EFI_DEVICE_PATH *);
+EFI_DEVICE_PATH *efi_name_to_devpath(const char *path);
+EFI_DEVICE_PATH *efi_name_to_devpath16(CHAR16 *path);
+void efi_devpath_free(EFI_DEVICE_PATH *dp);
 
 int efi_status_to_errno(EFI_STATUS);
 EFI_STATUS errno_to_efi_status(int errno);

Modified: head/stand/efi/libefi/devpath.c
==============================================================================
--- head/stand/efi/libefi/devpath.c	Fri Apr 19 19:45:15 2019	(r346408)
+++ head/stand/efi/libefi/devpath.c	Fri Apr 19 19:45:19 2019	(r346409)
@@ -28,12 +28,15 @@ __FBSDID("$FreeBSD$");
 
 #include <efi.h>
 #include <efilib.h>
+#include <efichar.h>
 
 static EFI_GUID ImageDevicePathGUID =
     EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID;
 static EFI_GUID DevicePathGUID = DEVICE_PATH_PROTOCOL;
 static EFI_GUID DevicePathToTextGUID = EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID;
-static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *textProtocol;
+static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *toTextProtocol;
+static EFI_GUID DevicePathFromTextGUID = EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL_GUID;
+static EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *fromTextProtocol;
 
 EFI_DEVICE_PATH *
 efi_lookup_image_devpath(EFI_HANDLE handle)
@@ -63,22 +66,20 @@ efi_lookup_devpath(EFI_HANDLE handle)
 CHAR16 *
 efi_devpath_name(EFI_DEVICE_PATH *devpath)
 {
-	static int once = 1;
 	EFI_STATUS status;
 
 	if (devpath == NULL)
 		return (NULL);
-	if (once) {
+	if (toTextProtocol == NULL) {
 		status = BS->LocateProtocol(&DevicePathToTextGUID, NULL,
-		    (VOID **)&textProtocol);
+		    (VOID **)&toTextProtocol);
 		if (EFI_ERROR(status))
-			textProtocol = NULL;
-		once = 0;
+			toTextProtocol = NULL;
 	}
-	if (textProtocol == NULL)
+	if (toTextProtocol == NULL)
 		return (NULL);
 
-	return (textProtocol->ConvertDevicePathToText(devpath, TRUE, TRUE));
+	return (toTextProtocol->ConvertDevicePathToText(devpath, TRUE, TRUE));
 }
 
 void
@@ -86,6 +87,46 @@ efi_free_devpath_name(CHAR16 *text)
 {
 
 	BS->FreePool(text);
+}
+
+EFI_DEVICE_PATH *
+efi_name_to_devpath(const char *path)
+{
+	EFI_DEVICE_PATH *devpath;
+	CHAR16 *uv;
+	size_t ul;
+
+	uv = NULL;
+	if (utf8_to_ucs2(path, &uv, &ul) != 0)
+		return (NULL);
+	devpath = efi_name_to_devpath16(uv);
+	free(uv);
+	return (devpath);
+}
+
+EFI_DEVICE_PATH *
+efi_name_to_devpath16(CHAR16 *path)
+{
+	EFI_STATUS status;
+
+	if (path == NULL)
+		return (NULL);
+	if (fromTextProtocol == NULL) {
+		status = BS->LocateProtocol(&DevicePathFromTextGUID, NULL,
+		    (VOID **)&fromTextProtocol);
+		if (EFI_ERROR(status))
+			fromTextProtocol = NULL;
+	}
+	if (fromTextProtocol == NULL)
+		return (NULL);
+
+	return (fromTextProtocol->ConvertTextToDevicePath(path));
+}
+
+void efi_devpath_free(EFI_DEVICE_PATH *devpath)
+{
+
+	BS->FreePool(devpath);
 }
 
 EFI_DEVICE_PATH *




More information about the svn-src-head mailing list