Skip to contentSkip to conversation

seabios: pci: pci initialization clean up

PATCH Superseded Isaku Yamahata 2 participants 4 messages Jul 5, 2010 – Jul 7, 2010 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover seabios: pci: pci initialization clean up

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/i440fx.c  |   52 ++++++++++++++++++
 src/i440fx.h  |   17 ++++++
 src/pci.c     |   20 +++++++
 src/pci.h     |   34 ++++++++++++
 src/pciinit.c |  160 ++++++++++++++++++++++++++-------------------------------
 6 files changed, 197 insertions(+), 88 deletions(-)
 create mode 100644 src/i440fx.c
 create mode 100644 src/i440fx.h
#1 lore raw

PATCH 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
index 1ab3c2c..c54b084 100644
@@ -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
index e40e116..fa6a32d 100644
@@ -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
#2 lore raw

PATCH 2/2 seabios: pciinit: use pci device initializer helper function.

In reply to 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.

---
 Makefile      |    2 +-
 src/i440fx.c  |   52 ++++++++++++++++++
 src/i440fx.h  |   17 ++++++
 src/pciinit.c |  160 ++++++++++++++++++++++++++-------------------------------
 4 files changed, 143 insertions(+), 88 deletions(-)
 create mode 100644 src/i440fx.c
 create mode 100644 src/i440fx.h
Makefile +1 -1
index 3798ca6..23ea990 100644
@@ -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 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/i440fx.c new file +52 -0

52 lines not on this page · raw message

src/i440fx.h new file +17 -0
new file mode 100644
index 0000000..9598db5
@@ -0,0 +1,17 @@
+// initialization function which are specific to i440fx chipset
+//
+// Copyright (C) 2008  Kevin O'Connor <[email protected]>
+// Copyright (C) 2006 Fabrice Bellard
+//
+// Copyright (C) 2010 Isaku Yamahata <yamahata at valinux co jp>
+// Split out from pciinit.c
+//
+// This file may be distributed under the terms of the GNU LGPLv3 license.
+#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
#3 lore raw

[Qemu-devel] Re: [SeaBIOS] [PATCH 2/2] seabios: pciinit: use pci device initializer helper function.

Quoted 3 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.

Looks okay to me. A couple of minor comments..

Makefile SRCBOTH=misc.c pmm.c stacks.c output.c util.c block.c floppy.c ata.c mouse.c \ · line 22

Quoted 4 lines
 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 \
Makefile +1 -1
-      lzmadecode.c bootsplash.c jpeg.c usb-hub.c paravirt.c
+      lzmadecode.c bootsplash.c jpeg.c usb-hub.c paravirt.c i440fx.c

The "i440fx.c" is a bit cryptic for someone unfamiliar with the hardware. Maybe "dev-i440fx.c" or something similar?

Quoted 9 lines

+++ b/src/i440fx.h

src/i440fx.h new file +7 -0
@@ -0,0 +1,17 @@
+// initialization function which are specific to i440fx chipset
+//
+// Copyright (C) 2008  Kevin O'Connor <[email protected]>
+// Copyright (C) 2006 Fabrice Bellard
+//
+// Copyright (C) 2010 Isaku Yamahata <yamahata at valinux co jp>
+// Split out from pciinit.c

src/i440fx.h line 17

Quoted 10 lines
src/i440fx.h new file +10 -0
+//
+// This file may be distributed under the terms of the GNU LGPLv3 license.
+#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

I would prefer not to add long copyright statements on function prototypes. Lets copyright the code, not the headers.

-Kevin