20 #include "IsaAtaController.h" 22 #include "modules/drivers/common/scsi/ScsiController.h" 23 #include "pedigree/kernel/Log.h" 24 #include "pedigree/kernel/machine/Device.h" 25 #include "pedigree/kernel/machine/IrqManager.h" 26 #include "pedigree/kernel/machine/Machine.h" 27 #include "pedigree/kernel/processor/IoBase.h" 28 #include "pedigree/kernel/time/Time.h" 29 #include "pedigree/kernel/utilities/Vector.h" 30 #include "pedigree/kernel/utilities/new" 35 IsaAtaController::IsaAtaController(
Controller *pDev,
int nController)
38 setSpecificType(
String(
"ata-controller"));
41 bool bPortsFound =
false;
42 for (
unsigned int i = 0; i < m_Addresses.count(); i++)
44 if (m_Addresses[i]->m_Name ==
"command" ||
45 m_Addresses[i]->m_Name ==
"bar0")
47 m_pCommandRegs = m_Addresses[i]->m_Io;
50 if (m_Addresses[i]->m_Name ==
"control" ||
51 m_Addresses[i]->m_Name ==
"bar1")
53 m_pControlRegs = m_Addresses[i]->m_Io;
60 ERROR(
"ISA ATA: No addresses found for this controller");
65 if (m_pControlRegs->read8(6) == 0xFF || m_pCommandRegs->read8(7) == 0xFF)
77 m_pControlRegs->write8(0x04, 6);
78 Time::delay(5 * Time::Multiplier::Millisecond);
80 m_pControlRegs->write8(0, 6);
81 Time::delay(5 * Time::Multiplier::Millisecond);
88 status = m_pControlRegs->read8(6);
91 else if (status & 0x1)
93 NOTICE(
"Error during ATA software reset, status = " << status);
101 AtaDisk *pMaster =
new AtaDisk(
this,
true, m_pCommandRegs, m_pControlRegs);
102 AtaDisk *pSlave =
new AtaDisk(
this,
false, m_pCommandRegs, m_pControlRegs);
107 size_t masterN = getNumChildren();
109 size_t slaveN = getNumChildren();
113 bool masterInitialised = pMaster->
initialise(masterN);
114 bool slaveInitialised = pSlave->
initialise(slaveN);
117 getInterruptNumber(), static_cast<IrqHandler *>(
this));
119 if (!masterInitialised)
121 removeChild(pMaster);
125 if (!slaveInitialised)
132 IsaAtaController::~IsaAtaController()
136 bool IsaAtaController::sendCommand(
137 size_t nUnit, uintptr_t pCommand, uint8_t nCommandSize,
138 uintptr_t pRespBuffer, uint16_t nRespBytes,
bool bWrite)
140 Device *pChild = getChild(nUnit);
143 ERROR(
"ISA ATA: sendCommand called with a bad unit number.");
149 nUnit, pCommand, nCommandSize, pRespBuffer, nRespBytes, bWrite);
153 uint64_t p1, uint64_t p2, uint64_t p3, uint64_t p4, uint64_t p5,
154 uint64_t p6, uint64_t p7, uint64_t p8)
157 if (p1 == SCSI_REQUEST_READ)
159 else if (p1 == SCSI_REQUEST_WRITE)
167 for (
unsigned int i = 0; i < getNumChildren(); i++)
bool initialise(size_t nUnit=~0)
virtual void setInterruptNumber(uintptr_t n)
virtual uint64_t doWrite(uint64_t location)
virtual bool irq(irq_id_t number, InterruptState &state)
virtual uint64_t doRead(uint64_t location)
virtual uint64_t executeRequest(uint64_t p1, uint64_t p2, uint64_t p3, uint64_t p4, uint64_t p5, uint64_t p6, uint64_t p7, uint64_t p8)
bool initialise() INITIALISATION_ONLY
virtual bool sendCommand(size_t nUnit, uintptr_t pCommand, uint8_t nCommandSize, uintptr_t pRespBuffer, uint16_t nRespBytes, bool bWrite)
virtual void irqReceived()
virtual irq_id_t registerIsaIrqHandler(uint8_t irq, IrqHandler *handler, bool bEdge=false)=0