Move most of ATA and CDEMU from ebda to global variables.
[seabios.git] / src / disk.h
index 30ef0bb3e4ff4a60a3d076385c224ada5421f6cc..a8b4ed902ecbb34c462c752f1b63c555ae1e76fb 100644 (file)
@@ -6,9 +6,8 @@
 #ifndef __DISK_H
 #define __DISK_H
 
-#include "ioport.h" // outb
-#include "biosvar.h" // struct bregs
-#include "util.h" // set_code_fail
+#include "types.h" // u8
+#include "config.h" // CONFIG_*
 
 #define DISK_RET_SUCCESS       0x00
 #define DISK_RET_EPARAM        0x01
 #define DISK_RET_EMEDIA        0xC0
 #define DISK_RET_ENOTREADY     0xAA
 
+
+/****************************************************************
+ * Interface structs
+ ****************************************************************/
+
 // Bios disk structures.
 struct int13ext_s {
     u8  size;
@@ -33,8 +37,7 @@ struct int13ext_s {
     u16 count;
     u16 offset;
     u16 segment;
-    u32 lba1;
-    u32 lba2;
+    u64 lba;
 } PACKED;
 
 #define GET_INT13EXT(regs,var)                                          \
@@ -49,8 +52,7 @@ struct int13dpt_s {
     u32 cylinders;
     u32 heads;
     u32 spt;
-    u32 sector_count1;
-    u32 sector_count2;
+    u64 sector_count;
     u16 blksize;
     u16 dpte_offset;
     u16 dpte_segment;
@@ -60,8 +62,8 @@ struct int13dpt_s {
     u16 reserved2;
     u8  host_bus[4];
     u8  iface_type[8];
-    u8  iface_path[8];
-    u8  device_path[8];
+    u64 iface_path;
+    u64 device_path;
     u8  reserved3;
     u8  checksum;
 } PACKED;
@@ -95,9 +97,77 @@ struct floppy_ext_dbt_s {
 } PACKED;
 
 // Helper function for setting up a return code.
-void __disk_ret(const char *fname, struct bregs *regs, u8 code);
+struct bregs;
+void __disk_ret(const char *fname, int lineno, struct bregs *regs, u8 code);
 #define disk_ret(regs, code) \
-    __disk_ret(__func__, (regs), (code))
+    __disk_ret(__func__, __LINE__, (regs), (code))
+
+
+/****************************************************************
+ * Global storage
+ ****************************************************************/
+
+struct chs_s {
+    u16 heads;      // # heads
+    u16 cylinders;  // # cylinders
+    u16 spt;        // # sectors / track
+};
+
+struct ata_channel_s {
+    u16 iobase1;      // IO Base 1
+    u16 iobase2;      // IO Base 2
+    u16 pci_bdf;
+    u8  irq;          // IRQ
+};
+
+struct ata_device_s {
+    u8  type;         // Detected type of ata (ata/atapi/none/unknown)
+    u8  device;       // Detected type of attached devices (hd/cd/none)
+    u8  removable;    // Removable device flag
+    u8  mode;         // transfer mode : PIO 16/32 bits - IRQ - ISADMA - PCIDMA
+    u16 blksize;      // block size
+
+    u8  translation;  // type of translation
+    struct chs_s  lchs;         // Logical CHS
+    struct chs_s  pchs;         // Physical CHS
+
+    u64 sectors;      // Total sectors count
+};
+
+struct ata_s {
+    // ATA channels info
+    struct ata_channel_s channels[CONFIG_MAX_ATA_INTERFACES];
+
+    // ATA devices info
+    struct ata_device_s  devices[CONFIG_MAX_ATA_DEVICES];
+    //
+    // map between bios hd/cd id and ata channels
+    u8 hdcount, cdcount;
+    u8 idmap[2][CONFIG_MAX_ATA_DEVICES];
+};
+
+// ElTorito Device Emulation data
+struct cdemu_s {
+    u8  media;
+    u8  emulated_drive;
+    u8  controller_index;
+    u16 device_spec;
+    u32 ilba;
+    u16 buffer_segment;
+    u16 load_segment;
+    u16 sector_count;
+
+    // Virtual device
+    struct chs_s  vdevice;
+};
+
+
+/****************************************************************
+ * Function defs
+ ****************************************************************/
+
+// ata.c
+extern struct ata_s ATA;
 
 // floppy.c
 extern struct floppy_ext_dbt_s diskette_param_table2;
@@ -110,11 +180,12 @@ void disk_13(struct bregs *regs, u8 device);
 void disk_13XX(struct bregs *regs, u8 device);
 
 // cdrom.c
+extern struct cdemu_s CDEMU;
 int cdrom_read_emu(u16 device, u32 lba, u32 count, void *far_buffer);
 void cdrom_13(struct bregs *regs, u8 device);
 void cdemu_13(struct bregs *regs);
 void cdemu_134b(struct bregs *regs);
-u16 cdrom_boot();
+int cdrom_boot();
 
 
 #endif // disk.h