linux-newbie.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mirko Banchi <mk.banchi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: ratheesh kannoth <ratheesh.ksz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: linux-newbie
	<linux-newbie-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	linux-c-programming-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-modules-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: virtual -->physical --> virtual address
Date: Sat, 15 Oct 2011 19:57:35 +0200	[thread overview]
Message-ID: <891A5DF8-FC7F-4B14-9439-7123352847FB@gmail.com> (raw)
In-Reply-To: <CAGZFCEHW9Rpk8ZaFbaQPMeA_jOGFnFsnyqXg8QYJs+T+WpxpKw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Il giorno 15/ott/2011, alle ore 09.01, ratheesh kannoth ha scritto:

> {
> virtual_addr1 =  kmalloc(0x20, GFP_USER);
> phy_addr1 = __pa(virtual_addr1 );
> virtual_addr2 =  ioremap(phy_addr1, 0x20 );
> 
> }
> 
> 
> I noticed that virtual_addr1  is not equal to virtual_addr2.  And if i
> dereference virtual_addr2 ( *virtual_addr2 ),
> kernel crash. What is wrong here ?
> 

Obviously virtual_addr1 and virtual_addr2 are not equals! kmalloc returns a logical address (in fact you can simply calc the relative physical address with macro __pa) and ioremap returns a virtual address in the range [VMALLOC_START - VMALLOC_END]. However usually ioremap is used to deal with iomem and you shouldn't dereference the returned pointer directly: you should use instead ioread{8,16,32} or iowrite{8,16,32} family functions in order to make code portable. However i try to write a simple LKM with your code and i can dereference the pointer returned by ioremap correctly. Can you post some detailed code?

Mirko

- --
Mirko Banchi

e-mail:    mk.banchi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
id-jabber: mk.banchi-/eSpBmjxGS4dnm+yROfE0A@public.gmane.org

PGP key fingerprint:

308F BFB1 4E67 2522 C88E 
DC69 7631 52ED 32A5 6456



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)

iEYEARECAAYFAk6ZyZAACgkQdjFS7TKlZFaeIACfY5w9Z12jBkIUFvdreBPIQBcC
CasAn1cAjnoWc/743741GREIDOa6zj9I
=nkdk
-----END PGP SIGNATURE-----

      parent reply	other threads:[~2011-10-15 17:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-15  7:01 virtual -->physical --> virtual address ratheesh kannoth
     [not found] ` <CAGZFCEHW9Rpk8ZaFbaQPMeA_jOGFnFsnyqXg8QYJs+T+WpxpKw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-10-15 17:57   ` Mirko Banchi [this message]

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=891A5DF8-FC7F-4B14-9439-7123352847FB@gmail.com \
    --to=mk.banchi-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=linux-c-programming-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-modules-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-newbie-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=ratheesh.ksz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).