From patchwork Tue Oct 29 02:11:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jordan Niethe X-Patchwork-Id: 1185800 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 472FTH02BRz9sPV for ; Tue, 29 Oct 2019 13:12:02 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="I+hZHg7c"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 472FTG2MJczDwND for ; Tue, 29 Oct 2019 13:12:02 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::443; helo=mail-pf1-x443.google.com; envelope-from=jniethe5@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="I+hZHg7c"; dkim-atps=neutral Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 472FT31GsZzDsNc for ; Tue, 29 Oct 2019 13:11:50 +1100 (AEDT) Received: by mail-pf1-x443.google.com with SMTP id b25so8345238pfi.13 for ; Mon, 28 Oct 2019 19:11:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i9wkK+6kxgPBxGGqzq6MQigHvA+oXKB9h/YN19OvJO4=; b=I+hZHg7crYZ6gzqSrFodC3jH2US86KGPozVVUeUdsaYDvkcY0LiSMmP87UcT89hPTL kMoEEKSVC8yrdaAo95Ol2d380wIWgtlXA4jKsqZO+jD4Z+uxjaBehEpWdNVXL/dHn+/e cJY1ANNk03cxdh2DGNr2WHbPyRKL7wSb0f5tjPWgcrS5n5TZf6h5tmvWFtL/n0p7O/Z8 v5DvmY33nhFuVCPKW2Pr0KhV8bEcGBYW2ZrK4dcu0PBrqRZDvsdCbhacz/lNsBx25R1v ZigYTSnx86QugGyMvBEoC/iNec0r3iqaAC+OYwUFTGY/HRiYS2WK0/X0lS64Q8bG0Nmf 3Tpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=i9wkK+6kxgPBxGGqzq6MQigHvA+oXKB9h/YN19OvJO4=; b=nk50TmEAawJG8oSoEqzjdMMHnkLID35TDNYosVMFzpef2chLXYoH1NDznxczlggnS+ RuZC7T1k6J46IT2h3vM7YS4I9Iwbs4XGgE1RutldGGmbZEh8rH+rJwMSgjUglw+UXIkk Sn+pvEkXjiogNgDo4PP4YaePuroQJro+Jnqydx+HEjKfJpXmNcHLVtxzfN9JTVYC+807 12Du2iLkqQZ6F8NMUOLZNpL8LQdxNhwJzMmYjyNEMlIkBhAOqG3ZkoDgcv5tqC0GAoop BwSG6pMbLt+nT6s4qwrnXOinFo28pJMQoLRFwHjmlIJ+Uejk/omMtTYFRWkR692lcxhG tpQQ== X-Gm-Message-State: APjAAAWoyaBLN0CStU5SN9Qt+2e5RPcABAO7GhJviy3UN8pUhO8+gZ0D k51ie4CaX5VdRIWI/R7rxnemba3Q X-Google-Smtp-Source: APXvYqygL9exQTgSFBD+lyNgN0X6mMfTMQbXAGivfqoGp112E3Fp5+mcrQLqFbvCFZFyYDAydKu90w== X-Received: by 2002:a63:fa4a:: with SMTP id g10mr23569797pgk.432.1572315108373; Mon, 28 Oct 2019 19:11:48 -0700 (PDT) Received: from sol.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id w14sm13710999pge.56.2019.10.28.19.11.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2019 19:11:47 -0700 (PDT) From: Jordan Niethe To: skiboot@lists.ozlabs.org Date: Tue, 29 Oct 2019 13:11:04 +1100 Message-Id: <20191029021106.29396-2-jniethe5@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191029021106.29396-1-jniethe5@gmail.com> References: <20191029021106.29396-1-jniethe5@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [RFC PATCH v2 1/3] core/pci: Add functions for iterating PCI devices X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Currently to visit all the devices under a PHB/PCI device the recursive pci_walk_dev() function is used. This does not make the state of where the walk is up to accessible which limits how it can be used. For example we might like to visit each device and perform tasks that require waiting. Rather than waiting in skiboot we would like to be able to return a timeout value to the caller. This requires keeping the state of the walk so that we can return to the device after waiting. To do this give each pci_device a member to record if it has been visited or not and add a member to each PHB to keep track of the current PCI device in the walk. Signed-off-by: Jordan Niethe --- v2: No changes core/pci.c | 37 +++++++++++++++++++++++++++++++++++++ include/pci.h | 6 ++++++ 2 files changed, 43 insertions(+) diff --git a/core/pci.c b/core/pci.c index 9ee70f4fddc5..547c8e32272b 100644 --- a/core/pci.c +++ b/core/pci.c @@ -1889,6 +1889,43 @@ struct pci_device *pci_find_dev(struct phb *phb, uint16_t bdfn) return pci_walk_dev(phb, NULL, __pci_find_dev, &bdfn); } +static int __pci_unsee_device(struct phb *phb, + struct pci_device *pd, + void *data __unused) +{ + if (!phb || !pd) { + return 0; + } + + pd->seen = false; + return 0; +} + +void pci_device_iter_reset(struct phb *phb, struct pci_device *pd) +{ + pci_walk_dev(phb, pd, __pci_unsee_device, NULL); +} + +static int __pci_device_iter_next(struct phb *phb, + struct pci_device *pd, + void *data __unused) +{ + if (!phb || !pd) { + return 0; + } + + if (pd->seen) + return 0; + + pd->seen = true; + return 1; +} + +struct pci_device *pci_device_iter_next(struct phb *phb, struct pci_device *pd) +{ + return pci_walk_dev(phb, pd, __pci_device_iter_next, NULL); +} + static int __pci_restore_bridge_buses(struct phb *phb, struct pci_device *pd, void *data __unused) diff --git a/include/pci.h b/include/pci.h index dcd354a7cfef..9672a2d342f6 100644 --- a/include/pci.h +++ b/include/pci.h @@ -75,6 +75,7 @@ struct pci_device { bool is_bridge; bool is_multifunction; bool is_vf; + bool seen; uint8_t dev_type; /* PCIE */ uint8_t primary_bus; uint8_t secondary_bus; @@ -378,6 +379,9 @@ struct phb { /* PCI-X only slot info, for PCI-E this is in the RC bridge */ struct pci_slot *slot; + /* Used for iteration */ + struct pci_device *current_pd; + /* Base location code used to generate the children one */ const char *base_loc_code; @@ -451,6 +455,8 @@ extern void pci_init_capabilities(struct phb *phb, struct pci_device *pd); extern bool pci_wait_crs(struct phb *phb, uint16_t bdfn, uint32_t *out_vdid); extern void pci_restore_slot_bus_configs(struct pci_slot *slot); extern void pci_device_init(struct phb *phb, struct pci_device *pd); +extern void pci_device_iter_reset(struct phb *phb, struct pci_device *pd); +extern struct pci_device *pci_device_iter_next(struct phb *phb, struct pci_device *pd); extern struct pci_device *pci_walk_dev(struct phb *phb, struct pci_device *pd, int (*cb)(struct phb *,