Patchwork [2/4] rom loader: make vga+rom loading target specific

login
register
mail settings
Submitter Gerd Hoffmann
Date Oct. 13, 2009, 11:06 a.m.
Message ID <1255431978-4992-3-git-send-email-kraxel@redhat.com>
Download mbox | patch
Permalink /patch/35839/
State New
Headers show

Comments

Gerd Hoffmann - Oct. 13, 2009, 11:06 a.m.
This patch adds a loader-target.c file for target-specific
rom loading functions.  The rom_add_vga() and rom_add_option()
macros are transformed into functions and sticked in there.  They
load the bios on TARGET_I386 and no nothing on other targets.

With this in place we can move the rom loading calls from pc.c to the
individual drivers.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 Makefile.target    |    2 +-
 hw/loader-target.c |   34 ++++++++++++++++++++++++++++++++++
 hw/loader.h        |    6 ++----
 3 files changed, 37 insertions(+), 5 deletions(-)
 create mode 100644 hw/loader-target.c
Blue Swirl - Oct. 13, 2009, 2:58 p.m.
On Tue, Oct 13, 2009 at 2:06 PM, Gerd Hoffmann <kraxel@redhat.com> wrote:
> This patch adds a loader-target.c file for target-specific
> rom loading functions.  The rom_add_vga() and rom_add_option()
> macros are transformed into functions and sticked in there.  They
> load the bios on TARGET_I386 and no nothing on other targets.

IIRC the VGA cards on non-x86 machines contain ROMs too, some (PPC?
Alpha?) machine had a simple x86 emulator just to run the ROM code.
Then you could enable the VGA ROM loading unconditionally. So maybe
the patch isn't necessary?

Otherwise you could add two files without macros, then the files can
be compiled just once.
Gerd Hoffmann - Oct. 13, 2009, 3:29 p.m.
On 10/13/09 16:58, Blue Swirl wrote:
> On Tue, Oct 13, 2009 at 2:06 PM, Gerd Hoffmann<kraxel@redhat.com>  wrote:
>> This patch adds a loader-target.c file for target-specific
>> rom loading functions.  The rom_add_vga() and rom_add_option()
>> macros are transformed into functions and sticked in there.  They
>> load the bios on TARGET_I386 and no nothing on other targets.
>
> IIRC the VGA cards on non-x86 machines contain ROMs too, some (PPC?
> Alpha?) machine had a simple x86 emulator just to run the ROM code.
> Then you could enable the VGA ROM loading unconditionally. So maybe
> the patch isn't necessary?

Is the vgabios actually loaded to 0xc0000 (like x86 does) or does it 
just sit in the PCI ROM bar?

> Otherwise you could add two files without macros, then the files can
> be compiled just once.

... with lot of Makefile.target changes which I wanted to avoid.

Or is there a simple way to say "all but i386 please use $thisfile.c"?

cheers,
   Gerd
Blue Swirl - Oct. 13, 2009, 4:45 p.m.
On Tue, Oct 13, 2009 at 6:29 PM, Gerd Hoffmann <kraxel@redhat.com> wrote:
> On 10/13/09 16:58, Blue Swirl wrote:
>>
>> On Tue, Oct 13, 2009 at 2:06 PM, Gerd Hoffmann<kraxel@redhat.com>  wrote:
>>>
>>> This patch adds a loader-target.c file for target-specific
>>> rom loading functions.  The rom_add_vga() and rom_add_option()
>>> macros are transformed into functions and sticked in there.  They
>>> load the bios on TARGET_I386 and no nothing on other targets.
>>
>> IIRC the VGA cards on non-x86 machines contain ROMs too, some (PPC?
>> Alpha?) machine had a simple x86 emulator just to run the ROM code.
>> Then you could enable the VGA ROM loading unconditionally. So maybe
>> the patch isn't necessary?
>
> Is the vgabios actually loaded to 0xc0000 (like x86 does) or does it just
> sit in the PCI ROM bar?

No idea, probably not loaded.

>> Otherwise you could add two files without macros, then the files can
>> be compiled just once.
>
> ... with lot of Makefile.target changes which I wanted to avoid.
>
> Or is there a simple way to say "all but i386 please use $thisfile.c"?

ifdef TARGET_I386
obj-y += loader-target.o
else
obj-y += loader-dummy.o
endif
?
Natalia Portillo - Oct. 13, 2009, 10:03 p.m.
SmartFirmware on Genesi Pegasos boards do.

I have one and when I boot I see the ATI Radeon 9200 BIOS message,  
then openfirmware prompt.

Macs do require openfirmware forth rom (powerpc macs) or EFI rom  
(intel macs, not know if compiled for x86 or efi interpreter)

I've head the AmigaONE openfirmware implementation does the same as  
SmartFirmware (emulator), not tested any other architecture.

El 13/10/2009, a las 15:58, Blue Swirl escribió:

> On Tue, Oct 13, 2009 at 2:06 PM, Gerd Hoffmann <kraxel@redhat.com>  
> wrote:
>> This patch adds a loader-target.c file for target-specific
>> rom loading functions.  The rom_add_vga() and rom_add_option()
>> macros are transformed into functions and sticked in there.  They
>> load the bios on TARGET_I386 and no nothing on other targets.
>
> IIRC the VGA cards on non-x86 machines contain ROMs too, some (PPC?
> Alpha?) machine had a simple x86 emulator just to run the ROM code.
> Then you could enable the VGA ROM loading unconditionally. So maybe
> the patch isn't necessary?
>
> Otherwise you could add two files without macros, then the files can
> be compiled just once.
>
>
Gerd Hoffmann - Oct. 14, 2009, 7:28 a.m.
>> Or is there a simple way to say "all but i386 please use $thisfile.c"?
>
> ifdef TARGET_I386
> obj-y += loader-target.o
> else
> obj-y += loader-dummy.o
> endif
> ?

Yep, should do, although I'd call it loader-i386.o or loader-pc.o then.

cheers,
   Gerd
Gerd Hoffmann - Oct. 14, 2009, 10:21 a.m.
On 10/14/09 00:03, Natalia Portillo wrote:
> SmartFirmware on Genesi Pegasos boards do.
>
> I have one and when I boot I see the ATI Radeon 9200 BIOS message, then
> openfirmware prompt.

Big question is whenever they actually load the rom to 0xc0000 or 
whenever they let the x86 emulator read the rom data directly from the 
pci address space.  I suspect the later.

cheers,
   Gerd
Natalia Portillo - Oct. 14, 2009, 12:37 p.m.
I suspect the later also.

Theorically, SmartFirmware source is available, as well as AmigaONE's  
implementation.

Dunno if the x86 emulator is included in the source.

What I know is that my SF is not enough stable to run Linux and check  
the OF memory map. (sadly)

El 14/10/2009, a las 11:21, Gerd Hoffmann escribió:

> On 10/14/09 00:03, Natalia Portillo wrote:
>> SmartFirmware on Genesi Pegasos boards do.
>>
>> I have one and when I boot I see the ATI Radeon 9200 BIOS message,  
>> then
>> openfirmware prompt.
>
> Big question is whenever they actually load the rom to 0xc0000 or  
> whenever they let the x86 emulator read the rom data directly from  
> the pci address space.  I suspect the later.
>
> cheers,
>  Gerd
>

Patch

diff --git a/Makefile.target b/Makefile.target
index 2726487..6054a68 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -154,7 +154,7 @@  endif #CONFIG_BSD_USER
 # System emulator target
 ifdef CONFIG_SOFTMMU
 
-obj-y = vl.o monitor.o pci.o machine.o gdbstub.o
+obj-y = vl.o monitor.o pci.o machine.o gdbstub.o loader-target.o
 # virtio has to be here due to weird dependency between PCI and virtio-net.
 # need to fix this properly
 obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o virtio-pci.o
diff --git a/hw/loader-target.c b/hw/loader-target.c
new file mode 100644
index 0000000..54a6745
--- /dev/null
+++ b/hw/loader-target.c
@@ -0,0 +1,34 @@ 
+/*
+ * target specific rom code
+ */
+
+#include "hw.h"
+#include "loader.h"
+
+#ifdef TARGET_I386
+
+int rom_add_vga(const char *file)
+{
+    return rom_add_file(file, PC_ROM_MIN_VGA, PC_ROM_MAX, PC_ROM_ALIGN);
+}
+
+int rom_add_option(const char *file)
+{
+    return rom_add_file(file, PC_ROM_MIN_OPTION, PC_ROM_MAX, PC_ROM_ALIGN);
+}
+
+#else
+
+int __attribute__((weak)) rom_add_vga(const char *file)
+{
+    /* nothing */
+    return 0;
+}
+
+int __attribute__((weak)) rom_add_option(const char *file)
+{
+    /* nothing */
+    return 0;
+}
+
+#endif
diff --git a/hw/loader.h b/hw/loader.h
index 945c662..d013253 100644
--- a/hw/loader.h
+++ b/hw/loader.h
@@ -38,9 +38,7 @@  void do_info_roms(Monitor *mon);
 #define PC_ROM_ALIGN       0x800
 #define PC_ROM_SIZE        (PC_ROM_MAX - PC_ROM_MIN_VGA)
 
-#define rom_add_vga(_f)                                                 \
-    rom_add_file(_f, PC_ROM_MIN_VGA,    PC_ROM_MAX, PC_ROM_ALIGN)
-#define rom_add_option(_f)                                              \
-    rom_add_file(_f, PC_ROM_MIN_OPTION, PC_ROM_MAX, PC_ROM_ALIGN)
+int rom_add_vga(const char *file);
+int rom_add_option(const char *file);
 
 #endif