blob: 5d0afb556f6c864d4c7f2b30d3869adadbcdeeb1 [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 {
12 u64 lba;
13 void *buf_fl;
Kevin O'Connor1902c942013-10-26 11:48:06 -040014 struct drive_s *drive_gf;
Kevin O'Connor135f3f62013-09-14 23:57:26 -040015 u16 count;
16 u8 command;
17};
18
19#define CMD_RESET 0x00
20#define CMD_READ 0x02
21#define CMD_WRITE 0x03
22#define CMD_VERIFY 0x04
23#define CMD_FORMAT 0x05
24#define CMD_SEEK 0x07
25#define CMD_ISREADY 0x10
26
27
28/****************************************************************
29 * Global storage
30 ****************************************************************/
31
32struct chs_s {
Kevin O'Connor8ab9a342013-09-28 23:34:49 -040033 u16 head;
34 u16 cylinder;
35 u16 sector;
Kevin O'Connor135f3f62013-09-14 23:57:26 -040036 u16 pad;
37};
38
39// ElTorito Device Emulation data
40struct cdemu_s {
41 struct drive_s *emulated_drive_gf;
42 u32 ilba;
43 u16 buffer_segment;
44 u16 load_segment;
45 u16 sector_count;
46 u8 active;
47 u8 media;
48 u8 emulated_extdrive;
49
50 // Virtual device
51 struct chs_s lchs;
52};
53
54struct drive_s {
55 u8 type; // Driver type (DTYPE_*)
56 u8 floppy_type; // Type of floppy (only for floppy drives).
57 struct chs_s lchs; // Logical CHS
58 u64 sectors; // Total sectors count
59 u32 cntl_id; // Unique id for a given driver type.
60 u8 removable; // Is media removable (currently unused)
61
62 // Info for EDD calls
63 u8 translation; // type of translation
64 u16 blksize; // block size
65 struct chs_s pchs; // Physical CHS
66};
67
68#define DISK_SECTOR_SIZE 512
69#define CDROM_SECTOR_SIZE 2048
70
71#define DTYPE_NONE 0x00
Kevin O'Connord1bb7e52013-12-30 22:06:47 -050072#define DTYPE_FLOPPY 0x10
73#define DTYPE_ATA 0x20
74#define DTYPE_ATA_ATAPI 0x21
75#define DTYPE_RAMDISK 0x30
76#define DTYPE_CDEMU 0x40
77#define DTYPE_AHCI 0x50
78#define DTYPE_AHCI_ATAPI 0x51
79#define DTYPE_VIRTIO_SCSI 0x60
80#define DTYPE_VIRTIO_BLK 0x61
81#define DTYPE_USB 0x70
Kevin O'Connorde30dad2013-12-30 22:09:04 -050082#define DTYPE_USB_32 0x71
83#define DTYPE_UAS 0x72
84#define DTYPE_UAS_32 0x73
Kevin O'Connord1bb7e52013-12-30 22:06:47 -050085#define DTYPE_LSI_SCSI 0x80
86#define DTYPE_ESP_SCSI 0x81
87#define DTYPE_MEGASAS 0x82
88#define DTYPE_PVSCSI 0x83
Kevin O'Connor135f3f62013-09-14 23:57:26 -040089
90#define MAXDESCSIZE 80
91
92#define TRANSLATION_NONE 0
93#define TRANSLATION_LBA 1
94#define TRANSLATION_LARGE 2
95#define TRANSLATION_RECHS 3
96
97#define EXTTYPE_FLOPPY 0
98#define EXTTYPE_HD 1
99#define EXTTYPE_CD 2
100
101#define EXTSTART_HD 0x80
102#define EXTSTART_CD 0xE0
103
104
105/****************************************************************
106 * Function defs
107 ****************************************************************/
108
109// block.c
110extern struct dpte_s DefaultDPTE;
111extern u8 FloppyCount, CDCount;
112extern u8 *bounce_buf_fl;
113struct drive_s *getDrive(u8 exttype, u8 extdriveoffset);
Kevin O'Connor1902c942013-10-26 11:48:06 -0400114int getDriveId(u8 exttype, struct drive_s *drive);
115void map_floppy_drive(struct drive_s *drive);
116void map_hd_drive(struct drive_s *drive);
117void map_cd_drive(struct drive_s *drive);
Kevin O'Connor135f3f62013-09-14 23:57:26 -0400118struct bregs;
119void __disk_ret(struct bregs *regs, u32 linecode, const char *fname);
120void __disk_ret_unimplemented(struct bregs *regs, u32 linecode
121 , const char *fname);
122int process_op(struct disk_op_s *op);
123int send_disk_op(struct disk_op_s *op);
124int create_bounce_buf(void);
125
126// Helper function for setting up a return code.
127#define disk_ret(regs, code) \
128 __disk_ret((regs), (code) | (__LINE__ << 8), __func__)
129#define disk_ret_unimplemented(regs, code) \
130 __disk_ret_unimplemented((regs), (code) | (__LINE__ << 8), __func__)
131
132#endif // block.h