From: "Antonino A. Daplas" <adaplas@hotpop.com>
To: linux-fbdev-devel@lists.sourceforge.net,
Shivappa Kushtagi <kushtagi@gmail.com>
Subject: Re: Re: Virtual framebuffer driver - mmap problem
Date: Thu, 9 Sep 2004 08:31:21 +0800 [thread overview]
Message-ID: <200409090831.21966.adaplas@hotpop.com> (raw)
In-Reply-To: <77e82a3f0409080651732d891e@mail.gmail.com>
On Wednesday 08 September 2004 21:51, Shivappa Kushtagi wrote:
> == You cannot mmap() the video memory of vfb.
>
> == Why don"t you use vesafb?
>
> As I had mentioned in my earlier post, I wanted to use virtual
> framebuffer to simulate the display of my target device (say some PDA
> with size 320*480 ). With vesafb, I will not be able to change the
> resolution ( fbset fails telling, invalid argument )
>
>
> Is there any other framebuffer based methods to simulate a display ?
>
There are 2 problems with vfb.c that makes mmap fail:
1. uses vmalloc to allocate framebuffer memory
2. has its own fb_mmap hook which always return -EINVAL
If you want to really use vfb.c, you can try to modify vfb.c so it behaves
like a normal, mmappable framebuffer.
A. First you need to change the framebuffer allocation method: Do not use
vmalloc, since it doesn't give you linear memory. Instead use
__get_free_pages.
videomemorysize = PAGE_SIZE << order;
So if PAGE_SIZE is 4096, to allocate 8192 bytes, use order = 1. Note that
there is an upper limit to order, so keep videomemorysize small.
videomemory = __get_free_pages(GFP_KERNEL, order)
B. Advertise the framebuffer to userspace:
In 2.6:
info->fix.smem_len = videomemorysize;
info->fix.smem_start = virt_to_phys(videomemory) & PAGE_MASK;
In 2.4, you can do the same, but do it in vfb_encode_fix().
C. Finally, create your own vfb_mmap() function. The important thing with
this version of mmap is the use of the VM_RESERVED flag when dealing with
system RAM. This flag is not necessary for actual framebuffers. You can
copy the fb_mmap function in fbmem.c and modify it for vfb. For 2.6, you
can use the example below.
Tony
static int vfb_mmap(struct fb_info *info, struct file *file,
struct vm_area_struct *vma)
{
unsigned long off;
#if !defined(__sparc__) || defined(__sparc_v9__)
unsigned long start;
u32 len;
#endif
if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
return -EINVAL;
off = vma->vm_pgoff << PAGE_SHIFT;
#if defined(__sparc__) && !defined(__sparc_v9__)
/* Should never get here, all fb drivers should have their own
mmap routines */
return -EINVAL;
#else
/* !sparc32... */
lock_kernel();
/* frame buffer memory */
start = info->fix.smem_start;
len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.smem_len);
if (off >= len) {
/* memory mapped io */
off -= len;
if (info->var.accel_flags) {
unlock_kernel();
return -EINVAL;
}
start = info->fix.mmio_start;
len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len);
}
unlock_kernel();
start &= PAGE_MASK;
if ((vma->vm_end - vma->vm_start + off) > len)
return -EINVAL;
off += start;
vma->vm_pgoff = off >> PAGE_SHIFT;
/* This is an IO map - tell maydump to skip this VMA */
vma->vm_flags |= VM_IO | VM_RESERVED;
#if defined(__sparc_v9__)
vma->vm_flags |= (VM_SHM | VM_LOCKED);
if (io_remap_page_range(vma, vma->vm_start, off,
vma->vm_end - vma->vm_start, vma->vm_page_prot, 0))
return -EAGAIN;
#else
#if defined(__mc68000__)
#if defined(CONFIG_SUN3)
pgprot_val(vma->vm_page_prot) |= SUN3_PAGE_NOCACHE;
#elif defined(CONFIG_MMU)
if (CPU_IS_020_OR_030)
pgprot_val(vma->vm_page_prot) |= _PAGE_NOCACHE030;
if (CPU_IS_040_OR_060) {
pgprot_val(vma->vm_page_prot) &= _CACHEMASK040;
/* Use no-cache mode, serialized */
pgprot_val(vma->vm_page_prot) |= _PAGE_NOCACHE_S;
}
#endif
#elif defined(__powerpc__)
pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE|_PAGE_GUARDED;
#elif defined(__alpha__)
/* Caching is off in the I/O space quadrant by design. */
#elif defined(__i386__) || defined(__x86_64__)
if (boot_cpu_data.x86 > 3)
pgprot_val(vma->vm_page_prot) |= _PAGE_PCD;
#elif defined(__mips__)
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
#elif defined(__hppa__)
pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE;
#elif defined(__ia64__) || defined(__arm__) || defined(__sh__)
vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
#else
#warning What do we have to do here??
#endif
if (io_remap_page_range(vma, vma->vm_start, off,
vma->vm_end - vma->vm_start, vma->vm_page_prot))
return -EAGAIN;
#endif /* !__sparc_v9__ */
return 0;
#endif /* !sparc32 */
}
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click
next prev parent reply other threads:[~2004-09-09 0:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-08 13:51 Virtual framebuffer driver - mmap problem Shivappa Kushtagi
2004-09-09 0:31 ` Antonino A. Daplas [this message]
2004-09-09 8:31 ` Geert Uytterhoeven
2004-09-09 10:16 ` Antonino A. Daplas
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=200409090831.21966.adaplas@hotpop.com \
--to=adaplas@hotpop.com \
--cc=kushtagi@gmail.com \
--cc=linux-fbdev-devel@lists.sourceforge.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.