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 Uint16 ATA_GetBasePort(int Disk);
25 // Read/Write Interface/Quantiser
26 int ATA_ReadRaw(void *Ptr, Uint64 Address, size_t Count, void *Buffer);
27 int ATA_WriteRaw(void *Ptr, Uint64 Address, size_t Count, const void *Buffer);
30 MODULE_DEFINE(0, VERSION, i386ATA, ATA_Install, NULL, "PCI", "LVM", NULL);
31 tLVM_VolType gATA_VolType = {
39 * \brief Initialise the ATA driver
41 int ATA_Install(char **Arguments)
48 ATA_SetupPartitions();
54 * \brief Scan all disks, looking for partitions
56 void ATA_SetupPartitions(void)
59 for( i = 0; i < MAX_ATA_DISKS; i ++ )
61 if( !ATA_ScanDisk(i) ) {
68 * \brief Scan a disk, getting the size and any paritions
69 * \param Disk Disk ID to scan
71 int ATA_ScanDisk(int Disk)
77 sector_count = ATA_GetDiskSize(Disk);
86 Uint64 val = sector_count / 2;
92 else if( val > 4*1024 ) {
96 else if( val > 4*1024 ) {
100 Log_Notice("ATA", "Disk %i: 0x%llx Sectors (%lli %s)",
101 Disk, sector_count, val, units);
105 char name[] = "ata0";
106 sprintf(name, "ata%i", Disk);
107 LVM_AddVolume(&gATA_VolType, name, (void*)(Uint)Disk, 512, sector_count);
112 ATA_ReadDMA( Disk, 1, 1, &mbr );
113 Debug_HexDump("ATA_ScanDisk", &mbr, 512);
121 // --- Disk Access ---
123 * \fn Uint ATA_ReadRaw(Uint64 Address, Uint Count, void *Buffer, Uint Disk)
125 int ATA_ReadRaw(void *Ptr, Uint64 Address, Uint Count, void *Buffer)
127 int Disk = (tVAddr)Ptr;
132 LOG("Reading %i sectors from 0x%llx of disk %i", Count, Address, Disk);
134 // Pass straight on to ATA_ReadDMAPage if we can
135 if(Count <= MAX_DMA_SECTORS)
137 ret = ATA_ReadDMA(Disk, Address, Count, Buffer);
142 // Else we will have to break up the transfer
144 while(Count > MAX_DMA_SECTORS)
146 ret = ATA_ReadDMA(Disk, Address+offset, MAX_DMA_SECTORS, Buffer+offset);
148 if(ret != 1) return done;
150 done += MAX_DMA_SECTORS;
151 Count -= MAX_DMA_SECTORS;
152 offset += MAX_DMA_SECTORS*SECTOR_SIZE;
155 ret = ATA_ReadDMA(Disk, Address+done, Count, Buffer+offset);
161 * \fn Uint ATA_WriteRaw(Uint64 Address, Uint Count, const void *Buffer, Uint Disk)
163 int ATA_WriteRaw(void *Ptr, Uint64 Address, Uint Count, const void *Buffer)
165 int Disk = (tVAddr)Ptr;
170 // Pass straight on to ATA_WriteDMA, if we can
171 if(Count <= MAX_DMA_SECTORS)
173 ret = ATA_WriteDMA(Disk, Address, Count, Buffer);
174 if(ret == 0) return 0;
178 // Else we will have to break up the transfer
180 while(Count > MAX_DMA_SECTORS)
182 ret = ATA_WriteDMA(Disk, Address+offset, MAX_DMA_SECTORS, Buffer+offset);
184 if(ret != 1) return done;
186 done += MAX_DMA_SECTORS;
187 Count -= MAX_DMA_SECTORS;
188 offset += MAX_DMA_SECTORS*SECTOR_SIZE;
191 ret = ATA_WriteDMA(Disk, Address+offset, Count, Buffer+offset);
192 if(ret != 1) return 0;