]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/VirtioNetDxe/ComponentName.c
IntelFsp2Pkg/SplitFspBin.py: Support rebasing 1.x binary.
[mirror_edk2.git] / OvmfPkg / VirtioNetDxe / ComponentName.c
1 /** @file
2
3 Component Name code for the virtio-net driver.
4
5 Copyright (C) 2013, Red Hat, Inc.
6 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
7
8 SPDX-License-Identifier: BSD-2-Clause-Patent
9
10 **/
11
12 #include <Library/UefiLib.h>
13
14 #include "VirtioNet.h"
15
16 STATIC
17 EFI_UNICODE_STRING_TABLE mVirtioNetDriverNameTable[] = {
18 { "eng;en", L"Virtio Network Driver" },
19 { NULL, NULL }
20 };
21
22 STATIC
23 EFI_UNICODE_STRING_TABLE mVirtioNetControllerNameTable[] = {
24 { "eng;en", L"Virtio Network Device" },
25 { NULL, NULL }
26 };
27
28 /**
29 Retrieves a Unicode string that is the user-readable name of the EFI Driver.
30
31 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
32 @param Language A pointer to a three-character ISO 639-2 language
33 identifier. This is the language of the driver name that
34 that the caller is requesting, and it must match one of
35 the languages specified in SupportedLanguages. The number
36 of languages supported by a driver is up to the driver
37 writer.
38 @param DriverName A pointer to the Unicode string to return. This Unicode
39 string is the name of the driver specified by This in the
40 language specified by Language.
41
42 @retval EFI_SUCCESS The Unicode string for the Driver specified by
43 This and the language specified by Language was
44 returned in DriverName.
45 @retval EFI_INVALID_PARAMETER Language is NULL.
46 @retval EFI_INVALID_PARAMETER DriverName is NULL.
47 @retval EFI_UNSUPPORTED The driver specified by This does not support
48 the language specified by Language.
49
50 **/
51
52 STATIC
53 EFI_STATUS
54 EFIAPI
55 VirtioNetGetDriverName (
56 IN EFI_COMPONENT_NAME_PROTOCOL *This,
57 IN CHAR8 *Language,
58 OUT CHAR16 **DriverName
59 )
60 {
61 return (Language == NULL || DriverName == NULL) ?
62 EFI_INVALID_PARAMETER :
63 LookupUnicodeString2 (
64 Language,
65 This->SupportedLanguages,
66 mVirtioNetDriverNameTable,
67 DriverName,
68 (BOOLEAN) (This == &gVirtioNetComponentName) // Iso639Language
69 );
70 }
71
72
73 /**
74 Retrieves a Unicode string that is the user readable name of the controller
75 that is being managed by an EFI Driver.
76
77 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL
78 instance.
79 @param ControllerHandle The handle of a controller that the driver specified
80 by This is managing. This handle specifies the
81 controller whose name is to be returned.
82 @param ChildHandle The handle of the child controller to retrieve the
83 name of. This is an optional parameter that may be
84 NULL. It will be NULL for device drivers. It will
85 also be NULL for a bus drivers that wish to retrieve
86 the name of the bus controller. It will not be NULL
87 for a bus driver that wishes to retrieve the name of
88 a child controller.
89 @param Language A pointer to a three character ISO 639-2 language
90 identifier. This is the language of the controller
91 name that the caller is requesting, and it must
92 match one of the languages specified in
93 SupportedLanguages. The number of languages
94 supported by a driver is up to the driver writer.
95 @param ControllerName A pointer to the Unicode string to return. This
96 Unicode string is the name of the controller
97 specified by ControllerHandle and ChildHandle in the
98 language specified by Language, from the point of
99 view of the driver specified by This.
100
101 @retval EFI_SUCCESS The Unicode string for the user-readable name
102 in the language specified by Language for the
103 driver specified by This was returned in
104 DriverName.
105 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
106 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
107 EFI_HANDLE.
108 @retval EFI_INVALID_PARAMETER Language is NULL.
109 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
110 @retval EFI_UNSUPPORTED The driver specified by This is not currently
111 managing the controller specified by
112 ControllerHandle and ChildHandle.
113 @retval EFI_UNSUPPORTED The driver specified by This does not support
114 the language specified by Language.
115
116 **/
117
118 STATIC
119 EFI_STATUS
120 EFIAPI
121 VirtioNetGetControllerName (
122 IN EFI_COMPONENT_NAME_PROTOCOL *This,
123 IN EFI_HANDLE ControllerHandle,
124 IN EFI_HANDLE ChildHandle,
125 IN CHAR8 *Language,
126 OUT CHAR16 **ControllerName
127 )
128 {
129 EFI_STATUS Status;
130
131 if (ControllerHandle == NULL || Language == NULL || ControllerName == NULL) {
132 return EFI_INVALID_PARAMETER;
133 }
134
135 //
136 // confirm that the device is managed by this driver, using the VirtIo
137 // Protocol
138 //
139 Status = EfiTestManagedDevice (
140 ControllerHandle,
141 gVirtioNetDriverBinding.DriverBindingHandle,
142 &gVirtioDeviceProtocolGuid
143 );
144 if (EFI_ERROR (Status)) {
145 return Status;
146 }
147
148 //
149 // we don't give different names to the bus (= parent) handle and the
150 // child (= MAC) handle
151 //
152 return LookupUnicodeString2 (
153 Language,
154 This->SupportedLanguages,
155 mVirtioNetControllerNameTable,
156 ControllerName,
157 (BOOLEAN) (This == &gVirtioNetComponentName) // Iso639Language
158 );
159 }
160
161 EFI_COMPONENT_NAME_PROTOCOL gVirtioNetComponentName = {
162 &VirtioNetGetDriverName,
163 &VirtioNetGetControllerName,
164 "eng" // SupportedLanguages, ISO 639-2 language codes
165 };
166
167 EFI_COMPONENT_NAME2_PROTOCOL gVirtioNetComponentName2 = {
168 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) &VirtioNetGetDriverName,
169 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) &VirtioNetGetControllerName,
170 "en" // SupportedLanguages, RFC 4646 language codes
171 };