Plug+&+Play+unplugged

Plug & Play: unplugged

It’s one of the best additions to Windows ever, taking 99 per cent of the hassle out of most hardware installations, but how does Plug and Play really work? In the good old days of Windows 3.1 and earlier, installing new hardware was a nightmare. Every expansion card had to be set up manually, forcing you to learn complex technical details about exactly how your PC functioned.

If you got anything wrong then the card simply wouldn’t work or, worse than that, some other item of hardware would stop working, and you’d have to reconfigure that as well.

Fortunately, Microsoft realised this was an unacceptable situation, especially if they wanted to sell PCs to regular home users, and Windows 95 saw the first appearance of their solution: Plug and Play.

Now new hardware would be detected and configured by a combination of the BIOS and Windows itself, with very little (if any) input required from the user.

That was the plan, anyway. The first versions weren’t too reliable, quickly earning the alternative nickname ‘Plug and Pray’, but the situation quickly improved.

Now you can take any of thousands of PC add‐ons, plug them into just about any system, and it’ll almost always work just as you expect.

Of course that’s only part of the Plug and Play story, which actually begins somewhere else entirely.


 * Plug and Play BIOS**

Most people see Plug and Play as the typical Windows response when you plug in a new USB device, for example, detecting it and prompting you to install a driver.

That’s just one small part of its work, however. Plug and Play is actually used to detect all your hardware every time you turn on your PC and then it allocates any system resources that might be required. IRQs (Interrupt Request Lines) are one example – hard‐wired signals that tell the CPU a particular device needs attention.

Your PC only has a limited number of these, and although they can be shared (Google for PCI Steering to find out how), it still pays to allocate them sensibly.

The allocation process starts early on, before Windows even begins to load, as your BIOS checks installed hardware and decides which IRQ goes where. Unused IRQs are then assigned to the PCI bus controller for reallocating later.

This BIOS assistance is helpful if you have an old PC that can’t fully handle regular Plug and Play, say, but almost entirely useless for everyone else.

In fact, Windows XP Professional ignores any system resource allocations made by your

BIOS, and enables Plug and Play to handle everything from scratch.

OK, that’s perhaps a slight exaggeration. Plug and Play is very smart, but it’s not just a Windows component: it also relies on your hardware, and particularly your system drivers.

The end result is far more lengthy than you might imagine.

Discovering devices

The Plug and Play process of hardware discovery begins with a virtual driver called‘Root’, which represents your PC. This uses a system called the HAL (Hardware Abstraction Layer) to pick up devices and controllers on the motherboard and to discover your main bus type.

The driver for your bus – probably PCI – then runs through what’s called an enumeration routine to find out which other devices and buses it has attached and reports the results back to the Plug and Play Manager.

Any new buses found (such as a USB controller) then run through an enumeration routine of their own, recording details of everything connected to them. The process cascades right down until Plug and Play knows about everything attached to your system.

The root of the tree

Is this beginning to sound a little like a tree or folder structure?

You’re right, with Root at the top, then a PCI folder with a USB folder within that, say, holding all your USB‐connected devices.

You can view much the same thing in Device Manager, just by clicking View ‐> Devices by Connection.

What has still not explained is how Plug and Play knows which drivers to use for each device.

That’s really not a problem for top‐level system devices such as the PCI bus, as Windows loads them in advance.

Which ones? The Registry reveals all: run REGEDIT, browse to

HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services, and look through the devices.

Anything with a Start type of 0 must be loaded for the system to boot, so Plug and Play has nothing to do with it.

Lower‐level devices such as a soundcard or USB add‐on are different, though.

As Windows encounters these, it has to check to see if there’s a suitable driver on your system.

Every item of hardware that Plug and Play discovers will return a couple of identifiers.

The first is a vendor code, and everyone who makes PC add‐ons has a unique one of their own. Iomega has been allocated 13CA, for instance, and no one else will ever be able to use that. (In a rare moment of PC‐standards humour, Intel was allocated 8086.)

The second is a product code that the manufacturer uses to identify that device.

Plug and Play then uses these codes to create a unique identifier for the device.

If you happen to have an hp OfficeJet G95, for instance, then it might look like

‘Vid_03f0&Pid_0411’. ‘Vid’ means vendor ID, 03f0 is the code for hp, ‘Pid’ is the product ID and 0411 is hp’s code for the G95.

Now Plug and Play needs to know if you’ve ever installed a driver for that product and it finds this out by looking in the Registry.

Assuming your G95 were plugged into a USB port, for example, it’d be listed under the

HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Enum \ USB key.

Once it’s been found, Plug and Play uses the Driver value to locate its driver, and ‘Hey Presto’ you’re done.

If this is a new product, however, there will be no entry recorded in the Registry and so

Plug and Play will launch the New Device wizard.

You then point it at the CD or folder containing the drivers, or at least their related INF files.

Next, they’re duly installed and Plug and Play proceeds with the boot.

It’s an involved process, but we rarely have to worry about the technical details any more, and that must be a definite move in the right direction.

Phew!!! Heavy stuff Yes ?