qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Tom Yan <tom.ty89@gmail.com>
To: qemu-devel@nongnu.org, mst@redhat.com
Cc: marcel@redhat.com, yamahata@valinux.co.jp, Tom Yan <tom.ty89@gmail.com>
Subject: [PATCH 2/3] pcie_chassis: add slot_max field
Date: Thu,  1 Apr 2021 00:08:34 +0800	[thread overview]
Message-ID: <20210331160835.160670-2-tom.ty89@gmail.com> (raw)
In-Reply-To: <20210331160835.160670-1-tom.ty89@gmail.com>

Keep track of the largested allocated slot number when adding slot.

Signed-off-by: Tom Yan <tom.ty89@gmail.com>
---
 hw/pci/pcie_port.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/hw/pci/pcie_port.c b/hw/pci/pcie_port.c
index 40fd80c4da..1e2348250c 100644
--- a/hw/pci/pcie_port.c
+++ b/hw/pci/pcie_port.c
@@ -49,6 +49,7 @@ void pcie_port_init_reg(PCIDevice *d)
  */
 struct PCIEChassis {
     uint8_t     number;
+    uint16_t    slot_max; // largest allocated slot number
 
     QLIST_HEAD(, PCIESlot) slots;
     QLIST_ENTRY(PCIEChassis) next;
@@ -94,19 +95,11 @@ static PCIESlot *pcie_chassis_find_slot_with_chassis(struct PCIEChassis *c,
 
 static void pcie_chassis_find_avail_slot_with_chassis(struct PCIEChassis *c, struct PCIESlot *slot)
 {
-    PCIESlot *s;
-    uint16_t slot_max = 0;
-    QLIST_FOREACH(s, &c->slots, next) {
-        if (s->slot > slot_max) {
-            slot_max = s->slot;
-        }
-    }
-
     /*
       find an available number to use from slot->slot (inclusive) to
-      slot_max; if there is none, use slot_max+1
+      c->slot_max; if there is none, use c->slot_max+1
     */
-    while (slot->slot <= slot_max) {
+    while (slot->slot <= c->slot_max) {
         if (!pcie_chassis_find_slot_with_chassis(c, slot->slot)) {
             break;
         }
@@ -137,6 +130,8 @@ int pcie_chassis_add_slot(struct PCIESlot *slot)
         return -EBUSY;
     }
     QLIST_INSERT_HEAD(&c->slots, slot, next);
+    if (slot->slot > c->slot_max)
+        c->slot_max = slot->slot;
     return 0;
 }
 
-- 
2.31.1



  reply	other threads:[~2021-03-31 16:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-31 16:08 [PATCH 1/3] pcie_chassis: use an available slot number if not explicity set Tom Yan
2021-03-31 16:08 ` Tom Yan [this message]
2021-03-31 16:08 ` [PATCH 3/3] pcie_root_port: reorder procedures in realize() Tom Yan

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=20210331160835.160670-2-tom.ty89@gmail.com \
    --to=tom.ty89@gmail.com \
    --cc=marcel@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=yamahata@valinux.co.jp \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).