Rev 4529 | Rev 4531 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4529 | Rev 4530 | ||
|---|---|---|---|
| Line 50... | Line 50... | ||
| 50 | #include <devmap.h> |
50 | #include <devmap.h> |
| 51 | #include <sys/types.h> |
51 | #include <sys/types.h> |
| 52 | #include <errno.h> |
52 | #include <errno.h> |
| 53 | #include <bool.h> |
53 | #include <bool.h> |
| 54 | 54 | ||
| 55 | #define NAME "ata_bd" |
55 | #include "ata_bd.h" |
| 56 | - | ||
| 57 | enum { |
- | |
| 58 | CTL_READ_START = 0, |
- | |
| 59 | CTL_WRITE_START = 1, |
- | |
| 60 | }; |
- | |
| 61 | - | ||
| 62 | enum { |
- | |
| 63 | STATUS_FAILURE = 0 |
- | |
| 64 | }; |
- | |
| 65 | - | ||
| 66 | enum { |
- | |
| 67 | MAX_DISKS = 2 |
- | |
| 68 | }; |
- | |
| 69 | - | ||
| 70 | typedef union { |
- | |
| 71 | /* Read */ |
- | |
| 72 | struct { |
- | |
| 73 | uint8_t data_port; |
- | |
| 74 | uint8_t error; |
- | |
| 75 | uint8_t sector_count; |
- | |
| 76 | uint8_t sector_number; |
- | |
| 77 | uint8_t cylinder_low; |
- | |
| 78 | uint8_t cylinder_high; |
- | |
| 79 | uint8_t drive_head; |
- | |
| 80 | uint8_t status; |
- | |
| 81 | }; |
- | |
| 82 | - | ||
| 83 | /* Write */ |
- | |
| 84 | struct { |
- | |
| 85 | uint8_t pad0[7]; |
- | |
| 86 | uint8_t command; |
- | |
| 87 | }; |
- | |
| 88 | } ata_cmd_t; |
- | |
| 89 | - | ||
| 90 | typedef union { |
- | |
| 91 | /* Read */ |
- | |
| 92 | struct { |
- | |
| 93 | uint8_t pad0[6]; |
- | |
| 94 | uint8_t alt_status; |
- | |
| 95 | uint8_t drive_address; |
- | |
| 96 | }; |
- | |
| 97 | 56 | ||
| 98 | /* Write */ |
- | |
| 99 | struct { |
- | |
| 100 | uint8_t pad1[6]; |
57 | #define NAME "ata_bd" |
| 101 | uint8_t device_control; |
- | |
| 102 | uint8_t pad2; |
- | |
| 103 | }; |
- | |
| 104 | } ata_ctl_t; |
- | |
| 105 | - | ||
| 106 | enum devctl_bits { |
- | |
| 107 | DCR_SRST = 0x04, /**< Software Reset */ |
- | |
| 108 | DCR_nIEN = 0x02 /**< Interrupt Enable (negated) */ |
- | |
| 109 | }; |
- | |
| 110 | - | ||
| 111 | enum status_bits { |
- | |
| 112 | SR_BSY = 0x80, /**< Busy */ |
- | |
| 113 | SR_DRDY = 0x40, /**< Drive Ready */ |
- | |
| 114 | SR_DWF = 0x20, /**< Drive Write Fault */ |
- | |
| 115 | SR_DSC = 0x10, /**< Drive Seek Complete */ |
- | |
| 116 | SR_DRQ = 0x08, /**< Data Request */ |
- | |
| 117 | SR_CORR = 0x04, /**< Corrected Data */ |
- | |
| 118 | SR_IDX = 0x02, /**< Index */ |
- | |
| 119 | SR_ERR = 0x01 /**< Error */ |
- | |
| 120 | }; |
- | |
| 121 | - | ||
| 122 | enum drive_head_bits { |
- | |
| 123 | DHR_DRV = 0x10 |
- | |
| 124 | }; |
- | |
| 125 | - | ||
| 126 | enum error_bits { |
- | |
| 127 | ER_BBK = 0x80, /**< Bad Block Detected */ |
- | |
| 128 | ER_UNC = 0x40, /**< Uncorrectable Data Error */ |
- | |
| 129 | ER_MC = 0x20, /**< Media Changed */ |
- | |
| 130 | ER_IDNF = 0x10, /**< ID Not Found */ |
- | |
| 131 | ER_MCR = 0x08, /**< Media Change Request */ |
- | |
| 132 | ER_ABRT = 0x04, /**< Aborted Command */ |
- | |
| 133 | ER_TK0NF = 0x02, /**< Track 0 Not Found */ |
- | |
| 134 | ER_AMNF = 0x01 /**< Address Mark Not Found */ |
- | |
| 135 | }; |
- | |
| 136 | - | ||
| 137 | typedef struct { |
- | |
| 138 | bool present; |
- | |
| 139 | unsigned heads; |
- | |
| 140 | unsigned cylinders; |
- | |
| 141 | unsigned sectors; |
- | |
| 142 | uint64_t blocks; |
- | |
| 143 | } disk_t; |
- | |
| 144 | 58 | ||
| 145 | static const size_t block_size = 512; |
59 | static const size_t block_size = 512; |
| 146 | static size_t comm_size; |
60 | static size_t comm_size; |
| 147 | 61 | ||
| 148 | static uintptr_t cmd_physical = 0x1f0; |
62 | static uintptr_t cmd_physical = 0x1f0; |