blob: 6489244858cd218245ff73f7e46e23508aab2c83 [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;
14 struct drive_s *drive_g;
15 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
72#define DTYPE_FLOPPY 0x01
73#define DTYPE_ATA 0x02
74#define DTYPE_ATA_ATAPI 0x03
75#define DTYPE_RAMDISK 0x04
76#define DTYPE_CDEMU 0x05
77#define DTYPE_AHCI 0x06
78#define DTYPE_AHCI_ATAPI 0x07
79#define DTYPE_VIRTIO_SCSI 0x08
80#define DTYPE_VIRTIO_BLK 0x09
81#define DTYPE_USB 0x0a
82#define DTYPE_UAS 0x0b
83#define DTYPE_LSI_SCSI 0x0c
84#define DTYPE_ESP_SCSI 0x0d
85#define DTYPE_MEGASAS 0x0e
86
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
93
94#define EXTTYPE_FLOPPY 0
95#define EXTTYPE_HD 1
96#define EXTTYPE_CD 2
97
98#define EXTSTART_HD 0x80
99#define EXTSTART_CD 0xE0
100
101
102/****************************************************************
103 * Function defs
104 ****************************************************************/
105
106// block.c
107extern struct dpte_s DefaultDPTE;
108extern u8 FloppyCount, CDCount;
109extern u8 *bounce_buf_fl;
110struct drive_s *getDrive(u8 exttype, u8 extdriveoffset);
111int getDriveId(u8 exttype, struct drive_s *drive_g);
112void map_floppy_drive(struct drive_s *drive_g);
113void map_hd_drive(struct drive_s *drive_g);
114void map_cd_drive(struct drive_s *drive_g);
115struct bregs;
116void __disk_ret(struct bregs *regs, u32 linecode, const char *fname);
117void __disk_ret_unimplemented(struct bregs *regs, u32 linecode
118 , const char *fname);
119int process_op(struct disk_op_s *op);
120int send_disk_op(struct disk_op_s *op);
121int create_bounce_buf(void);
122
123// Helper function for setting up a return code.
124#define disk_ret(regs, code) \
125 __disk_ret((regs), (code) | (__LINE__ << 8), __func__)
126#define disk_ret_unimplemented(regs, code) \
127 __disk_ret_unimplemented((regs), (code) | (__LINE__ << 8), __func__)
128
129#endif // block.h