Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::hardwarecommunication::PCIController Class Referencefinal

Handles the selecting and loading of drivers for PCI devices. More...

#include <pci.h>

Inheritance diagram for MaxOS::hardwarecommunication::PCIController:
MaxOS::drivers::DriverSelector

Public Member Functions

 PCIController ()
 Construct a new PCI Controller object.
 
void select_drivers (drivers::DriverSelectorEventHandler *handler) override
 Select the driver for the device.
 

Static Public Member Functions

static drivers::Driverget_driver (PCIDeviceDescriptor dev)
 Get the driver for the device.
 
static void list_known_device (const PCIDeviceDescriptor &dev)
 Print the vednor and device id of known devices, or "Unknown" + their ids if not known.
 

Detailed Description

Handles the selecting and loading of drivers for PCI devices.

Definition at line 88 of file pci.h.

Constructor & Destructor Documentation

◆ PCIController()

PCIController::PCIController ( )

Construct a new PCI Controller object.

Definition at line 99 of file pci.cpp.

100: m_data_port(0xCFC),
101 m_command_port(0xCF8)
102{
103
104
105}

Member Function Documentation

◆ get_driver()

Driver * PCIController::get_driver ( PCIDeviceDescriptor  dev)
static

Get the driver for the device.

Parameters
devDevice descriptor
Returns
Driver for the device, null pointer if there is no driver

Definition at line 251 of file pci.cpp.

251 {
252
253 switch (dev.vendor_id) {
254 case 0x1022: //AMD
255 {
256 switch (dev.device_id) {
257 case 0x2000: {
258 return new AMD_AM79C973(&dev);
259
260 }
261 default:
262 break;
263 }
264 break;
265 }
266 case 0x8086: //Intel
267 {
268 switch (dev.device_id) {
269
270 case 0x100E: //i217 (Ethernet Controller)
271 {
272 return new IntelI217(&dev);
273 }
274
275 case 0x7010: // PIIX4 (IDE Controller)
276 {
278 }
279
280 default:
281 break;
282 }
283 break;
284 }//End Intel
285 }
286
287 //If there is no driver for the particular device, go into generic devices
288 switch (dev.class_id) {
289 case 0x03: //Graphics
290 {
291
292 switch (dev.subclass_id) {
293 case 0x00: //VGA
294 {
295 return new VideoGraphicsArray();
296 }
297 }
298 break;
299 }
300 }
301
302 return nullptr;
303}
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
Driver for the IDE controller, handles the creation and management of the IDE devices.
Definition ide.h:25
Driver for the AMD AM79C973 Ethernet Controller.
Driver for the Intel I217 Ethernet Controller.
Definition intel_i217.h:64
Driver for the VGA graphics controller, handles the rendering of pixels to the screen.
Definition vga.h:28

Referenced by select_drivers().

◆ list_known_device()

void PCIController::list_known_device ( const PCIDeviceDescriptor dev)
static

Print the vednor and device id of known devices, or "Unknown" + their ids if not known.

Parameters
devThe device to print

Definition at line 310 of file pci.cpp.

310 {
311
312 switch (dev.vendor_id) {
313 case 0x1022: {
314 // The vendor is AMD
315 Logger::Out() << "AMD ";
316
317 // List the device
318 switch (dev.device_id) {
319 default:
320 Logger::Out() << "0x%x" << dev.device_id;
321 break;
322 }
323 break;
324 }
325
326 case 0x106B: {
327 // The vendor is Apple
328 Logger::Out() << "Apple ";
329
330 // List the device
331 switch (dev.device_id) {
332 case 0x003F: {
333 Logger::Out() << "KeyLargo/Intrepid USB";
334 break;
335 }
336
337 default:
338 Logger::Out() << "0x%x" << dev.device_id;
339 break;
340 }
341 break;
342 }
343
344 case 1234: {
345 // The vendor is QEMU
346 Logger::Out() << "QEMU ";
347
348 // List the device
349 switch (dev.device_id) {
350
351 case 0x1111: {
352 Logger::Out() << "Virtual Video Controller";
353 break;
354 }
355 }
356 break;
357 }
358
359 case 0x8086: {
360 // The vendor is Intel
361 Logger::Out() << "Intel ";
362
363 // List the device
364 switch (dev.device_id) {
365
366 case 0x1237: {
367 Logger::Out() << "440FX";
368 break;
369 }
370
371 case 0x2415: {
372 Logger::Out() << "AC'97";
373 break;
374 }
375
376 case 0x7000: {
377 Logger::Out() << "PIIX3";
378 break;
379
380 }
381
382 case 0x7111: {
383 Logger::Out() << "PIIX3 ACPI";
384 break;
385 }
386
387 case 0x7113: {
388 Logger::Out() << "PIIX4 ACPI";
389 break;
390 }
391
392 default:
393 Logger::Out() << "0x%x" << dev.device_id;
394 break;
395
396 }
397 break;
398 }
399
400 case 0x80EE: {
401
402 // The vendor is VirtualBox
403 Logger::Out() << "VirtualBox ";
404
405 // List the device
406 switch (dev.device_id) {
407
408 case 0xBEEF: {
409 Logger::Out() << "Graphics Adapter";
410 break;
411 }
412
413 case 0xCAFE: {
414 Logger::Out() << "Guest Service";
415 break;
416 }
417 }
418 break;
419 }
420
421 // Unknown
422 default:
423 Logger::Out() << "Unknown (0x" << dev.vendor_id << ":0x" << dev.device_id << ")";
424 break;
425
426 }
427}
static Logger & Out()
Gets the active logger.
Definition logger.cpp:149

References MaxOS::Logger::Out().

Referenced by select_drivers().

◆ select_drivers()

void PCIController::select_drivers ( drivers::DriverSelectorEventHandler handler)
overridevirtual

Select the driver for the device.

Parameters
handlerdevice driver event manager

Reimplemented from MaxOS::drivers::DriverSelector.

Definition at line 176 of file pci.cpp.

176 {
177
178 for (int bus = 0; bus < 8; ++bus) {
179 for (int device = 0; device < 32; ++device) {
180
181 int num_functions = (device_has_functions(bus, device)) ? 8 : 1;
182
183 for (int function = 0; function < num_functions; ++function) {
184
185 // Get the device descriptor, if the vendor id is 0x0000 or 0xFFFF, the device is not present/ready
186 PCIDeviceDescriptor device_descriptor = get_device_descriptor(bus, device,
187 function);
188 if (device_descriptor.vendor_id == 0x0000 || device_descriptor.vendor_id == 0x0001 ||
189 device_descriptor.vendor_id == 0xFFFF)
190 continue;
191
192 // Get the earliest port number
193 for (int bar_num = 5; bar_num >= 0; bar_num--) {
194 BaseAddressRegister bar = get_base_address_register(bus, device, function, bar_num);
195 if (bar.address && (bar.type == BARType::InputOutput))
196 device_descriptor.port_base = (uint64_t) bar.address;
197 }
198
199 Logger::DEBUG() << "DEVICE FOUND: " << device_descriptor.get_type() << " - ";
200
201 // Select the driver and print information about the device
203 if (driver != nullptr) {
204 handler->on_driver_selected(driver);
205 Logger::Out() << driver->vendor_name() << " " << driver->device_name();
206 } else {
208 }
209
210 Logger::Out() << "\n";
211 }
212 }
213 }
214}
static Logger DEBUG()
Gets active logger set to DEBUG level.
Definition logger.cpp:193
base class for all drivers, handles the activation, deactivation, initialisation and reset of the dri...
Definition driver.h:27
Used to store the Base Address Register (BAR) of a PCI device.
Definition pci.h:38
static void list_known_device(const PCIDeviceDescriptor &dev)
Print the vednor and device id of known devices, or "Unknown" + their ids if not known.
Definition pci.cpp:310
static drivers::Driver * get_driver(PCIDeviceDescriptor dev)
Get the driver for the device.
Definition pci.cpp:251
Stores information about a PCI device.
Definition pci.h:54

References MaxOS::Logger::DEBUG(), get_driver(), list_known_device(), and MaxOS::Logger::Out().


The documentation for this class was generated from the following files: