accessing the contents of video memory
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.
On Sun, Jan 16, 2011 at 01:55, 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?
Hi, probably not the brightest idea, but have check and try to read (carefully) these memory area, such as: $ cat /proc/iomem | grep -i video 000a0000-000bffff : Video RAM area 000c0000-000c7fff : Video ROM -- regards, Mulyadi Santosa Freelance Linux trainer and consultant blog: the-hydra.blogspot.com training: mulyaditraining.blogspot.com
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?
With modern cards, the video memory is a pretty large area. In order to find where the current screen actually resides, you will need to know more information like what is the driver used (Linux framebuffer? X? With what kind of card?) and probably dive into the driver code to understand where the current screen resides. In short, this is not impossible, but not simple neither. For many systems (e.g. X) there are also easier solutions for getting the contents of the current screen from user space (think of all these screenshot programs). Anyway some more information about your context would be helpful. Alex.
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 at <unassigned> [disabled] Capabilities: <access denied>
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@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
On Tue, Jan 18, 2011 at 3:40 PM, Prabhu nath <gprabhunath@gmail.com> wrote:
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 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.
Just gave it a shot, for the fun of it (program attached - needs root rights). Indeed after running it my screen was stripped with little black dots, as one could expect. However it also screwed my fonts and after a few seconds crashed my system. ;) Indeed, the video memory does not only contain the screen framebuffer, it also hosts other data related to 3d management, compositing, and probably data structures that X rely on. But at least this validates your approach to easily access video memory. Now all that is needed for Elvis to get the screen contents is to know the boundaries of the screen's buffer, as well as its format. Following your idea, he could probably access the memory-mapped registers of his video card, but this is highly vendor-dependant. Cannot think of a more generic way though. Alex.
Oops. Surprised to see it crashed :). Never I have seen a crash on my system. Regards, Prabhu On Tue, Jan 18, 2011 at 1:29 PM, Alexandre Courbot <gnurou@gmail.com> wrote:
On Tue, Jan 18, 2011 at 3:40 PM, Prabhu nath <gprabhunath@gmail.com> wrote:
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 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.
Just gave it a shot, for the fun of it (program attached - needs root rights). Indeed after running it my screen was stripped with little black dots, as one could expect. However it also screwed my fonts and after a few seconds crashed my system. ;) Indeed, the video memory does not only contain the screen framebuffer, it also hosts other data related to 3d management, compositing, and probably data structures that X rely on. But at least this validates your approach to easily access video memory.
Now all that is needed for Elvis to get the screen contents is to know the boundaries of the screen's buffer, as well as its format. Following your idea, he could probably access the memory-mapped registers of his video card, but this is highly vendor-dependant. Cannot think of a more generic way though.
Alex.
participants (4)
-
Alexandre Courbot -
Elvis Y. Tamayo Moyares -
Mulyadi Santosa -
Prabhu nath