| 246 | } |
| 247 | |
| 248 | EFI_STATUS |
| 249 | GetStoredOutput() |
| 250 | { |
| 251 | // Create variables. |
| 252 | EFI_STATUS Status; |
| 253 | UINTN h; |
| 254 | |
| 255 | // Device Path. |
| 256 | EFI_DEVICE_PATH_PROTOCOL *DevicePath = NULL; |
| 257 | UINT8 *StoredDevicePath = NULL; //it is EFI_DEVICE_PATH_PROTOCOL* |
| 258 | UINTN StoredDevicePathSize = 0; |
| 259 | |
| 260 | // Audio I/O. |
| 261 | EFI_HANDLE *AudioIoHandles = NULL; |
| 262 | UINTN AudioIoHandleCount = 0; |
| 263 | EFI_AUDIO_IO_PROTOCOL *AudioIoProto = NULL; |
| 264 | |
| 265 | // Output. |
| 266 | UINTN OutputPortIndex; |
| 267 | UINTN OutputPortIndexSize = sizeof(OutputPortIndex); |
| 268 | UINT8 OutputVolume; |
| 269 | UINTN OutputVolumeSize = sizeof(OutputVolume); |
| 270 | |
| 271 | // Get Audio I/O protocols. |
| 272 | Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiAudioIoProtocolGuid, NULL, &AudioIoHandleCount, &AudioIoHandles); |
| 273 | if (EFI_ERROR(Status)) { |
| 274 | MsgLog("No AudioIoProtocol, status=%s\n", efiStrError(Status)); |
| 275 | goto DONE; |
| 276 | } |
| 277 | DBG("found %llu handles with audio\n", AudioIoHandleCount); |
| 278 | // Get stored device path size. First from AppleBootGuid |
| 279 | StoredDevicePath = (__typeof__(StoredDevicePath))GetNvramVariable(L"Clover.SoundDevice", &gEfiAppleBootGuid, NULL, &StoredDevicePathSize); |
| 280 | if (!StoredDevicePath) { |
| 281 | // second attempt with BootChimeGuid |
| 282 | StoredDevicePath = (__typeof__(StoredDevicePath))GetNvramVariable(BOOT_CHIME_VAR_DEVICE, &gBootChimeVendorVariableGuid, NULL, &StoredDevicePathSize); |
| 283 | if (!StoredDevicePath) { |
| 284 | MsgLog("No AudioIoDevice stored\n"); |
| 285 | Status = EFI_NOT_FOUND; |
| 286 | goto DONE; |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | //we have to convert str->data if happen |
| 291 | if ((StoredDevicePath[0] != 2) && (StoredDevicePath[1] != 1)) { |
| 292 | XStringW StoredDevicePathStr = SWPrintf("%ls", (CHAR16*)StoredDevicePath); |
| 293 | FreePool(StoredDevicePath); |
| 294 | DBG("stored device=%ls\n", StoredDevicePathStr.wc_str()); |
| 295 | StoredDevicePath = (UINT8*)ConvertTextToDevicePath(StoredDevicePathStr.wc_str()); |
| 296 | StoredDevicePathSize = GetDevicePathSize((EFI_DEVICE_PATH_PROTOCOL *)StoredDevicePath); |
| 297 | } |
| 298 | |
| 299 | // Try to find the matching device exposing an Audio I/O protocol. |
| 300 | for (h = 0; h < AudioIoHandleCount; h++) { |
| 301 | // Open Device Path protocol. |
| 302 | Status = gBS->HandleProtocol(AudioIoHandles[h], &gEfiDevicePathProtocolGuid, (VOID**)&DevicePath); |
| 303 | if (EFI_ERROR(Status)) { |
| 304 | DBG("no DevicePath at %llu handle AudioIo\n", h); |
| 305 | continue; |
no test coverage detected