OSDev.org

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

All times are UTC - 6 hours




Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: MMIO_Starting_Physical_Address and PCIe
PostPosted: Tue Aug 10, 2021 12:09 pm 
Offline
Member
Member

Joined: Sun Aug 01, 2021 5:24 pm
Posts: 51
Where to get this address ?

https://wiki.osdev.org/PCI_Express

Quote:
To access a specific register within a device's PCI configuration space, you have to use the device's PCI Segment Group and bus to determine which memory mapped PCI configuration space area to use, and obtain the starting physical address and starting bus number for that memory mapped area. Once you have the correct starting physical address and starting bus number for that memory mapped area you would use the following formula to determine where the (4096-byte) area for a function's PCI configuration space is: Physical_Address = MMIO_Starting_Physical_Address + ( (Bus - MMIO_Starting_Bus) << 20 | Device << 15 | Function << 12 ).


Last edited by Rukog on Tue Aug 24, 2021 3:15 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: MMIO_Starting_Physical_Address
PostPosted: Tue Aug 10, 2021 12:17 pm 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 296
You do not have to use physical address, you can simply use ports 0xCF8 and 0xCFC. Everything is on PCI, driver for PCI will work on PCI express too.

_________________
https://github.com/VendelinSlezak/BleskOS


Top
 Profile  
 
 Post subject: Re: MMIO_Starting_Physical_Address
PostPosted: Tue Aug 10, 2021 12:18 pm 
Offline
Member
Member

Joined: Sun Aug 01, 2021 5:24 pm
Posts: 51
Klakap wrote:
You do not have to use physical address, you can simply use ports 0xCF8 and 0xCFC. Everything is on PCI, driver for PCI will work on PCI express too.

No thanks, I do not wish to use in/out, I prefer the MMIO way.

Update:
I found that in https://wiki.osdev.org/Memory_Map_(x86)
Attachment:
s.png
s.png [ 20.32 KiB | Viewed 6746 times ]

I like the
Quote:
(sometimes, depends on motherboard and devices)
????????????????

lmao


Top
 Profile  
 
 Post subject: Re: MMIO_Starting_Physical_Address
PostPosted: Tue Aug 10, 2021 12:45 pm 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 296
If you want to use MMIO in PCI, you have to find ACPI table MCFG. So it means that you have to find RSDP, where is pointer to RSDT. RSDT contains pointers to all ACPI tables. You have to search them and figure out of MCFG is here. If yes, you can read MMIO_Starting_Physical_Address from it. But it is not sure that you will find this table on every computer. I think that I/O way is much much easier than this.

_________________
https://github.com/VendelinSlezak/BleskOS


Top
 Profile  
 
 Post subject: Re: MMIO_Starting_Physical_Address
PostPosted: Tue Aug 10, 2021 12:51 pm 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
Klakap wrote:
I think that I/O way is much much easier than this.

True, but PCIe (which is what uses MMIO) became the industry standard in 2005. I have seen many motherboard that have no PCI slots, although I'm not sure if they emulate PCI internally. For this reason, I would prefer the MCFG way. It may be trickier, but you have support of the current industry standard.

_________________
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg


Top
 Profile  
 
 Post subject: Re: MMIO_Starting_Physical_Address
PostPosted: Fri Aug 13, 2021 12:14 pm 
Offline
Member
Member

Joined: Sun Aug 01, 2021 5:24 pm
Posts: 51
Klakap wrote:
If you want to use MMIO in PCI, you have to find ACPI table MCFG. So it means that you have to find RSDP, where is pointer to RSDT. RSDT contains pointers to all ACPI tables. You have to search them and figure out of MCFG is here. If yes, you can read MMIO_Starting_Physical_Address from it. But it is not sure that you will find this table on every computer. I think that I/O way is much much easier than this.


I think ive found it, so the RSDT address is 0x5150484B ?

Image


Top
 Profile  
 
 Post subject: Re: MMIO_Starting_Physical_Address
PostPosted: Fri Aug 13, 2021 12:52 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
If the checksum is correct, that's the RSDP, but you've got the wrong number for the RSDT address. Take another look at the RSDP structure.

Also, you should use the XSDT instead of the RSDT if it's available.


Top
 Profile  
 
 Post subject: Re: MMIO_Starting_Physical_Address
PostPosted: Fri Aug 13, 2021 3:17 pm 
Offline
Member
Member

Joined: Sun Aug 01, 2021 5:24 pm
Posts: 51
Octocontrabass wrote:
If the checksum is correct, that's the RSDP, but you've got the wrong number for the RSDT address. Take another look at the RSDP structure.

Also, you should use the XSDT instead of the RSDT if it's available.


Feelsbad, on Qemu impossible to retrieve the RSDP table descriptor, the checksum is bad and only RSD is showing as signature, it shows its limit real quick :shock:

Also the checksum was a success on real machine and the XSDT address is 0x873BE0A0.

Does it sounds like a correct address ?


Top
 Profile  
 
 Post subject: Re: MMIO_Starting_Physical_Address
PostPosted: Fri Aug 13, 2021 3:30 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Rukog wrote:
Feelsbad, on Qemu impossible to retrieve the RSDP table descriptor, the checksum is bad and only RSD is showing as signature, it shows its limit real quick :shock:

If the signature doesn't match, it's not the RSDP. Did you find anything else that looks like the RSDP?

Rukog wrote:
Also the checksum was a success on real machine and the XSDT address is 0x873BE0A0.

Does it sounds like a correct address ?

Yes.


Top
 Profile  
 
 Post subject: Re: MMIO_Starting_Physical_Address
PostPosted: Fri Aug 13, 2021 4:01 pm 
Offline
Member
Member

Joined: Sun Aug 01, 2021 5:24 pm
Posts: 51
Octocontrabass wrote:
Rukog wrote:
Feelsbad, on Qemu impossible to retrieve the RSDP table descriptor, the checksum is bad and only RSD is showing as signature, it shows its limit real quick :shock:

If the signature doesn't match, it's not the RSDP. Did you find anything else that looks like the RSDP?


Yes, ive two match after multiple scan pass
Image
Image


Top
 Profile  
 
 Post subject: Re: MMIO_Starting_Physical_Address
PostPosted: Fri Aug 13, 2021 4:12 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
The first picture looks like the correct RSDP, but why is it at 0x105B? It should be either within the first 1KB of the EBDA or between 0xE0000 and 0xFFFFF. (And it will always be aligned to a 16-byte boundary.)


Top
 Profile  
 
 Post subject: Re: MMIO_Starting_Physical_Address
PostPosted: Fri Aug 13, 2021 4:32 pm 
Offline
Member
Member

Joined: Sun Aug 01, 2021 5:24 pm
Posts: 51
Octocontrabass wrote:
The first picture looks like the correct RSDP, but why is it at 0x105B? It should be either within the first 1KB of the EBDA or between 0xE0000 and 0xFFFFF. (And it will always be aligned to a 16-byte boundary.)


Yes because I am dumping the RSDPDesc struct where I store the RSDP found.

Else I am just searching for "RSD " w/o "PTR ", on my real machine it redirects me directly to a good RSDP but not Qemu that redirect me to several RSDP.


Last edited by Rukog on Fri Aug 13, 2021 4:58 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: MMIO_Starting_Physical_Address
PostPosted: Fri Aug 13, 2021 4:43 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Yes, that's normal. You're supposed to ignore any invalid RSDP you find and keep searching until you find a valid one.


Top
 Profile  
 
 Post subject: Re: MMIO_Starting_Physical_Address
PostPosted: Fri Aug 13, 2021 5:01 pm 
Offline
Member
Member

Joined: Thu May 17, 2007 1:27 pm
Posts: 999
Qemu definitely presents a valid RSDP if you run a machine model that has ACPI support.

_________________
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: MMIO_Starting_Physical_Address
PostPosted: Sat Aug 14, 2021 2:13 am 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 296
As Occontrabass noted, you have to search RSDP in memory from 0xE0000 to 0xFFFFF as first. Only if you can not found RSDP in this memory, you can move to Bios EBDA area. When you found signature ‘RSD PTR ‘ you have to do checksum. If you do not do checksum, once in a while you will found computer with false RSDPs, e.g. Bochs. Checksum is made by adding all 20 bytes of RSDP/36 bytes of XSDP and checking if first byte of result is zero. If yes, you found valid RSDP. From my driver I can provide information that in Bochs is RSDP on address 0xFBB30, in QEMU on 0xF0980, and in Virtualbox on 0xE0000.

_________________
https://github.com/VendelinSlezak/BleskOS


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 56 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