OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:51 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Question About PC I/O
PostPosted: Mon Jun 17, 2019 10:32 pm 
Offline

Joined: Sun Jun 16, 2019 11:32 am
Posts: 9
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.


Top
 Profile  
 
 Post subject: Re: Question About PC I/O
PostPosted: Tue Jun 18, 2019 1:15 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
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.


Top
 Profile  
 
 Post subject: Re: Question About PC I/O
PostPosted: Tue Jun 18, 2019 2:45 pm 
Offline

Joined: Sun Jun 16, 2019 11:32 am
Posts: 9
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.


Top
 Profile  
 
 Post subject: Re: Question About PC I/O
PostPosted: Wed Jun 19, 2019 1:54 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
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.)


Top
 Profile  
 
 Post subject: Re: Question About PC I/O
PostPosted: Wed Jun 19, 2019 10:57 am 
Offline
Member
Member

Joined: Thu May 17, 2007 1:27 pm
Posts: 999
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).

_________________
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].


Top
 Profile  
 
 Post subject: Re: Question About PC I/O
PostPosted: Thu Jun 20, 2019 10:54 am 
Offline

Joined: Sun Jun 16, 2019 11:32 am
Posts: 9
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?


Top
 Profile  
 
 Post subject: Re: Question About PC I/O
PostPosted: Fri Jun 21, 2019 1:24 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
That's right.

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 58 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group