1 #ifndef __BLOCK_H
2 #define __BLOCK_H
3 
4 #include "types.h" // u32
5 
6 
7 /****************************************************************
8  * Disk command request
9  ****************************************************************/
10 
11 struct disk_op_s {
12     void *buf_fl;
13     struct drive_s *drive_fl;
14     u8 command;
15     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     };
25 };
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
34 #define CMD_SCSI    0x20
35 
36 
37 /****************************************************************
38  * Global storage
39  ****************************************************************/
40 
41 struct chs_s {
42     u16 head;
43     u16 cylinder;
44     u16 sector;
45     u16 pad;
46 };
47 
48 struct 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     u8 target, lun;     // SCSI target and LUN
62 };
63 
64 #define DISK_SECTOR_SIZE  512
65 #define CDROM_SECTOR_SIZE 2048
66 
67 #define DTYPE_NONE         0x00
68 #define DTYPE_FLOPPY       0x10
69 #define DTYPE_ATA          0x20
70 #define DTYPE_ATA_ATAPI    0x21
71 #define DTYPE_RAMDISK      0x30
72 #define DTYPE_CDEMU        0x40
73 #define DTYPE_AHCI         0x50
74 #define DTYPE_AHCI_ATAPI   0x51
75 #define DTYPE_VIRTIO_SCSI  0x60
76 #define DTYPE_VIRTIO_BLK   0x61
77 #define DTYPE_USB          0x70
78 #define DTYPE_USB_32       0x71
79 #define DTYPE_UAS          0x72
80 #define DTYPE_UAS_32       0x73
81 #define DTYPE_LSI_SCSI     0x80
82 #define DTYPE_ESP_SCSI     0x81
83 #define DTYPE_MEGASAS      0x82
84 #define DTYPE_PVSCSI       0x83
85 #define DTYPE_MPT_SCSI     0x84
86 #define DTYPE_SDCARD       0x90
87 #define DTYPE_NVME         0x91
88 
89 #define MAXDESCSIZE 80
90 
91 #define TRANSLATION_NONE  0
92 #define TRANSLATION_LBA   1
93 #define TRANSLATION_LARGE 2
94 #define TRANSLATION_RECHS 3
95 
96 #define EXTTYPE_FLOPPY 0
97 #define EXTTYPE_HD 1
98 #define EXTTYPE_CD 2
99 
100 #define EXTSTART_HD 0x80
101 #define EXTSTART_CD 0xE0
102 
103 
104 /****************************************************************
105  * Function defs
106  ****************************************************************/
107 
108 // block.c
109 extern u8 FloppyCount, CDCount;
110 extern u8 *bounce_buf_fl;
111 struct drive_s *getDrive(u8 exttype, u8 extdriveoffset);
112 int getDriveId(u8 exttype, struct drive_s *drive);
113 void map_floppy_drive(struct drive_s *drive);
114 void map_hd_drive(struct drive_s *drive);
115 void map_cd_drive(struct drive_s *drive);
116 struct int13dpt_s;
117 int fill_edd(struct segoff_s edd, struct drive_s *drive_fl);
118 void block_setup(void);
119 int default_process_op(struct disk_op_s *op);
120 int process_op(struct disk_op_s *op);
121 int create_bounce_buf(void);
122 
123 #endif // block.h
124