linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* phys-to-virt kernel mapping and ioremap()
@ 2000-07-20 18:06 Timur Tabi
  2000-07-21 13:49 ` Jeff Garzik
  0 siblings, 1 reply; 6+ messages in thread
From: Timur Tabi @ 2000-07-20 18:06 UTC (permalink / raw)
  To: Linux MM mailing list, Linux Kernel Mailing list

I'm studying the code for __ioremap and I'm confused by something.

The phys_to_virt and virt_to_phys macros are very simple.  Basically, in kernel
space, the virtual address is an offset of the physical address, so it's very
simple.

__ioremap is supposed to take high PCI memory and map it to kernel space. 
However, __ioremap() calls get_vm_area() which then calls kmalloc(), which
allocates some memory from the heap.  Then remap_area_pages() is called, and
that uses the three-level page tables to map the memory allocated by kmalloc to
the PCI memory.

And that's where I'm confused.  Particularly:

1) Doesn't this mapping break the phys_to_virt and virt_to_phys macros?

2) kmalloc takes real physical memory from the kernel heap.  But then the
virtual addresses are remapped to other physical memory.  What happens to the
physical memory that kmalloc allocated?  Why isn't it freed?	


--
Timur Tabi - ttabi@interactivesi.com
Interactive Silicon - http://www.interactivesi.com

When replying to a mailing-list message, please don't cc: me, because then I'll just get two copies of the same message.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: phys-to-virt kernel mapping and ioremap()
  2000-07-20 18:06 phys-to-virt kernel mapping and ioremap() Timur Tabi
@ 2000-07-21 13:49 ` Jeff Garzik
  0 siblings, 0 replies; 6+ messages in thread
From: Jeff Garzik @ 2000-07-21 13:49 UTC (permalink / raw)
  To: Timur Tabi; +Cc: Linux MM mailing list, Linux Kernel Mailing list


On Thu, 20 Jul 2000, Timur Tabi wrote:

> I'm studying the code for __ioremap and I'm confused by something.
> 
> The phys_to_virt and virt_to_phys macros are very simple.  Basically, in kernel
> space, the virtual address is an offset of the physical address, so it's very
> simple.
> 
> __ioremap is supposed to take high PCI memory and map it to kernel space. 
> However, __ioremap() calls get_vm_area() which then calls kmalloc(), which
> allocates some memory from the heap.  Then remap_area_pages() is called, and
> that uses the three-level page tables to map the memory allocated by kmalloc to
> the PCI memory.
> 
> And that's where I'm confused.  Particularly:
> 
> 1) Doesn't this mapping break the phys_to_virt and virt_to_phys macros?
> 
> 2) kmalloc takes real physical memory from the kernel heap.  But then the
> virtual addresses are remapped to other physical memory.  What happens to the
> physical memory that kmalloc allocated?  Why isn't it freed?	

You are being confused by the allocation.  kmalloc only allocates a
vm_area_struct, which holds information about the new mapping.

	Jeff




--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: phys-to-virt kernel mapping and ioremap()
       [not found] ` <20000720183534Z156966-31297+1096@vger.rutgers.edu>
  2000-07-20 19:06   ` Jes Sorensen
@ 2000-07-20 19:12   ` Ivan Passos
  1 sibling, 0 replies; 6+ messages in thread
From: Ivan Passos @ 2000-07-20 19:12 UTC (permalink / raw)
  To: Linux Kernel Mailing list; +Cc: Linux MM mailing list

On Thu, 20 Jul 2000, Timur Tabi wrote:
> 
> > Timur> 1) Doesn't this mapping break the phys_to_virt and virt_to_phys
> > Timur> macros?
> > 
> > Those two macros are not defined on ioremap'ed regions so it is
> > irrelevant.
> 
> In that case, how do I do virt-to-phys and phys-to-virt translations on the
> memory addresses for ioremap'ed regions?

Why would you wanna do that for a PCI MMIO region??

1) ioremap(PCI_addr) returns a virtual address.
2) Use read[bwl], write[bwl], memcpy_toio, memcpy_fromio, memset_io ...
   with the obtained virtual address to access the MMIO region.

What else do you need?? Please let us know.

Regards,
Ivan

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: phys-to-virt kernel mapping and ioremap()
       [not found] ` <20000720183534Z156966-31297+1096@vger.rutgers.edu>
@ 2000-07-20 19:06   ` Jes Sorensen
  2000-07-20 19:12   ` Ivan Passos
  1 sibling, 0 replies; 6+ messages in thread
From: Jes Sorensen @ 2000-07-20 19:06 UTC (permalink / raw)
  To: Timur Tabi; +Cc: Linux MM mailing list, Linux Kernel Mailing list

>>>>> "Timur" == Timur Tabi <ttabi@interactivesi.com> writes:

Timur> ** Reply to message from Jes Sorensen <jes@linuxcare.com> on 20
Timur> Jul 2000 20:41:51 +0200


Timur> 1) Doesn't this mapping break the phys_to_virt and virt_to_phys
Timur> macros?
>>  Those two macros are not defined on ioremap'ed regions so it is
>> irrelevant.

Timur> In that case, how do I do virt-to-phys and phys-to-virt
Timur> translations on the memory addresses for ioremap'ed regions?

The answer is that you don't because you don't need to. You use
ioremap to mape it and you usae real/writel to access the space. You
are not allowed to treat PCI shared memory as regular memory.

Jes

PS: Please fix your mailer, it eats the References lines which is
really broken.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: phys-to-virt kernel mapping and ioremap()
  2000-07-20 18:41 ` Jes Sorensen
@ 2000-07-20 18:53   ` Timur Tabi
  0 siblings, 0 replies; 6+ messages in thread
From: Timur Tabi @ 2000-07-20 18:53 UTC (permalink / raw)
  To: Linux MM mailing list, Linux Kernel Mailing list

** Reply to message from Jes Sorensen <jes@linuxcare.com> on 20 Jul 2000
20:41:51 +0200


> Timur> 1) Doesn't this mapping break the phys_to_virt and virt_to_phys
> Timur> macros?
> 
> Those two macros are not defined on ioremap'ed regions so it is
> irrelevant.

In that case, how do I do virt-to-phys and phys-to-virt translations on the
memory addresses for ioremap'ed regions?



--
Timur Tabi - ttabi@interactivesi.com
Interactive Silicon - http://www.interactivesi.com

When replying to a mailing-list message, please don't cc: me, because then I'll just get two copies of the same message.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: phys-to-virt kernel mapping and ioremap()
       [not found] <20000720174852Z156962-31297+1037@vger.rutgers.edu>
@ 2000-07-20 18:41 ` Jes Sorensen
  2000-07-20 18:53   ` Timur Tabi
       [not found] ` <20000720183534Z156966-31297+1096@vger.rutgers.edu>
  1 sibling, 1 reply; 6+ messages in thread
From: Jes Sorensen @ 2000-07-20 18:41 UTC (permalink / raw)
  To: Timur Tabi; +Cc: Linux MM mailing list, Linux Kernel Mailing list

>>>>> "Timur" == Timur Tabi <ttabi@interactivesi.com> writes:

Timur> I'm studying the code for __ioremap and I'm confused by
Timur> something.  The phys_to_virt and virt_to_phys macros are very
Timur> simple.  Basically, in kernel space, the virtual address is an
Timur> offset of the physical address, so it's very simple.

You are making a bad assumption here, that PCI shared memory can be
treated as regular memory which it cannot.

Timur> 1) Doesn't this mapping break the phys_to_virt and virt_to_phys
Timur> macros?

Those two macros are not defined on ioremap'ed regions so it is
irrelevant.

Timur> 2) kmalloc takes real physical memory from the kernel heap.
Timur> But then the virtual addresses are remapped to other physical
Timur> memory.  What happens to the physical memory that kmalloc
Timur> allocated?  Why isn't it freed?

I asume it is used to generate page tables for the io memory it is
mapping, but I haven't looked at the code.

Jes
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2000-07-21 13:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-07-20 18:06 phys-to-virt kernel mapping and ioremap() Timur Tabi
2000-07-21 13:49 ` Jeff Garzik
     [not found] <20000720174852Z156962-31297+1037@vger.rutgers.edu>
2000-07-20 18:41 ` Jes Sorensen
2000-07-20 18:53   ` Timur Tabi
     [not found] ` <20000720183534Z156966-31297+1096@vger.rutgers.edu>
2000-07-20 19:06   ` Jes Sorensen
2000-07-20 19:12   ` Ivan Passos

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox