accessing the contents of video memory

Prabhu nath gprabhunath at
Tue Jan 18 01:40:30 EST 2011

If you are working on a desktop machine, then the following idea works.
Usually, the VGA compatible controller memory will be mapped to the physical
address space which can be viewed with the help of "lspci -vv" command. Then
open the device file "/dev/mem" and mmap with the offset equal to the
physical address of the Graphics card. Here is a small snippet which works
on my machine

# lspci -vv | more /* Look for the section VGA compatible controller which
looks like below"

00:02.0 VGA compatible controller: Intel Corporation 82915G/GV/910GL
Integrated Graphics Controlle
r (rev 0e) (prog-if 00 [VGA controller])
        Subsystem: Hewlett-Packard Company Device 301d
        Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr-
Stepping- SERR- FastB2
B- DisINTx-
        Status: Cap+ 66MHz- UDF- FastB2B+ ParErr- DEVSEL=fast >TAbort-
<TAbort- <MAbort- >SERR- <P
        Latency: 0
        Interrupt: pin A routed to IRQ 11
        Region 0: Memory at fdf00000 (32-bit, non-prefetchable) [size=512K]
        Region 1: I/O ports at ff00 [size=8]
        *Region 2: Memory at d0000000 (32-bit, prefetchable) [size=256M]*
        Region 3: Memory at fdf80000 (32-bit, non-prefetchable) [size=256K]
        Expansion ROM at <unassigned> [disabled]
        Capabilities: <access denied>

>> Here, focus on Region 2, which shows 256MB of Graphics card memory is
    in the physical address space from 0xd0000000 to 0xe0000000.

Now open the device mem as
          fd = open = ("/dev/mem", O_RDWR)
and do an mmap as
          *vgamem *= mmap (NULL, 0x10000000, PROT_READ | PROT_WRITE,
                                     MAP_SHARED, fd, 0xd0000000)
0x10000000 = 256MB of graphics card memory
0xd0000000 = base of the physical address of graphics card memory

*vgamem *will be the user virtual address which is mapped to the physical
address of Graphics card memory.

To verify the mapping, write some bit patterns to 256MB of memory starting
from vgamem.
If you see distortion on your desktop, then you have written on to your
graphics card

Once you see see the distortion, move your mouse around so that graphics
memory is refreshed and your original screen contents are seen.


On Sun, Jan 16, 2011 at 12:25 AM, Elvis Y. Tamayo Moyares <
etmoyares at> wrote:

> Hello list. How I can access the video memory directly from user
> space? I tried to map the framebuffer (/dev/fb0) using mmap() and
> ioctl(), but I have not been successful. Really I want to make a copy
> of the contents of video memory and save it  as an image. have any
> suggestions?
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at
-------------- next part --------------
An HTML attachment was scrubbed...

More information about the Kernelnewbies mailing list