45 Packet.Inquiry.allocation_length = 36;
63 if (EFI_ERROR (Status)) {
64 return EFI_DEVICE_ERROR;
67 if ((Idata.peripheral_type & 0x1f) == 0x05) {
68 PeiBotDevice->DeviceType = USBCDROM;
69 PeiBotDevice->Media.BlockSize = 0x800;
70 PeiBotDevice->Media2.ReadOnly =
TRUE;
71 PeiBotDevice->Media2.RemovableMedia =
TRUE;
72 PeiBotDevice->Media2.BlockSize = 0x800;
74 PeiBotDevice->DeviceType = USBFLOPPY;
75 PeiBotDevice->Media.BlockSize = 0x200;
76 PeiBotDevice->Media2.ReadOnly =
FALSE;
77 PeiBotDevice->Media2.RemovableMedia =
TRUE;
78 PeiBotDevice->Media2.BlockSize = 0x200;
124 if (EFI_ERROR (Status)) {
125 return EFI_DEVICE_ERROR;
148 IN UINT8 *SenseKeyBuffer
166 Ptr = SenseKeyBuffer;
195 if (EFI_ERROR (Status)) {
196 if (*SenseCounts == 0) {
197 return EFI_DEVICE_ERROR;
203 if (Sense->sense_key != ATA_SK_NO_SENSE) {
210 if (*SenseCounts == MAXSENSEKEY) {
266 if (EFI_ERROR (Status)) {
267 return EFI_DEVICE_ERROR;
270 LastBlock = ((UINT32)Data.LastLba3 << 24) | (Data.LastLba2 << 16) | (Data.LastLba1 << 8) | Data.LastLba0;
272 if (LastBlock == 0xFFFFFFFF) {
273 DEBUG ((DEBUG_INFO,
"The usb device LBA count is larger than 0xFFFFFFFF!\n"));
276 PeiBotDevice->Media.LastBlock = LastBlock;
277 PeiBotDevice->Media.MediaPresent =
TRUE;
279 PeiBotDevice->Media2.LastBlock = LastBlock;
280 PeiBotDevice->Media2.MediaPresent =
TRUE;
312 Packet.ReadFormatCapacity.allocation_length_lo = 12;
328 if (EFI_ERROR (Status)) {
329 return EFI_DEVICE_ERROR;
332 if (FormatData.DesCode == 3) {
336 PeiBotDevice->Media.MediaPresent =
FALSE;
337 PeiBotDevice->Media.LastBlock = 0;
338 PeiBotDevice->Media2.MediaPresent =
FALSE;
339 PeiBotDevice->Media2.LastBlock = 0;
341 LastBlock = ((UINT32)FormatData.LastLba3 << 24) | (FormatData.LastLba2 << 16) | (FormatData.LastLba1 << 8) | FormatData.LastLba0;
342 if (LastBlock == 0xFFFFFFFF) {
343 DEBUG ((DEBUG_INFO,
"The usb device LBA count is larger than 0xFFFFFFFF!\n"));
346 PeiBotDevice->Media.LastBlock = LastBlock;
348 PeiBotDevice->Media.LastBlock--;
350 PeiBotDevice->Media.MediaPresent =
TRUE;
352 PeiBotDevice->Media2.MediaPresent =
TRUE;
353 PeiBotDevice->Media2.LastBlock = PeiBotDevice->Media.LastBlock;
386 UINT32 BlocksRemaining;
399 Read10Packet = &Packet.Read10;
403 BlockSize = (UINT32)PeiBotDevice->Media.BlockSize;
405 MaxBlock = (UINT16)(MAX_UINT16 / BlockSize);
406 ASSERT (NumberOfBlocks < MAX_UINT32);
407 BlocksRemaining = (UINT32)NumberOfBlocks;
410 while (BlocksRemaining > 0) {
411 SectorCount =
MIN (BlocksRemaining, MaxBlock);
422 Read10Packet->Lba3 = (UINT8)(Lba32 & 0xff);
423 Read10Packet->Lba2 = (UINT8)(Lba32 >> 8);
424 Read10Packet->Lba1 = (UINT8)(Lba32 >> 16);
425 Read10Packet->Lba0 = (UINT8)(Lba32 >> 24);
431 Read10Packet->TranLen1 = (UINT8)(SectorCount & 0xff);
432 Read10Packet->TranLen0 = (UINT8)(SectorCount >> 8);
434 ByteCount = SectorCount * BlockSize;
436 TimeOut = SectorCount * 2000;
449 (UINT16)
MIN (TimeOut, MAX_UINT16)
456 ASSERT (Lba32 <= (MAX_UINT32-SectorCount));
457 Lba32 += SectorCount;
458 PtrBuffer = (UINT8 *)PtrBuffer + SectorCount * BlockSize;
459 BlocksRemaining = BlocksRemaining - SectorCount;
486 SensePtr = SenseData;
488 for (Index = 0; Index < SenseCounts; Index++) {
489 switch (SensePtr->sense_key) {
490 case ATA_SK_NOT_READY:
495 case ATA_ASC_NO_MEDIA:
535 SensePtr = SenseData;
538 for (Index = 0; Index < SenseCounts; Index++) {
539 switch (SensePtr->sense_key) {
543 case ATA_SK_MEDIUM_ERROR:
545 case ATA_ASC_MEDIA_ERR1:
549 case ATA_ASC_MEDIA_ERR2:
553 case ATA_ASC_MEDIA_ERR3:
557 case ATA_ASC_MEDIA_ERR4:
570 case ATA_SK_NOT_READY:
572 case ATA_ASC_MEDIA_UPSIDE_DOWN:
614 SensePtr = SenseData;
616 for (Index = 0; Index < SenseCounts; Index++) {
620 switch (SensePtr->sense_key) {
621 case ATA_SK_UNIT_ATTENTION:
623 case ATA_ASC_MEDIA_CHANGE:
#define ATA_CMD_TEST_UNIT_READY
defined from ATA-1
#define ATA_CMD_REQUEST_SENSE
defined from ATA-4
#define ATA_CMD_READ_10
defined in ATAPI Removable Rewritable Media Devices
#define ATA_CMD_READ_CAPACITY
defined in ATAPI Removable Rewritable Media Devices
#define ATA_CMD_READ_FORMAT_CAPACITY
defined in ATAPI Removable Rewritable Media Devices
#define ATA_CMD_INQUIRY
defined in ATAPI Removable Rewritable Media Devices
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS PeiAtapiCommand(IN EFI_PEI_SERVICES **PeiServices, IN PEI_BOT_DEVICE *PeiBotDev, IN VOID *Command, IN UINT8 CommandSize, IN VOID *DataBuffer, IN UINT32 BufferLength, IN EFI_USB_DATA_DIRECTION Direction, IN UINT16 TimeOutInMilliSeconds)
#define DEBUG(Expression)
EFI_STATUS PeiUsbReadCapacity(IN EFI_PEI_SERVICES **PeiServices, IN PEI_BOT_DEVICE *PeiBotDevice)
EFI_STATUS PeiUsbRequestSense(IN EFI_PEI_SERVICES **PeiServices, IN PEI_BOT_DEVICE *PeiBotDevice, OUT UINTN *SenseCounts, IN UINT8 *SenseKeyBuffer)
EFI_STATUS PeiUsbRead10(IN EFI_PEI_SERVICES **PeiServices, IN PEI_BOT_DEVICE *PeiBotDevice, IN VOID *Buffer, IN EFI_PEI_LBA Lba, IN UINTN NumberOfBlocks)
EFI_STATUS PeiUsbReadFormattedCapacity(IN EFI_PEI_SERVICES **PeiServices, IN PEI_BOT_DEVICE *PeiBotDevice)
EFI_STATUS PeiUsbTestUnitReady(IN EFI_PEI_SERVICES **PeiServices, IN PEI_BOT_DEVICE *PeiBotDevice)
EFI_STATUS PeiUsbInquiry(IN EFI_PEI_SERVICES **PeiServices, IN PEI_BOT_DEVICE *PeiBotDevice)
BOOLEAN IsNoMedia(IN ATAPI_REQUEST_SENSE_DATA *SenseData, IN UINTN SenseCounts)
BOOLEAN IsMediaError(IN ATAPI_REQUEST_SENSE_DATA *SenseData, IN UINTN SenseCounts)
BOOLEAN IsMediaChange(IN ATAPI_REQUEST_SENSE_DATA *SenseData, IN UINTN SenseCounts)
UINT8 page_code
defined in SFF8090i, V6
UINT8 addnl_sense_code
mandatory