Thread (6 messages) 6 messages, 4 authors, 2011-01-18

accessing the contents of video memory

From: Prabhu nath <hidden>
Date: 2011-01-18 06:40:30

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
ERR- INTx-
        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@<unassigned> [disabled]
        Capabilities: <access denied>
quoted
Here, focus on Region 2, which shows 256MB of Graphics card memory is
mapped
    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
memory.

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

Regards,
Prabhu




On Sun, Jan 16, 2011 at 12:25 AM, Elvis Y. Tamayo Moyares <
etmoyares@grm.uci.cu> 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 kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110118/6024878b/attachment-0001.html 
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help