21 #include "AtaController.h" 22 #include "ata-common.h" 23 #include "pedigree/kernel/Log.h" 24 #include "pedigree/kernel/compiler.h" 25 #include "pedigree/kernel/panic.h" 26 #include "pedigree/kernel/processor/IoBase.h" 27 #include "pedigree/kernel/processor/Processor.h" 28 #include "pedigree/kernel/processor/types.h" 29 #include "pedigree/kernel/utilities/Cache.h" 30 #include "pedigree/kernel/utilities/PointerGuard.h" 31 #include "pedigree/kernel/utilities/assert.h" 32 #include "pedigree/kernel/utilities/utility.h" 35 #pragma GCC diagnostic ignored "-Wunreachable-code" 39 #define ATA_DEFAULT_BLOCK_SIZE 0x10000 * 2 45 :
ScsiDisk(), m_IsMaster(isMaster), m_SupportsLBA28(true),
46 m_SupportsLBA48(false), m_BlockSize(ATA_DEFAULT_BLOCK_SIZE),
47 m_IrqReceived(0), m_AtaDiskType(NotPacket), m_PacketSize(0),
48 m_Removable(false), m_CommandRegs(commandRegs),
49 m_ControlRegs(controlRegs), m_BusMaster(busMaster), m_PrdTableLock(false),
50 m_PrdTable(0), m_LastPrdTableOffset(0), m_PrdTablePhys(0),
51 m_PrdTableMemRegion(
"ata-prdtable"), m_bDma(true)
66 IoBase *commandRegs = m_CommandRegs;
67 IoBase *controlRegs = m_ControlRegs;
70 setFeatures(0x07, 0, 0, 0, 0);
73 uint8_t devSelect = (m_IsMaster) ? 0xA0 : 0xB0;
74 commandRegs->
write8(devSelect, 6);
75 commandRegs->
write8(0xEC, 7);
76 if (commandRegs->
read8(7) == 0)
78 NOTICE(
"ATA: No device present here");
83 devSelect = (m_IsMaster) ? 0xA0 : 0xB0;
84 commandRegs->
write8(devSelect, 6);
87 ataWait(commandRegs, controlRegs);
93 ataWait(commandRegs, controlRegs);
102 controlRegs->
write8(0x2, 2);
105 commandRegs->
read8(7);
106 commandRegs->
write8(0xEC, 7);
109 status = ataWait(commandRegs, controlRegs);
116 uint8_t m1 = commandRegs->
read8(2);
117 uint8_t m2 = commandRegs->
read8(3);
118 uint8_t m3 = commandRegs->
read8(4);
119 uint8_t m4 = commandRegs->
read8(5);
121 NOTICE(
"ATA signature: " << m1 <<
", " << m2 <<
", " << m3 <<
", " << m4);
123 m_AtaDiskType = None;
124 if (m3 == 0x14 && m4 == 0xeb)
127 commandRegs->
write8(devSelect, 6);
128 commandRegs->
write8(0xA1, 7);
129 status = ataWait(commandRegs, controlRegs);
133 m_AtaDiskType = NotPacket;
140 WARNING(
"ATA drive errored on IDENTIFY!");
145 for (
int i = 0; i < 256; i++)
147 m_pIdent.__raw[i] = commandRegs->
read16(0);
151 if (commandRegs->
read8(7) & 1)
154 "ATA drive now has an error status after reading IDENTIFY data.");
159 if (m_pIdent.data.signature == 0xA5)
163 uint8_t *bytes =
reinterpret_cast<uint8_t *
>(m_pIdent.__raw);
164 for (
size_t i = 0; i < 512; ++i)
170 WARNING(
"ATA IDENTIFY data failed checksum!");
178 if ((m_AtaDiskType == NotPacket) && m_pIdent.data.general_config.not_ata)
180 ERROR(
"ATA: Device does not conform to the ATA specification.");
184 (m_AtaDiskType != NotPacket) && (!m_pIdent.data.general_config.not_ata))
186 ERROR(
"ATA: PACKET device does not conform to the ATA specification.");
190 if (m_AtaDiskType != NotPacket)
192 m_AtaDiskType =
static_cast<AtaDiskType
>(
193 m_pIdent.data.general_config.packet_cmdset);
197 ataLoadSwapped(m_pName, m_pIdent.data.model_number, 20);
201 for (
int i = 39; i > 0; i--)
203 if (m_pName[i] !=
' ')
210 ataLoadSwapped(m_pSerialNumber, m_pIdent.data.serial_number, 10);
214 for (
int i = 19; i > 0; i--)
216 if (m_pSerialNumber[i] !=
' ')
218 m_pSerialNumber[i] =
'\0';
220 m_pSerialNumber[20] =
'\0';
223 ataLoadSwapped(m_pFirmwareRevision, m_pIdent.data.firmware_revision, 4);
227 for (
int i = 7; i > 0; i--)
229 if (m_pFirmwareRevision[i] !=
' ')
231 m_pFirmwareRevision[i] =
'\0';
233 m_pFirmwareRevision[8] =
'\0';
236 if (m_pIdent.data.command_sets_support.address48)
238 m_SupportsLBA48 = m_pIdent.data.command_sets_enabled.address48;
239 if (!m_SupportsLBA48)
240 WARNING(
"ATA: Device supports LBA48 but it isn't enabled.");
244 if (!m_pIdent.data.caps.lba)
247 ERROR(
"ATA: Device does not support LBA.");
253 if (m_pIdent.data.caps.dma)
256 NOTICE(
"ATA: Device supports DMA.");
258 if (m_pIdent.data.validity.multiword_dma_valid)
260 size_t highest_mode = ~0U;
261 if (m_pIdent.data.multiword_dma.mode0)
263 if (m_pIdent.data.multiword_dma.mode1)
265 if (m_pIdent.data.multiword_dma.mode2)
268 size_t sel_mode = ~0U;
269 if (m_pIdent.data.multiword_dma.sel_mode0)
271 if (m_pIdent.data.multiword_dma.sel_mode1)
273 if (m_pIdent.data.multiword_dma.sel_mode2)
276 if (highest_mode != ~0U)
279 "ATA: Device Multiword DMA: supports up to mode" 280 <<
Dec << highest_mode <<
Hex);
284 NOTICE(
"ATA: Device Multiword DMA: no support");
290 "ATA: Device Multiword DMA: mode" <<
Dec << sel_mode <<
Hex 295 if (m_pIdent.data.validity.ultra_dma_valid)
297 size_t highest_mode = ~0U;
298 if (m_pIdent.data.ultra_dma.supp_mode0)
300 if (m_pIdent.data.ultra_dma.supp_mode1)
302 if (m_pIdent.data.ultra_dma.supp_mode2)
304 if (m_pIdent.data.ultra_dma.supp_mode3)
306 if (m_pIdent.data.ultra_dma.supp_mode4)
308 if (m_pIdent.data.ultra_dma.supp_mode5)
310 if (m_pIdent.data.ultra_dma.supp_mode6)
313 size_t sel_mode = ~0U;
314 if (m_pIdent.data.ultra_dma.sel_mode0)
316 if (m_pIdent.data.ultra_dma.sel_mode1)
318 if (m_pIdent.data.ultra_dma.sel_mode2)
320 if (m_pIdent.data.ultra_dma.sel_mode3)
322 if (m_pIdent.data.ultra_dma.sel_mode4)
324 if (m_pIdent.data.ultra_dma.sel_mode5)
326 if (m_pIdent.data.ultra_dma.sel_mode6)
329 if (highest_mode != ~0U)
332 "ATA: Device Ultra DMA: supports up to mode" 333 <<
Dec << highest_mode <<
Hex);
337 NOTICE(
"ATA: Device Ultra DMA: no support");
343 "ATA: Device Ultra DMA: mode" <<
Dec << sel_mode <<
Hex 353 WARNING(
"ATA: Controller does not support DMA");
357 if (m_pIdent.data.sector_size.logical_larger_than_512b ||
358 m_pIdent.data.sector_size.multiple_logical_per_physical)
361 size_t logical_size = 512;
362 if (m_pIdent.data.sector_size.logical_larger_than_512b)
363 logical_size = m_pIdent.data.words_per_logical *
sizeof(uint16_t);
366 size_t log_per_phys = 1
367 << m_pIdent.data.sector_size.logical_per_physical;
368 size_t physical_size = log_per_phys * logical_size;
371 "ATA: Physical sector size is " <<
Dec << physical_size <<
Hex 374 "ATA: Logical sector size is " <<
Dec << logical_size <<
Hex 377 if (physical_size > 512)
380 if (m_BlockSize % physical_size)
383 WARNING(
"ATA: Default block size doesn't map well to physical " 384 "sectors, performance may be degraded.");
388 if (m_BlockSize < physical_size)
389 m_BlockSize = physical_size;
400 if (m_AtaDiskType != NotPacket)
403 m_PacketSize = m_pIdent.data.general_config.packet_sz ? 16 : 12;
405 "ATAPI: packet size is " <<
Dec << m_PacketSize <<
" bytes" <<
Hex);
407 commandRegs->
write8(devSelect, 6);
408 commandRegs->
write8(0xDA, 7);
409 status = ataWait(commandRegs, controlRegs);
413 uint8_t err = commandRegs->
read8(1);
418 WARNING(
"ATAPI: device does not support GET MEDIA STATUS.");
422 WARNING(
"ATAPI: No media present in the drive - aborting.");
423 WARNING(
" TODO: handle media changes/insertions/removal " 429 NOTICE(
"ATAPI: Media status: " << err <<
".");
436 ERROR(
"ATAPI: ScsiDisk init failed.");
442 m_Removable = ((pInquiry->Removable & (1 << 7)) != 0);
443 AtaDiskType inquiryType =
444 static_cast<AtaDiskType
>(pInquiry->Peripheral);
445 if (inquiryType != m_AtaDiskType)
447 ERROR(
"ATAPI: IDENTIY PACKET DEVICE and SCSI INQUIRY disagree on " 453 if (m_AtaDiskType != CdDvd && m_AtaDiskType != Block)
457 WARNING(
"Pedigree currently only supports CD/DVD and block ATAPI " 464 "Detected ATA device '" << m_pName <<
"', '" << m_pSerialNumber
465 <<
"', '" << m_pFirmwareRevision <<
"'");
471 size_t nUnit, uintptr_t pCommand, uint8_t nCommandSize,
472 uintptr_t pRespBuffer, uint16_t nRespBytes,
bool bWrite)
474 if (m_AtaDiskType == NotPacket)
476 ERROR(
"AtaDisk::sendCommand called on a non-PACKET device");
482 ERROR(
"sendCommand called but the packet size is not known!");
488 IoBase *commandRegs = m_CommandRegs;
489 IoBase *controlRegs = m_ControlRegs;
491 uint16_t *tmpPacket =
new uint16_t[m_PacketSize / 2];
493 MemoryCopy(tmpPacket, reinterpret_cast<void *>(pCommand), nCommandSize);
494 ByteSet(tmpPacket + (nCommandSize / 2), 0, m_PacketSize - nCommandSize);
497 controlRegs->
write8(2, 2);
500 ataWait(commandRegs, controlRegs);
503 uint8_t devSelect = m_IsMaster ? 0xA0 : 0xB0;
504 commandRegs->
write8(devSelect, 6);
505 ataWait(commandRegs, controlRegs);
508 if ((commandRegs->
read8(6) & devSelect) != devSelect)
510 WARNING(
"ATAPI: Device was not selected");
514 bool bDmaSetup =
false;
515 if (m_bDma && nRespBytes)
517 bDmaSetup = m_BusMaster->add(pRespBuffer, nRespBytes);
521 if ((m_pIdent.__raw[62] & (1 << 15)) &&
523 commandRegs->
write8((bWrite ? 1 : 5), 1);
525 commandRegs->
write8(1, 1);
527 commandRegs->
write8(0, 1);
528 commandRegs->
write8(0, 2);
529 commandRegs->
write8(0, 3);
530 commandRegs->
write8(nRespBytes & 0xFF, 4);
531 commandRegs->
write8(((nRespBytes >> 8) & 0xFF), 5);
535 commandRegs->
write8(0xA0, 7);
538 status = ataWait(commandRegs, controlRegs);
550 if (m_bDma && nRespBytes && bDmaSetup)
552 bDmaSetup = m_BusMaster->begin(bWrite);
556 for (
size_t i = 0; i < (m_PacketSize / 2); i++)
558 commandRegs->
write16(tmpPacket[i], 0);
562 for (
size_t i = 0; i < 4; ++i)
563 controlRegs->
read8(2);
567 uint8_t statusreg = commandRegs->
read8(7);
568 if ((statusreg & 1) && !(statusreg & 0x80))
571 uint8_t error = commandRegs->
read8(1);
574 WARNING(
"ATAPI command failed (ABORT)");
579 "ATAPI error with status " << statusreg <<
" [error=" << error
590 status = ataWait(commandRegs, controlRegs);
591 return !status.
reg.err;
597 status = ataWait(commandRegs, controlRegs);
601 if (m_bDma && bDmaSetup)
603 m_BusMaster->commandComplete();
604 WARNING(
"ATAPI: read failed during DMA data transfer");
610 if (m_bDma && bDmaSetup)
612 if (m_BusMaster->hasInterrupt() || m_BusMaster->hasCompleted())
616 bool bError = m_BusMaster->hasError();
617 m_BusMaster->commandComplete();
630 status = ataWait(commandRegs, controlRegs);
633 WARNING(
"ATAPI sendCommand failed after sending command packet");
634 logAtaStatus(status);
643 if (!m_bDma && !bDmaSetup)
645 size_t realSz = commandRegs->
read8(4) | (commandRegs->
read8(5) << 8);
646 uint16_t *dest =
reinterpret_cast<uint16_t *
>(pRespBuffer);
650 ((realSz > nRespBytes) ? nRespBytes : realSz) / 2;
651 for (
size_t i = 0; i < sizeToRead; i++)
654 commandRegs->
write16(dest[i], 0);
656 dest[i] = commandRegs->
read16(0);
661 if (realSz > nRespBytes)
664 "sendCommand has to read beyond provided buffer [" 665 << realSz <<
" is bigger than " << nRespBytes <<
"]");
666 for (
size_t i = nRespBytes; i < realSz; i += 2)
669 commandRegs->
write16(0xFFFF, 0);
677 uint8_t endStatus = commandRegs->
read8(7);
678 return (!(endStatus & 0x01));
683 if (m_AtaDiskType != NotPacket)
687 static char alreadyRead[4096]
ALIGN(4096);
690 size_t nBytes = getBlockSize();
691 location &= ~(nBytes - 1);
695 size_t nBuffers = nBytes / 0x1000;
699 bool bAlreadyAllRead =
true;
700 for (
size_t i = 0; i < nBuffers; ++i)
702 buffers[i].
offset = i * 0x1000;
704 uintptr_t buffer = getCache().lookup(location + buffers[i].offset);
707 getCache().release(location + buffers[i].offset);
708 buffer =
reinterpret_cast<uintptr_t
>(alreadyRead);
712 buffer = getCache().insert(location + buffers[i].offset);
714 FATAL(
"AtaDisk::doRead - couldn't get a buffer!");
716 bAlreadyAllRead =
false;
719 buffers[i].
buffer = buffer;
729 IoBase *commandRegs = m_CommandRegs;
731 IoBase *controlRegs = m_ControlRegs;
736 uint32_t nSectors = nBytes / 512;
740 ataWait(commandRegs, controlRegs);
745 devSelect = (m_IsMaster) ? 0xE0 : 0xF0;
747 devSelect = (m_IsMaster) ? 0xA0 : 0xB0;
748 commandRegs->
write8(devSelect, 6);
751 ataWait(commandRegs, controlRegs);
753 size_t buffersConsumed = 0;
757 while (!(commandRegs->
read8(7) & 0x40))
761 uint8_t nSectorsToRead =
762 min(m_pIdent.data.max_sectors_per_irq, nSectors);
763 nSectors -= nSectorsToRead;
767 size_t buffersThisRead = (nSectorsToRead * 512) / 0x1000;
769 bool bDmaSetup =
false;
772 for (
size_t i = 0; i < buffersThisRead; ++i)
774 bDmaSetup = m_BusMaster->add(
775 buffers[buffersConsumed + i].buffer, 0x1000);
778 ERROR(
"DMA setup failed!");
783 buffersConsumed += buffersThisRead;
787 setupLBA48(location, nSectorsToRead);
790 if (location >= 0x2000000000ULL)
792 WARNING(
"Ata: Sector > 128GB requested but LBA48 addressing " 795 setupLBA28(location, nSectorsToRead);
798 m_IrqReceived =
new Mutex(
true);
805 controlRegs->
write8(0, 2);
813 if (m_bDma && bDmaSetup)
816 bDmaSetup = m_BusMaster->begin(
false);
818 if (!m_SupportsLBA48)
821 commandRegs->
write8(0xC8, 7);
826 commandRegs->
write8(0x25, 7);
834 commandRegs->
write8(0x24, 7);
839 commandRegs->
write8(0x20, 7);
848 if (!m_IrqReceived->acquire(1, 10))
851 ERROR(
"ATA: timeout during data transfer");
857 status = ataWait(commandRegs, controlRegs);
861 if (m_bDma && bDmaSetup)
863 m_BusMaster->commandComplete();
864 WARNING(
"ATA: read failed during DMA data transfer");
869 if (m_bDma && bDmaSetup)
871 if (m_BusMaster->hasInterrupt() || m_BusMaster->hasCompleted())
875 bool bError = m_BusMaster->hasError();
876 m_BusMaster->commandComplete();
893 if (!m_bDma && !bDmaSetup)
895 size_t byteOffset = buffersConsumed * 0x1000;
896 for (
int i = 0; i < nSectorsToRead; i++)
899 status = ataWait(commandRegs, controlRegs);
904 WARNING(
"ATA: read failed during data transfer");
909 size_t nBuffer = byteOffset / 0x1000;
910 size_t offset = byteOffset % 0x1000;
913 uint16_t *target =
reinterpret_cast<uint16_t *
>(
914 buffers[nBuffer].
buffer + offset);
915 for (
int j = 0; j < 256; j++)
917 *target++ = commandRegs->
read16(0);
924 location += nSectorsToRead * 512;
927 assert(buffersConsumed == nBuffers);
930 for (
size_t i = 0; i < nBuffers; ++i)
932 if (buffers[i].buffer == reinterpret_cast<uintptr_t>(alreadyRead))
937 getCache().markNoLongerEditing(location + buffers[i].offset);
946 panic(
"AtaDisk: write request not on a sector boundary!");
953 if (m_AtaDiskType != NotPacket)
964 uintptr_t nBytes = 0x1000;
965 uintptr_t buffer = getCache().lookup(location);
968 FATAL(
"AtaDisk::doWrite - no buffer (completely misused method)");
975 getCache().release(location);
981 NOTICE(
"doWrite(" << location <<
")");
985 IoBase *commandRegs = m_CommandRegs;
987 IoBase *controlRegs = m_ControlRegs;
992 uint32_t nSectors = nBytes / 512;
998 ataWait(commandRegs, controlRegs);
1002 if (m_SupportsLBA48)
1003 devSelect = (m_IsMaster) ? 0xE0 : 0xF0;
1005 devSelect = (m_IsMaster) ? 0xA0 : 0xB0;
1006 commandRegs->
write8(devSelect, 6);
1009 ataWait(commandRegs, controlRegs);
1011 uint16_t *tmp =
reinterpret_cast<uint16_t *
>(buffer);
1013 while (nSectors > 0)
1016 while (!(commandRegs->
read8(7) & 0x40))
1020 uint8_t nSectorsToWrite =
1021 min(m_pIdent.data.max_sectors_per_irq, nSectors);
1022 nSectors -= nSectorsToWrite;
1024 bool bDmaSetup =
false;
1027 bDmaSetup = m_BusMaster->add(buffer, nSectorsToWrite * 512);
1030 if (m_SupportsLBA48)
1031 setupLBA48(location, nSectorsToWrite);
1034 if (location >= 0x2000000000ULL)
1036 WARNING(
"Ata: Sector > 128GB requested but LBA48 addressing " 1039 setupLBA28(location, nSectorsToWrite);
1044 controlRegs->
write8(0, 2);
1048 WARNING(
"ATA: IRQ mutex already existed");
1049 m_IrqReceived =
new Mutex(
true);
1056 if (m_bDma && bDmaSetup)
1059 bDmaSetup = m_BusMaster->begin(
true);
1061 if (!m_SupportsLBA48)
1064 commandRegs->
write8(0xCA, 7);
1069 commandRegs->
write8(0x35, 7);
1074 if (m_SupportsLBA48)
1077 commandRegs->
write8(0x34, 7);
1082 commandRegs->
write8(0x30, 7);
1092 if (!m_IrqReceived->acquire(1, 10))
1094 WARNING(
"ATA: failed to get IRQ");
1099 status = ataWait(commandRegs, controlRegs);
1103 if (m_bDma && bDmaSetup)
1105 m_BusMaster->commandComplete();
1106 WARNING(
"ATA: read failed during DMA data transfer");
1111 if (m_bDma && bDmaSetup)
1113 if (m_BusMaster->hasInterrupt() || m_BusMaster->hasCompleted())
1117 bool bError = m_BusMaster->hasError();
1118 m_BusMaster->commandComplete();
1129 if (!m_bDma && !bDmaSetup)
1131 for (
int i = 0; i < nSectorsToWrite; i++)
1134 status = ataWait(commandRegs, controlRegs);
1139 WARNING(
"ATA: write failed during data transfer");
1144 for (
int j = 0; j < 256; j++)
1145 commandRegs->
write16(*tmp++, 0);
1151 NOTICE(
"ATA: successfully wrote " << nBytes <<
" bytes to disk.");
1159 m_IrqReceived->release();
1164 IoBase *commandRegs = m_CommandRegs;
1166 commandRegs->
write8(static_cast<uint8_t>(nSectors & 0xFF), 2);
1171 uint8_t sector =
static_cast<uint8_t
>(n & 0xFF);
1172 uint8_t cLow =
static_cast<uint8_t
>((n >> 8) & 0xFF);
1173 uint8_t cHigh =
static_cast<uint8_t
>((n >> 16) & 0xFF);
1174 uint8_t head =
static_cast<uint8_t
>((n >> 24) & 0x0F);
1180 commandRegs->
write8(head, 6);
1181 commandRegs->
write8(sector, 3);
1182 commandRegs->
write8(cLow, 4);
1183 commandRegs->
write8(cHigh, 5);
1188 IoBase *commandRegs = m_CommandRegs;
1193 uint8_t lba1 =
static_cast<uint8_t
>(n & 0xFF);
1194 uint8_t lba2 =
static_cast<uint8_t
>((n >> 8) & 0xFF);
1195 uint8_t lba3 =
static_cast<uint8_t
>((n >> 16) & 0xFF);
1196 uint8_t lba4 =
static_cast<uint8_t
>((n >> 24) & 0xFF);
1197 uint8_t lba5 =
static_cast<uint8_t
>((n >> 32) & 0xFF);
1198 uint8_t lba6 =
static_cast<uint8_t
>((n >> 40) & 0xFF);
1200 commandRegs->
write8((nSectors & 0xFFFF) >> 8, 2);
1201 commandRegs->
write8(lba4, 3);
1202 commandRegs->
write8(lba5, 4);
1203 commandRegs->
write8(lba6, 5);
1204 commandRegs->
write8((nSectors & 0xFF), 2);
1205 commandRegs->
write8(lba1, 3);
1206 commandRegs->
write8(lba2, 4);
1207 commandRegs->
write8(lba3, 5);
1211 uint8_t command, uint8_t countreg, uint8_t lowreg, uint8_t midreg,
1215 IoBase *commandRegs = m_CommandRegs;
1217 uint8_t devSelect = (m_IsMaster) ? 0xA0 : 0xB0;
1218 commandRegs->
write8(devSelect, 6);
1220 commandRegs->
write8(command, 1);
1221 commandRegs->
write8(countreg, 2);
1222 commandRegs->
write8(lowreg, 3);
1223 commandRegs->
write8(midreg, 4);
1224 commandRegs->
write8(hireg, 5);
1225 commandRegs->
write8(0xEF, 7);
1230 if (m_AtaDiskType != NotPacket)
1236 size_t sector_count = 0;
1237 if (m_SupportsLBA48)
1240 if (m_pIdent.data.max_user_lba48)
1241 sector_count = m_pIdent.data.max_user_lba48;
1243 sector_count = m_pIdent.data.sector_count;
1247 sector_count = m_pIdent.data.sector_count;
1251 size_t sector_size = 512;
1252 if (m_pIdent.data.sector_size.logical_larger_than_512b)
1255 sector_size = m_pIdent.data.words_per_logical *
sizeof(uint16_t);
1258 return sector_count * sector_size;
1263 if (m_AtaDiskType != NotPacket)
1272 if (m_AtaDiskType != NotPacket)
1278 size_t sector_size = 512;
1279 if (m_pIdent.data.sector_size.logical_larger_than_512b)
1282 sector_size = m_pIdent.data.words_per_logical *
sizeof(uint16_t);
1288 size_t AtaDisk::getBlockCount()
const 1290 if (m_AtaDiskType != NotPacket)
1292 return ScsiDisk::getBlockCount();
1296 size_t sector_count = 0;
1297 if (m_SupportsLBA48)
1300 if (m_pIdent.data.max_user_lba48)
1301 sector_count = m_pIdent.data.max_user_lba48;
1303 sector_count = m_pIdent.data.sector_count;
1307 sector_count = m_pIdent.data.sector_count;
1310 return sector_count;
bool initialise(size_t nUnit=~0)
void setFeatures(uint8_t command, uint8_t countreg, uint8_t lowreg, uint8_t midreg, uint8_t hireg)
virtual size_t getBlockSize() const
Gets the block size of the disk.
static bool getInterrupts()
virtual size_t getBlockSize() const
Gets the block size of the disk.
void setupLBA48(uint64_t n, uint32_t nSectors)
virtual void write8(uint8_t value, size_t offset=0)=0
virtual uint64_t doWrite(uint64_t location)
virtual uint16_t read16(size_t offset=0)=0
Abstrace base class for hardware I/O capabilities.
virtual uintptr_t getInterruptNumber()
virtual uint64_t doRead(uint64_t location)
virtual size_t getNativeBlockSize() const
virtual size_t getNativeBlockSize() const
size_t offset
Offset into the read.
virtual void write16(uint16_t value, size_t offset=0)=0
virtual bool sendCommand(size_t nUnit, uintptr_t pCommand, uint8_t nCommandSize, uintptr_t pRespBuffer, uint16_t nRespBytes, bool bWrite)
uint8_t __reg_contents
"Hidden" integer which contains the actual register contents
virtual uint64_t doRead(uint64_t location)
virtual void irqReceived()
static void setInterrupts(bool bEnable)
void setupLBA28(uint64_t n, uint32_t nSectors)
virtual uint8_t read8(size_t offset=0)=0
bool initialise(class ScsiController *pController, size_t nUnit)
uintptr_t buffer
Virtual address of buffer to read into (page sized).
virtual size_t getSize() const
Gets the size of the disk.
void EXPORTED_PUBLIC panic(const char *msg) NORETURN
virtual size_t getSize() const
Gets the size of the disk.