piix_ide.hpp
00001 #if !defined(__PIIX3_IDE_HPP__)
00002 #define __PIIX3_IDE_HPP__
00003
00004
00005
00006
00007 #include "core/protocols/ata/ata_bm_block.hpp"
00008 #include "core/protocols/ata/ata_channel.hpp"
00009 #include "piix_ide_config_space.hpp"
00010
00016 struct piix_ide : public pci_device_base<piix_ide_config_space>
00017 {
00018 static const bool VERBOSE_ALLOCATION = false;
00019
00020 protected:
00021 typedef pci_device_base<piix_ide_config_space> super_type;
00022
00023
00024
00025
00026 static const struct compat_resource
00027 {
00028 l4_port_t command_base, control_base;
00029 l4_irq_t irq;
00030 } compat_resources[];
00031
00032
00033
00034
00035 static const struct chip_descriptor
00036 {
00037 const char *name;
00038 uint16_t deviceID;
00039 const char *device_name;
00040 bool native_supported;
00041
00042 static const chip_descriptor *get(const string &name);
00043 } chip_descriptors[];
00044
00045 enum ata_state_constants
00046 {
00047 DECODE_ENABLED = 0x01,
00048 COMMAND_REGISTERED = 0x02,
00049 CONTROL_REGISTERED = 0x04,
00050 IRQ_REGISTERED = 0x08,
00051 NATIVE_MODE_SUPPORTED = 0x10,
00052 NATIVE_MODE_ENABLED = 0x20,
00053
00054
00055 ALL_MASK = DECODE_ENABLED | COMMAND_REGISTERED | CONTROL_REGISTERED |
00056 IRQ_REGISTERED | NATIVE_MODE_SUPPORTED | NATIVE_MODE_ENABLED
00057 };
00058
00059 typedef bitmask<uint_value_t<ALL_MASK>::least> ata_state;
00060 static_assert(integer_traits<ata_state::word_type>::const_max >= ALL_MASK,
00061 "ata_state's max value is too small");
00062
00063
00064
00065
00066 ata_state ata_states[2];
00067
00068
00069
00070
00071 ata_channel ata0, ata1;
00072
00073
00074
00075
00076 ata_bm_block bm_block;
00077
00078 public:
00079 piix_ide(machine_base &machine, ata_drive *drives[4],
00080 const chip_descriptor *chip=nullptr, bool native_enabled=true);
00081
00082
00083
00084
00085 virtual uint32_t read_ioport(l4_port_t port, access_size access_size);
00086 virtual int write_ioport(l4_port_t port, uint32_t data, access_size access_size);
00087
00088
00089
00090
00091 virtual int reset(void);
00092 virtual int write_config_space(pci_config_header16::offset_t offset,
00093 l4_umword_t data, access_size access_size);
00094
00095
00096
00097
00098
00099
00100 virtual int ioregion_relocated(uint8_t region_num, l4_gpa_t old_base);
00101
00102 protected:
00103
00104
00105
00106 inline ata_channel &get_channel(const uint8_t channel_ix)
00107 {
00108 return (channel_ix & 0x01) ? ata1 : ata0;
00109 }
00110
00111 int enable_ports(uint8_t channel_ix, bool enable=true, bool verbose=VERBOSE_ALLOCATION,
00112 l4_port_t command_base=0, l4_port_t control_base=0);
00113 int enable_irqs(uint8_t channel_ix, bool enable=true, bool verbose=VERBOSE_ALLOCATION);
00114 int enable_channel(uint8_t channel_ix, bool enable=true, bool verbose=VERBOSE_ALLOCATION);
00115 int enable_native_mode(uint8_t channel_ix, bool enable=true, bool verbose=VERBOSE_ALLOCATION);
00116
00117 void start_stop_DMA(uint8_t channel_ix);
00118
00119 public:
00120 static pci_device *create(machine_base &machine, config_node &device_node);
00121 };
00122
00123 #endif
00124
00125
00126