20#include "pedigree/kernel/Log.h"
21#include "pedigree/kernel/linker/KernelElf.h"
22#include "pedigree/kernel/machine/Controller.h"
23#include "pedigree/kernel/machine/Device.h"
24#include "pedigree/kernel/processor/types.h"
25#include "pedigree/kernel/utilities/String.h"
26#include "pedigree/kernel/utilities/Vector.h"
27#include "pedigree/kernel/utilities/new"
29#include "IsaAtaController.h"
30#include "PciAtaController.h"
31#include "modules/Module.h"
33static int nController = 0;
35static bool bFound =
false;
39static bool bPiixControllerFound =
false;
40static int piixLevel = -1;
41static bool bFallBackISA =
false;
43static bool allowProbing =
false;
59 g_Controllers.pushBack(pController);
67 EMIT_IF(PEDIGREE_MACHINE_HASPCI) {
68 static uint8_t interrupt = 14;
80 "PCI IDE: Controller found with no IRQ and IRQs 14 and 15 "
81 "are already allocated");
82 delete pDevController;
89 g_Controllers.pushBack(pController);
104 bool foundCommand =
false;
105 bool foundControl =
false;
106 for (
unsigned int j = 0; j < dev->
addresses().count(); j++) {
107 if (dev->
addresses()[j]->m_Name.compare(
"command"))
109 if (dev->
addresses()[j]->m_Name.compare(
"control"))
113 if (foundCommand && foundControl) {
134 bool shouldProbe =
false;
137 if (allowProbing && piixLevel == 0) {
139 }
else if (piixLevel < 0) {
145 if (allowProbing && piixLevel == 3) {
147 }
else if (piixLevel < 3) {
153 if (allowProbing && piixLevel == 4) {
155 }
else if (piixLevel < 4) {
161 if (piixLevel != -1) {
162 bPiixControllerFound =
true;
165 if (allowProbing && shouldProbe) {
166 return probePiixController(pDev);
172 if (!bPiixControllerFound && bFallBackISA) {
177 bool foundCommand =
false;
178 bool foundControl =
false;
179 for (
unsigned int j = 0; j < pDev->
addresses().count(); j++) {
180 if (pDev->
addresses()[j]->m_Name.compare(
"command"))
182 if (pDev->
addresses()[j]->m_Name.compare(
"control"))
185 if (allowProbing && foundCommand && foundControl)
186 return probeIsaDevice(
static_cast<Controller*
>(pDev));
193static Module::UnloadAdmission admitUnload(
bool) {
194 for (
auto* controller : g_Controllers) {
195 if (controller && !controller->prepareDiskRemoval()) {
196 for (
auto* rollback : g_Controllers) {
198 rollback->cancelDiskRemoval();
200 return Module::UnloadAdmission::Busy;
203 return Module::UnloadAdmission::Ready;
216 if (bPiixControllerFound) {
234 for (
size_t i = 0; i < g_Controllers.count(); ++i) {
236 if (controller != device) {
243 g_Controllers[i] =
nullptr;
251 g_Controllers.clear();
254 bPiixControllerFound =
false;
256 bFallBackISA =
false;
257 allowProbing =
false;
261MODULE_INFO(
"ata", &entry, &exit,
"scsi",
"pci", 0);
virtual void shutdown()=0
uint16_t getPciDeviceId()
uint16_t getPciVendorId()
static void foreach(Callback callback, Device *root=0)
virtual Vector< Address * > & addresses()
virtual void setInterruptNumber(uintptr_t n)
uint8_t getPciClassCode()
uint8_t getPciSubclassCode()
Vector< Device * > m_Children
virtual uintptr_t getInterruptNumber()
bool registerUnloadAdmission(ModuleEntry ownerEntry, Module::UnloadAdmissionHook hook)
static KernelElf & instance()
A vector / dynamic array.
void clear(bool freeMem=false)