]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[efi] Define an interface operation to describe using an EFI device path
authorMichael Brown <mcb30@ipxe.org>
Fri, 16 Oct 2020 14:09:52 +0000 (15:09 +0100)
committerMichael Brown <mcb30@ipxe.org>
Fri, 16 Oct 2020 14:37:03 +0000 (15:37 +0100)
Allow arbitrary objects to support describing themselves using an EFI
device path.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/include/ipxe/efi/efi_path.h
src/interface/efi/efi_path.c

index f8b95fd21d880755877ec8d523304b40b67c1be8..0d5b902e545ccb2be56f80e26db103f13d9e0433 100644 (file)
@@ -9,6 +9,7 @@
 
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
+#include <ipxe/interface.h>
 #include <ipxe/efi/efi.h>
 #include <ipxe/efi/Protocol/DevicePath.h>
 
@@ -16,4 +17,8 @@ extern EFI_DEVICE_PATH_PROTOCOL *
 efi_path_end ( EFI_DEVICE_PATH_PROTOCOL *path );
 extern size_t efi_path_len ( EFI_DEVICE_PATH_PROTOCOL *path );
 
+extern EFI_DEVICE_PATH_PROTOCOL * efi_describe ( struct interface *interface );
+#define efi_describe_TYPE( object_type ) \
+       typeof ( EFI_DEVICE_PATH_PROTOCOL * ( object_type ) )
+
 #endif /* _IPXE_EFI_PATH_H */
index 1b297567c4bee9affcadbfa3eb758eeeecfb2aef..fa430602089c0e4dcf707e85a8c75e8c6c554859 100644 (file)
@@ -55,3 +55,29 @@ size_t efi_path_len ( EFI_DEVICE_PATH_PROTOCOL *path ) {
 
        return ( ( ( void * ) end ) - ( ( void * ) path ) );
 }
+
+/**
+ * Describe object as an EFI device path
+ *
+ * @v intf             Interface
+ * @ret path           EFI device path, or NULL
+ *
+ * The caller is responsible for eventually calling free() on the
+ * allocated device path.
+ */
+EFI_DEVICE_PATH_PROTOCOL * efi_describe ( struct interface *intf ) {
+       struct interface *dest;
+       efi_describe_TYPE ( void * ) *op =
+               intf_get_dest_op ( intf, efi_describe, &dest );
+       void *object = intf_object ( dest );
+       EFI_DEVICE_PATH_PROTOCOL *path;
+
+       if ( op ) {
+               path = op ( object );
+       } else {
+               path = NULL;
+       }
+
+       intf_put ( dest );
+       return path;
+}