Device Detection
Posted: Wed May 11, 2005 12:03 am
Hi,
My OS currently has code to scan PCI busses and detect PS/2 devices, and I'm about to add code to detect ISA Plug & Play devices. Before adding extra code I decided it'd be a good idea to ask if anyone can think of *any* problems with the planned detection sequence.
First, an overview. The OS is intended for 80486DX (or compatible) and later computers. The OS is a micro-kernel where device drivers are seperate user-level processes. In addition there's a few "kernel modules", which effectively become part of the kernel. One of the kernel modules is the "device manager" which is responsible for detecting devices, managing resources (DMA channels, IO ports, IRQs, etc), maintaining a "connection tree" (used for power management, etc), and loading/starting device drivers.
For ISA devices most of them don't support "Plug & Play" and can't be auto-detected. For these devices (which I'll call "fixed ISA devices") the device manager will load a "fixed ISA device detection utility" (possibly several of them) which will do anything it can to figure out what fixed ISA devices are present and what resources they use. The utility will inform the device manager of all details so that the device manager can load the device drivers like normal. This is partly to assist device driver writers - when a device driver is started the device manager tells it which resources to use, so a device driver doesn't have to care about this. For example, a driver for an NE2000 compatible ethernet card will work the same, regardless of whether it's a PCI, Plug & Play ISA or fixed ISA card.
It all sounds simple enough, but there's a few problems:
a) some USB devices emulate legacy devices (e.g. keyboard & mouse), so you can't detect PS/2 devices until USB devices are either fully working (with legacy mode disabled) or disabled some other way beforehand.
b) there's similar problems with PCI devices (e.g. an IDE controller) where the PCI device could be detected during the fixed ISA device detection, resulting in the same device being detected twice.
c) some things must be detected before others - for e.g. PCI USB controllers need to be found and configured before the USB device scan can start.
d) some ISA devices use 10 bit IO port addresses, such that a device that uses IO port 0x0321 would also appear at 0x0721, 0x0B21, 0x0F21, 0x1321, 0x1721, all the way up to 0xFF21. To assign resources for other devices (PCI and ISA Plug & Play) the fixed ISA devices must be detected first, including whether they decode all of the 16 IO address lines or not. PCI to PCI bridges can be configured such that only memory addresses within a certain range pass through to the secondary bus, but I don't know if a PCI to LPC bridge can do the same for IO addresses (to prevent these 10 bit devices from messing up the entire IO address space).
e) I think PCI devices and ISA Plug & Play devices can be disabled so that ISA fixed device detection doesn't interfere with or detect these devices, but I'm not sure..
f) The primary video card can't be disabled as it's being used. I need a good method of figuring out which device is the primary video device when there's multiple video cards installed.
[CONTINUED]
My OS currently has code to scan PCI busses and detect PS/2 devices, and I'm about to add code to detect ISA Plug & Play devices. Before adding extra code I decided it'd be a good idea to ask if anyone can think of *any* problems with the planned detection sequence.
First, an overview. The OS is intended for 80486DX (or compatible) and later computers. The OS is a micro-kernel where device drivers are seperate user-level processes. In addition there's a few "kernel modules", which effectively become part of the kernel. One of the kernel modules is the "device manager" which is responsible for detecting devices, managing resources (DMA channels, IO ports, IRQs, etc), maintaining a "connection tree" (used for power management, etc), and loading/starting device drivers.
For ISA devices most of them don't support "Plug & Play" and can't be auto-detected. For these devices (which I'll call "fixed ISA devices") the device manager will load a "fixed ISA device detection utility" (possibly several of them) which will do anything it can to figure out what fixed ISA devices are present and what resources they use. The utility will inform the device manager of all details so that the device manager can load the device drivers like normal. This is partly to assist device driver writers - when a device driver is started the device manager tells it which resources to use, so a device driver doesn't have to care about this. For example, a driver for an NE2000 compatible ethernet card will work the same, regardless of whether it's a PCI, Plug & Play ISA or fixed ISA card.
It all sounds simple enough, but there's a few problems:
a) some USB devices emulate legacy devices (e.g. keyboard & mouse), so you can't detect PS/2 devices until USB devices are either fully working (with legacy mode disabled) or disabled some other way beforehand.
b) there's similar problems with PCI devices (e.g. an IDE controller) where the PCI device could be detected during the fixed ISA device detection, resulting in the same device being detected twice.
c) some things must be detected before others - for e.g. PCI USB controllers need to be found and configured before the USB device scan can start.
d) some ISA devices use 10 bit IO port addresses, such that a device that uses IO port 0x0321 would also appear at 0x0721, 0x0B21, 0x0F21, 0x1321, 0x1721, all the way up to 0xFF21. To assign resources for other devices (PCI and ISA Plug & Play) the fixed ISA devices must be detected first, including whether they decode all of the 16 IO address lines or not. PCI to PCI bridges can be configured such that only memory addresses within a certain range pass through to the secondary bus, but I don't know if a PCI to LPC bridge can do the same for IO addresses (to prevent these 10 bit devices from messing up the entire IO address space).
e) I think PCI devices and ISA Plug & Play devices can be disabled so that ISA fixed device detection doesn't interfere with or detect these devices, but I'm not sure..
f) The primary video card can't be disabled as it's being used. I need a good method of figuring out which device is the primary video device when there's multiple video cards installed.
[CONTINUED]