xref: /rk3399_rockchip-uboot/lib/efi_loader/efi_device_path_to_text.c (revision cc5b70812f5e3b13ea9072c2dacc939818ef8e66)
1 /*
2  *  EFI device path interface
3  *
4  *  Copyright (c) 2017 Heinrich Schuchardt
5  *
6  *  SPDX-License-Identifier:     GPL-2.0+
7  */
8 
9 #include <common.h>
10 #include <efi_loader.h>
11 
12 #define MEDIA_DEVICE_PATH 4
13 #define FILE_PATH_MEDIA_DEVICE_PATH 4
14 
15 const efi_guid_t efi_guid_device_path_to_text_protocol =
16 		EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID;
17 
18 uint16_t *efi_convert_device_node_to_text(
19 		struct efi_device_path_protocol *device_node,
20 		bool display_only,
21 		bool allow_shortcuts)
22 {
23 	EFI_ENTRY("%p, %d, %d", device_node, display_only, allow_shortcuts);
24 
25 	EFI_EXIT(EFI_UNSUPPORTED);
26 	return NULL;
27 }
28 
29 uint16_t *efi_convert_device_path_to_text(
30 		struct efi_device_path_protocol *device_path,
31 		bool display_only,
32 		bool allow_shortcuts)
33 {
34 	EFI_ENTRY("%p, %d, %d", device_path, display_only, allow_shortcuts);
35 
36 	unsigned long buffer_size;
37 	efi_status_t r;
38 	uint16_t *buffer = NULL;
39 
40 	switch (device_path->type) {
41 	case MEDIA_DEVICE_PATH:
42 		switch (device_path->sub_type) {
43 		case FILE_PATH_MEDIA_DEVICE_PATH:
44 			buffer_size = device_path->length - 4;
45 			r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES,
46 					      buffer_size, (void **) &buffer);
47 			if (r == EFI_SUCCESS)
48 				memcpy(buffer, device_path->data, buffer_size);
49 			break;
50 		}
51 	}
52 
53 	if (buffer) {
54 		EFI_EXIT(EFI_SUCCESS);
55 	} else {
56 		debug("type %d, subtype %d\n",
57 		      device_path->type, device_path->sub_type);
58 		EFI_EXIT(EFI_UNSUPPORTED);
59 	}
60 
61 	return buffer;
62 }
63 
64 const struct efi_device_path_to_text_protocol efi_device_path_to_text = {
65 	.convert_device_node_to_text = efi_convert_device_node_to_text,
66 	.convert_device_path_to_text = efi_convert_device_path_to_text,
67 };
68