| 145 | } |
| 146 | |
| 147 | int AddDevice(int bus, int slot, int func){ |
| 148 | PCIDevice device; |
| 149 | |
| 150 | device.vendorID = GetVendor(bus, slot, func); |
| 151 | device.deviceID = GetDeviceID(bus, slot, func); |
| 152 | |
| 153 | device.bus = bus; |
| 154 | device.slot = slot; |
| 155 | device.func = func; |
| 156 | |
| 157 | device.UpdateClass(); |
| 158 | |
| 159 | /*Log::Info("Found Device! Vendor: "); |
| 160 | Log::Write(device.vendorID); |
| 161 | Log::Write(", Device: "); |
| 162 | Log::Write(device.deviceID); |
| 163 | Log::Write(", Class: "); |
| 164 | Log::Write(device.classCode); |
| 165 | Log::Write(", Subclass: "); |
| 166 | Log::Write(device.subclass);*/ |
| 167 | |
| 168 | device.capabilities = new Vector<uint16_t>(); |
| 169 | if(device.Status() & PCI_STATUS_CAPABILITIES){ |
| 170 | uint8_t ptr = ConfigReadWord(bus, slot, func, PCICapabilitiesPointer) & 0xFC; |
| 171 | uint16_t cap = ConfigReadDword(bus, slot, func, ptr); |
| 172 | do { |
| 173 | //Log::Info("PCI Capability: %x", cap & 0xFF); |
| 174 | |
| 175 | if((cap & 0xFF) == PCICapabilityIDs::PCICapMSI){ |
| 176 | device.msiPtr = ptr; |
| 177 | device.msiCapable = true; |
| 178 | device.msiCap.register0 = ConfigReadDword(bus, slot, func, ptr); |
| 179 | device.msiCap.register1 = ConfigReadDword(bus, slot, func, ptr + sizeof(uint32_t)); |
| 180 | device.msiCap.register2 = ConfigReadDword(bus, slot, func, ptr + sizeof(uint32_t) * 2); |
| 181 | |
| 182 | if(device.msiCap.msiControl & PCI_CAP_MSI_CONTROL_64){ // 64-bit capable |
| 183 | device.msiCap.data64 = ConfigReadDword(bus, slot, func, ptr + sizeof(uint32_t) * 3); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | ptr = (cap >> 8); |
| 188 | cap = ConfigReadDword(bus, slot, func, ptr); |
| 189 | |
| 190 | device.capabilities->add_back(cap & 0xFF); |
| 191 | } while((cap >> 8)); |
| 192 | } |
| 193 | |
| 194 | int ret = devices->get_length(); |
| 195 | devices->add_back(device); |
| 196 | return ret; |
| 197 | } |
| 198 | |
| 199 | void Init(){ |
| 200 | unknownDevice = new PCIDevice(); |
no test coverage detected