[SOLVED] GOP framebuffer outside of physical RAM

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
peachsmith
Member
Member
Posts: 44
Joined: Tue Aug 26, 2014 5:07 pm

[SOLVED] GOP framebuffer outside of physical RAM

Post by peachsmith »

I'm almost ready to set up my own paging structures in my 64-bit UEFI kernel, but something's bugging me.
The base address of the LFB appears to be outside of the RAM I've provided to qemu.

I passed the argument -m 512M when running the qemu-system-x86_64 command like so:

Code: Select all

qemu-system-x86_64 -serial stdio -L $(OVMF_DIR) -bios OVMF.fd -cdrom myos.iso -m 512M
So I would expect the limit of RAM to be something like 0x20000000, but my gop->Mode->FrameBufferBase appears to be 0x80000000.

Oddly enough, when I write to this location, pixels get plotted on the screen.

Since the FrameBufferBase field in the EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE struct is a EFI_PHYSICAL_ADDRESS, does that mean that the address could be completely outside of the memory given to qemu?

I feel like there's some super obvious rule in the spec I'm just completely overlooking, but I definitely need to understand this before I start assigning my own virtual addresses to things.
Last edited by peachsmith on Sun Jan 24, 2021 9:14 pm, edited 1 time in total.
Octocontrabass
Member
Member
Posts: 5568
Joined: Mon Mar 25, 2013 7:01 pm

Re: GOP framebuffer is apparently outside of physical RAM

Post by Octocontrabass »

The frame buffer is not RAM, it's MMIO. (Which is typically backed by RAM, but that's beside the point.)
User avatar
zaval
Member
Member
Posts: 656
Joined: Fri Feb 17, 2017 4:01 pm
Location: Ukraine, Bachmut
Contact:

Re: GOP framebuffer is apparently outside of physical RAM

Post by zaval »

and also, if you provided 512MB of RAM, it doesn't neccessarily mean, that RAM will be mapped at the System Address space range of 0 through 1F FF FF FF*. did you check the memory map?

as an example, Allwinner A20 (32 bit ARMv7) chip has SDRAM at 0x4000 0000 ... 0xBFFF FFFF.
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).
User avatar
peachsmith
Member
Member
Posts: 44
Joined: Tue Aug 26, 2014 5:07 pm

Re: GOP framebuffer is apparently outside of physical RAM

Post by peachsmith »

Octocontrabass wrote:The frame buffer is not RAM, it's MMIO.
Ah. So a physical address used for MMIO does not necessarily always map to a physical location in RAM at any given time and is therefore not restricted by the amount of RAM present in the system.
Good to know.

zaval wrote:did you check the memory map?
Yes indeed.

Just for completeness, here's my memory map:

Code: Select all

Type                 Address          Pages
 Boot Service Code    0000000000000000 1 
 Conventional         0000000000001000 159 
 Conventional         0000000000100000 1792 
 ACPI NVS             0000000000800000 8 
 Conventional         0000000000808000 8 
 ACPI NVS             0000000000810000 240 
 Boot Service Data    0000000000900000 3072 
 Conventional         0000000001500000 109110                                                                                        
 Boot Service Data    000000001BF36000 32                                                                                            
 Conventional         000000001BF56000 9422                                                                                          
 Loader Code          000000001E424000 20                                                                                            
 Conventional         000000001E438000 17                                                                                            
 Boot Service Data    000000001E449000 533                                                                                           
 Conventional         000000001E65E000 1                                                                                             
 Loader Data          000000001E65F000 2                                                                                             
 Boot Service Data    000000001E661000 6                                                                                             
 Conventional         000000001E667000 1                                                                                             
 Boot Service Data    000000001E668000 1210                                                                                          
 Boot Service Code    000000001EB22000 172                                                                                           
 Boot Service Data    000000001EBCE000 151                                                                                           
 Boot Service Code    000000001EC65000 62                                                                                            
 Boot Service Data    000000001ECA3000 4                                                                                             
 Boot Service Code    000000001ECA7000 63                                                                                            
 Boot Service Data    000000001ECE6000 5                                                                                             
 Boot Service Code    000000001ECEB000 34                                                                                            
 Boot Service Data    000000001ED0D000 1                                                                                             
 Boot Service Code    000000001ED0E000 30                                                                                            
 Boot Service Data    000000001ED2C000 11                                                                                            
 Boot Service Code    000000001ED37000 11                                                                                            
 Boot Service Data    000000001ED42000 5                                                                                             
 Boot Service Code    000000001ED47000 32                                                                                            
 Boot Service Data    000000001ED67000 4                                                                                             
 Boot Service Code    000000001ED6B000 48                                                                                            
 Boot Service Data    000000001ED9B000 8                                                                                             
 Boot Service Code    000000001EDA3000 13                                                                                            
 Boot Service Data    000000001EDB0000 2                                                                                             
 Boot Service Code    000000001EDB2000 46                                                                                            
 Boot Service Data    000000001EDE0000 5                                                                                             
 Boot Service Code    000000001EDE5000 27                                                                                            
 Boot Service Data    000000001EE00000 515                                                                                           
 Boot Service Code    000000001F003000 9                                                                                             
 Boot Service Data    000000001F00C000 5                                                                                             
 Boot Service Code    000000001F011000 42                                                                                            
 Boot Service Data    000000001F03B000 2                                                                                             
 Boot Service Code    000000001F03D000 45                                                                                            
 Boot Service Data    000000001F06A000 5                                                                                             
 Boot Service Code    000000001F06F000 18                                                                                            
 Boot Service Data    000000001F081000 4                                                                                             
 Boot Service Code    000000001F085000 7                                                                                             
 Boot Service Data    000000001F08C000 7                                                                                             
 Boot Service Code    000000001F093000 13                                                                                            
 Boot Service Data    000000001F0A0000 1                                                                                             
 Boot Service Code    000000001F0A1000 6 
 Boot Service Data    000000001F0A7000 4 
 Boot Service Code    000000001F0AB000 13 
 Boot Service Data    000000001F0B8000 3 
 Boot Service Code    000000001F0BB000 39 
 Boot Service Data    000000001F0E2000 5 
 Boot Service Code    000000001F0E7000 8 
 Boot Service Data    000000001F0EF000 1 
 Boot Service Code    000000001F0F0000 17 
 Boot Service Data    000000001F101000 4 
 Boot Service Code    000000001F105000 36 
 Boot Service Data    000000001F129000 7 
 Boot Service Code    000000001F130000 12 
 Boot Service Data    000000001F13C000 1 
 Boot Service Code    000000001F13D000 2 
 Boot Service Data    000000001F13F000 3 
 Boot Service Code    000000001F142000 8 
 Boot Service Data    000000001F14A000 3 
 Boot Service Code    000000001F14D000 5 
 Boot Service Data    000000001F152000 10 
 Boot Service Code    000000001F15C000 17 
 Boot Service Data    000000001F16D000 1 
 Boot Service Code    000000001F16E000 2 
 Boot Service Data    000000001F170000 2 
 Boot Service Code    000000001F172000 2 
 Boot Service Data    000000001F174000 4 
 Boot Service Code    000000001F178000 6 
 Boot Service Data    000000001F17E000 1024 
 Boot Service Code    000000001F57E000 6 
 Boot Service Data    000000001F584000 1 
 Boot Service Code    000000001F585000 9 
 Boot Service Data    000000001F58E000 3 
 Boot Service Code    000000001F591000 18 
 Boot Service Data    000000001F5A3000 844 
 Runtime Data         000000001F8EF000 256 
 Runtime Code         000000001F9EF000 256 
 Reserved             000000001FAEF000 128 
 ACPI Reclaim         000000001FB6F000 16 
 ACPI NVS             000000001FB7F000 128 
 Boot Service Data    000000001FBFF000 513 
 Conventional         000000001FE00000 132 
 Boot Service Data    000000001FE84000 32 
 Boot Service Code    000000001FEA4000 38 
 Boot Service Data    000000001FECA000 9 
 Boot Service Code    000000001FED3000 33 
 Runtime Data         000000001FEF4000 132 
 ACPI NVS             000000001FF78000 136
User avatar
zaval
Member
Member
Posts: 656
Joined: Fri Feb 17, 2017 4:01 pm
Location: Ukraine, Bachmut
Contact:

Re: GOP framebuffer is apparently outside of physical RAM

Post by zaval »

nice map btw, not as awfully fragmented as uboot's one. :mrgreen: then, in your case, framebuffer isn't (main) RAM at all, like octocontrabass pointed.
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).
User avatar
peachsmith
Member
Member
Posts: 44
Joined: Tue Aug 26, 2014 5:07 pm

Re: GOP framebuffer is apparently outside of physical RAM

Post by peachsmith »

zaval wrote:nice map btw
Ha, thanks. It comes courtesy of OVMF, I think.
linguofreak
Member
Member
Posts: 510
Joined: Wed Mar 09, 2011 3:55 am

Re: GOP framebuffer is apparently outside of physical RAM

Post by linguofreak »

peachsmith wrote:
Octocontrabass wrote:The frame buffer is not RAM, it's MMIO.
Ah. So a physical address used for MMIO does not necessarily always map to a physical location in RAM at any given time and is therefore not restricted by the amount of RAM present in the system.
Good to know.
None of the RAM that you put into a DIMM slot on physical hardware is, at least on most hardware, *ever* used for the framebuffer at *any* time. Your graphics controller has its own RAM that it uses to store the image to be displayed on screen (otherwise, it would have to contend with the CPU for bus cycles to read the framebuffer out of main RAM as it plotted pixels to the screen).

In general, MMIO looks to the CPU to be just like RAM, and for certain devices (such as a framebuffer), you may actually be reading/writing to RAM on the device, but the RAM you're writing to, once again, is not the RAM that's installed in the DIMM slots on your motherboard. And for other devices, a write to a certain address might just act as a command to the device, and reading from that address may not return the same data that you wrote. The read might just return zero, or random garbage, or might even be interpreted as a command by the device(!), or, depending on the platform and device, might do something nasty like raise a bus fault. I think I've even heard of architectures where attempting to read/write an address that neither RAM nor any device was listening on could lock up the bus.
thewrongchristian
Member
Member
Posts: 426
Joined: Tue Apr 03, 2018 2:44 am

Re: GOP framebuffer is apparently outside of physical RAM

Post by thewrongchristian »

linguofreak wrote:
None of the RAM that you put into a DIMM slot on physical hardware is, at least on most hardware, *ever* used for the framebuffer at *any* time. Your graphics controller has its own RAM that it uses to store the image to be displayed on screen (otherwise, it would have to contend with the CPU for bus cycles to read the framebuffer out of main RAM as it plotted pixels to the screen).
Any PC with integrated GFX (probably on the order of 90% of PCs sold) are exactly like that. The CPU relies on its caches to isolate it from slow memory access and contention with the GPU.

Luckily, GPU access will be burst mode accesses, transferring a large amount in a small time, which modern RAM is not too bad at doing.
User avatar
peachsmith
Member
Member
Posts: 44
Joined: Tue Aug 26, 2014 5:07 pm

Re: GOP framebuffer is apparently outside of physical RAM

Post by peachsmith »

linguofreak wrote:a write to a certain address might just act as a command to the device
Looks like I originally had a fundamental misunderstanding of what an "address" was.

I thought a physical address was a location in RAM and any MMIO was just using that location. But apparently an address is just a numerical abstraction over some arbitrary thing that can potentially contain a value.
User avatar
eekee
Member
Member
Posts: 891
Joined: Mon May 22, 2017 5:56 am
Location: Kerbin
Discord: eekee
Contact:

Re: GOP framebuffer is apparently outside of physical RAM

Post by eekee »

peachsmith wrote:I thought a physical address was a location in RAM and any MMIO was just using that location. But apparently an address is just a numerical abstraction over some arbitrary thing that can potentially contain a value.
Yup. I remember my surprise at the first memory map I saw; it was pretty-much the same realisation of a disconnect between address and memory. :) It was a 6502-powered machine with RAM from 0 to the 48K mark, ROM from 56K to 64K, and in between were these IO registers which were not memory in the same way. Eventually I got used to it, and then I thought other CPUs were strange with their extra instructions for i/o. ;)
Kaph — a modular OS intended to be easy and fun to administer and code for.
"May wisdom, fun, and the greater good shine forth in all your work." — Leo Brodie
Post Reply