//
// Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
//
-// This file may be distributed under the terms of the GNU GPLv3 license.
+// This file may be distributed under the terms of the GNU LGPLv3 license.
#ifndef __DISK_H
#define __DISK_H
#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;
// Helper function for setting up a return code.
struct bregs;
-void __disk_ret(const char *fname, int lineno, struct bregs *regs, u8 code);
+void __disk_ret(struct bregs *regs, u32 linecode, const char *fname);
#define disk_ret(regs, code) \
- __disk_ret(__func__, __LINE__, (regs), (code))
+ __disk_ret((regs), (code) | (__LINE__ << 8), __func__)
+
+
+/****************************************************************
+ * Disk command request
+ ****************************************************************/
+
+struct disk_op_s {
+ u64 lba;
+ void *far_buffer;
+ u16 count;
+ u8 driveid;
+ u8 command;
+};
+
+#define CMD_CDROM_READ 1
+#define CMD_CDEMU_READ 2
+
+
+/****************************************************************
+ * 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 cdcount;
+ u8 idmap[2][CONFIG_MAX_ATA_DEVICES];
+};
+
+
+/****************************************************************
+ * Function defs
+ ****************************************************************/
+
+// ata.c
+extern struct ata_s ATA;
+int ata_cmd_data(struct disk_op_s *op);
+int cdrom_read(struct disk_op_s *op);
+int cdrom_read_512(struct disk_op_s *op);
+int ata_cmd_packet(int driveid, u8 *cmdbuf, u8 cmdlen
+ , u32 length, void *far_buffer);
+void ata_reset(int driveid);
+void hard_drive_setup();
// floppy.c
extern struct floppy_ext_dbt_s diskette_param_table2;
void disk_13XX(struct bregs *regs, u8 device);
// cdrom.c
-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);
int cdrom_boot();
-
#endif // disk.h