views:

63

answers:

2

I know that peripheral devices such as a hard driver, a floppy driver, etc are controlled by reading/writing certain control registers on their device controllers.

I am wondering about the following questions:

  • Is it true that when these peripheral devices are plugged onto the computer, the addresses(port numbers) of their control registers are thus determined by how they are attached to the address bus (i.e. the hard-wiring rules, not any soft things)?
  • Who makes the scheme of the port number assignment?
  • If I was given a naked computer(with no operating system and with many peripheral devices), how could I figure out the port number assignment so I can use them to control peripheral deveices.

At last and as usual, thanks for your patience and reply. 8^)

+3  A: 

For a "naked computer" that is a relatively new PC compatible machine, you can find some answers in Conventional PCI description:

In a typical system, the firmware (or operating system) queries all PCI buses at startup time (via PCI Configuration Space) to find out what devices are present and what system resources (memory space, I/O space, interrupt lines, etc.) each needs. It then allocates the resources and tells each device what its allocation is.

The PCI configuration space also contains a small amount of device type information, which helps an operating system choose device drivers for it, or at least to have a dialogue with a user about the system configuration.

...

Finally, PCI configuration space provides access to 256 bytes of special configuration registers per PCI device. Each PCI slot gets its own configuration space address range. The registers are used to configure devices memory and I/O addresses ranges they should respond to from transaction initiators. When a computer is first turned on, all PCI devices respond only to their configuration space accesses. The computers BIOS scans for devices and assigns Memory and I/O address ranges to them.

Once you establish the I/O address(es) for a device, actual command codes are highly device-specific. Hopefully, some manufacturers provide relevant documentation online.

gimel
+1 for mentioing PCI configuration registers. More to the OPs question, every bus is different and some of the memory mapping is handled by the BIOS
Sam Post
Thanks gimel for your detailed reply.
smwikipedia
A: 

I would assume that I/O port numbers are primarily determined (or assigned) by the mainboard's chipset. I would further assume that the original IBM PC architecture used a specific assignment which was taken over by other manufacturers in order to be IBM PC-compliant.

AFAIK, not all devices use fixed I/O port numbers. This is especially true since more modern buses (starting with e.g. PCI) allow the reconfiguration of the port range that a particular device uses. You might have to look into P'n'P technology to learn more about this.

AFAIK, fixed I/O port numbers are mostly used for standard (legacy) components, such as ATA (IDE) HDD and FDD controllers, PS/2 keyboard, etc. I could imagine that on today's systems, those port numbers are only used for backward compatibility.

stakx