Get SATA AHCI BAR

Programming, for all ages and all languages.
nerdboy69
Posts: 17
Joined: Wed Apr 23, 2014 1:41 am

Get SATA AHCI BAR

Post 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?
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Get SATA AHCI BAR

Post 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
nerdboy69
Posts: 17
Joined: Wed Apr 23, 2014 1:41 am

Re: Get SATA AHCI BAR

Post 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
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Get SATA AHCI BAR

Post 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.
"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 ]
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Get SATA AHCI BAR

Post 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?
nerdboy69
Posts: 17
Joined: Wed Apr 23, 2014 1:41 am

Re: Get SATA AHCI BAR

Post 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???
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Get SATA AHCI BAR

Post 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?
"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 ]
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Get SATA AHCI BAR

Post 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.
nerdboy69
Posts: 17
Joined: Wed Apr 23, 2014 1:41 am

Re: Get SATA AHCI BAR

Post 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???
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Get SATA AHCI BAR

Post 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.
nerdboy69
Posts: 17
Joined: Wed Apr 23, 2014 1:41 am

Re: Get SATA AHCI BAR

Post 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??????????
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Get SATA AHCI BAR

Post 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.
nerdboy69
Posts: 17
Joined: Wed Apr 23, 2014 1:41 am

Re: Get SATA AHCI BAR

Post 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!
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Get SATA AHCI BAR

Post 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.
User avatar
Bender
Member
Member
Posts: 449
Joined: Wed Aug 21, 2013 3:53 am
Libera.chat IRC: bender|
Location: Asia, Singapore

Re: Get SATA AHCI BAR

Post 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.
"In a time of universal deceit - telling the truth is a revolutionary act." -- George Orwell
(R3X Runtime VM)(CHIP8 Interpreter OS)
Post Reply