LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Trouble in accessing device register using BAR (https://www.linuxquestions.org/questions/linux-general-1/trouble-in-accessing-device-register-using-bar-655639/)

gthakur 07-14-2008 07:41 AM

Trouble in accessing device register using BAR
 
Hi all,

I am writing a driver for linux in which I want to access a device register.This register is at offset 0x60 and is behind a IO BAR register.This BAR register is at offset 0x68 and present in PCI space.Therefore it can be accessed directly.After lot of searching I found that the device register which i want to access is present in IO space and can be accessed using inw() and outw().Register location in IO space can be calulated by

Contents of BAR register(having base address) + offset of device register

BIOS writes the base address into BAR from bits8 to bit31 after PCI device is discovered.My problem is do I have to shift bits8:31 7 places right and add the offset or should I keep the contents of BAR register as it is (except bits 0:7which are used for getting info abt whether device register is mapped into IO space or memory space and maksed to zero) and add it to offset of device regiser directly.Let me make myself clear from a little example
offset of device register = 0x60
contents of BAR(i.e. base address) = 0x00002401
last bit is one which indicates device register is mapped into IO space.

For calculating absolute address first I'll make all other bits zero except bits8:31.which makes content of BAR 0x00002400

Now here I am confused
address of device register in IO space = 0x00002400 + 0x60 = 0x00002460

OR

may be is calculated this way = 0x00000024 + 0x60 = 0x84

Which is the correct method?
Anybody can help me out of this confusion?

Is there any user space utility in linux with which I can read/write deice register in IO space.

resetreset 07-14-2008 12:32 PM

Quote:

Originally Posted by gthakur (Post 3213889)

Which is the correct method?
Anybody can help me out of this confusion?

Is there any user space utility in linux with which I can read/write deice register in IO space.



The only thing i can suggest is that you have to ask your BIOS manufacturer.

And as to the last question, *how* could that be possible, mister gthakur? :) Isnt Linux a protected mode OS? Although in the old days running "X" would lock the whole system as it probed ports, or *something* like that, although even then Linux was still a p-mode OS, running in pmode on an x86 CPU! (I still dont know what was going on).


All times are GMT -5. The time now is 01:09 PM.