Re: [SeaBIOS] [PATCH v3] config: allow DEBUG_IO for !QEMU

2013-06-02 Thread Laszlo Ersek
On 06/01/13 05:35, Kevin O'Connor wrote:

 The plan on uefi was to use the smbios
 tables to detect qemu.  Once detection is in place, the DEBUG_IO
 support could be made dependent on QEMU_HARDWARE and only activated
 after detection succeeds.

Understood.

I wasn't aware this was pending on me (skimmed src/csm.c). I'll see what
I can do in OvmfPkg/SmbiosPlatformDxe. Doesn't seem particularly easy,
given that qemu may optionally pass smbios structures over fw_cfg (see
the -smbios option, in which case OVMF should not build, just install
them), plus there's a big number of mandatory smbios structures for
which almost a full system configuration must be collected, seemingly. I
hope edk2 will at least provide the data types.

Thanks
Laszlo

___
SeaBIOS mailing list
SeaBIOS@seabios.org
http://www.seabios.org/mailman/listinfo/seabios


Re: [SeaBIOS] [PATCH v3] config: allow DEBUG_IO for !QEMU

2013-05-31 Thread Laszlo Ersek
On 05/31/13 03:09, Kevin O'Connor wrote:
 On Thu, May 30, 2013 at 09:30:33AM +0200, Gerd Hoffmann wrote:
 On 05/30/13 03:34, Kevin O'Connor wrote:
 On Wed, May 29, 2013 at 04:25:59PM +0200, Gerd Hoffmann wrote:
 Allow selecting DEBUG_IO for non-qemu configurations,
 which is useful when running coreboot+seabios on qemu.

 Unfortunately, if one does run seabios on real hardware and has
 DEBUG_IO enabled, it will write to IO port 0x402 before confirming
 that it is actually running on QEMU.  This could cause mysterious
 failures on real hardware if something is listening to that port.
 It's why I left the option dependent on QEMU instead of QEMU_HARDWARE.
 Ideally the code would verify it is on QEMU before using the IO port,
 while still providing the very early debugging when it is known to be
 safe.

 The debgconsole port returns 0xe9 on reads, so we could use that for
 probing and do something like the attached patch.  Which doesn't build
 for some reason.  Is the F segment read-only in 16bit mode?  Should I
 use something else instead?  Or #ifdef the SET_GLOBAL for 32bit mode,
 which should work fine given that POST runs in 32bit mode?
 
 Same problem - one can't reliably do an inb(0xe9) on real hardware
 without risking mysterious failures.

This entire problem seems to exist only if someone runs a SeaBIOS binary
on real hardware that was configured like:
- COREBOOT or CSM (ie. not QEMU),
- and QEMU_HARDWARE.

Why would someone set QEMU_HARDWARE (Support hardware found on
emulators) for a binary intended to run on real hardware?

In the rest of src/Kconfig, the following options depend on QEMU_HARDWARE:
- VIRTIO_BLK
- VIRTIO_SCSI
- ESP_SCSI
- LSI_SCSI

The first two clearly don't make sense on bare metal. The last two might
(no idea), but if that's the case, then their dependency on emulated
hardware is wrong.

We need a way to say in Kconfig, this is a CSM build specifically meant
for emulators, and CONFIG_CSM + QEMU_HARDWARE looks like an ideal
candidate. People building for bare metal shouldn't (need to) set
QEMU_HARDWARE.

Alternatively, we need code that can run in 16-bit mode (consequently,
without writing any globals) and that can identify *any* of the
supported hypervisors. PlatformRunningOn is too late. KVM and Xen
could be covered by cpuid() (*), but this approach is a pain because a
single patch would have to add detection for all supported hypervisors
at once.

(*) I checked the SDM and also there's code like this out there, eg.
http://lkml.indiana.edu/hypermail/linux/kernel/0705.0/0019.html.

What if we replace the inb() in the proposed patch with a cpuid call
that detects only KVM, as first step? On KVM it would do the right
thing, on bare metal, ditto. On other hypervisors it would err towards
safety and could be extended later. What do you think?

Thanks,
Laszlo

___
SeaBIOS mailing list
SeaBIOS@seabios.org
http://www.seabios.org/mailman/listinfo/seabios


Re: [SeaBIOS] [PATCH v3] config: allow DEBUG_IO for !QEMU

2013-05-31 Thread Kevin O'Connor
On Fri, May 31, 2013 at 03:30:48PM +0200, Laszlo Ersek wrote:
 On 05/31/13 03:09, Kevin O'Connor wrote:
  Same problem - one can't reliably do an inb(0xe9) on real hardware
  without risking mysterious failures.
 
 This entire problem seems to exist only if someone runs a SeaBIOS binary
 on real hardware that was configured like:
 - COREBOOT or CSM (ie. not QEMU),
 - and QEMU_HARDWARE.
 
 Why would someone set QEMU_HARDWARE (Support hardware found on
 emulators) for a binary intended to run on real hardware?

It's common to build seabios with all options enabled and let seabios
auto-detect what it can use.  That's the intent of QEMU_HARDWARE - it
allows one to compile in more drivers and seabios will use them if it
detects the corresponding hardware.  This does not obviate the need
for proper hardware detection though.

If this goes wrong on real hardware, it could require a lengthy
session with a soldering iron to fix it.  People don't like that.

[...]
 What if we replace the inb() in the proposed patch with a cpuid call
 that detects only KVM, as first step? On KVM it would do the right
 thing, on bare metal, ditto. On other hypervisors it would err towards
 safety and could be extended later. What do you think?

The plan was to detect qemu on coreboot via the mainboard vendor/part
info that coreboot generates.  The plan on uefi was to use the smbios
tables to detect qemu.  Once detection is in place, the DEBUG_IO
support could be made dependent on QEMU_HARDWARE and only activated
after detection succeeds.

-Kevin

___
SeaBIOS mailing list
SeaBIOS@seabios.org
http://www.seabios.org/mailman/listinfo/seabios


Re: [SeaBIOS] [PATCH v3] config: allow DEBUG_IO for !QEMU

2013-05-30 Thread Gerd Hoffmann
On 05/30/13 03:34, Kevin O'Connor wrote:
 On Wed, May 29, 2013 at 04:25:59PM +0200, Gerd Hoffmann wrote:
 Allow selecting DEBUG_IO for non-qemu configurations,
 which is useful when running coreboot+seabios on qemu.
 
 Unfortunately, if one does run seabios on real hardware and has
 DEBUG_IO enabled, it will write to IO port 0x402 before confirming
 that it is actually running on QEMU.  This could cause mysterious
 failures on real hardware if something is listening to that port.
 It's why I left the option dependent on QEMU instead of QEMU_HARDWARE.
 Ideally the code would verify it is on QEMU before using the IO port,
 while still providing the very early debugging when it is known to be
 safe.

The debgconsole port returns 0xe9 on reads, so we could use that for
probing and do something like the attached patch.  Which doesn't build
for some reason.  Is the F segment read-only in 16bit mode?  Should I
use something else instead?  Or #ifdef the SET_GLOBAL for 32bit mode,
which should work fine given that POST runs in 32bit mode?

cheers,
  Gerd

From ea131715b0b8f959f8f34768ef46ac029a5f84b0 Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann kra...@redhat.com
Date: Thu, 30 May 2013 09:25:40 +0200
Subject: [PATCH] [broken] probe for debug port

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 src/output.c |   13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/output.c b/src/output.c
index 79c3ada..102f177 100644
--- a/src/output.c
+++ b/src/output.c
@@ -24,6 +24,7 @@ struct putcinfo {
 #define DEBUG_TIMEOUT 10
 
 u16 DebugOutputPort VARFSEG = 0x402;
+u8 DebugOutputEnabled VARFSEG = 0xff;
 
 void
 debug_serial_preinit(void)
@@ -77,9 +78,17 @@ putc_debug(struct putcinfo *action, char c)
 {
 if (! CONFIG_DEBUG_LEVEL)
 return;
-if (CONFIG_DEBUG_IO)
+if (CONFIG_DEBUG_IO) {
 // Send character to debug port.
-outb(c, GET_GLOBAL(DebugOutputPort));
+u8 enabled = GET_GLOBAL(DebugOutputEnabled);
+if (enabled == 0xff) {
+enabled = (inb(GET_GLOBAL(DebugOutputPort)) == 0xe9);
+SET_GLOBAL(DebugOutputEnabled, enabled);
+}
+if (enabled ) {
+outb(c, GET_GLOBAL(DebugOutputPort));
+}
+}
 if (c == '\n')
 debug_serial('\r');
 debug_serial(c);
-- 
1.7.9.7

___
SeaBIOS mailing list
SeaBIOS@seabios.org
http://www.seabios.org/mailman/listinfo/seabios


Re: [SeaBIOS] [PATCH v3] config: allow DEBUG_IO for !QEMU

2013-05-30 Thread Peter Stuge
Gerd Hoffmann wrote:
 Allow selecting DEBUG_IO for non-qemu configurations,
 which is useful when running coreboot+seabios on qemu.
 
 [ v2: QEMU_HARDWARE is even better as DEBUG_IO default value ]
 [ v3: make QEMU_HARDWARE usage consistent with other config
   options, fix spellings in commit message ]
 
 Signed-off-by: Gerd Hoffmann kra...@redhat.com

Acked-by: Peter Stuge pe...@stuge.se

___
SeaBIOS mailing list
SeaBIOS@seabios.org
http://www.seabios.org/mailman/listinfo/seabios


Re: [SeaBIOS] [PATCH v3] config: allow DEBUG_IO for !QEMU

2013-05-30 Thread Kevin O'Connor
On Thu, May 30, 2013 at 09:30:33AM +0200, Gerd Hoffmann wrote:
 On 05/30/13 03:34, Kevin O'Connor wrote:
  On Wed, May 29, 2013 at 04:25:59PM +0200, Gerd Hoffmann wrote:
  Allow selecting DEBUG_IO for non-qemu configurations,
  which is useful when running coreboot+seabios on qemu.
  
  Unfortunately, if one does run seabios on real hardware and has
  DEBUG_IO enabled, it will write to IO port 0x402 before confirming
  that it is actually running on QEMU.  This could cause mysterious
  failures on real hardware if something is listening to that port.
  It's why I left the option dependent on QEMU instead of QEMU_HARDWARE.
  Ideally the code would verify it is on QEMU before using the IO port,
  while still providing the very early debugging when it is known to be
  safe.
 
 The debgconsole port returns 0xe9 on reads, so we could use that for
 probing and do something like the attached patch.  Which doesn't build
 for some reason.  Is the F segment read-only in 16bit mode?  Should I
 use something else instead?  Or #ifdef the SET_GLOBAL for 32bit mode,
 which should work fine given that POST runs in 32bit mode?

Same problem - one can't reliably do an inb(0xe9) on real hardware
without risking mysterious failures.

-Kevin

___
SeaBIOS mailing list
SeaBIOS@seabios.org
http://www.seabios.org/mailman/listinfo/seabios


[SeaBIOS] [PATCH v3] config: allow DEBUG_IO for !QEMU

2013-05-29 Thread Gerd Hoffmann
Allow selecting DEBUG_IO for non-qemu configurations,
which is useful when running coreboot+seabios on qemu.

[ v2: QEMU_HARDWARE is even better as DEBUG_IO default value ]
[ v3: make QEMU_HARDWARE usage consistent with other config
  options, fix spellings in commit message ]

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 src/Kconfig |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Kconfig b/src/Kconfig
index 3c80132..5882d11 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -425,7 +425,7 @@ menu Debugging
 Base port for serial - generally 0x3f8, 0x2f8, 0x3e8, or 0x2e8.
 
 config DEBUG_IO
-depends on QEMU  DEBUG_LEVEL != 0
+depends on QEMU_HARDWARE  DEBUG_LEVEL != 0
 bool Special IO port debugging
 default y
 help
-- 
1.7.9.7


___
SeaBIOS mailing list
SeaBIOS@seabios.org
http://www.seabios.org/mailman/listinfo/seabios


Re: [SeaBIOS] [PATCH v3] config: allow DEBUG_IO for !QEMU

2013-05-29 Thread Laszlo Ersek
On 05/29/13 16:25, Gerd Hoffmann wrote:
 Allow selecting DEBUG_IO for non-qemu configurations,
 which is useful when running coreboot+seabios on qemu.
 
 [ v2: QEMU_HARDWARE is even better as DEBUG_IO default value ]
 [ v3: make QEMU_HARDWARE usage consistent with other config
   options, fix spellings in commit message ]
 
 Signed-off-by: Gerd Hoffmann kra...@redhat.com
 ---
  src/Kconfig |2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
 
 diff --git a/src/Kconfig b/src/Kconfig
 index 3c80132..5882d11 100644
 --- a/src/Kconfig
 +++ b/src/Kconfig
 @@ -425,7 +425,7 @@ menu Debugging
  Base port for serial - generally 0x3f8, 0x2f8, 0x3e8, or 0x2e8.
  
  config DEBUG_IO
 -depends on QEMU  DEBUG_LEVEL != 0
 +depends on QEMU_HARDWARE  DEBUG_LEVEL != 0
  bool Special IO port debugging
  default y
  help
 

QEMU selects QEMU_HARDWARE, so OK in that direction.

CSM and COREBOOT (!QEMU in general) make the QEMU_HARDWARE option
available, which when set to y opens up DEBUG_IO.

Reviewed-by: Laszlo Ersek ler...@redhat.com

Thanks
Laszlo

___
SeaBIOS mailing list
SeaBIOS@seabios.org
http://www.seabios.org/mailman/listinfo/seabios


Re: [SeaBIOS] [PATCH v3] config: allow DEBUG_IO for !QEMU

2013-05-29 Thread Kevin O'Connor
On Wed, May 29, 2013 at 04:25:59PM +0200, Gerd Hoffmann wrote:
 Allow selecting DEBUG_IO for non-qemu configurations,
 which is useful when running coreboot+seabios on qemu.

Unfortunately, if one does run seabios on real hardware and has
DEBUG_IO enabled, it will write to IO port 0x402 before confirming
that it is actually running on QEMU.  This could cause mysterious
failures on real hardware if something is listening to that port.
It's why I left the option dependent on QEMU instead of QEMU_HARDWARE.
Ideally the code would verify it is on QEMU before using the IO port,
while still providing the very early debugging when it is known to be
safe.

-Kevin

___
SeaBIOS mailing list
SeaBIOS@seabios.org
http://www.seabios.org/mailman/listinfo/seabios