]> git.sesse.net Git - pistorm/blob - ide/ide.h
Merge pull request #6 from shanshe/wip-crap
[pistorm] / ide / ide.h
1 #include <stdint.h>
2
3 #define ACME_ROADRUNNER         1       /* 504MB classic IDE drive */
4 #define ACME_COYOTE             2       /* 20MB early IDE drive */
5 #define ACME_NEMESIS            3       /* 20MB LBA capable drive */
6 #define ACME_ULTRASONICUS       4       /* 40MB LBA capable drive */
7 #define ACME_ACCELLERATTI       5       /* 128MB LBA capable drive */
8 #define ACME_ZIPPIBUS           6       /* 256MB LBA capable drive */
9
10 #define MAX_DRIVE_TYPE          6
11
12 #define         ide_data        0
13 #define         ide_error_r     1
14 #define         ide_feature_w   1
15 #define         ide_sec_count   2
16 #define         ide_sec_num     3
17 #define         ide_lba_low     3
18 #define         ide_cyl_low     4
19 #define         ide_lba_mid     4
20 #define         ide_cyl_hi      5
21 #define         ide_lba_hi      5
22 #define         ide_dev_head    6
23 #define         ide_lba_top     6
24 #define         ide_status_r    7
25 #define         ide_command_w   7
26 #define         ide_altst_r     8
27 #define         ide_devctrl_w   8
28 #define         ide_data_latch  9
29
30 struct ide_taskfile {
31   uint16_t data;
32   uint8_t error;
33   uint8_t feature;
34   uint8_t count;
35   uint8_t lba1;
36   uint8_t lba2;
37   uint8_t lba3;
38   uint8_t lba4;
39   uint8_t status;
40   uint8_t command;
41   uint8_t devctrl;
42   struct ide_drive *drive;
43 };
44
45 struct ide_drive {
46   struct ide_controller *controller;
47   struct ide_taskfile taskfile;
48   unsigned int present:1, intrq:1, failed:1, lba:1, eightbit:1;
49   uint16_t cylinders;
50   uint8_t heads, sectors;
51   uint8_t data[512];
52   uint16_t identify[256];
53   uint8_t *dptr;
54   int state;
55   int fd;
56   off_t offset;
57   int length;
58 };
59
60 struct ide_controller {
61   struct ide_drive drive[2];
62   int selected;
63   const char *name;
64   uint16_t data_latch;
65 };
66
67 extern const uint8_t ide_magic[8];
68
69 void ide_reset_begin(struct ide_controller *c);
70 uint8_t ide_read8(struct ide_controller *c, uint8_t r);
71 void ide_write8(struct ide_controller *c, uint8_t r, uint8_t v);
72 uint16_t ide_read16(struct ide_controller *c, uint8_t r);
73 void ide_write16(struct ide_controller *c, uint8_t r, uint16_t v);
74 uint8_t ide_read_latched(struct ide_controller *c, uint8_t r);
75 void ide_write_latched(struct ide_controller *c, uint8_t r, uint8_t v);
76
77 struct ide_controller *ide_allocate(const char *name);
78 int ide_attach(struct ide_controller *c, int drive, int fd);
79 void ide_detach(struct ide_drive *d);
80 void ide_free(struct ide_controller *c);
81
82 int ide_make_drive(uint8_t type, int fd);