ARM Linux driver : how to write to a physical address? - Embedded

This is a discussion on ARM Linux driver : how to write to a physical address? - Embedded ; 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 ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: ARM Linux driver : how to write to a physical address?

  1. 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?

  2. Re: ARM Linux driver : how to write to a physical address?

    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


  3. Re: ARM Linux driver : how to write to a physical address?

    On Sep 20, 4:26*pm, Juergen Beisert 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.

  4. Re: ARM Linux driver : how to write to a physical address?

    On Oct 5, 4:02*am, subhasish wrote:
    > On Sep 20, 4:26*pm, Juergen Beisert 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.

  5. Re: ARM Linux driver : how to write to a physical address?

    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

    Cheers,
    John McCallum
    Edinburgh

  6. Re: ARM Linux driver : how to write to a physical address?


    Uzytkownik "John McCallum" napisal w
    wiadomosci news: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




  7. Re: ARM Linux driver : how to write to a physical address?

    On Oct 12, 5:52*am, "Grzegorz Kania" wrote:
    > Uzytkownik "John McCallum" 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

+ Reply to Thread