io_remap maps device registers to a virtual address. So, by definition, it is not backed by physical memory. So, __pa() shouldn't make sense, right? Besides, __pa() doesn't go through the page tables as Sebastian pointed out. All __pa() does is subtract PAGE_OFFSET from the address. Now, if you look at the code for __ioremap() which is called by ioremap(), it maps it to a virtual address that was unused. So, it *never* has a physical mapping anyways. Could you try one thing, just so that I'm sure this is correct... if you're on a standard 32 bit x86 box, could you check if the physical address you got was actually greater than the amount of RAM on your machine? Thanks Rahul On Wed, 2006-08-09 at 16:35 +0200, Sebastian Haas wrote: > I've just looked into the kernel sources and found that: > #define __pa(x) ((unsigned long)(x)-PAGE_OFFSET > #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET)) > > If you use ioremap to map PCI/ISA space, ioremap simply returns > __va(phys_addr), assuming phys_addr >= 0xA0000 && (phys_addr + size) < > 0x100000. And this is exactly the case if you map e.g. a ISA address. If > you use 0xD0000 you will get 0xC000D0000. And this is the same for PCI, see: > http://lxr.linux.no/source/arch/i386/mm/ioremap.c#L132 > > But I really wonder why you don't get the origin address. > > Yes, I know, we don't need to discuss about using or not using this > macros in drivers, but if I simply look at the code, I don't see any > reason why you don't get the original phys_addr? Am I wrong? > > Could you please post the code snippet and the address you use and get? > > From: Gregory CLEMENT > > So if you use it in driver you can't expect good result. Ioremap do > > more than a __va() on physicla address. You can't expect that > > __va(ioremap(x)) = x. > On a PCI/ISA I can expect: > __pa(ioremap(x)) = x > > Just for clearness: > __va is used by phys_to_virt > __pa is used by virt_to_phys > > Sebastian > > On 08/09/2006 03:07 PM, srinivas bakki wrote: > > > > > > On 8/9/06, *Sebastian Haas* <haas@xxxxxxxxxxxxxxxx > > <mailto:haas@xxxxxxxxxxxxxxxx>> wrote: > > > > On 08/08/2006 10:52 AM, srinivas bakki wrote: > > > hi, > > > i have this doubt regarding the addresses returned by > > > ioremap. > > > i mapped my devices's registers using ioremap. again when i try to > > > retrieve the physical address from the virtual address got from > > ioremap > > > using __pa(va) i see that the physical address is not the same > > which i > > > gave to ioremap function !! > > Which kind of device did you try to map? (ISA, PCI, ...) > > > > Sebastian > > > > > > -- > > Kernelnewbies: Help each other learn about the Linux kernel. > > Archive: http://mail.nl.linux.org/kernelnewbies/ > > FAQ: http://kernelnewbies.org/faq/ > > > > > > > > hi, > > Thanks for the reply . I mapped PCI device registers. i had mailed > > this query on arm mailing list as well and this is what i got as response. > > > > > >> hi, > > Hi, > >> i have a strange doubt regarding the addresses returned by > > ioremap. > >> i mapped my devices's registers using ioremap. again when i try to > > retrieve the physical address from the virtual address got from ioremap > > using __pa(va) i see that the physical address is not the same which i > > gave to ioremap function !! > >> > >> can anybody explain this please. > > > > __pa() use __virt_to_phys and with this function we ca read: > > * Physical vs virtual RAM address space conversion. These are > > * private definitions which should NOT be used outside memory.h > > * files. Use virt_to_phys/phys_to_virt/__pa/__va instead. > > and for virt_to_phys we can also read > > * These are *only* valid on the kernel direct mapped RAM memory. > > * Note: Drivers should NOT use these. They are the wrong > > * translation for translating DMA addresses. Use the driver > > * DMA support - see dma-mapping.h . > > > > So if you use it in driver you can't expect good result. Ioremap do > > more than a __va() on physicla address. You can't expect that > > __va(ioremap(x)) = x. > > > > -- > > Gregory CLEMENT > > Adeneo > > > > > > > > > > > > > -- > Kernelnewbies: Help each other learn about the Linux kernel. > Archive: http://mail.nl.linux.org/kernelnewbies/ > FAQ: http://kernelnewbies.org/faq/ > -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/