Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1827405pxb; Mon, 20 Sep 2021 06:18:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwY1iQWmUQZZFj6xctl8BNRKygMCq6NOLFIXJ4m/4TmGeIBaT0O2XfmmGS5lSwOF1KnGWw X-Received: by 2002:a05:6402:21c6:: with SMTP id bi6mr19781444edb.372.1632143922813; Mon, 20 Sep 2021 06:18:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632143922; cv=none; d=google.com; s=arc-20160816; b=DQba3M6w87MYKjFkJ0eDcj+ocBlo5H2zwZuq4STwispZxZSXVsZyoSq/ngCY9bW+sx PSS77XENJbMd+2mF7FWuz6K7UaqXIqKzx3yed00F620F/lTVw3HXHWKyuevFFpvU60jq gRsr1D+fb9MPDQ1fyvziaLeHTDDNJWBo64nFn/i6JtWxCIRx8w9usptZue8nf3YRHxXL dlDlxjRbaowYlq+5VpX5cqKcd6YLKJKgLmeh2sD6QyoBToC6zELJwZ6AXqCkM9hTozOx 59PGqrh7HdKL5y0TSWaD+HoVajJRsXjeajKMAEkqavK8qZ22co7OBCpAdVBonL3LAENQ 9p0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date; bh=u2FpdIKlkPoz102M2pfWwYvGCTjJkecklZ6LhapdzoM=; b=KmU7s6HTga8zdI2vKWXI8O8bn/olu3f2OUPDMzEDTlc68RN12dfuHH1kSU5XUWlyGN USbJAK7vNt0ZLRi1wVlgwqtliSaBYf5nh+47OamMXwXIeoag7WRuHpa0J1KqM7Q121yw 5bmoHtkAEffRm8fvxObYof0uG+hbQ/ywgC2UDdFnHAiC9IRaFtAkn8EfmjFVvw+sRil6 wBfqgp2GylUa42skVSqvL2KOBXKHUCPniBLWpZ83FJOj3Kzo34tX+aXuY45TWWq0dTxY 2Z4zO/4r3x04456VvWq0iqUt3TiYWXNIsEmCfJb0xz5AOdEURJ6yH+kA3FD8WpdTc1Ba +1Hw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j25si16119686eje.334.2021.09.20.06.18.15; Mon, 20 Sep 2021 06:18:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236079AbhITI5h (ORCPT + 99 others); Mon, 20 Sep 2021 04:57:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:48232 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236070AbhITI5g (ORCPT ); Mon, 20 Sep 2021 04:57:36 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DA34560ED8; Mon, 20 Sep 2021 08:56:09 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mSF5r-00Bivk-Tp; Mon, 20 Sep 2021 09:56:07 +0100 Date: Mon, 20 Sep 2021 09:56:07 +0100 Message-ID: <8735pzwrq0.wl-maz@kernel.org> From: Marc Zyngier To: Kishon Vijay Abraham I Cc: Thomas Gleixner , Bjorn Helgaas , , , Lorenzo Pieralisi , Subject: Re: [PATCH 1/3] PCI: Add support in pci_walk_bus() to invoke callback matching RID In-Reply-To: <20210920064133.14115-2-kishon@ti.com> References: <20210920064133.14115-1-kishon@ti.com> <20210920064133.14115-2-kishon@ti.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: kishon@ti.com, tglx@linutronix.de, bhelgaas@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, lorenzo.pieralisi@arm.com, lokeshvutla@ti.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 20 Sep 2021 07:41:31 +0100, Kishon Vijay Abraham I wrote: > > Add two arguments to pci_walk_bus() [requestorID and mask], and add > support in pci_walk_bus() to invoke the *callback* only for devices > whose RequestorID after applying *mask* matches with *requestorID* > passed as argument. > > This is done in preparation for calculating the total number of > interrupt vectors that has to be supported by a specific GIC ITS device ID, > specifically when "msi-map-mask" is populated in device tree. > > Signed-off-by: Kishon Vijay Abraham I > --- > drivers/pci/bus.c | 13 +++++++++---- > include/linux/pci.h | 7 +++++-- > 2 files changed, 14 insertions(+), 6 deletions(-) > > diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c > index 3cef835b375f..e381e639ceaa 100644 > --- a/drivers/pci/bus.c > +++ b/drivers/pci/bus.c > @@ -358,10 +358,12 @@ void pci_bus_add_devices(const struct pci_bus *bus) > } > EXPORT_SYMBOL(pci_bus_add_devices); > > -/** pci_walk_bus - walk devices on/under bus, calling callback. > +/** __pci_walk_bus - walk devices on/under bus matching requestor ID, calling callback. > * @top bus whose devices should be walked > * @cb callback to be called for each device found > * @userdata arbitrary pointer to be passed to callback. > + * @rid Requestor ID that has to be matched for the callback to be invoked > + * @mask Mask that has to be applied to pci_dev_id(), before compating it with @rid > * > * Walk the given bus, including any bridged devices > * on buses under this bus. Call the provided callback > @@ -371,8 +373,8 @@ EXPORT_SYMBOL(pci_bus_add_devices); > * other than 0, we break out. > * > */ > -void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *), > - void *userdata) > +void __pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *), > + void *userdata, u32 rid, u32 mask) > { > struct pci_dev *dev; > struct pci_bus *bus; > @@ -399,13 +401,16 @@ void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *), > } else > next = dev->bus_list.next; > > + if (mask != 0xffff && ((pci_dev_id(dev) & mask) != rid)) Why the check for the mask? I also wonder whether the mask should apply to the rid as well: if ((pci_dev_id(dev) & mask) != (rid & mask)) > + continue; > + > retval = cb(dev, userdata); > if (retval) > break; > } > up_read(&pci_bus_sem); > } > -EXPORT_SYMBOL_GPL(pci_walk_bus); > +EXPORT_SYMBOL_GPL(__pci_walk_bus); > > struct pci_bus *pci_bus_get(struct pci_bus *bus) > { > diff --git a/include/linux/pci.h b/include/linux/pci.h > index cd8aa6fce204..8500fec56e50 100644 > --- a/include/linux/pci.h > +++ b/include/linux/pci.h > @@ -1473,14 +1473,17 @@ const struct pci_device_id *pci_match_id(const struct pci_device_id *ids, > int pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, > int pass); > > -void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *), > - void *userdata); > +void __pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *), > + void *userdata, u32 rid, u32 mask); > int pci_cfg_space_size(struct pci_dev *dev); > unsigned char pci_bus_max_busnr(struct pci_bus *bus); > void pci_setup_bridge(struct pci_bus *bus); > resource_size_t pcibios_window_alignment(struct pci_bus *bus, > unsigned long type); > > +#define pci_walk_bus(top, cb, userdata) \ > + __pci_walk_bus((top), (cb), (userdata), 0x0, 0xffff) Please keep this close to the helper it replaces. I also really dislike the use of this raw 0xffff. Don't we already have a named constant that represents the mask for a RID? Thanks, M. -- Without deviation from the norm, progress is not possible.