| View previous topic :: View next topic |
| Author |
Message |
fred Guest
|
Posted: Fri Sep 19, 2008 11:24 pm Post subject: ARM Linux driver : how to write to a physical address? |
|
|
Hi All,
I'm writing a device driver for an ARM based board (Cirrus EP9302).
One of the functions of the driver is to be able to write values to
the address 0x23800000. How do you actually write to a physical
address
from within the kernel? |
|
| |
|
Back to top |
Juergen Beisert Guest
|
Posted: Sat Sep 20, 2008 4:26 pm Post subject: Re: ARM Linux driver : how to write to a physical address? |
|
|
fred wrote:
| Quote: | Hi All,
I'm writing a device driver for an ARM based board (Cirrus EP9302).
One of the functions of the driver is to be able to write values to
the address 0x23800000. How do you actually write to a physical
address
from within the kernel?
|
Did you check how the other device drivers do it? (BTW: The kernel is full
of examples).
jbe |
|
| |
|
Back to top |
subhasish Guest
|
Posted: Sun Oct 05, 2008 11:02 am Post subject: Re: ARM Linux driver : how to write to a physical address? |
|
|
On Sep 20, 4:26 pm, Juergen Beisert <jbeis...@netscape.net> wrote:
| Quote: | fred wrote:
Hi All,
I'm writing a device driver for an ARM based board (Cirrus EP9302).
One of the functions of the driver is to be able to write values to
the address 0x23800000. How do you actually write to a physical
address
from within the kernel?
Did you check how the other device drivers do it? (BTW: The kernel is full
of examples).
jbe
|
H!,
Just type cast the address to a variable and use it. Any thing that is
directly mapped to the processors address space can be accssed like
that. Also try __raw_read Api, should be available on ARM. |
|
| |
|
Back to top |
ramkey Guest
|
Posted: Tue Oct 07, 2008 11:39 pm Post subject: Re: ARM Linux driver : how to write to a physical address? |
|
|
On Oct 5, 4:02 am, subhasish <ghosh.subhas...@gmail.com> wrote:
| Quote: | On Sep 20, 4:26 pm, Juergen Beisert <jbeis...@netscape.net> wrote:
fred wrote:
Hi All,
I'm writing a device driver for an ARM based board (Cirrus EP9302).
One of the functions of the driver is to be able to write values to
the address 0x23800000. How do you actually write to a physical
address
from within the kernel?
Did you check how the other device drivers do it? (BTW: The kernel is full
of examples).
jbe
H!,
Just type cast the address to a variable and use it. Any thing that is
directly mapped to the processors address space can be accssed like
that. Also try __raw_read Api, should be available on ARM.
|
unsigned long *ptr = 0xphysicaladdr
*ptr = yourdata. |
|
| |
|
Back to top |
John McCallum Guest
|
Posted: Wed Oct 08, 2008 3:18 pm Post subject: Re: ARM Linux driver : how to write to a physical address? |
|
|
Hi,
ramkey wrote:
| Quote: | Just type cast the address to a variable and use it. Any thing that is
directly mapped to the processors address space can be accssed like
that. Also try __raw_read Api, should be available on ARM.
unsigned long *ptr = 0xphysicaladdr
*ptr = yourdata.
|
This would be wrong on other architectures (I am unfamiliar with ARM but I
believe most of them have an MMU and therefore it is wrong there too).
Normally you would need a phys_to_virt() to convert the physical address to
the virtual address used in the kernel process.
ie
unsigned long *ptr = phys_to_virt( 0xphysicaladdr );
*ptr = yourdata;
See
http://kerneltrap.org/man/linux/man9/phys_to_virt.9
Cheers,
John McCallum
Edinburgh |
|
| |
|
Back to top |
Grzegorz Kania Guest
|
Posted: Sun Oct 12, 2008 2:52 am Post subject: Re: ARM Linux driver : how to write to a physical address? |
|
|
Uzytkownik "John McCallum" <john.mccallum@skipthisemerson.com> napisal w
wiadomosci news:gci1ej$k03$1$8302bc10@news.demon.co.uk...
| Quote: | Hi,
ramkey wrote:
Just type cast the address to a variable and use it. Any thing that is
directly mapped to the processors address space can be accssed like
that. Also try __raw_read Api, should be available on ARM.
unsigned long *ptr = 0xphysicaladdr
*ptr = yourdata.
This would be wrong on other architectures (I am unfamiliar with ARM but I
believe most of them have an MMU and therefore it is wrong there too).
Normally you would need a phys_to_virt() to convert the physical address
to
the virtual address used in the kernel process.
ie
unsigned long *ptr = phys_to_virt( 0xphysicaladdr );
*ptr = yourdata;
See
http://kerneltrap.org/man/linux/man9/phys_to_virt.9
|
Please dont't forget about: volatile. Lot of time I spent, when I was trying
to understad WHY :)
volatile unsigned long *ptr = phys_to_virt( 0xphysicaladdr );
*ptr = yourdata;
Grzegorz Kania
Czerwionka, Poland |
|
| |
|
Back to top |
Marco Wang Guest
|
Posted: Thu Nov 06, 2008 9:29 am Post subject: Re: ARM Linux driver : how to write to a physical address? |
|
|
On Oct 12, 5:52 am, "Grzegorz Kania" <gka...@poczta.onet.pl> wrote:
| Quote: | Uzytkownik "John McCallum" <john.mccal...@skipthisemerson.com> napisal w
wiadomoscinews:gci1ej$k03$1$8302bc10@news.demon.co.uk...
Hi,
ramkey wrote:
Just type cast the address to a variable and use it. Any thing that is
directly mapped to the processors address space can be accssed like
that. Also try __raw_read Api, should be available on ARM.
unsigned long *ptr = 0xphysicaladdr
*ptr = yourdata.
This would be wrong on other architectures (I am unfamiliar with ARM but I
believe most of them have an MMU and therefore it is wrong there too).
Normally you would need a phys_to_virt() to convert the physical address
to
the virtual address used in the kernel process.
ie
unsigned long *ptr = phys_to_virt( 0xphysicaladdr );
*ptr = yourdata;
See
http://kerneltrap.org/man/linux/man9/phys_to_virt.9
Please dont't forget about: volatile. Lot of time I spent, when I was trying
to understad WHY :)
volatile unsigned long *ptr = phys_to_virt( 0xphysicaladdr );
*ptr = yourdata;
Grzegorz Kania
Czerwionka, Poland
|
phys_to_virt() only works with directly mapped physical address. I
don't think using phys_to_virt() is the best idea, anyway. Usually you
do this in several steps in a device driver:
1. Call request_mem_region() to request virtual memory region;
2. Call ioremap() to map physical address to virtual address;
3. Read/write mapped virtual address by using iowriteXX() /
ioreadXX(), etc. Here XX can be 8, 16, or 32 for example, represents
bit width.
4. Call iounmap() and release_mem_region() to release memory mapping;
Thanks,
Marco Wang |
|
| |
|
Back to top |
|