Device Detection

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Device Detection

Post by Brendan »

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]
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Device Detection

Post by Brendan »

[CONTINUED]

From the issues above I came up with the following order (to be followed by the device manager during boot). I'm not sure if I've found/listed all possible issues, so I'm not sure if this sequence is right...


Steps in order performed:

PCI bus scan
PCI device disabling (except primary video, bridges, etc)
ISA Plug & Play scan

ISA Plug & Play device disabling (except primary video)
Load ISA fixed device detection utilities
Get response/s from ISA fixed device detection utilities
Serial port detection
Serial device detection
Parallel port detection
Parallel device detection
PS/2 device detection
ISA Plug & Play device resource assignment
PCI to LPC bridge configuration
PCI device resource assignment
PCI to PCI bridge configuration
USB device scan
Load PCI device drivers
Load USB device drivers
Load PS/2 device drivers
Load ISA Plug & Play device drivers
Load ISA fixed device drivers
Load serial device drivers
Load parallel device drivers

Notes
- Loading a device driver implies enabling the device if it was disabled.
- The device manager handles USB controllers, the PS/2 controller chip, serial ports and parallel ports itself (without external drivers)

I also want to know if there's any way to detect the motherboard/chipset - there's things like the PCI IRQ router and power management (turning the computer off) that would be built into a "motherboard driver". The alternative here is ACPI, which I dislike a lot (and isn't supported by all computers anyway). I've looked through a few Intel chipset manuals (430TX, 440FX and 845) but it's like searching for a needle at a haymakers festival at night while wearing sunglasses and mittens (although I might be exaggerating :) ).


Thanks,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Device Detection

Post by distantvoices »

[quote=Brendan]
...but it's like searching for a needle at a haymakers festival at night while wearing sunglasses and mittens...
[quote][/quote]

That's one nice metaphor. Just think at it: Even a blind chicken picks a corn at some time.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
Post Reply