blob: c1b8d734798042c337de5963265f1cb02679c05a [file] [log] [blame]
Kevin O'Connor135f3f62013-09-14 23:57:26 -04001#ifndef __BLOCK_H
2#define __BLOCK_H
3
4#include "types.h" // u32
5
6
7/****************************************************************
8 * Disk command request
9 ****************************************************************/
10
11struct disk_op_s {
Kevin O'Connor135f3f62013-09-14 23:57:26 -040012 void *buf_fl;
Kevin O'Connore5a0b612017-07-11 12:24:50 -040013 struct drive_s *drive_fl;
Kevin O'Connor135f3f62013-09-14 23:57:26 -040014 u8 command;
Kevin O'Connor4dbe8292015-07-07 09:53:54 -040015 u16 count;
16 union {
17 // Commands: READ, WRITE, VERIFY, SEEK, FORMAT
18 u64 lba;
19 // Commands: SCSI
20 struct {
21 u16 blocksize;
22 void *cdbcmd;
23 };
24 };
Kevin O'Connor135f3f62013-09-14 23:57:26 -040025};
26
27#define CMD_RESET 0x00
28#define CMD_READ 0x02
29#define CMD_WRITE 0x03
30#define CMD_VERIFY 0x04
31#define CMD_FORMAT 0x05
32#define CMD_SEEK 0x07
33#define CMD_ISREADY 0x10
Kevin O'Connor4dbe8292015-07-07 09:53:54 -040034#define CMD_SCSI 0x20
Kevin O'Connor135f3f62013-09-14 23:57:26 -040035
36
37/****************************************************************
38 * Global storage
39 ****************************************************************/
40
41struct chs_s {
Kevin O'Connor8ab9a342013-09-28 23:34:49 -040042 u16 head;
43 u16 cylinder;
44 u16 sector;
Kevin O'Connor135f3f62013-09-14 23:57:26 -040045 u16 pad;
46};
47
Kevin O'Connor135f3f62013-09-14 23:57:26 -040048struct drive_s {
49 u8 type; // Driver type (DTYPE_*)
50 u8 floppy_type; // Type of floppy (only for floppy drives).
51 struct chs_s lchs; // Logical CHS
52 u64 sectors; // Total sectors count
53 u32 cntl_id; // Unique id for a given driver type.
54 u8 removable; // Is media removable (currently unused)
55
56 // Info for EDD calls
57 u8 translation; // type of translation
58 u16 blksize; // block size
59 struct chs_s pchs; // Physical CHS
60};
61
62#define DISK_SECTOR_SIZE 512
63#define CDROM_SECTOR_SIZE 2048
64
65#define DTYPE_NONE 0x00
Kevin O'Connord1bb7e52013-12-30 22:06:47 -050066#define DTYPE_FLOPPY 0x10
67#define DTYPE_ATA 0x20
68#define DTYPE_ATA_ATAPI 0x21
69#define DTYPE_RAMDISK 0x30
70#define DTYPE_CDEMU 0x40
71#define DTYPE_AHCI 0x50
72#define DTYPE_AHCI_ATAPI 0x51
73#define DTYPE_VIRTIO_SCSI 0x60
74#define DTYPE_VIRTIO_BLK 0x61
75#define DTYPE_USB 0x70
Kevin O'Connorde30dad2013-12-30 22:09:04 -050076#define DTYPE_USB_32 0x71
77#define DTYPE_UAS 0x72
78#define DTYPE_UAS_32 0x73
Kevin O'Connord1bb7e52013-12-30 22:06:47 -050079#define DTYPE_LSI_SCSI 0x80
80#define DTYPE_ESP_SCSI 0x81
81#define DTYPE_MEGASAS 0x82
82#define DTYPE_PVSCSI 0x83
Don Slutzf2645a82016-03-25 17:04:31 +010083#define DTYPE_MPT_SCSI 0x84
Kevin O'Connor72691a52014-12-16 09:55:16 -050084#define DTYPE_SDCARD 0x90
Julian Stecklinac83e15b2017-02-13 10:03:59 +010085#define DTYPE_NVME 0x91
Kevin O'Connor135f3f62013-09-14 23:57:26 -040086
87#define MAXDESCSIZE 80
88
89#define TRANSLATION_NONE 0
90#define TRANSLATION_LBA 1
91#define TRANSLATION_LARGE 2
92#define TRANSLATION_RECHS 3
Sam Eidermanc9ba5272019-06-26 15:38:16 +030093#define TRANSLATION_HOST 4
Kevin O'Connor135f3f62013-09-14 23:57:26 -040094
95#define EXTTYPE_FLOPPY 0
96#define EXTTYPE_HD 1
97#define EXTTYPE_CD 2
98
99#define EXTSTART_HD 0x80
100#define EXTSTART_CD 0xE0
101
102
103/****************************************************************
104 * Function defs
105 ****************************************************************/
106
107// block.c
Kevin O'Connor135f3f62013-09-14 23:57:26 -0400108extern u8 FloppyCount, CDCount;
109extern u8 *bounce_buf_fl;
110struct drive_s *getDrive(u8 exttype, u8 extdriveoffset);
Kevin O'Connor1902c942013-10-26 11:48:06 -0400111int getDriveId(u8 exttype, struct drive_s *drive);
112void map_floppy_drive(struct drive_s *drive);
113void map_hd_drive(struct drive_s *drive);
114void map_cd_drive(struct drive_s *drive);
Kevin O'Connor39ca4982014-05-10 11:42:22 -0400115struct int13dpt_s;
Kevin O'Connore5a0b612017-07-11 12:24:50 -0400116int fill_edd(struct segoff_s edd, struct drive_s *drive_fl);
Kevin O'Connor7c480762016-02-03 11:00:17 -0500117void block_setup(void);
Kevin O'Connor85c72c62015-07-07 09:01:52 -0400118int default_process_op(struct disk_op_s *op);
Kevin O'Connor135f3f62013-09-14 23:57:26 -0400119int process_op(struct disk_op_s *op);
Kevin O'Connor135f3f62013-09-14 23:57:26 -0400120int create_bounce_buf(void);
121
Kevin O'Connor135f3f62013-09-14 23:57:26 -0400122#endif // block.h