]> xenbits.xensource.com Git - seabios.git/log
seabios.git
3 months agoFix AHCI Disk Detection when using EDK2 CSM master
Christopher Lentocha [Tue, 21 Jan 2025 16:59:14 +0000 (11:59 -0500)]
Fix AHCI Disk Detection when using EDK2 CSM

For whatever reason, when you compile SeaBIOS in Csm16 mode, and use it
under EDK2's OvmfPkg, the ATA_CMD_IDENTIFY_PACKET_DEVICE command
doesn't work properly, therefore, SeaBIOS detects the "SATA HARDDISK"
as a "SATA CDROM" device, in QEMU. Despite the Tianocore developers
seem to have removed support for Csm16 some time ago, if we decide to
remove Csm16 mode in SeaBIOS in favor of that, at least we have the
last commit of Csm16 working properly and not half-broken. In order to
fix this bug, I decided to add another command, that command being
ATA_CMD_DEVICE_RESET, right before the ATA_CMD_IDENTIFY_PACKET_DEVICE
command is called.

Signed-off-by: Christopher Lentocha <christopherericlentocha@gmail.com>
Message-ID: <eabe9bd2-a7c4-84dd-9a18-7e2e5e1f1247@gmail.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
3 months agoupdate pci_pad_mem64 handling
Gerd Hoffmann [Thu, 21 Nov 2024 15:35:41 +0000 (16:35 +0100)]
update pci_pad_mem64 handling

Add a new possible state: '-1' means 'use default'.  In that case
seabios continue to use the current heuristic:  In case memory
above 4G is present enable 64-bit guest friendly configuration.

This allows forcing the one or the other behavior by setting the
pci_pad_mem64 variable beforehand (which is done by another patch).

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
3 months agoadd romfile_loadbool()
Gerd Hoffmann [Fri, 22 Nov 2024 14:16:32 +0000 (15:16 +0100)]
add romfile_loadbool()

Translates strings in fw_cfg files into boolean values.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
3 months agodrop acpi tables and hex includes
Gerd Hoffmann [Wed, 20 Nov 2024 11:29:37 +0000 (12:29 +0100)]
drop acpi tables and hex includes

They are not used any more.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
3 months agodrop obsolete acpi table code
Gerd Hoffmann [Wed, 20 Nov 2024 11:42:13 +0000 (12:42 +0100)]
drop obsolete acpi table code

It's there for backward compatibility with qemu 1.6 and older.  This
release is older than a decade.  Even qemu itself has removed backward
compatibility support (i.e. machine types) for qemu versions that old.

It should be safe to remove this code now.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
3 months agousb-hid: Support multiple USB HID devices by storing them in a linked list
Daniel Khodabakhsh [Thu, 7 Nov 2024 18:34:47 +0000 (10:34 -0800)]
usb-hid: Support multiple USB HID devices by storing them in a linked list

Signed-off-by: Daniel Khodabakhsh <d.khodabakhsh@gmail.com>
4 months agoboot: Force display of the boot menu when boot-menu-wait is a negative number
Daniel Khodabakhsh [Fri, 8 Nov 2024 02:46:16 +0000 (18:46 -0800)]
boot: Force display of the boot menu when boot-menu-wait is a negative number

Signed-off-by: Daniel Khodabakhsh <d.khodabakhsh@gmail.com>
6 months agovgabios: Fix generating modes list for static_functionality
Steven Price [Sat, 12 Oct 2024 11:34:34 +0000 (11:34 +0000)]
vgabios: Fix generating modes list for static_functionality

Accessing the data in the vga_modes array requires using GET_GLOBAL(),
and the bits set in the bit array should correspond to the modes, not
the indexes in vga_modes.

With this change the modes calculated matches the expected value of
0xfe0ff.

Fixes: 12900b1a2431 ("vgabios: Fill in available legacy modes in video_func_static at runtime")
Signed-off-by: Steven Price <steven@ecrips.co.uk>
8 months agoesp-scsi: indicate acceptance of MESSAGE IN phase data
Mark Cave-Ayland [Thu, 29 Aug 2024 11:58:46 +0000 (12:58 +0100)]
esp-scsi: indicate acceptance of MESSAGE IN phase data

When the target has sent its MESSAGE IN phase data to the initiator, it waits
for the initiator to release the ACK signal before disconnecting from the bus.

Send a MSG_ACC command to the ESP so that the initiator releases the ACK signal
to allow the target to disconnect, and also return the ASC back to the
disconnected state.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Message-ID: <20240829115846.954993-1-mark.cave-ayland@ilande.co.uk>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
10 months agolimit address space used for pci devices, part two
Gerd Hoffmann [Mon, 24 Jun 2024 08:44:09 +0000 (10:44 +0200)]
limit address space used for pci devices, part two

This patch changes the logic added by commit a6ed6b701f0a ("limit
address space used for pci devices.") a bit.  Further testing showed
that the limit of 46 phys-bits applies to x86_64 kernels only, for i386
kernels the limit is 44.  So change the limit from 46 to 44 for better
compatibility with i386 guests.

Also add one more condition to refine the configuration heuristic:
Apply the limit only in case the guest has less than 1 TB of memory
installed, so huge guests run without address space limits.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
12 months agopciinit: don't misalign large BARs
Daniil Tatianin [Thu, 11 Apr 2024 19:51:35 +0000 (22:51 +0300)]
pciinit: don't misalign large BARs

Previously we would unconditionally lower the alignment for large BARs
in case their alignment was greater than "pci_mem64_top >> 11", this
would make it impossible to use these devices by the kernel:
    [   13.821108] pci 0000:9c:00.0: can't claim BAR 1 [mem 0x66000000000-0x67fffffffff 64bit pref]: no compatible bridge window
    [   13.823492] pci 0000:9d:00.0: can't claim BAR 1 [mem 0x64000000000-0x65fffffffff 64bit pref]: no compatible bridge window
    [   13.824218] pci 0000:9e:00.0: can't claim BAR 1 [mem 0x62000000000-0x63fffffffff 64bit pref]: no compatible bridge window
    [   13.828322] pci 0000:8a:00.0: can't claim BAR 1 [mem 0x6e000000000-0x6ffffffffff 64bit pref]: no compatible bridge window
    [   13.830691] pci 0000:8b:00.0: can't claim BAR 1 [mem 0x6c000000000-0x6dfffffffff 64bit pref]: no compatible bridge window
    [   13.832218] pci 0000:8c:00.0: can't claim BAR 1 [mem 0x6a000000000-0x6bfffffffff 64bit pref]: no compatible bridge window

Fix it by only overwriting the alignment in case it's actually greater
than the desired by the BAR window.

Fixes: 96a8d130a8c ("be less conservative with the 64bit pci io window")
Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
12 months agostdvgaio: Only read/write one color palette entry at a time
Kevin O'Connor [Mon, 1 Apr 2024 17:44:58 +0000 (13:44 -0400)]
stdvgaio: Only read/write one color palette entry at a time

Introduce stdvga_dac_read_many() and stdvga_dac_write_many() for
writing multiple dac palette entries.  Convert the stdvga_dac_read()
and stdvga_dac_write() low-level IO access functions in stdvgaio.c to
access just one color palette entry.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
13 months agostdvga: Add stdvga_set_vertical_size() helper function
Kevin O'Connor [Tue, 2 Apr 2024 17:07:58 +0000 (13:07 -0400)]
stdvga: Add stdvga_set_vertical_size() helper function

Add helper function and update the bochsvga.c code to use it.  This
emphasizes the relationship between stdvga_get_vertical_size() and
stdvga_set_vertical_size() code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
13 months agostdvga: Rename stdvga_get_vde() to stdvga_get_vertical_size()
Kevin O'Connor [Mon, 1 Apr 2024 15:27:57 +0000 (11:27 -0400)]
stdvga: Rename stdvga_get_vde() to stdvga_get_vertical_size()

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
13 months agostdvga: Rename stdvga_set_scan_lines() to stdvga_set_character_height()
Kevin O'Connor [Mon, 1 Apr 2024 15:08:14 +0000 (11:08 -0400)]
stdvga: Rename stdvga_set_scan_lines() to stdvga_set_character_height()

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
13 months agostdvga: Rename stdvga_set_text_block_specifier() to stdvga_set_font_location()
Kevin O'Connor [Mon, 1 Apr 2024 15:03:59 +0000 (11:03 -0400)]
stdvga: Rename stdvga_set_text_block_specifier() to stdvga_set_font_location()

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
13 months agostdvga: Rework stdvga palette index paging interface functions
Kevin O'Connor [Mon, 1 Apr 2024 02:59:06 +0000 (22:59 -0400)]
stdvga: Rework stdvga palette index paging interface functions

Rename the functions to make them a little easier to understand.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
13 months agostdvga: Rename stdvga_toggle_intensity() to stdvga_set_palette_blinking()
Kevin O'Connor [Mon, 1 Apr 2024 02:22:13 +0000 (22:22 -0400)]
stdvga: Rename stdvga_toggle_intensity() to stdvga_set_palette_blinking()

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
13 months agostdvga: Add comments to interface functions in stdvga.c
Kevin O'Connor [Mon, 1 Apr 2024 01:45:46 +0000 (21:45 -0400)]
stdvga: Add comments to interface functions in stdvga.c

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
13 months agostdvga: Rename CGA palette functions
Kevin O'Connor [Mon, 1 Apr 2024 01:58:12 +0000 (21:58 -0400)]
stdvga: Rename CGA palette functions

Rename stdvga_set_border_color() to stdvga_set_cga_background_color()
and stdvga_set_palette() to stdvga_set_cga_palette().  These functions
implement compatibility for old CGA cards - rename them so they are
not confused with the functions that manipulte the VGA palette.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
13 months agostdvgamodes: Improve naming of dac palette tables
Kevin O'Connor [Mon, 1 Apr 2024 01:42:27 +0000 (21:42 -0400)]
stdvgamodes: Improve naming of dac palette tables

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
13 months agostdvgamodes: No need to store pelmask in vga_modes[]
Kevin O'Connor [Mon, 1 Apr 2024 01:33:59 +0000 (21:33 -0400)]
stdvgamodes: No need to store pelmask in vga_modes[]

The pelmask is always 0xff so no need to store in a static table.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
13 months agovgasrc: Rename vgahw_get_linesize() to vgahw_minimum_linelength()
Kevin O'Connor [Fri, 15 Mar 2024 23:50:29 +0000 (19:50 -0400)]
vgasrc: Rename vgahw_get_linesize() to vgahw_minimum_linelength()

Make the relationship between vgahw_get_linelength() and
vgahw_get_linesize() more clear by renaming it to
vgahw_minimum_linelength().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
13 months agovgasrc: Use curmode_g instead of vmode_g when mode is the current video mode
Kevin O'Connor [Fri, 15 Mar 2024 14:58:57 +0000 (10:58 -0400)]
vgasrc: Use curmode_g instead of vmode_g when mode is the current video mode

Many functions are passed a pointer to the current video mode
vgamode_s struct.  Use the name 'curmode_g' for these functions and
use 'vmode_g' for functions that can accept an arbitrary video mode.
Hopefully this will make the goals of the functions more clear.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
13 months agovbe: implement function 09h (get/set palette data)
Daniel Verkamp [Tue, 12 Mar 2024 03:26:18 +0000 (20:26 -0700)]
vbe: implement function 09h (get/set palette data)

Since the VBE mode attributes indicate that all modes are not VGA
compatible, applications must use VBE function 09h to manipulate the
palette rather than directly accessing the VGA registers.

This implementation uses the standard VGA registers for all hardware,
which may not be appropriate; I only verified qemu -device VGA.

Without this patch, the get/set palette function returns an error code,
so programs that use 8-bit indexed color modes fail. For example, Quake
(DOS) printed "Error: Unable to load VESA palette" and exited when
trying to set a SVGA mode like 640x480, but with the patch it succeeds.
This fixes qemu issue #251 and #1862.

<https://gitlab.com/qemu-project/qemu/-/issues/251>
<https://gitlab.com/qemu-project/qemu/-/issues/1862>

Signed-off-by: Daniel Verkamp <daniel@drv.nu>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
13 months agovgasrc: round up save/restore size
Daniel Verkamp [Tue, 12 Mar 2024 00:56:40 +0000 (17:56 -0700)]
vgasrc: round up save/restore size

When calculating the size of the buffer required for the VGA/VBE state,
round up rather than truncating when dividing the number of bytes to get
the number of 64-byte blocks. Without this modification, the save state
function will write past the end of a buffer of the size requested.

Signed-off-by: Daniel Verkamp <daniel@drv.nu>
13 months agovbe: Add VBE 2.0+ OemData field to struct vbe_info
Daniel Verkamp [Thu, 7 Mar 2024 09:08:27 +0000 (01:08 -0800)]
vbe: Add VBE 2.0+ OemData field to struct vbe_info

Per the VBE 2.0 specification, the VBE controller information is 512
bytes long when the "VBE2" signature is provided, instead of the
original 256 bytes.

src/bootsplash.c uses the original pre-VBE-2.0 256-byte structure while
also filling in the "VBE2" signature, so a video BIOS that makes use of
the VBE2 OemData area could write past the end of the allocated region.

The original bootsplash code did not have this bug; it was introduced
when the bootsplash VBE structures were merged with the VGA ROM struct
definitions.

Fixes: 69e941c159ed ("Merge bootsplash and VGA ROM vbe structure definitions")
Signed-off-by: Daniel Verkamp <daniel@drv.nu>
14 months agofix smbios blob length overflow
Igor Mammedov [Fri, 23 Feb 2024 15:05:22 +0000 (16:05 +0100)]
fix smbios blob length overflow

When tables are more than 64K, size of copied tables will be
truncated due to cast from u32 to u16, and as result only
a small portion of the tables will be copied in the end.
That leads to corrupted tables (a part from QEMU and
remainder is whatever was in memory block allocated for
the tables).

Fix it by making qtables_len 32bit int.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
15 months agoAdd LBA 64bit support for reads beyond 2TB.
Max Tottenham [Thu, 25 Jan 2024 15:00:50 +0000 (10:00 -0500)]
Add LBA 64bit support for reads beyond 2TB.

When booting from a >2TB drive/filesystem, it's possible what the
kernel/bootloader may be updated and written out at an LBA address
beyond what is normally accessible by the READ(10) SCSI commands.
If this happens to the kernel grub will fail to boot the kernel
as it will call into the BIOS with an LBA address >2TB, and the
BIOS will return an error. Per the SCSI spec, >2TB drives should
return 0XFFFFFFFF, and a READ CAPACITY(16) command should be issued
to determine the full size of the drive, READ(16) commands can then
be used in order to read data at LBA addresses beyond 2TB (64 bit
LBA addresses)

Signed-off-by: Max Tottenham <mtottenh@akamai.com>
Message-ID: <20240125150050.3775834-2-mtottenh@akamai.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
15 months agoAdd AHCI Power ON + ICC_ACTIVE into port setup code
Andrej Kruták [Tue, 9 Jan 2024 15:34:23 +0000 (16:34 +0100)]
Add AHCI Power ON + ICC_ACTIVE into port setup code

Windows appears to put the AHCI port into 'Partial power management state'
during reboot, the command puts it back into 'active state'.

AHCI/1: link down 0x00000231 (SCR STAT register)
 ->
AHCI/1: link up 0x00000133

Signed-off-by: Andrej Krutak andrej.krutak@sysgo.com
Message-ID: <1531455205.6484.1704814463638@ox.sysgo.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
15 months agoesp-scsi: terminate DMA transfer when ESP data transfer completes
Mark Cave-Ayland [Mon, 1 Jan 2024 12:19:42 +0000 (12:19 +0000)]
esp-scsi: terminate DMA transfer when ESP data transfer completes

When the ESP data transfer completes indicated by the STAT_TC flag being set,
terminate the DMA transfer by issuing a DMA IDLE command. Otherwise in the case
where the guest sends a reset followed by an ESP command, the DMA signal remains
enabled and so the next SeaBIOS DMA transfer begins immediately when the next
ESP command is received rather than waiting until the data is ready and the DMA
command is issued.

With this fix it is possible to boot a Windows XP ISO to the installer and
complete a full installation within QEMU directly using SeaBIOS.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Message-ID: <20240101121942.383191-1-mark.cave-ayland@ilande.co.uk>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
17 months agolimit address space used for pci devices. rel-1.16.3
Gerd Hoffmann [Tue, 7 Nov 2023 12:49:31 +0000 (13:49 +0100)]
limit address space used for pci devices.

For better compatibility with old linux kernels,
see source code comment.

Also rename some variables to make the code more
readable, following suggestions by Kevin.

Related (same problem in ovmf):
https://github.com/tianocore/edk2/commit/c1e853769046

Cc: Kevin O'Connor <kevin@koconnor.net>
Reported-by: Claudio Fontana <cfontana@suse.de>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
20 months agocheck for e820 conflict
Gerd Hoffmann [Fri, 21 Apr 2023 10:42:51 +0000 (12:42 +0200)]
check for e820 conflict

Add support to check for overlaps with e820 entries.
In case the 64bit pci io window has conflicts move it down.

The only known case where this happens is AMD processors
with 1TB address space which has some space just below
1TB reserved for HT.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
20 months agoqemu: log reservations in fw_cfg e820 table
Gerd Hoffmann [Fri, 21 Apr 2023 10:45:04 +0000 (12:45 +0200)]
qemu: log reservations in fw_cfg e820 table

With loglevel 1 (same we use for RAM entries),
so it is included in the firmware log by default.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
20 months agobe less conservative with the 64bit pci io window
Gerd Hoffmann [Fri, 9 Sep 2022 08:17:15 +0000 (10:17 +0200)]
be less conservative with the 64bit pci io window

Current seabios code will only enable and use the 64bit pci io window in
case it runs out of space in the 32bit pci mmio window below 4G.

This patch will also enable the 64bit pci io window when
  (a) RAM above 4G is present, and
  (b) the physical address space size is known, and
  (c) seabios is running on a 64bit capable processor.

This operates with the assumption that guests which are ok with memory
above 4G most likely can handle mmio above 4G too.

In case the 64bit pci io window is enabled also assign more memory to
prefetchable pci bridge windows and the complete 64bit pci io window.

The total mmio window size is 1/8 of the physical address space.
Minimum bridge windows size is 1/256 of the total mmio window size.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
20 months agomove 64bit pci window to end of address space
Gerd Hoffmann [Fri, 9 Sep 2022 08:16:31 +0000 (10:16 +0200)]
move 64bit pci window to end of address space

When the size of the physical address space is known (PhysBits is not
zero) move the 64bit pci io window to the end of the address space.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
20 months agodetect physical address space size
Gerd Hoffmann [Wed, 31 Aug 2022 06:27:33 +0000 (08:27 +0200)]
detect physical address space size

Check for pae and long mode using cpuid.  If present also read the
physical address bits.  Apply some qemu sanity checks (see below).
Record results in PhysBits and LongMode variables.  In case we are not
sure what the address space size is leave the PhysBits variable unset.

On qemu we have the problem that for historical reasons x86_64
processors advertise 40 physical address space bits by default, even in
case the host supports less than that so actually using the whole
address space will not work.

Because of that the code applies some extra sanity checks in case we
find 40 (or less) physical address space bits advertised.  Only
known-good values (which is 40 for amd processors and 36+39 for intel
processors) will be accepted as valid.

Recommendation is to use 'qemu -cpu ${name},host-phys-bits=on' to
advertise valid physical address space bits to the guest.  Some distro
builds enable this by default, and most likely the qemu default will
change in near future too.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
20 months agobetter kvm detection
Gerd Hoffmann [Fri, 9 Sep 2022 05:45:13 +0000 (07:45 +0200)]
better kvm detection

In case kvm emulates features of another hypervisor (for example hyperv)
two VMM CPUID blocks will be present, one for the emulated hypervisor
and one for kvm itself.

This patch makes seabios loop over the VMM CPUID blocks to make sure it
will properly detect kvm when multiple blocks are present.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
20 months agoesp-scsi: handle non-DMA SCSI commands with no data phase
Mark Cave-Ayland [Mon, 7 Aug 2023 06:53:00 +0000 (07:53 +0100)]
esp-scsi: handle non-DMA SCSI commands with no data phase

The existing esp-scsi state machine checks for the STAT_TC bit to exit state 1
but in the case where there is no data phase, a non-DMA command is executed
which doesn't set STAT_TC. This only works because QEMU currently always sets
STAT_TC just after issuing every SCSI command.

Update the esp-scsi state machine so that in the case where there is no data
phase, we immediately execute CMD_ICCS instead of waiting for STAT_TC to be
set which will never happen with a non-DMA CMD_SELATN command.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Message-ID: <20230807065300.366070-4-mark.cave-ayland@ilande.co.uk>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
20 months agoesp-scsi: check for INTR_BS/INTR_FC instead of STAT_TC for command completion
Mark Cave-Ayland [Mon, 7 Aug 2023 06:52:59 +0000 (07:52 +0100)]
esp-scsi: check for INTR_BS/INTR_FC instead of STAT_TC for command completion

The ESP SELATN command used to send SCSI commands from the ESP to the SCSI bus
is not a DMA command and therefore does not affect the STAT_TC bit. The only
reason this works at all is due to a bug in QEMU which (currently) always
updates the STAT_TC bit in ESP_RSTAT regardless of the state of the ESP_CMD_DMA
bit.

According to the NCR datasheet [1] the INTR_BS/INTR_FC bits are set when the
SELATN command has completed, so update the existing logic to check for these
bits in ESP_RINTR instead. Note that the read of ESP_RINTR needs to be
restricted to state == 0 as reading ESP_RINTR resets the ESP_RSTAT register
which breaks the STAT_TC check when state == 1.

This commit also includes an extra read of ESP_INTR to clear all the interrupt
bits before submitting the SELATN command to ensure that we don't accidentally
immediately progress to the data phase handling logic where ESP_RINTR bits have
already been set by a previous ESP command.

[1] "NCR 53C94, 53C95, 53C96 Advanced SCSI Controller"
    NCR_53C94_53C95_53C96_Data_Sheet_Feb90.pdf

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-ID: <20230807065300.366070-3-mark.cave-ayland@ilande.co.uk>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
20 months agoesp-scsi: flush FIFO before sending SCSI command
Mark Cave-Ayland [Mon, 7 Aug 2023 06:52:58 +0000 (07:52 +0100)]
esp-scsi: flush FIFO before sending SCSI command

The ESP FIFO is used as a buffer for DMA requests and so isn't guaranteed to
be empty in the case of SCSI errors or a mixed DMA/non-DMA request. Flush the
FIFO before sending a SCSI command to guarantee that it is correctly
positioned at the start of the FIFO.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20230807065300.366070-2-mark.cave-ayland@ilande.co.uk>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
20 months agoIncrease BUILD_MAX_E820 to 128
Tony Titus via SeaBIOS [Fri, 28 Jul 2023 04:41:48 +0000 (04:41 +0000)]
Increase BUILD_MAX_E820 to 128

For platforms with high number of numa nodes, 32 e820 entries are not
enough. Linux kernel sets the maximum e820 entries to a base value of
128. Setting BUILD_MAX_E820 to 128 to be in sync with this base value.

Signed-off-by: Tony Titus <tonydt@amazon.com>
Message-ID: <20230728044148.58041-1-tonydt@amazon.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
22 months agoahci: handle TFES irq correctly
Niklas Cassel via SeaBIOS [Tue, 30 May 2023 13:44:05 +0000 (15:44 +0200)]
ahci: handle TFES irq correctly

According to AHCI 1.3.1, 5.3.8.1 RegFIS:Entry, if ERR_STAT is set in the
received FIS, the HBA shall jump to state ERR:FatalTaskfile, which will
raise a TFES IRQ.

This means that if ERR_STAT is set in the recevied FIS, PxIS.TFES will
be set, without either PxIS.DHRS or PxIS.PSS being set.

SeaBIOS function ahci_port_setup() will try to identify an AHCI device
by sending an ATAPI identify device command. However, such a command
will be aborted with ERR_STAT set for a regular (non-ATAPI) device.

ahci_command() already performs the correct error recovery steps when
status is correctly set, so simply modify ahci_command() to read the
correct status when PxIS.TFES is set.

It is safe to read PxTFD when PxIS.TFES is set, even for systems with a
port multiplier, see AHCI 1.3.1, 9.3.7 PxTFD Register Information:
"When a taskfile error occurs (PxIS.TFES is set to '1'), the host may
refer to the values in PxTFD. The values in PxTFD at this time are
guaranteed to correspond to the device that reported the taskfile error
condition."

Without this, each boot will be delayed by 32 seconds, waiting for the
AHCI command to timeout.

Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
22 months agovirtio-blk: Fix integer overflow for large max IO sizes
Lukas Stockner via SeaBIOS [Tue, 6 Jun 2023 13:29:52 +0000 (15:29 +0200)]
virtio-blk: Fix integer overflow for large max IO sizes

When the maximum IO size supported by the virtio-blk backend is large
enough (>= 32MiB for 512B sectors), the computed blk_num_max will
overflow. In particular, if it's a multiple of 32MiB, blk_num_max
will end up as zero, causing IO requests to fail.

This is triggered by e.g. the SPDK virtio-blk vhost-user backend.

To fix it, just limit blk_num_max to 65535 before converting to u16.

Signed-off-by: Lukas Stockner <lstockner@genesiscloud.com>
22 months agoFix high memory zone initialization in CSM mode
José Martínez [Tue, 13 Jun 2023 15:01:34 +0000 (11:01 -0400)]
Fix high memory zone initialization in CSM mode

malloc_high() cannot allocate any memory in CSM mode due to an empty
ZoneHigh. SeaBIOS cannot find any disk to boot from because device
initialization fails.

The bug was introduced in 1.16.1 (commit dc88f9b) when the meaning of
BUILD_MAX_HIGHTABLE changed but CSM code was not updated. This patch
reverts to the previous behavior by using BUILD_MIN_HIGHTABLE in CSM
methods.

Signed-off-by: José Martínez <xose@google.com>
2 years agodisable array bounds warning
Gerd Hoffmann [Wed, 3 May 2023 09:16:30 +0000 (11:16 +0200)]
disable array bounds warning

The segmented pointer casting magic confuses gcc, recent versions
throw array bound warnings.  Disable the warning.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agoxen: require Xen info structure at 0x1000 to detect Xen rel-1.16.2
David Woodhouse [Fri, 20 Jan 2023 11:33:19 +0000 (11:33 +0000)]
xen: require Xen info structure at 0x1000 to detect Xen

When running under Xen, hvmloader places a table at 0x1000 with the e820
information and BIOS tables. If this isn't present, SeaBIOS will
currently panic.

We now have support for running Xen guests natively in QEMU/KVM, which
boots SeaBIOS directly instead of via hvmloader, and does not provide
the same structure.

As it happens, this doesn't matter on first boot. because although we
set PlatformRunningOn to PF_QEMU|PF_XEN, reading it back again still
gives zero. Presumably because in true Xen, this is all already RAM. But
in QEMU with a faithfully-emulated PAM config in the host bridge, it's
still in ROM mode at this point so we don't see what we've just written.

On reboot, however, the region *is* set to RAM mode and we do see the
updated value of PlatformRunningOn, do manage to remember that we've
detected Xen in CPUID, and hit the panic.

It's not trivial to detect QEMU vs. real Xen at the time xen_preinit()
runs, because it's so early. We can't even make a XENVER_extraversion
hypercall to look for hints, because we haven't set up the hypercall
page (and don't have an allocator to give us a page in which to do so).

So just make Xen detection contingent on the info structure being
present. If it wasn't, we were going to panic anyway. That leaves us
taking the standard QEMU init path for Xen guests in native QEMU,
which is just fine.

Untested on actual Xen but ObviouslyCorrect™.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
2 years agousb: fix wrong init of keyboard/mouse's if first interface is not boot protocol
Qi Zhou [Mon, 14 Nov 2022 12:55:44 +0000 (20:55 +0800)]
usb: fix wrong init of keyboard/mouse's if first interface is not boot protocol

There is always some endpoint descriptors after each interface descriptor, We
should only decrement num_iface if interface type is USB_DT_INTERFACE, see
https://www.beyondlogic.org/usbnutshell/usb5.shtml#ConfigurationDescriptors

Signed-off-by: Qi Zhou <atmgnd@outlook.com>
2 years agovirtio: finalize features before using device rel-1.16.1
Xuan Zhuo [Mon, 14 Nov 2022 03:58:18 +0000 (11:58 +0800)]
virtio: finalize features before using device

Under the standard of Virtio 1.0, the initialization process of the
device must first write sub-features back to device before
using device, such as finding vqs.

There are four places using vp_find_vq().

1. virtio-blk.pci:    put the code of finalizing features in front of using device
2. virtio-blk.mmio:   put the code of finalizing features in front of using device
3. virtio-scsi.pci:   is ok
4. virtio-scsi.mmio:  add the code of finalizing features before vp_find_vq()

Link: https://www.mail-archive.com/qemu-devel@nongnu.org/msg920776.html
Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Message-Id: <20221114035818.109511-3-xuanzhuo@linux.alibaba.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agovirtio-mmio: read/write the hi 32 features for mmio
Xuan Zhuo [Mon, 14 Nov 2022 03:58:17 +0000 (11:58 +0800)]
virtio-mmio: read/write the hi 32 features for mmio

Under mmio, when we read the feature from the device, we should read the
high 32-bit part. Similarly, when writing the feature back, we should
also write back the high 32-bit feature.

Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Message-Id: <20221114035818.109511-2-xuanzhuo@linux.alibaba.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agoacpi: parse Alias object
Igor Mammedov [Fri, 18 Nov 2022 14:27:55 +0000 (15:27 +0100)]
acpi: parse Alias object

Since QEMU commit
  47a373faa6 (acpi: pc/q35: drop ad-hoc PCI-ISA bridge AML routines and let bus ennumeration generate AML)
SeaBIOS fails to parse ISA bridge AML with:

   parse_termlist: parse error, skip from 92/517
   ...
   ACPI: no PS/2 keyboard present

due to Alias term in DSDT which isn't handled by SeaBIOS properly.
Add dumb Alias parsing which just skips over term,
so the rest of AML could be parsed successfully.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reported-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20221118142755.3879231-1-imammedo@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2 years agovirtio-blk: Fix incorrect type conversion in virtio_blk_op()
Xiaofei Lee [Mon, 21 Nov 2022 14:54:10 +0000 (22:54 +0800)]
virtio-blk: Fix incorrect type conversion in virtio_blk_op()

When using spdk aio bdev driver, the qemu command line like this:

qemu-system-x86_64 \
    -chardev socket,id=char0,path=/tmp/vhost.0 \
    -device vhost-user-blk-pci,id=blk0,chardev=char0 \
    ...

Boot failure message as below:

e820 map has 7 items:
  0: 0000000000000000 - 000000000009fc00 = 1 RAM
  1: 000000000009fc00 - 00000000000a0000 = 2 RESERVED
  2: 00000000000f0000 - 0000000000100000 = 2 RESERVED
  3: 0000000000100000 - 000000007ffdd000 = 1 RAM
  4: 000000007ffdd000 - 0000000080000000 = 2 RESERVED
  5: 00000000feffc000 - 00000000ff000000 = 2 RESERVED
  6: 00000000fffc0000 - 0000000100000000 = 2 RESERVED
enter handle_19:
  NULL
Booting from Hard Disk...
Boot failed: could not read the boot disk

Fixes: a05af290bac5 ("virtio-blk: split large IO according to size_max")
Acked-by: Andy Pei <andy.pei@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Paul Menzel <pmenzel@molgen.mpg.de>
Signed-off-by: Xiaofei Lee <hbuxiaofei@gmail.com>
2 years agovirtio-blk: use larger default request size
Gerd Hoffmann [Thu, 30 Jun 2022 15:28:40 +0000 (17:28 +0200)]
virtio-blk: use larger default request size

Bump default from 8 to 64 blocks.  Using 8 by default leads
to requests being splitted on qemu, which slows down boot.

Some (temporary) debug logging added showed that almost all
requests on a standard fedora install are less than 64 blocks,
so that should bring us back to 1.15 performance levels.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
3 years agomalloc: use large ZoneHigh when there is enough memory
Gerd Hoffmann [Mon, 25 Apr 2022 07:25:31 +0000 (09:25 +0200)]
malloc: use large ZoneHigh when there is enough memory

In case there is enough memory installed use a large ZoneHigh.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
3 years agomalloc: use variable for ZoneHigh size
Gerd Hoffmann [Mon, 25 Apr 2022 07:20:02 +0000 (09:20 +0200)]
malloc: use variable for ZoneHigh size

Use the variable highram_size instead of the BUILD_MAX_HIGHTABLE #define
for the ZoneHigh size. Initialize the new variable with the old #define,
so behavior does not change.

This allows to easily adjust the ZoneHigh size at runtime in a followup
patch.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
3 years agoreset: force standard PCI configuration access
Volker Rümelin [Sat, 2 Apr 2022 18:28:39 +0000 (20:28 +0200)]
reset: force standard PCI configuration access

After a reset of a QEMU -machine q35 guest, the PCI Express
Enhanced Configuration Mechanism is disabled and the variable
mmconfig no longer matches the configuration register PCIEXBAR
of the Q35 chipset. Until the variable mmconfig is reset to 0,
all pci_config_*() functions no longer work.

The variable mmconfig is located in one of the read-only C-F
segments. To reset it the pci_config_*() functions are needed,
but they do not work.

Replace all pci_config_*() calls with Standard PCI Configuration
Mechanism pci_ioconfig_*() calls until mmconfig is overwritten
with 0 by a fresh copy of the BIOS.

This fixes

In resume (status=0)
In 32bit resume
Attempting a hard reboot
Unable to unlock ram - bridge not found

and a reset loop with QEMU -accel tcg.

Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
3 years agopci: refactor the pci_config_*() functions
Volker Rümelin [Sat, 2 Apr 2022 18:28:38 +0000 (20:28 +0200)]
pci: refactor the pci_config_*() functions

Split out the Standard PCI Configuration Access Mechanism
pci_ioconfig_*() functions from the pci_config_*() functions.
The standard PCI CAM functions will be used in the next patch.

Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
3 years agodocs: Note v1.16.0 release rel-1.16.0
Kevin O'Connor [Wed, 2 Mar 2022 01:29:02 +0000 (20:29 -0500)]
docs: Note v1.16.0 release

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
3 years agonvme: fix LBA format data structure
Florian Larysch [Sun, 23 Jan 2022 16:43:57 +0000 (17:43 +0100)]
nvme: fix LBA format data structure

The LBA Format Data structure is dword-sized, but struct nvme_lba_format
erroneously contains an additional member, misaligning all LBAF
descriptors after the first and causing them to be misinterpreted.
Remove it.

Signed-off-by: Florian Larysch <fl@n621.de>
Reviewed-by: Alexander Graf <graf@amazon.com>
3 years agonvme: avoid use-after-free in nvme_controller_enable()
Jan Beulich via SeaBIOS [Mon, 24 Jan 2022 09:20:53 +0000 (10:20 +0100)]
nvme: avoid use-after-free in nvme_controller_enable()

Commit b68f313c9139 ("nvme: Record maximum allowed request size")
introduced a use of "identify" past it being passed to free(). Latch the
value of interest into a local variable.

Reported-by: Coverity (ID 1497613)
Signed-off-by: Jan Beulich <jbeulich@suse.com>
3 years agosercon: Fix missing GET_LOW() to access rx_bytes
Kevin O'Connor [Thu, 20 Jan 2022 00:07:47 +0000 (19:07 -0500)]
sercon: Fix missing GET_LOW() to access rx_bytes

The variable rx_bytes is marked VARLOW, but there was a missing
GET_LOW() to access rx_bytes.  Fix by copying rx_bytes to a local
variable and avoid the repetitive segment memory accesses.

Reported-by: Gabe Black <gabe.black@gmail.com>
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
3 years agonvme: Only allocate one dma bounce buffer for all nvme drives
Kevin O'Connor [Wed, 19 Jan 2022 19:08:05 +0000 (14:08 -0500)]
nvme: Only allocate one dma bounce buffer for all nvme drives

There is no need to create multiple dma bounce buffers as the BIOS
disk code isn't reentrant capable.

Also, verify that the allocation succeeds.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Reviewed-by: Alexander Graf <graf@amazon.com>
3 years agonvme: Build the page list in the existing dma buffer
Kevin O'Connor [Wed, 19 Jan 2022 18:20:21 +0000 (13:20 -0500)]
nvme: Build the page list in the existing dma buffer

Commit 01f2736cc905d ("nvme: Pass large I/O requests as PRP lists")
introduced multi-page requests using the NVMe PRP mechanism. To store the
list and "first page to write to" hints, it added fields to the NVMe
namespace struct.

Unfortunately, that struct resides in fseg which is read-only at runtime.
While KVM ignores the read-only part and allows writes, real hardware and
TCG adhere to the semantics and ignore writes to the fseg region. The net
effect of that is that reads and writes were always happening on address 0,
unless they went through the bounce buffer logic.

This patch builds the PRP maintenance data in the existing "dma bounce
buffer" and only builds it when needed.

Fixes: 01f2736cc905d ("nvme: Pass large I/O requests as PRP lists")
Reported-by: Matt DeVillier <matt.devillier@gmail.com>
Signed-off-by: Alexander Graf <graf@amazon.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Reviewed-by: Alexander Graf <graf@amazon.com>
3 years agonvme: Pass prp1 and prp2 directly to nvme_io_xfer()
Kevin O'Connor [Wed, 19 Jan 2022 18:01:19 +0000 (13:01 -0500)]
nvme: Pass prp1 and prp2 directly to nvme_io_xfer()

When using a prp2 parameter, build it in nvme_prpl_xfer() and pass it
directly to nvme_io_xfer().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Reviewed-by: Alexander Graf <graf@amazon.com>
3 years agonvme: Convert nvme_build_prpl() to nvme_prpl_xfer()
Kevin O'Connor [Wed, 19 Jan 2022 17:51:55 +0000 (12:51 -0500)]
nvme: Convert nvme_build_prpl() to nvme_prpl_xfer()

Rename nvme_build_prpl() to nvme_prpl_xfer() and directly invoke
nvme_io_xfer() or nvme_bounce_xfer() from that function.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Reviewed-by: Alexander Graf <graf@amazon.com>
3 years agonvme: Add nvme_bounce_xfer() helper function
Kevin O'Connor [Wed, 19 Jan 2022 16:54:55 +0000 (11:54 -0500)]
nvme: Add nvme_bounce_xfer() helper function

Move bounce buffer processing to a new helper function.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Reviewed-by: Alexander Graf <graf@amazon.com>
3 years agonvme: Rework nvme_io_readwrite() to return -1 on error
Kevin O'Connor [Wed, 19 Jan 2022 16:45:31 +0000 (11:45 -0500)]
nvme: Rework nvme_io_readwrite() to return -1 on error

Rename nvme_io_readwrite() to nvme_io_xfer() and change it so it
implements the debugging dprintf() and it returns -1 on an error.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Reviewed-by: Alexander Graf <graf@amazon.com>
3 years agosmm: Suppress gcc array-bounds warnings
Kevin O'Connor [Thu, 13 Jan 2022 16:12:35 +0000 (11:12 -0500)]
smm: Suppress gcc array-bounds warnings

Add a hack to suppress spurious gcc array-bounds warning (on at least
gcc v11).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Tested-by: Paul Menzel <pmenzel@molgen.mpg.de>
3 years agoscripts: Remove python23compat.py
Kevin O'Connor [Sun, 19 Dec 2021 06:31:09 +0000 (01:31 -0500)]
scripts: Remove python23compat.py

It's simpler to use b"" designations around binary strings than to use
the as_bytes() function.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
3 years agoreadserial: Improve Python3 compatibility
Kevin O'Connor [Sun, 19 Dec 2021 14:44:13 +0000 (09:44 -0500)]
readserial: Improve Python3 compatibility

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
3 years agomemmap: Fix gcc out-of-bounds warning
Kevin O'Connor [Sat, 18 Dec 2021 17:08:53 +0000 (12:08 -0500)]
memmap: Fix gcc out-of-bounds warning

Use a different definition for the linker script symbol to avoid a gcc
warning.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
3 years agovgasrc: Don't use VAR16 in header files to fix gcc warning
Kevin O'Connor [Sat, 18 Dec 2021 17:00:16 +0000 (12:00 -0500)]
vgasrc: Don't use VAR16 in header files to fix gcc warning

Some versions of gcc complain when VAR16 is used in both the header
and C files - use only in the C file to fix the warning.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
3 years agosvgamodes: add standard 4k modes
Gerd Hoffmann [Thu, 16 Dec 2021 07:20:58 +0000 (08:20 +0100)]
svgamodes: add standard 4k modes

Add all three 4k modes.  Computer monitors typically use
the first one (3840x2160).

Add 16 and 32 bpp variants.  24bpp is dead these days, and
software which is so old that still uses those modes most
likely doesn't even know what 4k is.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
3 years agovirtio-blk: split large IO according to size_max
Andy Pei [Tue, 7 Dec 2021 01:31:08 +0000 (09:31 +0800)]
virtio-blk: split large IO according to size_max

if driver reads data larger than VIRTIO_BLK_F_SIZE_MAX,
it will cause some issue to the DMA engine.

So when upper software wants to read data larger than
VIRTIO_BLK_F_SIZE_MAX, virtio-blk driver split one large
request into multiple smaller ones.

Signed-off-by: Andy Pei <andy.pei@intel.com>
Signed-off-by: Ding Limin <dinglimin@cmss.chinamobile.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
3 years agovirtio-blk: abstract a function named virtio_blk_op_one_segment to handle r/w request
Andy Pei [Tue, 7 Dec 2021 01:31:07 +0000 (09:31 +0800)]
virtio-blk: abstract a function named virtio_blk_op_one_segment to handle r/w request

abstract virtio-blk queue operation to form a function named virtio_blk_op_one_segment

Signed-off-by: Andy Pei <andy.pei@intel.com>
Signed-off-by: Ding Limin <dinglimin@cmss.chinamobile.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
3 years agovirtio-blk: add feature VIRTIO_BLK_F_SIZE_MAX and VIRTIO_BLK_F_SEG_MAX
Andy Pei [Tue, 7 Dec 2021 01:31:06 +0000 (09:31 +0800)]
virtio-blk: add feature VIRTIO_BLK_F_SIZE_MAX and VIRTIO_BLK_F_SEG_MAX

according to virtio spec, add feature VIRTIO_BLK_F_SIZE_MAX
and VIRTIO_BLK_F_SEG_MAX parse to virtio blk driver.

Signed-off-by: Andy Pei <andy.pei@intel.com>
Signed-off-by: Ding Limin <dinglimin@cmss.chinamobile.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
3 years agopci: let firmware reserve IO for pcie-pci-bridge
Igor Mammedov [Mon, 29 Nov 2021 11:48:12 +0000 (06:48 -0500)]
pci: let firmware reserve IO for pcie-pci-bridge

With [1] patch hotplug of rtl8139 succeeds, with caveat that it
fails to initialize IO bar, which is caused by [2] that makes
firmware skip IO reservation for any PCIe device, which isn't
correct in case of pcie-pci-bridge.
Fix it by exposing hotplug type and making IO resource optional
only if PCIe hotplug is in use.

[1]
 "pci: reserve resources for pcie-pci-bridge to fix regressed hotplug on q35"
[2]
Fixes: 76327b9f32a ("fw/pci: do not automatically allocate IO region for PCIe bridges")
Signed-off-by: Igor Mammedov imammedo@redhat.com
Tested-by: Laurent Vivier <lvivier@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
CC: mapfelba@redhat.com
CC: kraxel@redhat.com
CC: mst@redhat.com
CC: lvivier@redhat.com
CC: jusual@redhat.com
3 years agopci: reserve resources for pcie-pci-bridge to fix regressed hotplug on q35
Igor Mammedov [Mon, 29 Nov 2021 11:48:11 +0000 (06:48 -0500)]
pci: reserve resources for pcie-pci-bridge to fix regressed hotplug on q35

If QEMU is started with unpopulated pcie-pci-bridge with ACPI PCI
hotplug enabled (default since QEMU-6.1), hotplugging a PCI device
into one of the bridge slots fails due to lack of resources.

once linux guest is booted (test used Fedora 34), hotplug NIC from
QEMU monitor:
  (qemu) device_add rtl8139,bus=pcie-pci-bridge-0,addr=0x2

guest fails hotplug with:
  pci 0000:01:02.0: [10ec:8139] type 00 class 0x020000
  pci 0000:01:02.0: reg 0x10: [io  0x0000-0x00ff]
  pci 0000:01:02.0: reg 0x14: [mem 0x00000000-0x000000ff]
  pci 0000:01:02.0: reg 0x30: [mem 0x00000000-0x0003ffff pref]
  pci 0000:01:02.0: BAR 6: no space for [mem size 0x00040000 pref]
  pci 0000:01:02.0: BAR 6: failed to assign [mem size 0x00040000 pref]
  pci 0000:01:02.0: BAR 0: no space for [io  size 0x0100]
  pci 0000:01:02.0: BAR 0: failed to assign [io  size 0x0100]
  pci 0000:01:02.0: BAR 1: no space for [mem size 0x00000100]
  pci 0000:01:02.0: BAR 1: failed to assign [mem size 0x00000100]
  8139cp: 8139cp: 10/100 PCI Ethernet driver v1.3 (Mar 22, 2004)
  PCI Interrupt Link [GSIG] enabled at IRQ 22
  8139cp 0000:01:02.0: no MMIO resource
  8139cp: probe of 0000:01:02.0 failed with error -5

Reason for this is that commit [1] didn't take into account
pcie-pci-bridge, marking bridge as non hotpluggable instead of
handling it as possibly SHPC capable bridge.
Fix issue by checking if pcie-pci-bridge is SHPC capable and
if it is mark it as hotpluggable.

Fixes regression in QEMU-6.1 and later, since it was switched
to ACPI based PCI hotplug on Q35 by default at that time.

RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=2001732
[1]
Fixes: 3aa31d7d637 ("hw/pci: reserve IO and mem for pci express downstream ports with no devices attached")
Signed-off-by: Igor Mammedov imammedo@redhat.com
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Laurent Vivier <lvivier@redhat.com>
CC: mapfelba@redhat.com
CC: kraxel@redhat.com
CC: mst@redhat.com
CC: lvivier@redhat.com
CC: jusual@redhat.com
3 years agosmbios: Support SMBIOS 3.0 entry point at smbios_romfile_setup()
Eduardo Habkost [Thu, 10 Dec 2020 19:11:34 +0000 (14:11 -0500)]
smbios: Support SMBIOS 3.0 entry point at smbios_romfile_setup()

Support SMBIOS 3.0 entry points if exposed by QEMU in fw_cfg.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
3 years agosmbios: Support SMBIOS 3.0 entry point at copy_table()
Eduardo Habkost [Thu, 10 Dec 2020 20:19:30 +0000 (15:19 -0500)]
smbios: Support SMBIOS 3.0 entry point at copy_table()

This will make coreboot code (scan_tables()) and xen code
(xen_biostable_setup()) copy SMBIOS 3.0 entry points if
found.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
3 years agosmbios: copy_smbios_30() function
Eduardo Habkost [Thu, 10 Dec 2020 15:32:44 +0000 (10:32 -0500)]
smbios: copy_smbios_30() function

Add new copy_smbios_30() function, that will be used to support
SMBIOS 3.0 entry points.

The SMBIOS 3.0 entry point will be tracked in a separate
SMBios30Addr variable, because both 2.1 and 3.0 entry points may
exist at the same time.

Adjust the smbios_get_tables(), smbios_major_version(), and
smbios_minor_version() helpers to use the SMBIOS 3.0 entry point
if available.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
3 years agosmbios: Make smbios_build_tables() ready for 64-bit tables
Eduardo Habkost [Thu, 10 Dec 2020 19:07:16 +0000 (14:07 -0500)]
smbios: Make smbios_build_tables() ready for 64-bit tables

Make smbios_build_tables() get u64 address and u32 length
arguments, making it usable for SMBIOS 3.0.  Adapt
smbios_21_setup_entry_point() to use intermediate variables when
calling smbios_build_tables().

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
3 years agosmbios: Make some smbios_build_tables() arguments optional
Eduardo Habkost [Thu, 10 Dec 2020 18:29:29 +0000 (13:29 -0500)]
smbios: Make some smbios_build_tables() arguments optional

Make max_structure_size and number_of_structures optional,
as we don't have those fields in SMBIOS 3.0 entry points.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
3 years agosmbios: smbios_21_setup_entry_point() function
Eduardo Habkost [Thu, 10 Dec 2020 18:52:14 +0000 (13:52 -0500)]
smbios: smbios_21_setup_entry_point() function

Extract the code specific for building the SMBIOS 2.1 entry point
from smbios_romfile_setup() to a new
smbios_21_setup_entry_point() function.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
3 years agosmbios: Make smbios_build_tables() more generic
Eduardo Habkost [Thu, 10 Dec 2020 18:10:15 +0000 (13:10 -0500)]
smbios: Make smbios_build_tables() more generic

Instead of taking a SMBIOS 2.1 entry point as argument, make
smbios_build_tables() take pointers to the fields it actually
changes.  This will allow us to reuse the function for SMBIOS 3.0
later.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
3 years agosmbios: Extract SMBIOS table building code to separate function
Eduardo Habkost [Thu, 10 Dec 2020 18:05:17 +0000 (13:05 -0500)]
smbios: Extract SMBIOS table building code to separate function

Move the code that builds the SMBIOS tables to a separate
smbios_build_tables() function, to keep it isolated from the code
that initializes the SMBIOS entry point.

Thew new function will still take a smbios_21_entry_point
argument to make code review easier, but this will be changed by
the next commits.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
3 years agosmbios: Use smbios_next() at smbios_romfile_setup()
Eduardo Habkost [Thu, 10 Dec 2020 17:32:37 +0000 (12:32 -0500)]
smbios: Use smbios_next() at smbios_romfile_setup()

Use smbios_next() instead of smbios_21_next(), to make the code
more generic and reusable for SMBIOS 3.0 support.

Note that `qtables_len` is initialized to `ftables->size` instead
of `ep.structure_table_length` now, but both fields are
guaranteed to have exactly the same value.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
3 years agosmbios: Make SMBios21Addr variable static
Eduardo Habkost [Thu, 10 Dec 2020 20:48:19 +0000 (15:48 -0500)]
smbios: Make SMBios21Addr variable static

The variable is now only used inside biostables.c, there's no
need to make it global.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
3 years agocsm: Don't check SMBios21Addr before calling copy_smbios_21()
Eduardo Habkost [Thu, 10 Dec 2020 20:47:12 +0000 (15:47 -0500)]
csm: Don't check SMBios21Addr before calling copy_smbios_21()

copy_smbios_21() already checks if SMBios21Addr is NULL, there's
no need to check it before calling the function.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
3 years agotpm: Use smbios_get_tables()
Eduardo Habkost [Thu, 10 Dec 2020 20:18:28 +0000 (15:18 -0500)]
tpm: Use smbios_get_tables()

Instead of using the SMBios21Addr global variable, use the
smbios_get_tables() helper.  This doesn't change any behavior
yet, but it will be useful when we start supporting SMBIOS 3.0
entry points.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
3 years agosmbios: smbios_major_version()/smbios_minor_version() helpers
Eduardo Habkost [Thu, 10 Dec 2020 20:17:16 +0000 (15:17 -0500)]
smbios: smbios_major_version()/smbios_minor_version() helpers

They new helpers will be useful when we start supporting SMBIOS
3.0 entry points.  Use the new helpers at display_uuid().

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
3 years agosmbios: Use smbios_get_tables()/smbios_next() at display_uuid()
Eduardo Habkost [Thu, 10 Dec 2020 20:08:34 +0000 (15:08 -0500)]
smbios: Use smbios_get_tables()/smbios_next() at display_uuid()

Make the code more generic, and not specific for SMBIOS 2.1 entry
points.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
3 years agosmbios: smbios_get_tables() function
Eduardo Habkost [Thu, 10 Dec 2020 20:06:27 +0000 (15:06 -0500)]
smbios: smbios_get_tables() function

The new function will be useful for code that just needs the
address and length of SMBIOS tables.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
3 years agosmbios: Generic smbios_next() function
Eduardo Habkost [Thu, 10 Dec 2020 15:57:55 +0000 (10:57 -0500)]
smbios: Generic smbios_next() function

Extract generic code from smbios_21_next(), so it can be reused
for SMBIOS 3.0 support.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
3 years agosmbios: Rename code specific for SMBIOS 2.1 entry points
Eduardo Habkost [Thu, 10 Dec 2020 15:10:42 +0000 (10:10 -0500)]
smbios: Rename code specific for SMBIOS 2.1 entry points

Rename copy_smbios(), smbios_next(), SMBIOS_SIGNATURE,
smbios_entry_point, and SMBiosAddr, to indicate they refer to
SMBIOS 2.1 entry points.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
3 years agoutil.h: Delete unused get_smbios_entry_point() prototype
Eduardo Habkost [Thu, 10 Dec 2020 15:13:58 +0000 (10:13 -0500)]
util.h: Delete unused get_smbios_entry_point() prototype

The get_smbios_entry_point() function doesn't exist, delete
unused prototype.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
3 years agobiostables: copy_fseg_table() function
Eduardo Habkost [Thu, 10 Dec 2020 15:26:43 +0000 (10:26 -0500)]
biostables: copy_fseg_table() function

Replace the common malloc_fseg() + memcpy() code pattern
with a helper function.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
3 years agodocs: Note v1.15.0 release rel-1.15.0
Kevin O'Connor [Fri, 3 Dec 2021 01:43:20 +0000 (20:43 -0500)]
docs: Note v1.15.0 release

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
3 years agotcgbios: Disable platform hierarchy in case of failure
Stefan Berger [Tue, 7 Sep 2021 21:05:52 +0000 (17:05 -0400)]
tcgbios: Disable platform hierarchy in case of failure

In the rare case of a TPM 2 failure, disable the platform hierarchy after
disabling the endorsement and owner hierarchies.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
3 years agonvme: fix missing newline on sq full print
Alex Martens via SeaBIOS [Sat, 26 Jun 2021 22:13:40 +0000 (22:13 +0000)]
nvme: fix missing newline on sq full print

Signed-off-by: Alex Martens <alexmgit@protonmail.com>