Alexander Graf [Wed, 30 Sep 2020 21:10:53 +0000 (23:10 +0200)]
nvme: Record maximum allowed request size
NVMe has a limit on how many sectors it can handle at most within a single
request. Remember that number, so that in a follow-up patch, we can verify
that we don't exceed it.
usb/xhci: add support for mmio host adapters (via acpi).
Add xhci_controller_setup_acpi() function to initialize usb host
adapters declared in the DSDT table. Search the acpi devices list
for xhci controllers.
usb/xhci: split xhci setup into generic and pci parts
Split the pci-specific code into a separate xhci_controller_setup_pci()
function, turn xhci_controller_setup() to a generic xhci setup function
which only needs the mmio address if the control registers.
USB:Fix xHCI initail fail by using longer reset and CNR clear timeout value
Some xHCI controller's reset time than 100ms,such as 120ms.
On the on hand, xHCI spec has not specified a timeout value.
Maybe setting xHCI HCRST and CNR bit clear timeout value larger
is a nice thing.As a compromise between compatibility and
latency,we can take 1000ms as a timeout value.
Matt DeVillier [Fri, 11 Sep 2020 17:54:21 +0000 (12:54 -0500)]
usb.c: Fix devices using non-primary interface descriptor
A fair number of USB devices (keyboards in particular) use an
interface descriptor
other than the first available, making them non-functional currently.
To correct this, iterate through all available interface descriptors
until one with the correct class/subclass is found, then proceed to set the
configuration and setup the driver.
Tested on an ultimate hacking keyboard (UHK 60)
Signed-off-by: Matt DeVillier <matt.devillier@puri.sm>
smbios: avoid integer overflow when adding SMBIOS type 0 table
SeaBIOS implements the SMBIOS 2.1 entry point which is limited to a
maximum length of 0xffff. If the SMBIOS data received from QEMU is large
enough, then adding the type 0 table will cause integer overflow. This
results in fun behaviour such as KVM crash, or hangs in SeaBIOS.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Stefan Reiter [Mon, 27 Jul 2020 13:14:15 +0000 (15:14 +0200)]
virtio-scsi: fix boot prio detection by using correct lun
Commits
d6bdb85eb0 virtio-scsi: skip initializing non-bootable devices f82e82a5ab2 virtio-mmio: add support for scsi devices.
both use the lun value from tmpl_drv, which is always 0, instead of the
correct one passed as a separate parameter. This causes systems where
LUNs other than 0 are set as bootable, but 0 is not, to not boot.
Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de> Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
Kevin O'Connor [Wed, 22 Jul 2020 15:31:40 +0000 (11:31 -0400)]
ldnoexec: Add script to remove ET_EXEC flag from intermediate build objects
Add a script to remove the ET_EXEC flag from the 16bit and "32bit
segmented" intermediate objects. This avoids build failures with some
linkers that will not allow linking these objects again.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Roman Bolshakov [Fri, 26 Jun 2020 18:06:58 +0000 (21:06 +0300)]
timer: Handle decrements of PIT counter
There's a fallback to PIT if TSC is not present but it doesn't work
properly. It prevents boot from floppy on isapc and 486 cpu [1][2].
SeaBIOS configures PIT in Mode 2. PIT counter is decremented in the mode
but timer_adjust_bits() thinks that the counter overflows and increases
32-bit tick counter on each detected "overflow". Invalid overflow
detection results in 55ms time advance (1 / 18.2Hz) on each read from
PIT counter. So all timers expire much faster and 5-second floppy
timeout expires in 83 real microseconds (or just a bit longer).
It can be fixed by making the counter recieved from PIT an increasing
value so it can be passed to timer_adjust_bits():
0, 1, 2 and up to 65535 and then the counter is re-loaded with 0.
Fixes: eac11944019 ("Unify pmtimer_read() and pittimer_read() code.") Reported-by: Philippe Mathieu-Daudé <philmd@redhat.com> Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
Jason Andryuk [Wed, 24 Jun 2020 14:25:13 +0000 (10:25 -0400)]
serialio: Preserve Xen DebugOutputPort
xen_preinit() runs early and changes DebugOutputPort. qemu_preinit() runs
soon after. inb on DebugOutputPort doesn't work on Xen, so the check
will always fail and DebugOutputPort will be cleared to 0 disabling
output.
Quick exit the function when running on Xen to preserve the modified
DebugOutputPort.
Gerd Hoffmann [Mon, 25 May 2020 09:06:27 +0000 (11:06 +0200)]
pci: fix mmconfig support
The MODESEGMENT condition is backwards, with the effect that
mmconfig mode is not used to configure pci bars during POST.
Oops. Fix it.
The only real mode pci config space access seems to come from the
ipxe option rom initialiation. Which happens to work via mmconfig
because it runs in big real mode so this went unnoticed ...
Matt DeVillier [Sun, 24 May 2020 22:45:34 +0000 (17:45 -0500)]
boot: Fix logic for boot menu display
Commit c61193d3 [boot: Extend `etc/show-boot-menu`...] changed the
logic surrounding the use of show_boot_menu incorrectly, leading the
boot menu to be skipped by default with no way to override. Correct
the logic error so that show_boot_menu works as documented.
Test: build/boot SeaBIOS, verify boot menu option shown by default.
Signed-off-by: Matt DeVillier <matt.devillier@gmail.com>
Paul Menzel [Tue, 19 May 2020 21:39:42 +0000 (23:39 +0200)]
boot: Extend `etc/show-boot-menu` to configure skipping boot menu with only one device
Concerns were raised, that skipping the boot menu, if only one device is
present, might make debugging issues more difficult. So, extend the
current runtime configuration option `etc/show-boot-menu` to enable this
feature by setting it to 2.
Fixes: 29ee1fb8 ("Skip boot menu and timeout with only one boot device") Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
Gerd Hoffmann [Tue, 24 Mar 2020 11:13:32 +0000 (12:13 +0100)]
acpi: add dsdt parser
Create a list of devices found in the DSDT table. Add helper functions
to find devices, walk the list and figure device informations like mmio
ranges and irqs.
Gerd Hoffmann [Fri, 6 Mar 2020 18:44:47 +0000 (19:44 +0100)]
virtio-mmio: add support to vp_*() functions
Add support for virtio-mmio to the vp_*() helper functions.
Both legacy and 1.0 virto-mmio versions are supported. They
are very simliar anyway, only the virtqueue initialization
is slightly different.
Gerd Hoffmann [Fri, 6 Mar 2020 13:34:18 +0000 (14:34 +0100)]
virtio-mmio: device probing and initialization.
Add virtio_mmio_setup_one() to setup virtio mmio devices. Add
vp_init_mmio() to initialize device struct. Because virtio-pci and
virtio-mmio are quite simliar we reuse the infrastructure we already
have for virtio-pci and just setup struct vp_cap for virtio-mmio.
Gerd Hoffmann [Thu, 7 May 2020 11:53:26 +0000 (13:53 +0200)]
qemu: check rtc presence before reading cpu count from cmos
Read month register which should never have a value larger than 12.
In case the read returns 0xff assume the rtc isn't there.
Don't try to read the cpu count from cmos without rtc.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Gerd Hoffmann [Fri, 8 May 2020 10:22:53 +0000 (12:22 +0200)]
qemu: rework e820 detection
Read e820 table from fw_cfg early. This avoids reading the cmos for ram
detection on modern qemu. It also simplifies the ram detection logic.
We stop doing ram detecion in two steps, so we don't have to worry about
the second step overwriting the setup done by the first step.
Some hardened gcc v9 compilers (such as the one in Ubuntu)
default this option which for seabios leads to emulation errors
when running in KVM (does not trigger in TCG) on older intel
chips of the Penryn generation (~2006-2008).
Stefan Berger [Mon, 30 Mar 2020 11:55:55 +0000 (07:55 -0400)]
tcgbios: Only write logs for PCRs that are in active PCR banks
Only write the logs for those PCRs that are in active PCR banks.
A PCR banks is assumed to be active if any of the BIOS relevant
PCRs 0 - 7 is enabled, thus pcrSelect[0] != 0.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Gerd Hoffmann [Mon, 23 Mar 2020 14:59:11 +0000 (15:59 +0100)]
pci: add mmconfig support
Add support for pci config space access via mmconfig bar. Enable for
qemu q35 chipset. Main advantage is that we need only one instead of
two io operations per config space access, which translates to one
instead of two vmexits for virtualization.
Paul Menzel [Wed, 4 Mar 2020 13:51:27 +0000 (14:51 +0100)]
std/tcg: Replace zero-length array with flexible-array member
GCC 10 gives the warnings below:
In file included from out/ccode32flat.o.tmp.c:54:
./src/tcgbios.c: In function 'tpm20_write_EfiSpecIdEventStruct':
./src/tcgbios.c:290:30: warning: array subscript '(<unknown>) + 4294967295' is outside the bounds of an interior zero-length array 'struct TCG_EfiSpecIdEventAlgorithmSize[0]' [-Wzero-length-bounds]
290 | event.hdr.digestSizes[count].algorithmId = be16_to_cpu(sel->hashAlg);
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~
In file included from ./src/tcgbios.c:22,
from out/ccode32flat.o.tmp.c:54:
./src/std/tcg.h:527:7: note: while referencing 'digestSizes'
527 | } digestSizes[0];
| ^~~~~~~~~~~
In file included from out/ccode32flat.o.tmp.c:54:
./src/tcgbios.c:291:30: warning: array subscript '(<unknown>) + 4294967295' is outside the bounds of an interior zero-length array 'struct TCG_EfiSpecIdEventAlgorithmSize[0]' [-Wzero-length-bounds]
291 | event.hdr.digestSizes[count].digestSize = hsize;
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~
In file included from ./src/tcgbios.c:22,
from out/ccode32flat.o.tmp.c:54:
./src/std/tcg.h:527:7: note: while referencing 'digestSizes'
527 | } digestSizes[0];
| ^~~~~~~~~~~
[Description copied from Gustavo A. R. Silva <gustavo@embeddedor.com>
from his Linux kernel commits.]
The current codebase makes use of the zero-length array language
extension to the C90 standard, but the preferred mechanism to declare
variable-length types such as these ones is a flexible array
member [1][2], introduced in C99:
struct foo {
int stuff;
struct boo array[];
};
By making use of the mechanism above, we will get a compiler warning
in case the flexible array does not occur last in the structure, which
will help us prevent some kind of undefined behavior bugs from being
inadvertently introduced[3] to the codebase from now on.
Also, notice that, dynamic memory allocations won't be affected by
this change:
"Flexible array members have incomplete type, and so the sizeof operator
may not be applied. As a quirk of the original implementation of
zero-length arrays, sizeof evaluates to zero."[1]
Matt DeVillier [Fri, 12 Aug 2016 19:21:58 +0000 (14:21 -0500)]
ps2port: adjust init routine to fix PS/2 keyboard issues
PS/2 keyboards on Chromebooks with upstream coreboot + SeaBIOS often
fail to init properly / register keystrokes. Modify ps2port init
to match that of TianoCore, which doesn't have said issues.
Signed-off-by: Matt DeVillier <matt.devillier@gmail.com> Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
Message-Id: <248435f9-c169-e1db-fc3e-62185b74899c@molgen.mpg.de> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Gerd Hoffmann [Tue, 10 Mar 2020 10:22:45 +0000 (11:22 +0100)]
timer: add tsctimer_setfreq()
Add function to set tsc frequency directly, without calibration.
Also tweak timer setup functions a bit: skip setup in case TimerPort
has not the default value any more, i.e. another timer has been setup
already.
Matt DeVillier [Fri, 13 Dec 2019 03:51:19 +0000 (21:51 -0600)]
hw/usb-hid: Don't abort if setting key repeat rate fails
Since the USB stack doesn't handle stalled pipes,
don't abort keyboard setup if the set_idle command fails,
since it's a non-critical feature. Instead, log a warning.
Test: build/boot Google Pixel Slate, observe keyboard functional
Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de> Signed-off-by: Matt DeVillier <matt.devillier@gmail.com>
Kevin O'Connor [Fri, 6 Mar 2020 13:21:37 +0000 (08:21 -0500)]
usb-hid: Improve max packet size checking
Some USB keyboards report 9 or 10-byte max packet sizes instead of the
8-byte max specified by the USB HID spec. Increase the available size
and simplify the boundary checks.
Signed-off-by: Matt DeVillier <matt.devillier@gmail.com> Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Alexey Kirillov [Tue, 7 Jan 2020 17:19:17 +0000 (20:19 +0300)]
virtio: Do not init non-bootable devices
Because initializing a virtio-blk or virtio-scsi device requires a large
amount of memory, you cannot create more than about 10 virtio devices.
Since initialization is required for booting from media, we will not
initialize those devices that are not in the boot order list.
We use these values in get_translation() and setup_translation() by
introducing a new translation type: "TRANSLATION_HOST".
We treat this translation as TRANSLATION_NONE in fill_ata_edd(),
although this does not really matter since now the translation between
physical and logical geometry does not exist.
Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com> Reviewed-by: Arbel Moshe <arbel.moshe@oracle.com> Signed-off-by: Sam Eiderman <shmuel.eiderman@oracle.com>
Message-Id: <20190626123816.8907-6-shmuel.eiderman@oracle.com>
Sam Eiderman [Wed, 26 Jun 2019 12:38:12 +0000 (15:38 +0300)]
geometry: Read LCHS from fw_cfg
Read bios geometry for boot devices from fw_cfg.
By receiving LCHS values directly from QEMU through fw_cfg we will be
able to support logical geometries which can not be inferred by SeaBIOS
itself.
(For instance: A 8GB virtio-blk hard drive which was originally created
as an IDE and must report LCHS of */32/63 for its operating system to
function will always break under SeaBIOS since a LARGE/LBA translation
will be used, causing the number of reported logical heads to be > 32.)
The only LCHS paravirtual interface available at the moment is for IDE
disks (rtc_read() in get_translation()) and it's limited to a maximum
of 4 disks (this code existed in SeaBIOS's translation function before
SCSI and VirtIO were even introduced).
This is why we create a new interface which allows passing LCHS
information per hdd.
Boot device information is serialized in the following way:
* device_path lcyls lheads lsecs\n
...
* device_path lcyls lheads lsecs\0
Device path is a null terminated string in the "Open Firmware" device
path format, the same path as used in bootorder.
Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com> Reviewed-by: Arbel Moshe <arbel.moshe@oracle.com> Signed-off-by: Sam Eiderman <shmuel.eiderman@oracle.com>
Message-Id: <20190626123816.8907-2-shmuel.eiderman@oracle.com>
Stefan Berger [Wed, 6 Nov 2019 21:36:00 +0000 (16:36 -0500)]
tcgbios: Check for enough bytes returned from TPM2_GetCapability
When querying a TPM 2.0 for its PCRs, make sure that we get enough bytes
from it in a response that did not indicate a failure. Basically we are
defending against a TPM 2.0 sending responses that are not compliant to
the specs.
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Gerd Hoffmann [Wed, 13 Nov 2019 09:13:02 +0000 (10:13 +0100)]
ahci: zero-initialize port struct
Specifically port->drive.lchs needs clearing, otherwise seabios will
try interpret whatever random crap happens to be there as disk geometry,
which may or may not break boot depending on how lucky you are.
We use these values in get_translation() and setup_translation() by
introducing a new translation type: "TRANSLATION_MACHINE".
We treat this translation as TRANSLATION_NONE in fill_ata_edd(),
although this does not really matter since now the translation between
physical and logical geometry does not exist.
Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com> Reviewed-by: Arbel Moshe <arbel.moshe@oracle.com> Signed-off-by: Sam Eiderman <shmuel.eiderman@oracle.com>
Message-Id: <20190612093704.47175-6-shmuel.eiderman@oracle.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Sam Eiderman [Wed, 12 Jun 2019 09:37:03 +0000 (12:37 +0300)]
config: Add toggle for bootdevice information
Add the "BOOTDEVICES" toggle to remove boot device information received
through fw_cfg.
We will use this toggle in QEMU to reduce the size of the 128k SeaBIOS
rom, which is only used in old compat versions, where this boot device
information does not exist.
Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com> Reviewed-by: Arbel Moshe <arbel.moshe@oracle.com> Signed-off-by: Sam Eiderman <shmuel.eiderman@oracle.com>
Message-Id: <20190612093704.47175-5-shmuel.eiderman@oracle.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Sam Eiderman [Wed, 12 Jun 2019 09:37:01 +0000 (12:37 +0300)]
boot: Reorder functions in boot.c
Currently glob_prefix() and build_pci_path() are under the "Boot
priority ordering" section.
Move them to a new "Helper search functions" section since we will reuse
them in the next commit.
Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com> Reviewed-by: Arbel Moshe <arbel.moshe@oracle.com> Signed-off-by: Sam Eiderman <shmuel.eiderman@oracle.com>
Message-Id: <20190612093704.47175-3-shmuel.eiderman@oracle.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Sam Eiderman [Wed, 12 Jun 2019 09:37:00 +0000 (12:37 +0300)]
geometry: Read LCHS from fw_cfg
Read boot device information from fw_cfg.
Boot device information will contain logical geometry (LCHS) values,
but it is implemented in a manner which allows extension.
By receiving LCHS values directly from QEMU through fw_cfg we will be
able to support logical geometries which can not be inferred by SeaBIOS
itself.
(For instance: A 8GB virtio-blk hard drive which was originally created
as an IDE and must report LCHS of */32/63 for its operating system to
function will always break under SeaBIOS since a LARGE/LBA translation
will be used, causing the number of reported logical heads to be > 32.)
The only LCHS paravirtual interface available at the moment is for IDE
disks (rtc_read() in get_translation()) and it's limited to a maximum
of 4 disks (this code existed in SeaBIOS's translation function before
SCSI and VirtIO were even introduced).
This is why we create a new interface which allows passing LCHS
information per hdd. As mentioned, this interface may be easily extended
to support more information per hdd.
Boot device information is serialized in the following way:
* struct_size (u32)
* device path (sz string)
* device information (struct_size)
...
* device path (sz string)
* device information (struct_size)
Device path is a null terminated string in the "Open Firmware" device
path format, the same path as used in bootorder.
Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com> Reviewed-by: Arbel Moshe <arbel.moshe@oracle.com> Signed-off-by: Sam Eiderman <shmuel.eiderman@oracle.com>
Message-Id: <20190612093704.47175-2-shmuel.eiderman@oracle.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Uwe Kleine-König [Sun, 20 Oct 2019 20:07:26 +0000 (22:07 +0200)]
Remove dos line endings introduced in the last two commits
These were added somewhere between the mailing list server and Gerd's
working copy (as the patch I got via the mailing list is fine). These
don't disturb the compiler, but they look ugly so remove them.
Denis Plotnikov [Thu, 17 Oct 2019 14:01:00 +0000 (17:01 +0300)]
virtio: extend virtio queue size to 256
The goal of the patch is to work around a performance bug in guest
linux kernels.
Old linux kernels has a performance flaw in virtio block device access:
on some frequent disk access patterns, e.g. 1M read, the kernel produces
more block requests than needed. This happens because of virtio seg_max
parameter set to 126 (virtqueue_size - 2) which limits the maximum block
request to 516096 (126 * 4096_PAGE_SIZE) bytes.
Setting seg_max > 126 fixes the issue, however, not all linux kernels
allow that without increasing virtio virtqueue size. The old kernels have
a restriction: virtqueue_size >= seg_max. In case of the restriction
violation the old kernels crash.
The restriction is relaxed in the recent linux kernels (ver >= 4.13) with:
scsi: virtio: Reduce BUG if total_sg > virtqueue size to WARN.
and the recent linux kernels don't crash if total_sg > virtqueue size
allowing to set seg_max to the needed value without virtqueue size
increasing.
To fix the performance flaw in the old linux kernels, it's needed to
increse seg_max to 254, and comply the restriction by setting
virtqueue_size to 256.
This is achievable if seabios can support virtqueue size > 128
which this patch actually does.
Windows kernels don't have virtqueue_size >= seg_max restriction and
isn't affected with this kind of the performance bug.
Kevin O'Connor [Wed, 21 Aug 2019 13:18:25 +0000 (09:18 -0400)]
Makefile: Build with -Wno-address-of-packed-member
Building with gcc v9 causes lots of warnings about pointers to packed
variables. However, SeaBIOS is limited to x86 where unaligned
reads/writes are supported by the cpu. So, disable that warning.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
David Woodhouse [Fri, 28 Jun 2019 13:57:47 +0000 (14:57 +0100)]
csm: Fix boot priority translation
Explicitly handle the BBS_DO_NOT_BOOT_FROM and BBS_IGNORE_ENTRY values.
Also add one to the other priority values, as find_prio() does for
entries from bootorder. SeaBIOS uses zero for an item explicitly
selected in interactive_bootmenu().
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
David Woodhouse [Thu, 13 Jun 2019 15:25:13 +0000 (16:25 +0100)]
csm: Sanitise alignment constraint in Legacy16GetTableAddress
The alignment constraint is defined in the CSM specifications as
"Bit mapped. First non-zero bit from the right is the alignment."
Use __fls() to sanitise the alignment given that definition, since
passing a non-power-of-two alignment to _malloc() isn't going to work
well. And cope with being passed zero, which was happening for the
E820 table allocation from EDK2.
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Gerd Hoffmann [Tue, 20 Nov 2018 07:06:55 +0000 (08:06 +0100)]
optionrom: disallow int19 redirect for pnp roms.
Check whenever pnp roms attempt to redirect int19, and in case it does
log a message and undo the redirect.
A pnp rom should not need this, we have BEVs and BCVs for that.
Nevertheless there are roms in the wild which are redirecting int19.
At least some BIOS implementations for physical hardware have a config
option in the setup to allow/disallow int19 redirections, so just not
allowing this seems to be the way to deal with this situation.