public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jes Sorensen <Jes.Sorensen@cern.ch>
To: Linux Lists <lists@cyclades.com>
Cc: Linux Kernel List <linux-kernel@vger.rutgers.edu>
Subject: Re: Access to I/O-mapped / Memory-mapped resources
Date: 11 Dec 1998 11:11:59 +0100	[thread overview]
Message-ID: <d3iufjyols.fsf@valhall.cern.ch> (raw)
In-Reply-To: Linux Lists's message of "Wed, 9 Dec 1998 15:19:10 -0800 (PST)"

>>>>> "Ivan" == Linux Lists <lists@cyclades.com> writes:

Ivan> Hi, there,

Ivan> I have a question: is there any reference in regards to how /
Ivan> when to use the virt_to_phys, virt_to_bus, ioremap,
Ivan> etc. ... functions, other than
Ivan> /usr/src/linux/Documentation/IO-mapping.txt ?!? I'd like to
Ivan> understand it better, but this text has not been enough (for me,
Ivan> of course).

It's really quite simple:

When you want to map shared memory provided by a device, in most cases
this will PCI shared memory, use ioremap() (or equivalent on other
archs) to map it into kernel shared memory. By doing this the kernel
can directly access this memory, though you really want to use the
read[bwl]()/write[bwl]() macros to access it to ensure portabillity of
your code (ie. Alphas with this wicked sparse memory).

Use virt_to_bus()/bus_to_virt() when you want to convert memory
addresses from/to kernel virtual address and the addresses as seen
from your bus(ses). Ie. on some machines, the physical memory layout
looks different from the CPU as it does from devices on the PCI (or
other) bus(ses). Thus you will normally use these functions to convert
addresses when filling ring descriptors for things like Ethernet
interfaces and other bus master devices (I just use network interfaces
as an example as this is what I hack the most).

virt_to_phys()/phys_to_virt() converts between kernel virtual and
physical addresses, the physical addresses as seen by the main system
that it. These functions are mainly used by the memory management
code. An example is conversion of virtual addresses to physical ones
on architectures that has the cache physically mapped and needs to do
deal with cache coherency in software and the cache management
functions requiring physical addresses (like the m68k).

Conclusion, for most driver related stuff you want to use
virt_to_bus()/bus_to_virt(). However you don't need to deal with any
of this when dealing with non bus mastering devices that only uses
traditional PC ISA I/O (all the inb()/outb() crap).

Jes

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

       reply	other threads:[~1998-12-11 23:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Pine.LNX.3.96.981209151147.10129A-100000@main.cyclades.com>
1998-12-11 10:11 ` Jes Sorensen [this message]
     [not found] <no.id>
1998-12-11 14:16 ` Access to I/O-mapped / Memory-mapped resources Jamie Lokier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d3iufjyols.fsf@valhall.cern.ch \
    --to=jes.sorensen@cern.ch \
    --cc=linux-kernel@vger.rutgers.edu \
    --cc=lists@cyclades.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox