]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/VirtioNetDxe/ComponentName.c
OvmfPkg: Make the VirtIo devices use the new VIRTIO_DEVICE_PROTOCOL
[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 This program and the accompanying materials are licensed and made available
9 under the terms and conditions of the BSD License which accompanies this
10 distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
14 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17
18 #include <Library/UefiLib.h>
19
20 #include "VirtioNet.h"
21
22 STATIC
23 EFI_UNICODE_STRING_TABLE mVirtioNetDriverNameTable[] = {
24 { "eng;en", L"Virtio Network Driver" },
25 { NULL, NULL }
26 };
27
28 STATIC
29 EFI_UNICODE_STRING_TABLE mVirtioNetControllerNameTable[] = {
30 { "eng;en", L"Virtio Network Device" },
31 { NULL, NULL }
32 };
33
34 /**
35 Retrieves a Unicode string that is the user-readable name of the EFI Driver.
36
37 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
38 @param Language A pointer to a three-character ISO 639-2 language
39 identifier. This is the language of the driver name that
40 that the caller is requesting, and it must match one of
41 the languages specified in SupportedLanguages. The number
42 of languages supported by a driver is up to the driver
43 writer.
44 @param DriverName A pointer to the Unicode string to return. This Unicode
45 string is the name of the driver specified by This in the
46 language specified by Language.
47
48 @retval EFI_SUCCESS The Unicode string for the Driver specified by
49 This and the language specified by Language was
50 returned in DriverName.
51 @retval EFI_INVALID_PARAMETER Language is NULL.
52 @retval EFI_INVALID_PARAMETER DriverName is NULL.
53 @retval EFI_UNSUPPORTED The driver specified by This does not support
54 the language specified by Language.
55
56 **/
57
58 STATIC
59 EFI_STATUS
60 EFIAPI
61 VirtioNetGetDriverName (
62 IN EFI_COMPONENT_NAME_PROTOCOL *This,
63 IN CHAR8 *Language,
64 OUT CHAR16 **DriverName
65 )
66 {
67 return (Language == NULL || DriverName == NULL) ?
68 EFI_INVALID_PARAMETER :
69 LookupUnicodeString2 (
70 Language,
71 This->SupportedLanguages,
72 mVirtioNetDriverNameTable,
73 DriverName,
74 (BOOLEAN) (This == &gVirtioNetComponentName) // Iso639Language
75 );
76 }
77
78
79 /**
80 Retrieves a Unicode string that is the user readable name of the controller
81 that is being managed by an EFI Driver.
82
83 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL
84 instance.
85 @param ControllerHandle The handle of a controller that the driver specified
86 by This is managing. This handle specifies the
87 controller whose name is to be returned.
88 @param ChildHandle The handle of the child controller to retrieve the
89 name of. This is an optional parameter that may be
90 NULL. It will be NULL for device drivers. It will
91 also be NULL for a bus drivers that wish to retrieve
92 the name of the bus controller. It will not be NULL
93 for a bus driver that wishes to retrieve the name of
94 a child controller.
95 @param Language A pointer to a three character ISO 639-2 language
96 identifier. This is the language of the controller
97 name that the caller is requesting, and it must
98 match one of the languages specified in
99 SupportedLanguages. The number of languages
100 supported by a driver is up to the driver writer.
101 @param ControllerName A pointer to the Unicode string to return. This
102 Unicode string is the name of the controller
103 specified by ControllerHandle and ChildHandle in the
104 language specified by Language, from the point of
105 view of the driver specified by This.
106
107 @retval EFI_SUCCESS The Unicode string for the user-readable name
108 in the language specified by Language for the
109 driver specified by This was returned in
110 DriverName.
111 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
112 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
113 EFI_HANDLE.
114 @retval EFI_INVALID_PARAMETER Language is NULL.
115 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
116 @retval EFI_UNSUPPORTED The driver specified by This is not currently
117 managing the controller specified by
118 ControllerHandle and ChildHandle.
119 @retval EFI_UNSUPPORTED The driver specified by This does not support
120 the language specified by Language.
121
122 **/
123
124 STATIC
125 EFI_STATUS
126 EFIAPI
127 VirtioNetGetControllerName (
128 IN EFI_COMPONENT_NAME_PROTOCOL *This,
129 IN EFI_HANDLE ControllerHandle,
130 IN EFI_HANDLE ChildHandle,
131 IN CHAR8 *Language,
132 OUT CHAR16 **ControllerName
133 )
134 {
135 EFI_STATUS Status;
136
137 if (ControllerHandle == NULL || Language == NULL || ControllerName == NULL) {
138 return EFI_INVALID_PARAMETER;
139 }
140
141 //
142 // confirm that the device is managed by this driver, using the VirtIo
143 // Protocol
144 //
145 Status = EfiTestManagedDevice (
146 ControllerHandle,
147 gVirtioNetDriverBinding.DriverBindingHandle,
148 &gVirtioDeviceProtocolGuid
149 );
150 if (EFI_ERROR (Status)) {
151 return Status;
152 }
153
154 //
155 // we don't give different names to the bus (= parent) handle and the
156 // child (= MAC) handle
157 //
158 return LookupUnicodeString2 (
159 Language,
160 This->SupportedLanguages,
161 mVirtioNetControllerNameTable,
162 ControllerName,
163 (BOOLEAN) (This == &gVirtioNetComponentName) // Iso639Language
164 );
165 }
166
167 EFI_COMPONENT_NAME_PROTOCOL gVirtioNetComponentName = {
168 &VirtioNetGetDriverName,
169 &VirtioNetGetControllerName,
170 "eng" // SupportedLanguages, ISO 639-2 language codes
171 };
172
173 EFI_COMPONENT_NAME2_PROTOCOL gVirtioNetComponentName2 = {
174 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) &VirtioNetGetDriverName,
175 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) &VirtioNetGetControllerName,
176 "en" // SupportedLanguages, RFC 4646 language codes
177 };