[SeaBIOS] [Qemu-devel] [PATCH] piix: do not reset APIC base address (0x80) on piix4_reset.

Kevin O'Connor kevin at koconnor.net
Thu Dec 19 19:17:17 CET 2013

On Thu, Dec 19, 2013 at 08:03:15PM +0200, Marcel Apfelbaum wrote:
> On Thu, 2013-12-19 at 11:06 -0500, Kevin O'Connor wrote:
> > On Wed, Dec 18, 2013 at 06:55:24PM +0200, Marcel Apfelbaum wrote:
> > > On Wed, 2013-12-18 at 11:34 -0500, Paolo Bonzini wrote:
> > > > Or put an array of (bdf, offset, size, value) tuples somewhere in low memory,
> > > > fill it at startup, and reproduce it blindly at S3 resume time.  This is similar
> > > > to what UEFI does.
> > > Could you please elaborate a little more?
> > > Let me see first if I understand the problem:
> > > PciDevices list is a list of pointers that cannot be used
> > > inside init code which is 16 bit code, right?
> > 
> > FYI, all the code at this point is 32bit code.  Both the SeaBIOS init
> > code (aka POST) and the SeaBIOS resume code run in 32bit mode.
> > 
> > The problem is that SeaBIOS has ownership of all ram during its
> > initialization phase, but it must release ownership during its runtime
> > phase.  (During the runtime phase, the OS has ownership of the bulk of
> > ram and SeaBIOS only has a tiny fraction that it reserves.)  The PCI
> > device cache that SeaBIOS builds is not placed in reserved memory, and
> > that's why it is marked as VARVERIFY32INIT.  It's to try and prevent
> > pointers that no longer point to valid memory from being accessed
> > after the init phase has completed.
> > 
> > The error it produces is correct - one must not access the pci_device
> > structs from the resume code in the current code.
> Thank you Kevin for the detailed explanation! By the way, do you know
> how this fraction is allocated by Seabios and how can one "decide" to move
> the device cache to this region reserved by the BIOS ? (not that I want to,
> but to understand how Seabios does this)

In pci.c:pci_probe_devices(), you'll see that it calls malloc_tmp() to
allocate the struct pci_device.  That allocation function takes memory
from ram that will eventually be given back to the OS.  To make it not
do that, one would need to choose one of the reserved zones (ie,
malloc_fseg, malloc_low, or malloc_high).  There is some freedom in
the choice of zones - malloc_fseg would probably be the simplest to

However, as you suspected, I don't think just allocating in a reserved
zone is the right thing to do.  Caching all the PCI devices after init
could lead to confusion as the devices cached may not be present later
on or have different parameters (eg, due to hotplug).


More information about the SeaBIOS mailing list