public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Cc: platform-driver-x86@vger.kernel.org,
	"Hans de Goede" <hdegoede@redhat.com>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Lukas Wunner" <lukas@wunner.de>,
	linux-pci@vger.kernel.org, linux-i2c@vger.kernel.org
Subject: Re: [PATCH v2] platform/x86: p2sb: Allow p2sb_bar() calls during PCI device probe
Date: Fri, 22 Dec 2023 16:36:44 +0200	[thread overview]
Message-ID: <ZYWe_P7-TkbaOl0k@smile.fi.intel.com> (raw)
In-Reply-To: <ZYWcRupBcrGCSgcb@smile.fi.intel.com>

On Fri, Dec 22, 2023 at 04:25:10PM +0200, Andy Shevchenko wrote:
> On Fri, Dec 22, 2023 at 04:20:54PM +0900, Shin'ichiro Kawasaki wrote:

...

> > +static int p2sb_scan_and_cache(struct pci_bus *bus, unsigned int devfn)
> > +{
> > +	unsigned int slot, fn;
> > +	int ret;
> > +
> > +	/* Scan the P2SB device and cache its BAR0 */
> > +	ret = p2sb_scan_and_cache_devfn(bus, devfn);
> > +	if (ret)
> > +		return ret;
> > +
> > +	/*
> > +	 * When function number of the P2SB device is zero, scan other function
> > +	 * numbers.
> > +	 */
> > +	if (PCI_FUNC(devfn) != 0)
> > +		return 0;
> > +
> > +	/* If devices are available, cache their BAR0 */
> > +	slot = PCI_SLOT(devfn);
> > +	for (fn = 1; fn < NR_P2SB_RES_CACHE; fn++)
> > +		p2sb_scan_and_cache_devfn(bus, PCI_DEVFN(slot, fn));
> > +
> > +	return 0;
> > +}
> 
> So, we can actually do the for-loop from index 0.
> 
> 	if (PCI_FUNC(devfn) == 0) {
> 		/*
> 		 * When function number of the P2SB device is zero, scan it
> 		 * and other function numbers, and if devices are available,
> 		 * cache their BAR0s.
> 		 */
> 		slot = PCI_SLOT(devfn);
> 
> // This will allow us to have something like pci_dev_for_each_func() in the future.
> 
> 		for (fn = 0; fn < NR_P2SB_RES_CACHE; fn++)
> 			p2sb_scan_and_cache_devfn(bus, PCI_DEVFN(slot, fn));
> 	} else {
> 		/* Scan the P2SB device and cache its BAR0 */
> 		ret = p2sb_scan_and_cache_devfn(bus, devfn);
> 		if (ret)
> 			return ret;
> 	}

Even going further

	if (PCI_FUNC(devfn) == 0) {
		/*
		 * When function number of the P2SB device is zero, scan it
		 * and other function numbers, and if devices are available,
		 * cache their BAR0s.
		 */
		slot = PCI_SLOT(devfn);
		for (fn = 0; fn < NR_P2SB_RES_CACHE; fn++)
			p2sb_scan_and_cache_devfn(bus, PCI_DEVFN(slot, fn));
	} else {
		/* Scan the P2SB device and cache its BAR0 */
		p2sb_scan_and_cache_devfn(bus, devfn);
	}

	return p2sb_valid_resource(&p2sb_resources[PCI_FUNC(devfn)]);

// With this it's maybe p2sb_scan_and_cache_devfn() can be void.

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2023-12-22 14:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-22  7:20 [PATCH v2] platform/x86: p2sb: Allow p2sb_bar() calls during PCI device probe Shin'ichiro Kawasaki
2023-12-22 14:25 ` Andy Shevchenko
2023-12-22 14:36   ` Andy Shevchenko [this message]
2023-12-25  6:10     ` Shinichiro Kawasaki

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=ZYWe_P7-TkbaOl0k@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=hdegoede@redhat.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=shinichiro.kawasaki@wdc.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox