/* Read or write specified flag of a UFS device. */
EFI_STATUS UfsRwFlags(IN UFS_PASS_THRU_PRIVATE_DATA *Private, IN BOOLEAN Read, IN UINT8 FlagId, IN OUT UINT8 *Value)
/* Read or write specified flag of a UFS device. */
EFI_STATUS UfsRwFlags(IN UFS_PASS_THRU_PRIVATE_DATA *Private, IN BOOLEAN Read, IN UINT8 FlagId, IN OUT UINT8 *Value)
{
  UFS_DEVICE_MANAGEMENT_REQUEST_PACKET  Packet;
  if (Value == NULL) {
    return EFI_INVALID_PARAMETER;
  }
  ZeroMem (&Packet, sizeof (UFS_DEVICE_MANAGEMENT_REQUEST_PACKET));
  if (Read) {
    ASSERT (Value != NULL);
    Packet.DataDirection = UfsDataIn;
    Packet.Opcode        = UtpQueryFuncOpcodeRdFlag;
  } else {
    Packet.DataDirection = UfsDataOut;
    if (*Value == 1) {
      Packet.Opcode = UtpQueryFuncOpcodeSetFlag;
    } else if (*Value == 0) {
      Packet.Opcode = UtpQueryFuncOpcodeClrFlag;
    } else {
      return EFI_INVALID_PARAMETER;
    }
  }
  Packet.DataBuffer = Value;
  Packet.DescId     = FlagId;
  Packet.Index      = 0;
  Packet.Selector   = 0;
  Packet.Timeout    = UFS_TIMEOUT;
  return UfsSendDmRequest (Private, &Packet);
}