Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 1 | // Definitions for X86 bios disks. |
| 2 | // |
| 3 | // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net> |
| 4 | // |
| 5 | // This file may be distributed under the terms of the GNU GPLv3 license. |
Kevin O'Connor | 786502d | 2008-02-27 10:41:41 -0500 | [diff] [blame] | 6 | #ifndef __DISK_H |
| 7 | #define __DISK_H |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 8 | |
Kevin O'Connor | 9521e26 | 2008-07-04 13:04:29 -0400 | [diff] [blame] | 9 | #include "types.h" // u8 |
Kevin O'Connor | 609da23 | 2008-12-28 23:18:57 -0500 | [diff] [blame] | 10 | #include "config.h" // CONFIG_* |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 11 | |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 12 | #define DISK_RET_SUCCESS 0x00 |
| 13 | #define DISK_RET_EPARAM 0x01 |
Kevin O'Connor | b74102d | 2008-03-03 21:57:30 -0500 | [diff] [blame] | 14 | #define DISK_RET_EADDRNOTFOUND 0x02 |
| 15 | #define DISK_RET_EWRITEPROTECT 0x03 |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 16 | #define DISK_RET_ECHANGED 0x06 |
| 17 | #define DISK_RET_EBOUNDARY 0x09 |
| 18 | #define DISK_RET_EBADTRACK 0x0c |
| 19 | #define DISK_RET_ECONTROLLER 0x20 |
| 20 | #define DISK_RET_ETIMEOUT 0x80 |
Kevin O'Connor | b74102d | 2008-03-03 21:57:30 -0500 | [diff] [blame] | 21 | #define DISK_RET_ENOTLOCKED 0xb0 |
| 22 | #define DISK_RET_ELOCKED 0xb1 |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 23 | #define DISK_RET_ENOTREMOVABLE 0xb2 |
Kevin O'Connor | b74102d | 2008-03-03 21:57:30 -0500 | [diff] [blame] | 24 | #define DISK_RET_ETOOMANYLOCKS 0xb4 |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 25 | #define DISK_RET_EMEDIA 0xC0 |
| 26 | #define DISK_RET_ENOTREADY 0xAA |
| 27 | |
Kevin O'Connor | 609da23 | 2008-12-28 23:18:57 -0500 | [diff] [blame] | 28 | |
| 29 | /**************************************************************** |
| 30 | * Interface structs |
| 31 | ****************************************************************/ |
| 32 | |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 33 | // Bios disk structures. |
| 34 | struct int13ext_s { |
| 35 | u8 size; |
| 36 | u8 reserved; |
| 37 | u16 count; |
| 38 | u16 offset; |
| 39 | u16 segment; |
Kevin O'Connor | 1bb3b5c | 2008-05-14 00:43:13 -0400 | [diff] [blame] | 40 | u64 lba; |
Kevin O'Connor | ed12849 | 2008-03-11 11:14:59 -0400 | [diff] [blame] | 41 | } PACKED; |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 42 | |
| 43 | #define GET_INT13EXT(regs,var) \ |
| 44 | GET_FARVAR((regs)->ds, ((struct int13ext_s*)((regs)->si+0))->var) |
| 45 | #define SET_INT13EXT(regs,var,val) \ |
| 46 | SET_FARVAR((regs)->ds, ((struct int13ext_s*)((regs)->si+0))->var, (val)) |
| 47 | |
| 48 | // Disk Physical Table definition |
| 49 | struct int13dpt_s { |
| 50 | u16 size; |
| 51 | u16 infos; |
| 52 | u32 cylinders; |
| 53 | u32 heads; |
| 54 | u32 spt; |
Kevin O'Connor | 1bb3b5c | 2008-05-14 00:43:13 -0400 | [diff] [blame] | 55 | u64 sector_count; |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 56 | u16 blksize; |
| 57 | u16 dpte_offset; |
| 58 | u16 dpte_segment; |
| 59 | u16 key; |
| 60 | u8 dpi_length; |
| 61 | u8 reserved1; |
| 62 | u16 reserved2; |
| 63 | u8 host_bus[4]; |
| 64 | u8 iface_type[8]; |
Kevin O'Connor | 53236cc | 2008-08-31 11:16:33 -0400 | [diff] [blame] | 65 | u64 iface_path; |
| 66 | u64 device_path; |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 67 | u8 reserved3; |
| 68 | u8 checksum; |
Kevin O'Connor | ed12849 | 2008-03-11 11:14:59 -0400 | [diff] [blame] | 69 | } PACKED; |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 70 | |
| 71 | #define GET_INT13DPT(regs,var) \ |
| 72 | GET_FARVAR((regs)->ds, ((struct int13dpt_s*)((regs)->si+0))->var) |
| 73 | #define SET_INT13DPT(regs,var,val) \ |
| 74 | SET_FARVAR((regs)->ds, ((struct int13dpt_s*)((regs)->si+0))->var, (val)) |
| 75 | |
Kevin O'Connor | 44c631d | 2008-03-02 11:24:36 -0500 | [diff] [blame] | 76 | // Floppy "Disk Base Table" |
| 77 | struct floppy_dbt_s { |
| 78 | u8 specify1; |
| 79 | u8 specify2; |
| 80 | u8 shutoff_ticks; |
| 81 | u8 bps_code; |
| 82 | u8 sectors; |
| 83 | u8 interblock_len; |
| 84 | u8 data_len; |
| 85 | u8 gap_len; |
| 86 | u8 fill_byte; |
| 87 | u8 settle_time; |
| 88 | u8 startup_time; |
Kevin O'Connor | ed12849 | 2008-03-11 11:14:59 -0400 | [diff] [blame] | 89 | } PACKED; |
Kevin O'Connor | 44c631d | 2008-03-02 11:24:36 -0500 | [diff] [blame] | 90 | |
| 91 | struct floppy_ext_dbt_s { |
| 92 | struct floppy_dbt_s dbt; |
| 93 | // Extra fields |
| 94 | u8 max_track; |
| 95 | u8 data_rate; |
| 96 | u8 drive_type; |
Kevin O'Connor | ed12849 | 2008-03-11 11:14:59 -0400 | [diff] [blame] | 97 | } PACKED; |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 98 | |
Kevin O'Connor | 31d8c8a | 2008-03-04 19:56:41 -0500 | [diff] [blame] | 99 | // Helper function for setting up a return code. |
Kevin O'Connor | 9521e26 | 2008-07-04 13:04:29 -0400 | [diff] [blame] | 100 | struct bregs; |
Kevin O'Connor | 0560034 | 2009-01-02 13:10:58 -0500 | [diff] [blame^] | 101 | void __disk_ret(struct bregs *regs, u32 linecode, const char *fname); |
Kevin O'Connor | 567e4e3 | 2008-04-05 11:37:51 -0400 | [diff] [blame] | 102 | #define disk_ret(regs, code) \ |
Kevin O'Connor | 0560034 | 2009-01-02 13:10:58 -0500 | [diff] [blame^] | 103 | __disk_ret((regs), (code) | (__LINE__ << 8), __func__) |
Kevin O'Connor | 31d8c8a | 2008-03-04 19:56:41 -0500 | [diff] [blame] | 104 | |
Kevin O'Connor | 609da23 | 2008-12-28 23:18:57 -0500 | [diff] [blame] | 105 | |
| 106 | /**************************************************************** |
Kevin O'Connor | 4524bf7 | 2008-12-31 00:31:03 -0500 | [diff] [blame] | 107 | * Disk command request |
| 108 | ****************************************************************/ |
| 109 | |
| 110 | struct disk_op_s { |
| 111 | u64 lba; |
| 112 | void *far_buffer; |
| 113 | u16 count; |
| 114 | u8 driveid; |
| 115 | u8 command; |
| 116 | }; |
| 117 | |
| 118 | #define CMD_CDROM_READ 1 |
| 119 | #define CMD_CDEMU_READ 2 |
| 120 | |
| 121 | |
| 122 | /**************************************************************** |
Kevin O'Connor | 609da23 | 2008-12-28 23:18:57 -0500 | [diff] [blame] | 123 | * Global storage |
| 124 | ****************************************************************/ |
| 125 | |
| 126 | struct chs_s { |
| 127 | u16 heads; // # heads |
| 128 | u16 cylinders; // # cylinders |
| 129 | u16 spt; // # sectors / track |
| 130 | }; |
| 131 | |
| 132 | struct ata_channel_s { |
| 133 | u16 iobase1; // IO Base 1 |
| 134 | u16 iobase2; // IO Base 2 |
| 135 | u16 pci_bdf; |
| 136 | u8 irq; // IRQ |
| 137 | }; |
| 138 | |
| 139 | struct ata_device_s { |
| 140 | u8 type; // Detected type of ata (ata/atapi/none/unknown) |
| 141 | u8 device; // Detected type of attached devices (hd/cd/none) |
| 142 | u8 removable; // Removable device flag |
| 143 | u8 mode; // transfer mode : PIO 16/32 bits - IRQ - ISADMA - PCIDMA |
| 144 | u16 blksize; // block size |
| 145 | |
| 146 | u8 translation; // type of translation |
| 147 | struct chs_s lchs; // Logical CHS |
| 148 | struct chs_s pchs; // Physical CHS |
| 149 | |
| 150 | u64 sectors; // Total sectors count |
| 151 | }; |
| 152 | |
| 153 | struct ata_s { |
| 154 | // ATA channels info |
| 155 | struct ata_channel_s channels[CONFIG_MAX_ATA_INTERFACES]; |
| 156 | |
| 157 | // ATA devices info |
| 158 | struct ata_device_s devices[CONFIG_MAX_ATA_DEVICES]; |
| 159 | // |
| 160 | // map between bios hd/cd id and ata channels |
Kevin O'Connor | 4a16ef6 | 2008-12-31 00:09:28 -0500 | [diff] [blame] | 161 | u8 cdcount; |
Kevin O'Connor | 609da23 | 2008-12-28 23:18:57 -0500 | [diff] [blame] | 162 | u8 idmap[2][CONFIG_MAX_ATA_DEVICES]; |
| 163 | }; |
| 164 | |
Kevin O'Connor | 609da23 | 2008-12-28 23:18:57 -0500 | [diff] [blame] | 165 | |
| 166 | /**************************************************************** |
| 167 | * Function defs |
| 168 | ****************************************************************/ |
| 169 | |
| 170 | // ata.c |
| 171 | extern struct ata_s ATA; |
Kevin O'Connor | 4524bf7 | 2008-12-31 00:31:03 -0500 | [diff] [blame] | 172 | int ata_cmd_data(struct disk_op_s *op); |
| 173 | int cdrom_read(struct disk_op_s *op); |
| 174 | int cdrom_read_512(struct disk_op_s *op); |
| 175 | int ata_cmd_packet(int driveid, u8 *cmdbuf, u8 cmdlen |
| 176 | , u32 length, void *far_buffer); |
| 177 | void ata_reset(int driveid); |
| 178 | void hard_drive_setup(); |
Kevin O'Connor | 609da23 | 2008-12-28 23:18:57 -0500 | [diff] [blame] | 179 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 180 | // floppy.c |
Kevin O'Connor | 941d3e4 | 2008-03-04 19:45:04 -0500 | [diff] [blame] | 181 | extern struct floppy_ext_dbt_s diskette_param_table2; |
Kevin O'Connor | 3bbcc14 | 2008-04-13 17:07:33 -0400 | [diff] [blame] | 182 | void floppy_drive_setup(); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 183 | void floppy_13(struct bregs *regs, u8 drive); |
| 184 | void floppy_tick(); |
Kevin O'Connor | 786502d | 2008-02-27 10:41:41 -0500 | [diff] [blame] | 185 | |
Kevin O'Connor | 31d8c8a | 2008-03-04 19:56:41 -0500 | [diff] [blame] | 186 | // disk.c |
Kevin O'Connor | 31d8c8a | 2008-03-04 19:56:41 -0500 | [diff] [blame] | 187 | void disk_13(struct bregs *regs, u8 device); |
| 188 | void disk_13XX(struct bregs *regs, u8 device); |
| 189 | |
| 190 | // cdrom.c |
| 191 | void cdrom_13(struct bregs *regs, u8 device); |
| 192 | void cdemu_13(struct bregs *regs); |
| 193 | void cdemu_134b(struct bregs *regs); |
Kevin O'Connor | a05223c | 2008-06-28 12:15:57 -0400 | [diff] [blame] | 194 | int cdrom_boot(); |
Kevin O'Connor | 31d8c8a | 2008-03-04 19:56:41 -0500 | [diff] [blame] | 195 | |
Kevin O'Connor | 786502d | 2008-02-27 10:41:41 -0500 | [diff] [blame] | 196 | #endif // disk.h |