From: "swayampakulaa, sudhindra" <swayampakulaa_sudhindra@emc.com>
To: "'linux-kernel@vger.kernel.org'" <linux-kernel@vger.kernel.org>
Subject: mmap() driver entry point
Date: Tue, 8 Oct 2002 16:04:44 -0400 [thread overview]
Message-ID: <7FAAE4DE7248554ABD8C69DD4A18289B803064@srnamath> (raw)
> iam using this driver to fetch me some memory
> in my user space application by calling mmap with
> the file descriptor got by opening the device file
> for this driver.
> mmap(0, length, flags, flags, fd, offset)
> and the mmap entry point in the driver is implemented as below:
> In the implementation, it tries to write an index into the first
> four bytes, which i use to store in my internal structures
> ( to later reference it through the index),
> before zeroing out the buffer. But the index is always -1.
> I dont understand the part where its getting the
> physical address to map.
> whats the high_memory and whats the PAGE_OFFSET.
> Can someone help me in understanding what exactly
> is the mmap() entry point doing here and if its doing it right.
>
> himem_buf_allocated = 0;
>
> int xxx_mmap(struct file *filp,
> struct vm_area_struct *vma)
> {
> unsigned long size;
> char * virt_addr;
> int index;
>
> size = vma->vm_end - vma->vm_start;
> if ((size % PAGE_SIZE) != 0){
> size = (size / PAGE_SIZE) * PAGE_SIZE + PAGE_SIZE;
> }
>
> /* himem_buf_size is 0x80000000 */
> if (size + himem_buf_allocated >= himem_buf_size){
>
> return -ENOMEM;
> }
>
> /* himem_buf is calculated as high_memory - PAGE_OFFSET */
> umem_addr = himem_buf + himem_buf_allocated;
> if (umem_addr == 0){
> return -ENOMEM;
> }
> himem_buf_allocated += size;
>
>
> virt_addr = ioremap((unsigned long)umem_addr, PAGE_SIZE);
> if (virt_addr == 0){
> return -ENOMEM;
> }
> /* write the index into the first 4 bytes */
> writel(index, (uint32_t *)virt_addr);
>
> /* the values of index and *(virt_addr) do not match */
> /* *(virt_addr) is always -1 */
> /* Is something wrong here */
> dbg_printf(0,"index is %d, *(virt_addr) is %d\n", index,
> (int)readl(virt_addr));
> iounmap(virt_addr);
>
>
>
> remap_page_range(vma->vm_start, (ulong)umem_addr,
> vma->vm_end - vma->vm_start, vma->vm_page_prot);
>
> return 0;
>
next reply other threads:[~2002-10-08 20:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-08 20:04 swayampakulaa, sudhindra [this message]
-- strict thread matches above, loose matches on Subject: below --
2002-10-08 19:59 mmap " Ankit
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=7FAAE4DE7248554ABD8C69DD4A18289B803064@srnamath \
--to=swayampakulaa_sudhindra@emc.com \
--cc=linux-kernel@vger.kernel.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
all inboxes | Powered by JetHome®