[SeaBIOS] [PATCH] Locally allocate busses[] and always make it maximum sized.
Kevin O'Connor
kevin at koconnor.net
Sat Oct 1 22:01:11 CEST 2011
One more patch.
-Kevin
>From c0068c484162337afda1ede0322a4cfcd37ded23 Mon Sep 17 00:00:00 2001
From: Kevin O'Connor <kevin at koconnor.net>
Date: Sat, 1 Oct 2011 15:50:55 -0400
Subject: [PATCH] Locally allocate busses[] and always make it maximum sized.
To: seabios at seabios.org
Don't bother tracking busses_count - there is plenty of dynamic ram -
just always allocate the maximum size it can be (256).
Since only a few functions need to access busses[] pass it by
reference instead of using a global.
Signed-off-by: Kevin O'Connor <kevin at koconnor.net>
---
src/pciinit.c | 42 +++++++++++++++++-------------------------
1 files changed, 17 insertions(+), 25 deletions(-)
diff --git a/src/pciinit.c b/src/pciinit.c
index e2c5f3c..c618a8f 100644
--- a/src/pciinit.c
+++ b/src/pciinit.c
@@ -1,6 +1,6 @@
// Initialize PCI devices (on emulators)
//
-// Copyright (C) 2008 Kevin O'Connor <kevin at koconnor.net>
+// Copyright (C) 2008-2011 Kevin O'Connor <kevin at koconnor.net>
// Copyright (C) 2006 Fabrice Bellard
//
// This file may be distributed under the terms of the GNU LGPLv3 license.
@@ -31,7 +31,7 @@ static const char *region_type_name[] = {
[ PCI_REGION_TYPE_PREFMEM ] = "prefmem",
};
-static struct pci_bus {
+struct pci_bus {
struct {
/* pci region stats */
u32 count[32 - PCI_MEM_INDEX_SHIFT];
@@ -42,8 +42,7 @@ static struct pci_bus {
u32 bases[32 - PCI_MEM_INDEX_SHIFT];
u32 base;
} r[PCI_REGION_TYPE_COUNT];
-} *busses;
-static int busses_count;
+};
static int pci_size_to_index(u32 size, enum pci_region_type type)
{
@@ -313,7 +312,6 @@ pci_bios_init_bus(void)
{
u8 pci_bus = 0;
pci_bios_init_bus_rec(0 /* host bus */, &pci_bus);
- busses_count = pci_bus + 1;
}
@@ -362,21 +360,15 @@ static void pci_bios_bus_reserve(struct pci_bus *bus, int type, u32 size)
bus->r[type].max = size;
}
-static void pci_bios_check_device(struct pci_device *dev)
+static void pci_bios_check_device(struct pci_bus *busses, struct pci_device *dev)
{
struct pci_bus *bus = &busses[pci_bdf_to_bus(dev->bdf)];
if (dev->class == PCI_CLASS_BRIDGE_PCI) {
- if (dev->secondary_bus >= busses_count) {
- /* should never trigger */
- dprintf(1, "PCI: bus count too small (%d), skipping bus #%d\n",
- busses_count, dev->secondary_bus);
- return;
- }
dprintf(1, "PCI: check devices bus %d\n", dev->secondary_bus);
struct pci_device *pci;
foreachchildpci(pci, dev) {
- pci_bios_check_device(pci);
+ pci_bios_check_device(busses, pci);
}
struct pci_bus *s = &busses[dev->secondary_bus];
@@ -420,7 +412,7 @@ static void pci_bios_check_device(struct pci_device *dev)
#define ROOT_BASE(top, sum, max) ALIGN_DOWN((top)-(sum),(max) ?: 1)
// Setup region bases (given the regions' size and alignment)
-static int pci_bios_init_root_regions(u32 start, u32 end)
+static int pci_bios_init_root_regions(struct pci_bus *busses, u32 start, u32 end)
{
struct pci_bus *bus = &busses[0];
@@ -482,7 +474,7 @@ static u32 pci_bios_bus_get_addr(struct pci_bus *bus, int type, u32 size)
#define PCI_MEMORY_SHIFT 16
#define PCI_PREF_MEMORY_SHIFT 16
-static void pci_bios_map_device(struct pci_device *dev)
+static void pci_bios_map_device(struct pci_bus *busses, struct pci_device *dev)
{
struct pci_bus *bus = &busses[pci_bdf_to_bus(dev->bdf)];
u16 bdf = dev->bdf;
@@ -491,9 +483,6 @@ static void pci_bios_map_device(struct pci_device *dev)
, pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf), pci_bdf_to_fn(bdf));
if (dev->class == PCI_CLASS_BRIDGE_PCI) {
- if (dev->secondary_bus >= busses_count) {
- return;
- }
struct pci_bus *s = &busses[dev->secondary_bus];
int type;
for (type = 0; type < PCI_REGION_TYPE_COUNT; type++) {
@@ -523,7 +512,7 @@ static void pci_bios_map_device(struct pci_device *dev)
struct pci_device *pci;
foreachchildpci(pci, dev) {
- pci_bios_map_device(pci);
+ pci_bios_map_device(busses, pci);
}
return;
}
@@ -577,13 +566,17 @@ pci_setup(void)
pci_probe_devices();
dprintf(1, "=== PCI new allocation pass #1 ===\n");
- busses = malloc_tmp(sizeof(*busses) * busses_count);
- memset(busses, 0, sizeof(*busses) * busses_count);
+ struct pci_bus *busses = malloc_tmp(sizeof(*busses) * 256);
+ if (!busses) {
+ warn_noalloc();
+ return;
+ }
+ memset(busses, 0, sizeof(*busses) * 256);
struct pci_device *pci;
foreachhostpci(pci) {
- pci_bios_check_device(pci);
+ pci_bios_check_device(busses, pci);
}
- if (pci_bios_init_root_regions(start, end) != 0) {
+ if (pci_bios_init_root_regions(busses, start, end) != 0) {
panic("PCI: out of address space\n");
}
@@ -591,11 +584,10 @@ pci_setup(void)
dprintf(1, "PCI: init bases bus 0 (primary)\n");
pci_bios_init_bus_bases(&busses[0]);
foreachhostpci(pci) {
- pci_bios_map_device(pci);
+ pci_bios_map_device(busses, pci);
}
pci_bios_init_devices();
free(busses);
- busses_count = 0;
}
--
1.7.6.2
More information about the SeaBIOS
mailing list