From: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
To: Hu Tao <hutao@cn.fujitsu.com>
Cc: qemu-devel@nongnu.org, "Michael S. Tsirkin" <mst@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 1/5] pci: introduce PC_PCI_CONFIG_ENABLED()
Date: Tue, 04 Nov 2014 15:41:11 +0200 [thread overview]
Message-ID: <1415108471.2327.44.camel@localhost.localdomain> (raw)
In-Reply-To: <27c47334bab155b7219a6fcc4547701e2a6e2060.1415091929.git.hutao@cn.fujitsu.com>
Hi,
On Tue, 2014-11-04 at 17:12 +0800, Hu Tao wrote:
> This makes code more readable.
>
> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
> ---
> hw/mips/gt64xxx_pci.c | 4 ++--
> hw/pci/pci_host.c | 5 +++--
> include/hw/pci/pci.h | 2 ++
> 3 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/hw/mips/gt64xxx_pci.c b/hw/mips/gt64xxx_pci.c
> index 1f2fe5f..a49dbd7 100644
> --- a/hw/mips/gt64xxx_pci.c
> +++ b/hw/mips/gt64xxx_pci.c
> @@ -564,7 +564,7 @@ static void gt64120_writel (void *opaque, hwaddr addr,
> if (!(s->regs[GT_PCI0_CMD] & 1) && (phb->config_reg & 0x00fff800)) {
> val = bswap32(val);
> }
> - if (phb->config_reg & (1u << 31)) {
> + if (PC_PCI_CONFIG_ENABLED(phb->config_reg))
I really like readable MACROS instead of magic numbers,
however I have 3 suggestions:
1. PC_PCI_CONFIG_ENABLED is still not really clear, because
of the "PC" prefix that is too wide in my IMHO (maybe PCI_HOST_BRIDGE_CONFIG_ENABLED)
when this macro refers only to host bridges.
2. Maybe go the "extra mile" and let the macro receive
a host bridge as parameter PCI_HOST_BRIDGE_CONFIG_ENABLED(host_bridge).
3. Maybe make it an inline function? Just wondering
> pci_data_write(phb->bus, phb->config_reg, val, 4);
> }
> break;
> @@ -804,7 +804,7 @@ static uint64_t gt64120_readl (void *opaque,
> val = phb->config_reg;
> break;
> case GT_PCI0_CFGDATA:
> - if (!(phb->config_reg & (1 << 31))) {
> + if (!PC_PCI_CONFIG_ENABLED(phb->config_reg)) {
> val = 0xffffffff;
> } else {
> val = pci_data_read(phb->bus, phb->config_reg, 4);
> diff --git a/hw/pci/pci_host.c b/hw/pci/pci_host.c
> index 3e26f92..f2a69ea 100644
> --- a/hw/pci/pci_host.c
> +++ b/hw/pci/pci_host.c
> @@ -133,8 +133,9 @@ static void pci_host_data_write(void *opaque, hwaddr addr,
> PCIHostState *s = opaque;
> PCI_DPRINTF("write addr " TARGET_FMT_plx " len %d val %x\n",
> addr, len, (unsigned)val);
> - if (s->config_reg & (1u << 31))
> + if (PC_PCI_CONFIG_ENABLED(s->config_reg)) {
> pci_data_write(s->bus, s->config_reg | (addr & 3), val, len);
> + }
> }
>
> static uint64_t pci_host_data_read(void *opaque,
> @@ -142,7 +143,7 @@ static uint64_t pci_host_data_read(void *opaque,
> {
> PCIHostState *s = opaque;
> uint32_t val;
> - if (!(s->config_reg & (1U << 31))) {
> + if (!PC_PCI_CONFIG_ENABLED(s->config_reg)) {
> return 0xffffffff;
> }
> val = pci_data_read(s->bus, s->config_reg | (addr & 3), len);
> diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
> index c352c7b..3d42d7f 100644
> --- a/include/hw/pci/pci.h
> +++ b/include/hw/pci/pci.h
> @@ -13,6 +13,8 @@
>
> #include "hw/pci/pcie.h"
>
> +#define PC_PCI_CONFIG_ENABLED(addr) (addr & (1U << 31))
Again, maybe move this to "hw/pci/pci_host" since is specific to host bridges?
Thanks,
Marcel
> +
> /* PCI bus */
>
> #define PCI_DEVFN(slot, func) ((((slot) & 0x1f) << 3) | ((func) & 0x07))
next prev parent reply other threads:[~2014-11-04 13:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-04 9:12 [Qemu-devel] [PATCH 0/5] Some PCI related cleanup patches Hu Tao
2014-11-04 9:12 ` [Qemu-devel] [PATCH 1/5] pci: introduce PC_PCI_CONFIG_ENABLED() Hu Tao
2014-11-04 13:41 ` Marcel Apfelbaum [this message]
2014-11-05 5:57 ` Hu Tao
2014-11-04 9:12 ` [Qemu-devel] [PATCH 2/5] pc: define PC_PCI_CONFIG_ADDR and PC_PCI_CONFIG_DATA Hu Tao
2014-11-04 13:44 ` Marcel Apfelbaum
2014-11-05 7:58 ` Hu Tao
2014-11-04 9:12 ` [Qemu-devel] [PATCH 3/5] pci: move initialization of pci's conf_addr and conf_data to common place Hu Tao
2014-11-04 14:21 ` Marcel Apfelbaum
2014-11-05 6:03 ` Hu Tao
2014-11-04 9:12 ` [Qemu-devel] [PATCH 4/5] pci: remove the limit parameter of pci_host_config_read_common Hu Tao
2014-11-04 9:12 ` [Qemu-devel] [PATCH 5/5] pci: remove the limit parameter of pci_host_config_write_common Hu Tao
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=1415108471.2327.44.camel@localhost.localdomain \
--to=marcel.apfelbaum@gmail.com \
--cc=hutao@cn.fujitsu.com \
--cc=marcel.a@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).