2 * Acess2 IDE Harddisk Driver
11 #include <api_drv_common.h>
12 #include <api_drv_disk.h>
14 #include <Storage/LVM/include/lvm.h>
17 #define IO_DELAY() do{inb(0x80); inb(0x80); inb(0x80); inb(0x80);}while(0)
20 int ATA_Install(char **Arguments);
21 void ATA_SetupPartitions(void);
22 int ATA_ScanDisk(int Disk);
23 void ATA_ParseGPT(int Disk);
24 void ATA_int_MakePartition(tATA_Partition *Part, int Disk, int Num, Uint64 Start, Uint64 Length);
25 Uint16 ATA_GetBasePort(int Disk);
26 // Read/Write Interface/Quantiser
27 int ATA_ReadRaw(void *Ptr, Uint64 Address, size_t Count, void *Buffer);
28 int ATA_WriteRaw(void *Ptr, Uint64 Address, size_t Count, const void *Buffer);
31 MODULE_DEFINE(0, VERSION, i386ATA, ATA_Install, NULL, "PCI", "LVM", NULL);
32 tLVM_VolType gATA_VolType = {
35 .Write = ATA_WriteRaw,
41 * \brief Initialise the ATA driver
43 int ATA_Install(char **Arguments)
50 ATA_SetupPartitions();
56 * \brief Scan all disks, looking for partitions
58 void ATA_SetupPartitions(void)
61 for( i = 0; i < MAX_ATA_DISKS; i ++ )
63 if( !ATA_ScanDisk(i) ) {
70 * \brief Scan a disk, getting the size and any paritions
71 * \param Disk Disk ID to scan
73 int ATA_ScanDisk(int Disk)
79 sector_count = ATA_GetDiskSize(Disk);
88 Uint64 val = sector_count / 2;
94 else if( val > 4*1024 ) {
98 else if( val > 4*1024 ) {
102 Log_Notice("ATA", "Disk %i: 0x%llx Sectors (%lli %s)",
103 Disk, sector_count, val, units);
107 char name[] = "ata0";
108 sprintf(name, "ata%i", Disk);
109 LVM_AddVolume(&gATA_VolType, name, (void*)(Uint*)Disk, sector_count);
114 ATA_ReadDMA( Disk, 1, 1, &mbr );
115 Debug_HexDump("ATA_ScanDisk", &mbr, 512);
123 // --- Disk Access ---
125 * \fn Uint ATA_ReadRaw(Uint64 Address, Uint Count, void *Buffer, Uint Disk)
127 int ATA_ReadRaw(void *Ptr, Uint64 Address, Uint Count, void *Buffer)
129 int Disk = (tVAddr)Ptr;
134 LOG("Reading %i sectors from 0x%llx of disk %i", Count, Address, Disk);
136 // Pass straight on to ATA_ReadDMAPage if we can
137 if(Count <= MAX_DMA_SECTORS)
139 ret = ATA_ReadDMA(Disk, Address, Count, Buffer);
144 // Else we will have to break up the transfer
146 while(Count > MAX_DMA_SECTORS)
148 ret = ATA_ReadDMA(Disk, Address+offset, MAX_DMA_SECTORS, Buffer+offset);
150 if(ret != 1) return done;
152 done += MAX_DMA_SECTORS;
153 Count -= MAX_DMA_SECTORS;
154 offset += MAX_DMA_SECTORS*SECTOR_SIZE;
157 ret = ATA_ReadDMA(Disk, Address+done, Count, Buffer+offset);
163 * \fn Uint ATA_WriteRaw(Uint64 Address, Uint Count, const void *Buffer, Uint Disk)
165 int ATA_WriteRaw(void *Ptr, Uint64 Address, Uint Count, const void *Buffer)
167 int Disk = (tVAddr)Ptr;
172 // Pass straight on to ATA_WriteDMA, if we can
173 if(Count <= MAX_DMA_SECTORS)
175 ret = ATA_WriteDMA(Disk, Address, Count, Buffer);
176 if(ret == 0) return 0;
180 // Else we will have to break up the transfer
182 while(Count > MAX_DMA_SECTORS)
184 ret = ATA_WriteDMA(Disk, Address+offset, MAX_DMA_SECTORS, Buffer+offset);
186 if(ret != 1) return done;
188 done += MAX_DMA_SECTORS;
189 Count -= MAX_DMA_SECTORS;
190 offset += MAX_DMA_SECTORS*SECTOR_SIZE;
193 ret = ATA_WriteDMA(Disk, Address+offset, Count, Buffer+offset);
194 if(ret != 1) return 0;