]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg: VirtioNetDxe: Component Name Protocol implementation
authorLaszlo Ersek <lersek@redhat.com>
Fri, 14 Jun 2013 07:39:46 +0000 (07:39 +0000)
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 14 Jun 2013 07:39:46 +0000 (07:39 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14407 6f19259b-4bc3-4df7-8a09-765794883524

OvmfPkg/VirtioNetDxe/ComponentName.c [new file with mode: 0644]

diff --git a/OvmfPkg/VirtioNetDxe/ComponentName.c b/OvmfPkg/VirtioNetDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..a291405
--- /dev/null
@@ -0,0 +1,177 @@
+/** @file\r
+\r
+  Component Name code for the virtio-net driver.\r
+\r
+  Copyright (C) 2013, Red Hat, Inc.\r
+  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials are licensed and made available\r
+  under the terms and conditions of the BSD License which accompanies this\r
+  distribution. The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r
+  WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Library/UefiLib.h>\r
+\r
+#include "VirtioNet.h"\r
+\r
+STATIC\r
+EFI_UNICODE_STRING_TABLE mVirtioNetDriverNameTable[] = {\r
+  { "eng;en", L"Virtio Network Driver" },\r
+  { NULL,     NULL                     }\r
+};\r
+\r
+STATIC\r
+EFI_UNICODE_STRING_TABLE mVirtioNetControllerNameTable[] = {\r
+  { "eng;en", L"Virtio Network Device" },\r
+  { NULL,     NULL                     }\r
+};\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user-readable name of the EFI Driver.\r
+\r
+  @param  This       A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+  @param  Language   A pointer to a three-character ISO 639-2 language\r
+                     identifier. This is the language of the driver name that\r
+                     that the caller is requesting, and it must match one of\r
+                     the languages specified in SupportedLanguages.  The number\r
+                     of languages supported by a driver is up to the driver\r
+                     writer.\r
+  @param  DriverName A pointer to the Unicode string to return.  This Unicode\r
+                     string is the name of the driver specified by This in the\r
+                     language specified by Language.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the Driver specified by\r
+                                This and the language specified by Language was\r
+                                returned in DriverName.\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+VirtioNetGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL *This,\r
+  IN  CHAR8                       *Language,\r
+  OUT CHAR16                      **DriverName\r
+  )\r
+{\r
+  return (Language == NULL || DriverName == NULL) ?\r
+         EFI_INVALID_PARAMETER :\r
+         LookupUnicodeString2 (\r
+           Language,\r
+           This->SupportedLanguages,\r
+           mVirtioNetDriverNameTable,\r
+           DriverName,\r
+           (BOOLEAN) (This == &gVirtioNetComponentName) // Iso639Language\r
+           );\r
+}\r
+\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the controller\r
+  that is being managed by an EFI Driver.\r
+\r
+  @param  This             A pointer to the EFI_COMPONENT_NAME_PROTOCOL\r
+                           instance.\r
+  @param  ControllerHandle The handle of a controller that the driver specified\r
+                           by This is managing.  This handle specifies the\r
+                           controller whose name is to be returned.\r
+  @param  ChildHandle      The handle of the child controller to retrieve the\r
+                           name of.  This is an optional parameter that may be\r
+                           NULL.  It will be NULL for device drivers.  It will\r
+                           also be NULL for a bus drivers that wish to retrieve\r
+                           the name of the bus controller.  It will not be NULL\r
+                           for a bus driver that wishes to retrieve the name of\r
+                           a child controller.\r
+  @param  Language         A pointer to a three character ISO 639-2 language\r
+                           identifier.  This is the language of the controller\r
+                           name that the caller is requesting, and it must\r
+                           match one of the languages specified in\r
+                           SupportedLanguages.  The number of languages\r
+                           supported by a driver is up to the driver writer.\r
+  @param  ControllerName   A pointer to the Unicode string to return.  This\r
+                           Unicode string is the name of the controller\r
+                           specified by ControllerHandle and ChildHandle in the\r
+                           language specified by Language, from the point of\r
+                           view of the driver specified by This.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the user-readable name\r
+                                in the language specified by Language for the\r
+                                driver specified by This was returned in\r
+                                DriverName.\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
+  @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
+                                EFI_HANDLE.\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+  @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
+  @retval EFI_UNSUPPORTED       The driver specified by This is not currently\r
+                                managing the controller specified by\r
+                                ControllerHandle and ChildHandle.\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+VirtioNetGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL *This,\r
+  IN  EFI_HANDLE                  ControllerHandle,\r
+  IN  EFI_HANDLE                  ChildHandle,\r
+  IN  CHAR8                       *Language,\r
+  OUT CHAR16                      **ControllerName\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  if (ControllerHandle == NULL || Language == NULL || ControllerName == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // confirm that the device is managed by this driver, using the PCI IO\r
+  // Protocol\r
+  //\r
+  Status = EfiTestManagedDevice (\r
+             ControllerHandle,\r
+             gVirtioNetDriverBinding.DriverBindingHandle,\r
+             &gEfiPciIoProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // we don't give different names to the bus (= parent, = PCI) handle and the\r
+  // child (= MAC) handle\r
+  //\r
+  return LookupUnicodeString2 (\r
+           Language,\r
+           This->SupportedLanguages,\r
+           mVirtioNetControllerNameTable,\r
+           ControllerName,\r
+           (BOOLEAN) (This == &gVirtioNetComponentName) // Iso639Language\r
+           );\r
+}\r
+\r
+EFI_COMPONENT_NAME_PROTOCOL gVirtioNetComponentName = {\r
+  &VirtioNetGetDriverName,\r
+  &VirtioNetGetControllerName,\r
+  "eng" // SupportedLanguages, ISO 639-2 language codes\r
+};\r
+\r
+EFI_COMPONENT_NAME2_PROTOCOL gVirtioNetComponentName2 = {\r
+  (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)     &VirtioNetGetDriverName,\r
+  (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) &VirtioNetGetControllerName,\r
+  "en" // SupportedLanguages, RFC 4646 language codes\r
+};\r