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 = {
40 * \brief Initialise the ATA driver
42 int ATA_Install(char **Arguments)
49 ATA_SetupPartitions();
55 * \brief Scan all disks, looking for partitions
57 void ATA_SetupPartitions(void)
60 for( i = 0; i < MAX_ATA_DISKS; i ++ )
62 if( !ATA_ScanDisk(i) ) {
69 * \brief Scan a disk, getting the size and any paritions
70 * \param Disk Disk ID to scan
72 int ATA_ScanDisk(int Disk)
78 sector_count = ATA_GetDiskSize(Disk);
87 Uint64 val = sector_count / 2;
93 else if( val > 4*1024 ) {
97 else if( val > 4*1024 ) {
101 Log_Notice("ATA", "Disk %i: 0x%llx Sectors (%lli %s)",
102 Disk, sector_count, val, units);
106 char name[] = "ata0";
107 sprintf(name, "ata%i", Disk);
108 LVM_AddVolume(&gATA_VolType, name, (void*)(Uint*)Disk, 512, sector_count);
113 ATA_ReadDMA( Disk, 1, 1, &mbr );
114 Debug_HexDump("ATA_ScanDisk", &mbr, 512);
122 // --- Disk Access ---
124 * \fn Uint ATA_ReadRaw(Uint64 Address, Uint Count, void *Buffer, Uint Disk)
126 int ATA_ReadRaw(void *Ptr, Uint64 Address, Uint Count, void *Buffer)
128 int Disk = (tVAddr)Ptr;
133 LOG("Reading %i sectors from 0x%llx of disk %i", Count, Address, Disk);
135 // Pass straight on to ATA_ReadDMAPage if we can
136 if(Count <= MAX_DMA_SECTORS)
138 ret = ATA_ReadDMA(Disk, Address, Count, Buffer);
143 // Else we will have to break up the transfer
145 while(Count > MAX_DMA_SECTORS)
147 ret = ATA_ReadDMA(Disk, Address+offset, MAX_DMA_SECTORS, Buffer+offset);
149 if(ret != 1) return done;
151 done += MAX_DMA_SECTORS;
152 Count -= MAX_DMA_SECTORS;
153 offset += MAX_DMA_SECTORS*SECTOR_SIZE;
156 ret = ATA_ReadDMA(Disk, Address+done, Count, Buffer+offset);
162 * \fn Uint ATA_WriteRaw(Uint64 Address, Uint Count, const void *Buffer, Uint Disk)
164 int ATA_WriteRaw(void *Ptr, Uint64 Address, Uint Count, const void *Buffer)
166 int Disk = (tVAddr)Ptr;
171 // Pass straight on to ATA_WriteDMA, if we can
172 if(Count <= MAX_DMA_SECTORS)
174 ret = ATA_WriteDMA(Disk, Address, Count, Buffer);
175 if(ret == 0) return 0;
179 // Else we will have to break up the transfer
181 while(Count > MAX_DMA_SECTORS)
183 ret = ATA_WriteDMA(Disk, Address+offset, MAX_DMA_SECTORS, Buffer+offset);
185 if(ret != 1) return done;
187 done += MAX_DMA_SECTORS;
188 Count -= MAX_DMA_SECTORS;
189 offset += MAX_DMA_SECTORS*SECTOR_SIZE;
192 ret = ATA_WriteDMA(Disk, Address+offset, Count, Buffer+offset);
193 if(ret != 1) return 0;