All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexey Korolev <alexey.korolev@endace.com>
To: Kevin O'Connor <kevin@koconnor.net>
Cc: sfd@endace.com, seabios@seabios.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 3/4] Switch from array based resource allocation to list
Date: Tue, 3 Apr 2012 18:39:22 +1200	[thread overview]
Message-ID: <4F7A9B1A.6090905@endace.com> (raw)
In-Reply-To: <20120401084415.GA7080@morn.localdomain>

Hi Kevin,

Thank you for the patches!
I've created a diff of final version of your changes over mine, to make it clear what has changed.

Rather than including the complete diff, I've just left relevant parts and added comments.

--- a/src/pciinit.c +++ b/src/pciinit.c@@ -12,8 +12,9 @@
........
@@ -34,25 +35,44 @@
 struct pci_region_entry {
     struct pci_device *dev;
     int bar;
-    u32 base;
     u32 size;
-    int is64bit;
+    int is64;
     enum pci_region_type type;
-    struct pci_bus *this_bus;
+    struct pci_bus *child_bus;

Structure members naming was one of difficult things when I was writing the code.
The child_bus might be a bit confusing as people may thing that it describes a
child bus in the bus topology,in fact this element describes the bus this pci_region_entry
is representing.

.......

+
+static int pci_size_to_index(u32 size, enum pci_region_type type)
+{
+    int index = __fls(size);
+    int shift = (type == PCI_REGION_TYPE_IO) ?
+        PCI_IO_INDEX_SHIFT : PCI_MEM_INDEX_SHIFT;
+
+    if (index < shift)
+        index = shift;
+    index -= shift;
+    return index;
+}
+
+static u32 pci_index_to_size(int index, enum pci_region_type type)
+{
+    int shift = (type == PCI_REGION_TYPE_IO) ?
+        PCI_IO_INDEX_SHIFT : PCI_MEM_INDEX_SHIFT;
+
+    return 0x1 << (index + shift);
+}

The only purpose to have these functions is to define the minimum size of pci BAR.
They are used only once.
What if we add size adjustment to pci_region_create_entry, or just create a function like
pci_adjust_size(u32 size, enum pci_region_type type, int bridge)?
 
.........

-    list_add_head(&bus->r[type].list, entry);
     entry->parent_bus = bus;
-
+    // Insert into list in sorted order.
+    struct pci_region_entry **pprev;
+    for (pprev = &bus->r[type].list; *pprev; pprev = &(*pprev)->next) {
+        struct pci_region_entry *pos = *pprev;
+        if (pos->size < size)
+            break;
+    }
+    entry->next = *pprev;
+    *pprev = entry;
+
..........
 static void pci_bios_map_devices(struct pci_bus *busses)
 {
-    struct pci_region_entry *entry, *next;
-
+    // Map regions on each device.
     int bus;
     for (bus = 0; bus<=MaxPCIBus; bus++) {
         int type;
         for (type = 0; type < PCI_REGION_TYPE_COUNT; type++) {
-            u32 size;
-            for (size = busses[bus].r[type].max; size > 0; size >>= 1) {
-                    list_foreach_entry_safe(busses[bus].r[type].list,
-                                              next, entry) {
-                        if (size == entry->size) {
-                            entry->base = busses[bus].r[type].base;
-                            busses[bus].r[type].base += size;
-                            pci_region_map_one_entry(entry);
-                            list_del(entry);
-                            free(entry);
-                    }
-                }
+            struct pci_region_entry *entry = busses[bus].r[type].list;
+            while (entry) {
+                pci_region_map_one_entry(entry);
+                struct pci_region_entry *next = entry->next;
+                free(entry);
+                entry = next;
             }
         }
     }
Right, instead of sorting entries by size in pci_bios_map_devices, the entries are sorted when they are created.
This makes the implementation simpler.
Note: In case of 64bit BARs we have to migrate entries, so just sorting on create won't be enough,
we should also add sorting when entries are migrated. This will add some more complexity, while in case of old
implementation complexity will remain the same. I expect it shouldn't be that complicated, so any of these approaches
are fine for me.

  reply	other threads:[~2012-04-03  6:40 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-28  4:25 [Qemu-devel] [PATCH 0/4] Redesign of pciinit.c (take 3) Alexey Korolev
2012-03-28  4:28 ` [Qemu-devel] [PATCH 1/4] Add basic linked list operations Alexey Korolev
2012-03-28 14:39   ` [Qemu-devel] [SeaBIOS] " Gerd Hoffmann
2012-03-29  2:03     ` Alexey Korolev
2012-03-29  2:27     ` Kevin O'Connor
2012-03-29 10:41       ` Ian Campbell
2012-03-28  4:41 ` [Qemu-devel] [PATCH 2/4] Added a pci_region_entry structure Alexey Korolev
2012-03-28  4:54 ` [Qemu-devel] [PATCH 3/4] Switch from array based resource allocation to list Alexey Korolev
2012-04-01  7:28   ` Kevin O'Connor
2012-04-01  8:44     ` Kevin O'Connor
2012-04-03  6:39       ` Alexey Korolev [this message]
2012-04-04  3:31         ` Kevin O'Connor
2012-03-28  4:56 ` [Qemu-devel] [PATCH 4/4] Get rid of size element of pci_bus->r structure Alexey Korolev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F7A9B1A.6090905@endace.com \
    --to=alexey.korolev@endace.com \
    --cc=kevin@koconnor.net \
    --cc=qemu-devel@nongnu.org \
    --cc=seabios@seabios.org \
    --cc=sfd@endace.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.