OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 3:59 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Changing AHCI Base BAR in PCI Configuration[SOLVED]
PostPosted: Fri Jul 26, 2013 6:00 am 
Offline
Member
Member

Joined: Sun Oct 02, 2011 3:36 am
Posts: 25
Location: Spain
Hello everyone.
I have designed a simple AHCI controller (following the AHCI specification 1.3), without Port Multiplier support. When my OS is getting AHCI configuration from PCI, detects that the ABAR is not placed in a good place, so it has to change it (concretely to the MB 7). But when it try to read the configuration from HBA Mem (supposedly in the MB 7), it gets that no ports are connected, but I know that there is one device connected to port 0, because I'm using VirtualBox and I have checked it.
Code:
PCI_WriteReg32(_ahci->bus, _ahci->slot, _ahci->function, 0x24, (AHCI_BASE | 0xF0000000));
      if(PCI_ReadReg32(_ahci->bus, _ahci->slot, _ahci->function, 0x24) != (AHCI_BASE | 0xF0000000)){
         DEBUG(true, "No se pudo cambiar la base del AHCI\n");
         return 3;
      }
      ___ahci_pci_conf_abar = AHCI_BASE;


PD: Sorry for my English :oops:


Last edited by ateno3 on Fri Aug 02, 2013 10:20 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Changing AHCI Base BAR in PCI Configuration
PostPosted: Fri Jul 26, 2013 8:28 am 
Offline
Member
Member
User avatar

Joined: Tue Dec 25, 2007 6:03 am
Posts: 734
Location: Perth, Western Australia
May I ask why you are changing the contents of the BARs on VirtualBox? (All PCs have the PCI BIOS which does this for you)

Also, what is the purpose of the '| 0xF0000000'? Surely that would cause the actual programmed base to be not what you expect it to be.

_________________
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc


Top
 Profile  
 
 Post subject: Re: Changing AHCI Base BAR in PCI Configuration
PostPosted: Fri Jul 26, 2013 10:47 am 
Offline
Member
Member

Joined: Sun Oct 02, 2011 3:36 am
Posts: 25
Location: Spain
thepowersgang wrote:
May I ask why you are changing the contents of the BARs on VirtualBox? (All PCs have the PCI BIOS which does this for you)

Also, what is the purpose of the '| 0xF0000000'? Surely that would cause the actual programmed base to be not what you expect it to be.


Because the address which is pointed by BAR 5 (ABAR) is already being used by the paging map, I can't move that.
With regard to the "| 0xF0000000":
Before modifying the ABAR content, I read it and, it had the 0xF0500000 value, but the size of the RAM is 32 MB, so it can't be (It fired a PAGE FAULT). I supposed that the ABAR was in 0x500000, and I checked it. I derived that the ABAR content must be "or"ed with that.

PD: Again, sorry for my English.


Top
 Profile  
 
 Post subject: Re: Changing AHCI Base BAR in PCI Configuration
PostPosted: Sat Jul 27, 2013 12:21 am 
Offline
Member
Member
User avatar

Joined: Tue Dec 25, 2007 6:03 am
Posts: 734
Location: Perth, Western Australia
You seem to be confused about both the concept of MMIO and Virtual/Physical addressing.

The BARs contain physical addresses, and should never point to present RAM (because the RAM is just another device listening on the address bus). To access the register contents, you'll want to map the area pointed to by the BAR into virtual memory (this can be anywhere you want it to be)

_________________
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc


Top
 Profile  
 
 Post subject: Re: Changing AHCI Base BAR in PCI Configuration
PostPosted: Sat Jul 27, 2013 4:53 am 
Offline
Member
Member

Joined: Sun Oct 02, 2011 3:36 am
Posts: 25
Location: Spain
thepowersgang wrote:
You seem to be confused about both the concept of MMIO and Virtual/Physical addressing.

The BARs contain physical addresses, and should never point to present RAM (because the RAM is just another device listening on the address bus). To access the register contents, you'll want to map the area pointed to by the BAR into virtual memory (this can be anywhere you want it to be)


First of all, thank you for answering.
My OS works with an Identity Paging, so physical memory is the same as virtual memory.
But, even changing that, I would have the same problem, the paging map, which is the MB 2 and it fills the next 4 MB (until MB 6) and the ABAR points to the MB 5, so they go into conflict.

Moreover, I would want you to answer me a question, could I change the ABAR content?


Top
 Profile  
 
 Post subject: Re: Changing AHCI Base BAR in PCI Configuration
PostPosted: Sat Jul 27, 2013 5:00 am 
Offline
Member
Member
User avatar

Joined: Tue Dec 25, 2007 6:03 am
Posts: 734
Location: Perth, Western Australia
You can change the BAR values, but you'd want to be sure that you don't change it to somewhere that is already in use by another device.

Also, how can you be using identity paging, but still have something else occupying the upper area of memory?

_________________
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc


Top
 Profile  
 
 Post subject: Re: Changing AHCI Base BAR in PCI Configuration
PostPosted: Sat Jul 27, 2013 5:34 am 
Offline
Member
Member

Joined: Sun Oct 02, 2011 3:36 am
Posts: 25
Location: Spain
thepowersgang wrote:
You can change the BAR values, but you'd want to be sure that you don't change it to somewhere that is already in use by another device.

Also, how can you be using identity paging, but still have something else occupying the upper area of memory?


Thank for your answer.
I have not understand very well your question(English isn't my mother tongue), but I'm going to try to answer you: No, there still is nothing in the upper memory,but it'll be used for task and other things.
Another question.
I have changed the ABAR content to the MB 7, but when I dump its content, I get that there are nothing, all is zeroed. Then, I used the ABAR which was previously(MB 5) , and I get the same. Could you tell me why? I'm using VirtualBox, and I have 2 devices connected, a SATA harddisk in the port 0 and a SATAPI disk in the port 1, but when I read the PI register I see a 0 value.


Top
 Profile  
 
 Post subject: Re: Changing AHCI Base BAR in PCI Configuration
PostPosted: Sat Jul 27, 2013 9:47 am 
Offline
Member
Member
User avatar

Joined: Tue Dec 25, 2007 6:03 am
Posts: 734
Location: Perth, Western Australia
The BAR cannot be set to any address in RAM. It must be in an 'unused' area (which is why it was ~0xF0000000 to start with). You should never have to alter the BARs on a PCI device (unless you really know what you're doing, and there's no PCIBIOS to set them for you).

_________________
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc


Top
 Profile  
 
 Post subject: Re: Changing AHCI Base BAR in PCI Configuration
PostPosted: Sat Jul 27, 2013 2:13 pm 
Offline
Member
Member

Joined: Sun Oct 02, 2011 3:36 am
Posts: 25
Location: Spain
thepowersgang wrote:
The BAR cannot be set to any address in RAM. It must be in an 'unused' area (which is why it was ~0xF0000000 to start with). You should never have to alter the BARs on a PCI device (unless you really know what you're doing, and there's no PCIBIOS to set them for you).

Thank you again.
Two question:
1. So, you're telling me that there are no way to change the address where the AHCI will write its data(HBA Mem and Ports descriptors), not?
2. But when I'm using the original ABAR, I also get nothing from there(all is zeroed). I've rewritten the paging module in order not to use the place where the content of ABAR points. It tells me that there are no ports, when I know that there must be, two at least.


Last edited by ateno3 on Sat Jul 27, 2013 4:46 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Changing AHCI Base BAR in PCI Configuration
PostPosted: Sat Jul 27, 2013 2:29 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Quote:
1. So, you're telling me that there are no way to change the direction where the AHCI will write its data(HBA Mem and Ports descriptors), not?
As far as I got spanish right, "direccion" isn't the proper translation for direction, it's address (as it does in email address).

You really are confusing the direction here. The PCI bar dictates what section of memory addresses the device is supposed to listen to when the CPU wants to do something. If the device needs to read or write to memory of its own, it'll have a different place where that information is stored.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: Changing AHCI Base BAR in PCI Configuration
PostPosted: Sat Jul 27, 2013 2:54 pm 
Offline
Member
Member

Joined: Sun Oct 02, 2011 3:36 am
Posts: 25
Location: Spain
Combuster wrote:
Quote:
1. So, you're telling me that there are no way to change the direction where the AHCI will write its data(HBA Mem and Ports descriptors), not?
As far as I got spanish right, "direccion" isn't the proper translation for direction, it's address (as it does in email address).

You really are confusing the direction here. The PCI bar dictates what section of memory addresses the device is supposed to listen to when the CPU wants to do something. If the device needs to read or write to memory of its own, it'll have a different place where that information is stored.

:oops: Thank you for helping with my really bad "English".You're right :oops:
OK. Then, how can I know where the information is stored?

PD: If you knew the answer to the second question, could you tell it to me?

EDIT: I have mapped the content of ABAR( 0xF0500000 ) into virtual memory. Now the address 0xF0500000 to the MB 7(Physical Memory), but I still have the second problem: I get that there are no attached devices( there are 2, in the port 0 and 1)


Top
 Profile  
 
 Post subject: Re: Changing AHCI Base BAR in PCI Configuration
PostPosted: Sun Jul 28, 2013 5:40 pm 
Offline
Member
Member
User avatar

Joined: Tue Dec 25, 2007 6:03 am
Posts: 734
Location: Perth, Western Australia
(From a PM)
ateno3 wrote:
Subject: Changing AHCI Base BAR in PCI Configuration

thepowersgang wrote:
The BAR cannot be set to any address in RAM. It must be in an 'unused' area (which is why it was ~0xF0000000 to start with). You should never have to alter the BARs on a PCI device (unless you really know what you're doing, and there's no PCIBIOS to set them for you).

Hello. I hope not to bother you, but you're the only one who have answered me. :oops:
I have done what you said, I mapped the address (contained in ABAR) to some memory which exists(in the 7th MB), but I get that all is zeroed, and the AHCI HBA does not response the MMIO accesses.
I hope you can help... and sorry.


Please note that I find it exceptionally rude when I receive a private message for something that should be in the thread.

I suggest you read up on paging, because it sounds like you are not mapping the IO space correctly (and you were getting virtual and physical memory mixed up).

_________________
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc


Top
 Profile  
 
 Post subject: Re: Changing AHCI Base BAR in PCI Configuration
PostPosted: Mon Jul 29, 2013 4:14 pm 
Offline
Member
Member

Joined: Sun Oct 02, 2011 3:36 am
Posts: 25
Location: Spain
thepowersgang wrote:
(From a PM)
ateno3 wrote:
Subject: Changing AHCI Base BAR in PCI Configuration

thepowersgang wrote:
The BAR cannot be set to any address in RAM. It must be in an 'unused' area (which is why it was ~0xF0000000 to start with). You should never have to alter the BARs on a PCI device (unless you really know what you're doing, and there's no PCIBIOS to set them for you).

Hello. I hope not to bother you, but you're the only one who have answered me. :oops:
I have done what you said, I mapped the address (contained in ABAR) to some memory which exists(in the 7th MB), but I get that all is zeroed, and the AHCI HBA does not response the MMIO accesses.
I hope you can help... and sorry.


Please note that I find it exceptionally rude when I receive a private message for something that should be in the thread.

I suggest you read up on paging, because it sounds like you are not mapping the IO space correctly (and you were getting virtual and physical memory mixed up).


Hello.
I have done what you said to me. I have been reading about the paging.
I think I found the problem: I use the mmap function, to map the content of ABAR to the physical address I want, but when I read the page directory and I look for the page, which the virtual address is, it returns another address. The code is the following:
Code:
bool mmap(void* virtual, void* phys, u8 flags){
      if(((u32)virtual & 0xFFF) || ((u32)phys & 0xFFF)) return false;
      
      u32 pdindex = (u32)virtual >> 22;
      u32 ptindex = ((u32)virtual >> 12) & 0x3FF;
      
      u32* pt = (u32*)(PAGE_DIRECTORY[pdindex]);

      *(pt + ptindex) = (((u32)phys) | (flags & 0xFFF) | PAG_PRESENT);
      //__asm__ volatile("invlpg (%0)\n\t"::"r"((u32)virtual): "memory");
      
      return true;


And again sorry....


Top
 Profile  
 
 Post subject: Re: Changing AHCI Base BAR in PCI Configuration
PostPosted: Tue Jul 30, 2013 10:21 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Since you're hopelessly stuck trying to do advanced stuff while not even knowing the basics, a brief lesson:

Quote:
PD: If you knew the answer to the second question, could you tell it to me?
Learn to debug?
Quote:
I mapped the address (contained in ABAR) to some memory which exists(in the 7th MB), but I get that all is zeroed,
Learn to debug?
Quote:
but when I read the page directory and I look for the page, which the virtual address is, it returns another address.
Learn to debug?

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: Changing AHCI Base BAR in PCI Configuration
PostPosted: Tue Jul 30, 2013 10:40 am 
Offline
Member
Member

Joined: Sun Oct 02, 2011 3:36 am
Posts: 25
Location: Spain
Combuster wrote:
Since you're hopelessly stuck trying to do advanced stuff while not even knowing the basics, a brief lesson:

Quote:
PD: If you knew the answer to the second question, could you tell it to me?
Learn to debug?
Quote:
I mapped the address (contained in ABAR) to some memory which exists(in the 7th MB), but I get that all is zeroed,
Learn to debug?
Quote:
but when I read the page directory and I look for the page, which the virtual address is, it returns another address.
Learn to debug?


Thank you, Combuster.
The real code has a lot of DEBUG functions. For example, when I call mmap in my kernel, it prints all parameters in the screen, the intermediate steps, and when it finishes it also gives me the page address, which is in the page table. This is the problem, the result and what I've written are not the same.
PS: I also use GDB.

EDIT: The mmap function works properly, but the AHCI HBA is still sending me no response. By using the VirtualBox Debbuger, I could see that the MMIO space of AHCI is filled with correct information, but I can't get it. Can somebody help me??

EDIT2: Finally, the AHCI response to the MMIO accesses, but the "Identify Device" command doesn't work at all.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], SanderR and 70 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