seabios: pci: pci initialization clean up
v2 cover seabios: pci: pci initialization clean up
Changes from v1 -> v2
- renamed files i440fx -> dev->i440fx.
- dropped copyright notice from dev-i440fx.h
This patch series cleans up pci device initialization by introducing a helper function.
This makes it easier to add more device initialization code cleanly as preparation for q35 chipset.
Isaku Yamahata (2):
seabios: pci: introduce helper function to initialize a given device.
seabios: pciinit: use pci device initializer helper function.
Makefile | 2 +- src/dev-i440fx.c | 52 ++++++++++++++++++ src/dev-i440fx.h | 8 +++ src/pci.c | 20 +++++++ src/pci.h | 34 ++++++++++++ src/pciinit.c | 160 +++++++++++++++++++++++++----------------------------- 6 files changed, 188 insertions(+), 88 deletions(-) create mode 100644 src/dev-i440fx.c create mode 100644 src/dev-i440fx.h
PATCH v2 1/2 seabios: pci: introduce helper function to initialize a given device.
introduce helper function to initialize a given device, This will be used later.
--- src/pci.c | 20 ++++++++++++++++++++ src/pci.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 0 deletions(-)
src/pci.c +20 -0
@@ -183,3 +183,23 @@ pci_find_class(u16 classid) }return -1 ; } + +int pci_init_device (const struct pci_device_id *ids,u16 bdf,void *arg) +{ +u16 vendor_id =pci_config_readw (bdf,PCI_VENDOR_ID ); +u16 device_id =pci_config_readw (bdf,PCI_DEVICE_ID ); +u16 class =pci_config_readw (bdf,PCI_CLASS_DEVICE ); + +while (ids->vendid || ids->class_mask) { +if ((ids->vendid ==PCI_ANY_ID || ids->vendid == vendor_id) && + (ids->devid ==PCI_ANY_ID || ids->devid == device_id) && + !((ids->class ^ class) & ids->class_mask)) { +if (ids->func) { + ids->func (bdf, arg); + } +return 0 ; + } + ids++; + } +return -1 ; +}
src/pci.h +34 -0
@@ -60,6 +60,40 @@ int pci_next(int bdf, int *pmax); ; MAX = pci_bus_devfn_to_bdf(BUS, 0) + 0x0100, \ BDF = pci_next(BDF + 1, &MAX)) +#define PCI_ANY_ID (~0) +struct pci_device_id { +u32 vendid; +u32 devid; +u32 class; +u32 class_mask; +void (*func)(u16 bdf,void *arg); +}; + +#define PCI_DEVICE (vendor_id, device_id, init_func) \ + { \ + .vendid = (vendor_id), \ + .devid = (device_id), \ + .class = PCI_ANY_ID, \ + .class_mask = 0, \ + .func = (init_func) \ + } + +#define PCI_DEVICE_CLASS (vendor_id, device_id, class_code, init_func) \ + { \ + .vendid = (vendor_id), \ + .devid = (device_id), \ + .class = (class_code), \ + .class_mask = ~0, \ + .func = (init_func) \ + } + +#define PCI_DEVICE_END \ + { \ + .vendid = 0, \ + } + +int pci_init_device (const struct pci_device_id *table,u16 bdf,void *arg); +// pirtable.c void create_pirtable (void );
Signature · 1 line
1.7.1.1
PATCH v2 2/2 seabios: pciinit: use pci device initializer helper function.
In reply to Isaku YamahataThis patch makes use of pci device initialization helper function to convert if/switch clause to table driven.
So this makes it easier to add q35 initialization code.
---
changes v1 -> v2
- renamed files i440fx -> dev->i440fx.
- dropped copyright notice from dev-i440fx.h
--- Makefile | 2 +- src/dev-i440fx.c | 52 ++++++++++++++++++ src/dev-i440fx.h | 8 +++ src/pciinit.c | 160 +++++++++++++++++++++++++----------------------------- 4 files changed, 134 insertions(+), 88 deletions(-) create mode 100644 src/dev-i440fx.c create mode 100644 src/dev-i440fx.h
Makefile +1 -1
@@ -19,7 +19,7 @@ SRCBOTH=misc.c pmm.c stacks.c output.c util.c block.c floppy.c ata.c mouse.c \ SRC16=$(SRCBOTH) system.c disk.c apm.c font.c SRC32FLAT=$(SRCBOTH) post.c shadow.c memmap.c coreboot.c boot.c \ acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.c \ - lzmadecode.c bootsplash.c jpeg.c usb-hub.c paravirt.c + lzmadecode.c bootsplash.c jpeg.c usb-hub.c paravirt.c dev-i440fx.c SRC32SEG=util.c output.c pci.c pcibios.c apm.c stacks.c cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
src/dev-i440fx.c new file +52 -0
52 lines not on this page · raw message
src/dev-i440fx.h new file +8 -0
@@ -0,0 +1,8 @@ +#ifndef __I440FX_H +#define __I440FX_H + +void piix_isa_bridge_init (u16 bdf,void *arg); +void piix_ide_init (u16 bdf,void *arg); +void piix4_pm_init (u16 bdf,void *arg); + +#endif // __I440FX_H
src/pciinit.c +73 -87
210 lines not on this page · raw message
Signature · 1 line
1.7.1.1
[Qemu-devel] Re: [SeaBIOS] [PATCH v2 2/2] seabios: pciinit: use pci device initializer helper function.
Quoted 5 lines · Isaku Yamahata
This patch makes use of pci device initialization helper function to convert if/switch clause to table driven.
So this makes it easier to add q35 initialization code.Signed-off-by Isaku Yamahata <[email protected]>
I committed the first patch. I committed the second patch after fixing up the compile on it.
You're likely seeing " Working around non-functional -combine" printed during the build. When in this mode the build textually includes all the .c files in order to still take advantage of the -fwhole-program optimization. Unfortunately in this mode, improper includes can slip through.
You might want to try grabbing a newer version of gcc. I believe both the latest gcc v4.4 and gcc v4.5 work correctly.
-Kevin
[Qemu-devel] Re: [SeaBIOS] [PATCH v2 2/2] seabios: pciinit: use pci device initializer helper function.
Quoted 9 lines · Kevin O'Connor
Quoted 5 lines · Isaku Yamahata
This patch makes use of pci device initialization helper function to convert if/switch clause to table driven.
So this makes it easier to add q35 initialization code.Signed-off-by Isaku Yamahata <[email protected]>I committed the first patch. I committed the second patch after fixing up the compile on it.
Thank you for fixing the patch.
Quoted 8 lines
You're likely seeing " Working around non-functional -combine" printed during the build. When in this mode the build textually includes all the .c files in order to still take advantage of the -fwhole-program optimization. Unfortunately in this mode, improper includes can slip through.
You might want to try grabbing a newer version of gcc. I believe both the latest gcc v4.4 and gcc v4.5 work correctly.
Yes, the message was printed out.
I've upgraded gcc from v4.3.4 to v4.4.4 and confirmed the error. Future patches will be tested with gcc v4.4.
Signature · 1 line
yamahata