OSDev.org
https://forum.osdev.org/

Question About PC I/O
https://forum.osdev.org/viewtopic.php?f=1&t=33738
Page 1 of 1

Author:  Malfunction [ Mon Jun 17, 2019 10:32 pm ]
Post subject:  Question About PC I/O

Hello, I'm new in OS development. I have a question about I/O system of PC.

As I know it, this is a simplified view of PC bus system (it excludes the bridges I'm aware of it).

Image

and we have an address space of 65536 bytes (0000-FFFF) in modern x86 CPUs as far as I know. These are I/O addresses.

Considering PCs (x86 cpus) the following are my questions:

1-) Can I add a device to this I/O bus without using PCI or any other bus? If yes how are I/O addresses assigned? Don't they conflict?
2-) If my CPU supports PCI and I²C (yes some do!), how does the cpu differentiate between their I/O addresses? How does it know that an I/O address belongs to PCI or I²C.
(btw I don't know if I²C addresses are just logical and not about I/O ports but this is another question I also need the answer of)


Thanks and regards.

Author:  Octocontrabass [ Tue Jun 18, 2019 1:15 am ]
Post subject:  Re: Question About PC I/O

Malfunction wrote:
Can I add a device to this I/O bus without using PCI or any other bus?

It sounds like you're thinking of the CPU's local bus (as opposed to something like PCI or LPC), which is still a bus. Whether you can attach devices to the CPU's local bus or not depends on the CPU; some of them don't expose the local bus externally.

Malfunction wrote:
If yes how are I/O addresses assigned? Don't they conflict?

If you're not using a standardized bus, then you can assign them however you want, and you'll cause conflicts if you are careless in how you assign them. Modern x86 PCs tell the OS about these assignments using firmware (e.g. ACPI), so the OS won't try to configure some other device to use a conflicting address. Non-PC x86 hardware, as well as very old PCs, may expect the OS to know about reserved addresses without being told.

Malfunction wrote:
If my CPU supports PCI and I²C (yes some do!), how does the cpu differentiate between their I/O addresses?

If your CPU has integrated peripherals like that, then it must also have integrated address decoders that decide which integrated peripheral is selected by each I/O address. Those address decoders may be configurable, fixed, or a mixture of both (for example, a fixed address decoder to address the PCI configuration space, where the configurable address decoders appear as PCI devices).

Malfunction wrote:
(btw I don't know if I²C addresses are just logical and not about I/O ports but this is another question I also need the answer of)

The answer to that question is most likely in the CPU datasheet, but I can't help more than that without knowing which CPU it is.

Author:  Malfunction [ Tue Jun 18, 2019 2:45 pm ]
Post subject:  Re: Question About PC I/O

First of all thanks for your wise answer, Octocontrabass.

Octocontrabass wrote:
It sounds like you're thinking of the CPU's local bus (as opposed to something like PCI or LPC), which is still a bus. Whether you can attach devices to the CPU's local bus or not depends on the CPU; some of them don't expose the local bus externally.

I mean using just address/data buses but not through PCI or something else in between them. Something more closer to a "direct connection".

Octocontrabass wrote:
If your CPU has integrated peripherals like that, then it must also have integrated address decoders that decide which integrated peripheral is selected by each I/O address. Those address decoders may be configurable, fixed, or a mixture of both (for example, a fixed address decoder to address the PCI configuration space, where the configurable address decoders appear as PCI devices).

My CPU has both PCI and I²C support. Are these considered peripherals? Did you mean the CPU allocates parts of address space to certain buses? For example PCI and I²C in my case may share the I/O address space of 0000-FFFF?

Octocontrabass wrote:
The answer to that question is most likely in the CPU datasheet, but I can't help more than that without knowing which CPU it is.

This is an I²C question tbh. Devices have I²C addresses. Are those addresses from I/O address space I'm talking about or just logical addresses in I²C's protocol?


Thanks.

Author:  Octocontrabass [ Wed Jun 19, 2019 1:54 am ]
Post subject:  Re: Question About PC I/O

Malfunction wrote:
I mean using just address/data buses but not through PCI or something else in between them. Something more closer to a "direct connection".

Yep, that's the local bus.

Malfunction wrote:
My CPU has both PCI and I²C support. Are these considered peripherals?

Yes. They're separate from the x86 CPU core, although they are part of the same physical chip.

Malfunction wrote:
Did you mean the CPU allocates parts of address space to certain buses? For example PCI and I²C in my case may share the I/O address space of 0000-FFFF?

Yes, sort of. The allocations are decided by the integrated peripherals, not the CPU core. Since those are all part of the CPU package, there's not much difference from an outside perspective. The distinction is sometimes important for software.

Malfunction wrote:
This is an I²C question tbh. Devices have I²C addresses. Are those addresses from I/O address space I'm talking about or just logical addresses in I²C's protocol?

Those are logical addresses in I²C. They're independent of the I/O addresses. (Unless your I²C controller uses the I/O address to determine the I²C address, but that would be a very strange I²C controller.)

Author:  Korona [ Wed Jun 19, 2019 10:57 am ]
Post subject:  Re: Question About PC I/O

To slightly elaborate: The PCI bus is the "native" external interconnect of the CPU (by external I mean that I ignore internal interconnects like hypertransport or IUP that cannot directly talk to peripheral devices). Every read and write that is not backed by RAM goes through PCI. The PCI bus (and not the CPU) decides which device is mapped to which MMIO or port address.

I²C OTOH is not (usually?) used as a native CPU interconnect. Instead, the I²C controller is accessed as a PCI device. In this regard, I²C is similar to USB or (S)ATA which also define busses, or the serial port which defines a certain wire protocol (bit not a bus).

Author:  Malfunction [ Thu Jun 20, 2019 10:54 am ]
Post subject:  Re: Question About PC I/O

Thank you both for valuable information Octocontrabass and Korona.

The last question is to check if I got it right.

PCI allocates I/O addresses (those in range 0000-FFFF in x86) but I²C allocates logical addresses because PCI is "native" interconnect and I²C is not. Is this right?

Author:  Octocontrabass [ Fri Jun 21, 2019 1:24 am ]
Post subject:  Re: Question About PC I/O

That's right.

PCI can also use addresses in the memory address space, not just the I/O address space.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/