| 97 | } |
| 98 | |
| 99 | int Init(){ |
| 100 | if(!PCI::FindGenericDevice(ideClassCode, ideSubclass)){ |
| 101 | Log::Warning("[ATA] No IDE controller found!"); |
| 102 | return 1; |
| 103 | } |
| 104 | |
| 105 | controllerPCIDevice = &PCI::GetGenericPCIDevice(ideClassCode, ideSubclass); |
| 106 | assert(controllerPCIDevice->vendorID != 0xFFFF); |
| 107 | |
| 108 | Log::Info("[ATA] Initializing..."); |
| 109 | |
| 110 | if(controllerPCIDevice->BarIsIOPort(0)){ |
| 111 | uintptr_t bar; |
| 112 | if((bar = controllerPCIDevice->GetBaseAddressRegister(0))){ |
| 113 | port0 = bar; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | if(controllerPCIDevice->BarIsIOPort(1)){ |
| 118 | uintptr_t bar; |
| 119 | if((bar = controllerPCIDevice->GetBaseAddressRegister(1))){ |
| 120 | port1 = bar; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | if(controllerPCIDevice->BarIsIOPort(2)){ |
| 125 | uintptr_t bar; |
| 126 | if((bar = controllerPCIDevice->GetBaseAddressRegister(2))){ |
| 127 | controlPort0 = bar; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | if(controllerPCIDevice->BarIsIOPort(3)){ |
| 132 | uintptr_t bar; |
| 133 | if((bar = controllerPCIDevice->GetBaseAddressRegister(3))){ |
| 134 | controlPort1 = bar; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | assert(controllerPCIDevice->BarIsIOPort(4)); |
| 139 | busMasterPort = controllerPCIDevice->GetBaseAddressRegister(4); |
| 140 | controllerPCIDevice->EnableBusMastering(); |
| 141 | |
| 142 | if(debugLevelATA >= DebugLevelNormal){ |
| 143 | Log::Info("[ATA] Using Ports: Primary %x, Secondary %x", port0, port1); |
| 144 | } |
| 145 | |
| 146 | for(int i = 0; i < 2; i++){ // Port |
| 147 | WriteControlRegister(i, 0, ReadControlRegister(i, 0) | 4); // Software Reset |
| 148 | |
| 149 | for(int z = 0; z < 4; z++) inportb(controlPort0); |
| 150 | |
| 151 | WriteControlRegister(i, 0, 0); |
| 152 | |
| 153 | for(int j = 0; j < 2; j++){ // Drive (master/slave) |
| 154 | if(DetectDrive(i, j)){ |
| 155 | if(debugLevelATA >= DebugLevelNormal){ |
| 156 | Log::Info("Found ATA Drive: Port: %d, %s", i, j ? "slave" : "master"); |
no test coverage detected