Page 1 of 2

Get SATA AHCI BAR

Posted: Wed Apr 23, 2014 1:53 am
by nerdboy69
when i try teh following code at two of my PCs this works correctly:

Code: Select all

WORD GetBAR
{
...
...
...
__asm {
mov eax,addr
mov dx,0xcf8
OUT DX,EAX
mov dx,0xcfc
IN EAX,DX
MOV BAR,EAX
}
return BAR;
}
BAR = GetBAR(0,0x1f,2,0x10) & 0xfffe;
My problem is that when I try this PCI code to get BAR of HDC of other of my PCs BAR==0. Why don't work in one PC and at the two other the code above work?

Re: Get SATA AHCI BAR

Posted: Wed Apr 23, 2014 2:01 am
by iansjack
Where did your code come from? Did you write it yourself or is it just a random copy-and-paste?

Read: http://wiki.osdev.org/PCI#Configuration_Space

Re: Get SATA AHCI BAR

Posted: Wed Apr 23, 2014 2:04 am
by nerdboy69
iansjack wrote:Where did your code come from? Did you write it yourself or is it just a random copy-and-paste?

Read: http://wiki.osdev.org/PCI#Configuration_Space
of course that I write this code without copy anything. I only hide the first parts to someone

Re: Get SATA AHCI BAR

Posted: Wed Apr 23, 2014 2:06 am
by Combuster
You only posted a read-from-PCI function without defining proper arguments, typed it "WORD" (which implies 16 bits which is either a bug or really bad terminology, and also devitates from standards-prescribed stdint.h), and pass in some magic values which are most likely wrong because they are not the same on every computer.

Do proper PCI device detection, and please, make your code sane and legible.

Re: Get SATA AHCI BAR

Posted: Wed Apr 23, 2014 2:07 am
by iansjack
BAR = GetBAR(0,0x1f,2,0x10) & 0xfffe;
OK - explain the 5 magic numbers that you have used here. Where did they all come from?

Re: Get SATA AHCI BAR

Posted: Wed Apr 23, 2014 2:24 am
by nerdboy69
Combuster wrote:You only posted a read-from-PCI function without defining proper arguments, typed it "WORD" (which implies 16 bits which is either a bug or really bad terminology, and also devitates from standards-prescribed stdint.h), and pass in some magic values which are most likely wrong because they are not the same on every computer.

Do proper PCI device detection, and please, make your code sane and legible.
Combuster wrote:You only posted a read-from-PCI function without defining proper arguments, typed it "WORD" (which implies 16 bits which is either a bug or really bad terminology, and also devitates from standards-prescribed stdint.h), and pass in some magic values which are most likely wrong because they are not the same on every computer.

Do proper PCI device detection, and please, make your code sane and legible.
ok... here is the part missing:

Code: Select all

addr = (1L << 31) + ((DWORD) b << 16)+((DWORD)d << 11) + ((WORD)f <<8) + (reg & 0xfc);
Why my code don't work in all PCs???

Re: Get SATA AHCI BAR

Posted: Wed Apr 23, 2014 3:24 am
by Combuster
b, d, f, reg
Make your code sane and legible
Not fixed #1.
typed it "WORD" which implies 16 bits
Not fixed #2
Do proper PCI device detection
Not fixed #3
explain the 5 magic numbers
Not fixed #4.

Conclusion:
Lazy?

Re: Get SATA AHCI BAR

Posted: Wed Apr 23, 2014 4:02 am
by iansjack
Why my code don't work in all PCs???
Because your magic numbers aren't going to work in all PCs. Unfortunately you decline to tell us where the magic numbers come from.

If you understand enough about the PCI bus to write that code (which is a very dubious supposition) then you must know what is wrong with it.

Re: Get SATA AHCI BAR

Posted: Wed Apr 23, 2014 5:08 am
by nerdboy69
If you don't wants tio help me I've already DISCOVER anything wrong with my code. In the PC that the code don't works the bus = 0, device = 5, function = 0 but why the AHCI Controller is in other bus device and function in that PC???

Re: Get SATA AHCI BAR

Posted: Wed Apr 23, 2014 5:43 am
by iansjack
We are trying to help by leading you to the answer, which it appears has now happened. That way you might actually understand what you are doing rather than just blindly following what others tell you. Unfortunately you have demonstrated, in the process, that you don't really understand the PCI bus, how to enumerate it, or why you should want to. Read the Wiki link that I gave and you may then understand more about the code that you claim to have written.

There's nothing wrong with using other people's code, as long as you understand it, but there's little point in BSing here that you wrote it yourself when you clearly didn't. People aren't going to be fooled like that.

Re: Get SATA AHCI BAR

Posted: Wed Apr 23, 2014 7:07 am
by nerdboy69
iansjack wrote:We are trying to help by leading you to the answer, which it appears has now happened. That way you might actually understand what you are doing rather than just blindly following what others tell you. Unfortunately you have demonstrated, in the process, that you don't really understand the PCI bus, how to enumerate it, or why you should want to. Read the Wiki link that I gave and you may then understand more about the code that you claim to have written.

There's nothing wrong with using other people's code, as long as you understand it, but there's little point in BSing here that you wrote it yourself when you clearly didn't. People aren't going to be fooled like that.
Aaaaaarrrrggghhh! The only thinhg that I want know is:
WHAT IS THE BUS, DEVICE, FUNCTION OF A AHCI SATA CONTROLLER??????????

Re: Get SATA AHCI BAR

Posted: Wed Apr 23, 2014 7:21 am
by sortie
These are not constants. You iterate the PCI bus to find them.

Also, read the forum rules, behave yourself and try to spell check your posts.

Re: Get SATA AHCI BAR

Posted: Wed Apr 23, 2014 7:27 am
by nerdboy69
sortie wrote:These are not constants. You iterate the PCI bus to find them.

Also, read the forum rules, behave yourself and try to spell check your posts.
then please give me code example of how iterate PCI Bus to search AHCI SATA Controller!

Re: Get SATA AHCI BAR

Posted: Wed Apr 23, 2014 7:31 am
by sortie
Read the replies you already got! The first reply linked to the PCI tutorial that covers all this. See the section about recursive scans.

Re: Get SATA AHCI BAR

Posted: Wed Apr 23, 2014 8:40 am
by Bender
I'm sorry for asking an ignorant question, but does the same go for a IDE controller? For now I assumed it as port 0x1F0.