]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/MptScsiDxe/MptScsi.c
OvmfPkg/MptScsiDxe: Build and decode DevicePath
[mirror_edk2.git] / OvmfPkg / MptScsiDxe / MptScsi.c
index d396bff85cb6df7f81e2f6e63089deb51f28b7af..66d57f1c85d877b21b944c54abe6c5004dea0954 100644 (file)
@@ -147,7 +147,36 @@ MptScsiBuildDevicePath (
   IN OUT EFI_DEVICE_PATH_PROTOCOL                  **DevicePath\r
   )\r
 {\r
-  return EFI_UNSUPPORTED;\r
+  MPT_SCSI_DEV     *Dev;\r
+  SCSI_DEVICE_PATH *ScsiDevicePath;\r
+\r
+  if (DevicePath == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // This device support 256 targets only, so it's enough to dereference\r
+  // the LSB of Target.\r
+  //\r
+  Dev = MPT_SCSI_FROM_PASS_THRU (This);\r
+  if (*Target > Dev->MaxTarget || Lun > 0) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  ScsiDevicePath = AllocateZeroPool (sizeof (*ScsiDevicePath));\r
+  if (ScsiDevicePath == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  ScsiDevicePath->Header.Type      = MESSAGING_DEVICE_PATH;\r
+  ScsiDevicePath->Header.SubType   = MSG_SCSI_DP;\r
+  ScsiDevicePath->Header.Length[0] = (UINT8)sizeof (*ScsiDevicePath);\r
+  ScsiDevicePath->Header.Length[1] = (UINT8)(sizeof (*ScsiDevicePath) >> 8);\r
+  ScsiDevicePath->Pun              = *Target;\r
+  ScsiDevicePath->Lun              = (UINT16)Lun;\r
+\r
+  *DevicePath = &ScsiDevicePath->Header;\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 STATIC\r
@@ -160,7 +189,35 @@ MptScsiGetTargetLun (
   OUT UINT64                                       *Lun\r
   )\r
 {\r
-  return EFI_UNSUPPORTED;\r
+  MPT_SCSI_DEV     *Dev;\r
+  SCSI_DEVICE_PATH *ScsiDevicePath;\r
+\r
+  if (DevicePath == NULL ||\r
+      Target == NULL || *Target == NULL || Lun == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (DevicePath->Type    != MESSAGING_DEVICE_PATH ||\r
+      DevicePath->SubType != MSG_SCSI_DP) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Dev = MPT_SCSI_FROM_PASS_THRU (This);\r
+  ScsiDevicePath = (SCSI_DEVICE_PATH *)DevicePath;\r
+  if (ScsiDevicePath->Pun > Dev->MaxTarget ||\r
+      ScsiDevicePath->Lun > 0) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  ZeroMem (*Target, TARGET_MAX_BYTES);\r
+  //\r
+  // This device support 256 targets only, so it's enough to set the LSB\r
+  // of Target.\r
+  //\r
+  **Target = (UINT8)ScsiDevicePath->Pun;\r
+  *Lun = ScsiDevicePath->Lun;\r
+\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 STATIC\r