Hi:
The kernel does not enumerate drivers. What you see being done by the horde of tutorial followers here is not good practice. Drivers enumerate drivers. The kernel manages device classes, and loads drivers as requested. A kernel should not be aware of the hardware details of any chipset, and thus should not be able to enumerate devices on that chipset.
The kernel sets up a set of classes to generically represent and manage classes of devices. You have for example, co-ordinate input devices, character input devices, graphical output devices, disk devices, buses, timers, etc. Your driver framework (whether self-designed, or taken
stock from an already well-designed and documented API) specifies APIs for communicating with each type of device, and what inputs and outputs should be given to and received from each API call to each device class.
For enumeration, you load a base chipset class driver. The chipset driver enumerates all buses present. The kernel does not. Next, the chipset driver returns all of the enumerated buses to the kernel, and the kernel does something like:
Code: Select all
bus_t **chipsetBuses;
for (; nBusesEnumerated > 0; nBusesEnumerated--)
{
chipsetBuses[nBusesEnumerated] = (bus_t *)malloc(sizeof(bus_t));
driverMgr::initializeBusMetadata(chipsetBuses[nBusesEnumerated], dataReturnedFromDriver[nBusesEnumerated]);
};
search_for_bus_drivers(chipsetBuses);
As each bus driver is loaded (assuming one is found) that bus will enumerate the devices which pertain to it. So an ISA bus driver will enumerate a VGA function, the PIT, etc. EISA will enumerate EISA devices. PCI will enumerate PCI devices, and possible more buses, whose drivers will be loaded. Each non-bus node in the tree of devices is enumerated by its device class.
So a VGA function enumerated by the ISA bus driver will present a graphics device to the kernel, with some information on which driver would be optimal for controlling that particular graphical device. A CMOS timer enumerated by the ISA bus driver would be presented to the kernel as two different types of devices: a one shot timer device and a continuous timer with interdependencies.
So:
For example, does the kernel need to detect that a device exists, then inform the driver, or should the driver detect the device and register it with the kernel?
The answer would be the latter. Designing a proper driver API by yourself is going to be cumbersome, and very difficult. The experienced developers of the Linux kernel haven't got it right, and MS has more than one driver framework to date, with another one due to be released. You may find it expedient to adopt a portable and relatively reliable API that has already been designed.
--All the best,
gravaera.