mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Dirk Brandewie <dirk.brandewie@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	Dirk Brandewie <dirk.j.brandewie@intel.com>,
	x86@kernel.org
Subject: Re: [PATCH 2/6] ce4100: add PCI register emulation for CE4100
Date: Thu, 11 Nov 2010 12:51:27 +0100 (CET)	[thread overview]
Message-ID: <alpine.LFD.2.00.1011111247570.2900@localhost6.localdomain6> (raw)
In-Reply-To: <40b6751381c2275dc359db5a17989cce22ad8db7.1289331834.git.dirk.brandewie@gmail.com>

On Tue, 9 Nov 2010, dirk.brandewie@gmail.com wrote:
> +
> +static int ce4100_conf_read(unsigned int seg, unsigned int bus,
> +			  unsigned int devfn, int reg, int len, u32 *value)
> +{
> +	int retval = 1;
> +	int i;
> +
> +	if (bus == 0 && (PCI_DEVFN(1, 0) == devfn))
> +		retval = bridge_read(devfn, reg, len, value);
> +
> +	if (bus == 1) {
> +		for (i = 0; i < num_bus1_fixups; i++) {
> +			if (bus1_fixups[i].dev_func == devfn &&
> +				bus1_fixups[i].reg == (reg & ~3) &&
> +				bus1_fixups[i].read) {
> +				bus1_fixups[i].read(&(bus1_fixups[i]),
> +					value);
> +				extract_bytes(value, reg, len);
> +				retval = 0;

  Shouldn't we return 0 here and be done ?

> +			}
> +		}
> +	}
> +	if (retval)
> +		retval = pci_direct_conf1.read(seg, bus, devfn, reg,
> +					len, value);
> +	return retval;
> +}
> +
> +
> +static int ce4100_conf_write(unsigned int seg, unsigned int bus,
> +			   unsigned int devfn, int reg, int len, u32 value)
> +{
> +	int retval = 1;
> +	int i;
> +
> +	if (bus == 1) {
> +		for (i = 0; i < num_bus1_fixups; i++) {
> +			if (bus1_fixups[i].dev_func == devfn &&
> +				bus1_fixups[i].reg == (reg & ~3) &&
> +				bus1_fixups[i].write) {
> +				bus1_fixups[i].write(&(bus1_fixups[i]),
> +					value);
> +				retval = 0;

  Ditto

> +			}
> +		}
> +	}
> +
> +	/* Discard writes to A/V bridge BAR. */
> +	if (bus == 0 && PCI_DEVFN(1, 0) == devfn &&
> +		((reg & ~3) == PCI_BASE_ADDRESS_0))
> +		retval = 0;

  Ditto

> +
> +	if (retval)
> +		retval = pci_direct_conf1.write(seg, bus, devfn, reg,
> +						len, value);
> +	return retval;
> +}

It took me some time to grok the above retval magic. I'd rather write
it this way:

+static int ce4100_conf_read(unsigned int seg, unsigned int bus,
+			    unsigned int devfn, int reg, int len, u32 *value)
+{
+	int i;
+
+	if (bus == 1) {
+		for (i = 0; i < ARRAY_SIZE(bus1_fixups); i++) {
+			if (bus1_fixups[i].dev_func == devfn &&
+			    bus1_fixups[i].reg == (reg & ~3) &&
+			    bus1_fixups[i].read) {
+				bus1_fixups[i].read(&(bus1_fixups[i]),
+						    value);
+				extract_bytes(value, reg, len);
+				return 0;
+			}
+		}
+	}
+
+	if (bus == 0 && (PCI_DEVFN(1, 0) == devfn) &&
+	    !bridge_read(devfn, reg, len, value))
+		return 0;
+
+	return pci_direct_conf1.read(seg, bus, devfn, reg, len, value);
+}
+
+static int ce4100_conf_write(unsigned int seg, unsigned int bus,
+			     unsigned int devfn, int reg, int len, u32 value)
+{
+	int i;
+
+	if (bus == 1) {
+		for (i = 0; i < ARRAY_SIZE(bus1_fixups); i++) {
+			if (bus1_fixups[i].dev_func == devfn &&
+			    bus1_fixups[i].reg == (reg & ~3) &&
+			    bus1_fixups[i].write) {
+				bus1_fixups[i].write(&(bus1_fixups[i]),
+						     value);
+				return 0;
+			}
+		}
+	}
+
+	/* Discard writes to A/V bridge BAR. */
+	if (bus == 0 && PCI_DEVFN(1, 0) == devfn &&
+	    ((reg & ~3) == PCI_BASE_ADDRESS_0))
+		return 0;
+
+	return pci_direct_conf1.write(seg, bus, devfn, reg, len, value);
+}

Thanks,

	tglx

  reply	other threads:[~2010-11-11 11:51 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-09 20:08 [PATCH 0/6] Add support for the Intel CE4100 dirk.brandewie
2010-11-09 20:08 ` [PATCH 1/6] x86: Add CE4100 platform support dirk.brandewie
2010-11-09 20:08 ` [PATCH 2/6] ce4100: add PCI register emulation for CE4100 dirk.brandewie
2010-11-11 11:51   ` Thomas Gleixner [this message]
2010-11-09 20:08 ` [PATCH 3/6] serial/ce4100: Add PCI UART support for the ce4100 dirk.brandewie
2010-11-09 21:14   ` Greg KH
2010-11-09 21:54     ` Dirk Brandewie
2010-11-17 15:35   ` [PATCH] " dirk.brandewie
2010-11-09 20:08 ` [PATCH 4/6] ce4100: Add errata fixes for UART on CE4100 dirk.brandewie
2010-11-11 11:34   ` Thomas Gleixner
2010-11-11 11:52     ` Dirk Brandewie
2010-11-11 11:47       ` Thomas Gleixner
2010-11-11 12:10         ` Dirk Brandewie
2010-11-11 12:06           ` Thomas Gleixner
2010-11-22 14:28   ` [PATCH] " dirk.brandewie
2010-12-06 15:00     ` [tip:x86/platform] " tip-bot for Dirk Brandewie
2010-11-09 20:08 ` [PATCH 5/6] x86: ce4100: Add reboot_fixup() for CE4100 dirk.brandewie
2010-11-09 20:08 ` [PATCH 6/6] ce4100: Add support for CE4100 EHCI IP block to EHCI driver dirk.brandewie
2010-11-09 22:01   ` Dirk Brandewie
2010-11-10  2:36     ` Alan Stern
2010-11-10 10:51       ` Sergei Shtylyov
2010-11-16 21:46         ` Greg KH
2010-11-16 23:24           ` Dirk Brandewie
2010-11-17 15:43   ` [PATCH] " dirk.brandewie

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=alpine.LFD.2.00.1011111247570.2900@localhost6.localdomain6 \
    --to=tglx@linutronix.de \
    --cc=dirk.brandewie@gmail.com \
    --cc=dirk.j.brandewie@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=x86@kernel.org \
    /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

all inboxes | Powered by JetHome®