No more ATA debug (fixed the Qemu bug)
[tpg/acess2.git] / Modules / Storage / ATA / common.h
1 /*
2  * Acess2 IDE Harddisk Driver
3  * - main.c
4  */
5 #ifndef _COMMON_H_
6 #define _COMMON_H_
7
8 #include <acess.h>
9 #include <vfs.h>
10
11 // === CONSTANTS ===
12 #define MAX_ATA_DISKS   4
13 #define SECTOR_SIZE             512
14 #define MAX_DMA_SECTORS (0x1000 / SECTOR_SIZE)
15
16 #define IDE_PRI_BASE    0x1F0
17 #define IDE_SEC_BASE    0x170
18
19 #define IDE_PRDT_LAST   0x8000
20 /**
21  \enum HddControls
22  \brief Commands to be sent to HDD_CMD
23 */
24 enum HddControls {
25         HDD_PIO_R28 = 0x20,
26         HDD_PIO_R48 = 0x24,
27         HDD_DMA_R48 = 0x25,
28         HDD_PIO_W28 = 0x30,
29         HDD_PIO_W48 = 0x34,
30         HDD_DMA_W48 = 0x35,
31         HDD_DMA_R28 = 0xC8,
32         HDD_DMA_W28 = 0xCA,
33         HDD_IDENTIFY = 0xEC
34 };
35
36 // === STRUCTURES ===
37 typedef struct
38 {
39         Uint8   BootCode[0x1BE];
40         struct {
41                 Uint8   Boot;
42                 Uint8   Unused1;        // Also CHS Start
43                 Uint16  StartHi;        // Also CHS Start
44                 Uint8   SystemID;
45                 Uint8   Unused2;        // Also CHS Length
46                 Uint16  LengthHi;       // Also CHS Length
47                 Uint32  LBAStart;
48                 Uint32  LBALength;
49         } __attribute__ ((packed)) Parts[4];
50         Uint16  BootFlag;       // = 0xAA 55
51 } __attribute__ ((packed))      tMBR;
52
53 typedef struct
54 {
55         Uint64  Start;
56         Uint64  Length;
57         char    Name[4];
58         tVFS_Node       Node;
59 }       tATA_Partition;
60
61 typedef struct
62 {
63         Uint64  Sectors;
64         char    Name[2];
65         tVFS_Node       Node;
66          int    NumPartitions;
67         tATA_Partition  *Partitions;
68 }       tATA_Disk;
69
70 // === GLOBALS ===
71 extern tATA_Disk        gATA_Disks[];
72
73 // === FUNCTIONS ===
74 // --- Common ---
75 extern void     ATA_int_MakePartition(tATA_Partition *Part, int Disk, int Num, Uint64 Start, Uint64 Length);
76
77 // --- MBR Parsing ---
78 extern void     ATA_ParseMBR(int Disk, tMBR *MBR);
79
80 // --- IO Functions ---
81 extern int      ATA_SetupIO(void);
82 extern Uint64   ATA_GetDiskSize(int Disk);
83 extern int      ATA_ReadDMA(Uint8 Disk, Uint64 Address, Uint Count, void *Buffer);
84 extern int      ATA_WriteDMA(Uint8 Disk, Uint64 Address, Uint Count, const void *Buffer);
85
86 #endif

UCC git Repository :: git.ucc.asn.au