]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg: introduce QemuFwCfgFindFile ()
authorjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 23 Jul 2012 17:10:29 +0000 (17:10 +0000)
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 23 Jul 2012 17:10:29 +0000 (17:10 +0000)
Tested with the "bootorder" fw_cfg file. Example contents (leading space
added and line terminators transcribed for readability):

  /pci@i0cf8/ide@1,1/drive@0/disk@0<LF>
  /pci@i0cf8/ide@1,1/drive@1/disk@0<LF>
  /pci@i0cf8/ethernet@3/ethernet-phy@0<NUL>

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13549 6f19259b-4bc3-4df7-8a09-765794883524

OvmfPkg/Include/Library/QemuFwCfgLib.h
OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c

index 5a3db7e8099c135a475a6b720b66decece0123b4..3776d79ea97b43445ac015459d199836d2cce90b 100644 (file)
@@ -41,6 +41,7 @@ typedef enum {
   QemuFwCfgItemKernelSetupAddress   = 0x0016,\r
   QemuFwCfgItemKernelSetupSize      = 0x0017,\r
   QemuFwCfgItemKernelSetupData      = 0x0018,\r
+  QemuFwCfgItemFileDir              = 0x0019,\r
 \r
   QemuFwCfgItemX86AcpiTables        = 0x8000,\r
   QemuFwCfgItemX86SmbiosTables      = 0x8001,\r
@@ -153,5 +154,25 @@ QemuFwCfgRead64 (
   );\r
 \r
 \r
+/**\r
+  Find the configuration item corresponding to the firmware configuration file.\r
+\r
+  @param[in]  Name - Name of file to look up.\r
+  @param[out] Item - Configuration item corresponding to the file, to be passed\r
+                     to QemuFwCfgSelectItem ().\r
+  @param[out] Size - Number of bytes in the file.\r
+\r
+  @return    RETURN_SUCCESS       If file is found.\r
+             RETURN_NOT_FOUND     If file is not found.\r
+             RETURN_UNSUPPORTED   If firmware configuration is unavailable.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+QemuFwCfgFindFile (\r
+  IN   CONST CHAR8           *Name,\r
+  OUT  FIRMWARE_CONFIG_ITEM  *Item,\r
+  OUT  UINTN                 *Size\r
+  );\r
 #endif\r
 \r
index b94dc67392882464d91fc479fcfab0bd8501dc25..8caab42e8b0a9c27c574aed09dbf63cafd07ad6b 100644 (file)
@@ -244,3 +244,56 @@ QemuFwCfgInitialize (
   DEBUG ((EFI_D_INFO, "QemuFwCfg interface is supported.\n"));\r
   return RETURN_SUCCESS;\r
 }\r
+\r
+\r
+/**\r
+  Find the configuration item corresponding to the firmware configuration file.\r
+\r
+  @param[in]  Name - Name of file to look up.\r
+  @param[out] Item - Configuration item corresponding to the file, to be passed\r
+                     to QemuFwCfgSelectItem ().\r
+  @param[out] Size - Number of bytes in the file.\r
+\r
+  @return    RETURN_SUCCESS       If file is found.\r
+             RETURN_NOT_FOUND     If file is not found.\r
+             RETURN_UNSUPPORTED   If firmware configuration is unavailable.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+QemuFwCfgFindFile (\r
+  IN   CONST CHAR8           *Name,\r
+  OUT  FIRMWARE_CONFIG_ITEM  *Item,\r
+  OUT  UINTN                 *Size\r
+  )\r
+{\r
+  UINT32 Count;\r
+  UINT32 Idx;\r
+\r
+  if (!mQemuFwCfgSupported) {\r
+    return RETURN_UNSUPPORTED;\r
+  }\r
+\r
+  QemuFwCfgSelectItem (QemuFwCfgItemFileDir);\r
+  Count = SwapBytes32 (QemuFwCfgRead32 ());\r
+\r
+  for (Idx = 0; Idx < Count; ++Idx) {\r
+    UINT32 FileSize;\r
+    UINT16 FileSelect;\r
+    UINT16 FileReserved;\r
+    CHAR8  FName[56];\r
+\r
+    FileSize     = QemuFwCfgRead32 ();\r
+    FileSelect   = QemuFwCfgRead16 ();\r
+    FileReserved = QemuFwCfgRead16 ();\r
+    InternalQemuFwCfgReadBytes (sizeof (FName), FName);\r
+\r
+    if (AsciiStrCmp (Name, FName) == 0) {\r
+      *Item = SwapBytes16 (FileSelect);\r
+      *Size = SwapBytes32 (FileSize);\r
+      return RETURN_SUCCESS;\r
+    }\r
+  }\r
+\r
+  return RETURN_NOT_FOUND;\r
+}\r