From: "Michael S. Tsirkin" <mst@redhat.com>
To: Isaku Yamahata <yamahata@valinux.co.jp>
Cc: skandasa@cisco.com, adnan@khaleel.us, etmartin@cisco.com,
qemu-devel@nongnu.org, wexu2@cisco.com
Subject: [Qemu-devel] Re: [PATCH v9 1/8] pci: revise pci command register initialization
Date: Tue, 16 Nov 2010 12:50:19 +0200 [thread overview]
Message-ID: <20101116105019.GB19668@redhat.com> (raw)
In-Reply-To: <f784da8cd1e993b58435ebba8b8d003c65e4192a.1289895735.git.yamahata@valinux.co.jp>
On Tue, Nov 16, 2010 at 05:26:05PM +0900, Isaku Yamahata wrote:
> This patch cleans up command register initialization with
> comments. It also fixes the initialization of io/memory bit of command register.
> Those bits for type 1 device is RW.
> Those bits for type 0 device is
> RO = 0 if it has no io/memory BAR
> RW if it has io/memory BAR
>
> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
There's a bug here: you can not assume that device that has
no io BAR claims no io transactions.
Another bug is that migrating from qemu where a bit is writeable to one
where it's RO creates a situation where a RW bit becomes RO, or the
reverse, which might confuse guests. So we will need a compatibility
flag and set it for old machine types.
> ---
> Changes v8 -> v9
> - patch squash
> ---
> hw/pci.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
> 1 files changed, 57 insertions(+), 1 deletions(-)
>
> diff --git a/hw/pci.c b/hw/pci.c
> index 962886e..2fc8ab1 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -544,8 +544,53 @@ static void pci_init_wmask(PCIDevice *dev)
>
> dev->wmask[PCI_CACHE_LINE_SIZE] = 0xff;
> dev->wmask[PCI_INTERRUPT_LINE] = 0xff;
> +
> + /*
> + * bit 0: PCI_COMMAND_IO
> + * type 0: if IO BAR is used, RW
> + * This is handled by pci_register_bar()
> + * type 1: RW:
> + * This is fixed by pci_init_wmask_bridge()
> + * bit 1: PCI_COMMAND_MEMORY
> + * type 0: if IO BAR is used, RW
> + * This is handled by pci_register_bar()
> + * type 1: RW
> + * This is fixed by pci_init_wmask_bridge()
> + * bit 2: PCI_COMMAND_MASTER
> + * type 0: RW if bus master
> + * type 1: RW
> + * bit 3: PCI_COMMAND_SPECIAL
> + * RO=0, optionally RW: Such device should set this bit itself
> + * bit 4: PCI_COMMAND_INVALIDATE
> + * RO=0, optionally RW: Such device should set this bit itself
> + * bit 5: PCI_COMMAND_VGA_PALETTE
> + * RO=0, optionally RW: Such device should set this bit itself
> + * bit 6: PCI_COMMAND_PARITY
> + * RW with exceptions: Such device should clear this bit itself
> + * Given that qemu doesn't emulate pci bus cycles, so that there
> + * is no place to generate parity error. So just making this
> + * register RW is okay because there is no place which refers
> + * this bit.
> + * TODO: When device assignment tried to inject PERR# into qemu,
> + * some extra work would be needed.
> + * bit 7: PCI_COMMAND_WAIT: reserved (PCI 3.0)
> + * RO=0
> + * bit 8: PCI_COMMAND_SERR
> + * RW with exceptions: Such device should clear this bit itself
> + * Given that qemu doesn't emulate pci bus cycles, so that there
> + * is no place to generate system error. So just making this
> + * register RW is okay because there is no place which refers
> + * this bit.
> + * TODO: When device assignment tried to inject SERR# into qemu,
> + * some extra work would be needed.
> + * bit 9: PCI_COMMAND_FAST_BACK
> + * RO=0, optionally RW: Such device should set this bit itself
> + * bit 10: PCI_COMMAND_INTX_DISABLE
> + * RW
> + * bit 11-15: reserved
> + */
Let's document non-obvious things, like maybe COMMAND_PARITY/COMMAND_SERR.
I don't cherish writing each bit up in two places.
> pci_set_word(dev->wmask + PCI_COMMAND,
> - PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
> + PCI_COMMAND_MASTER | PCI_COMMAND_PARITY | PCI_COMMAND_SERR |
> PCI_COMMAND_INTX_DISABLE);
>
> memset(dev->wmask + PCI_CONFIG_HEADER_SIZE, 0xff,
> @@ -554,6 +599,9 @@ static void pci_init_wmask(PCIDevice *dev)
>
> static void pci_init_wmask_bridge(PCIDevice *d)
> {
> + pci_word_test_and_set_mask(d->wmask + PCI_COMMAND,
> + PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
> +
> /* PCI_PRIMARY_BUS, PCI_SECONDARY_BUS, PCI_SUBORDINATE_BUS and
> PCI_SEC_LETENCY_TIMER */
> memset(d->wmask + PCI_PRIMARY_BUS, 0xff, 4);
> @@ -791,6 +839,14 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num,
> if (region_num == PCI_ROM_SLOT) {
> /* ROM enable bit is writeable */
> wmask |= PCI_ROM_ADDRESS_ENABLE;
> + } else {
> + if (r->type & PCI_BASE_ADDRESS_SPACE_IO) {
> + pci_word_test_and_set_mask(pci_dev->wmask + PCI_COMMAND,
> + PCI_COMMAND_IO);
> + } else {
> + pci_word_test_and_set_mask(pci_dev->wmask + PCI_COMMAND,
> + PCI_COMMAND_MEMORY);
> + }
> }
> pci_set_long(pci_dev->config + addr, type);
> if (!(r->type & PCI_BASE_ADDRESS_SPACE_IO) &&
> --
> 1.7.1.1
next prev parent reply other threads:[~2010-11-16 10:50 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-16 8:26 [Qemu-devel] [PATCH v9 0/8] pcie port switch emulators Isaku Yamahata
2010-11-16 8:26 ` [Qemu-devel] [PATCH v9 1/8] pci: revise pci command register initialization Isaku Yamahata
2010-11-16 10:50 ` Michael S. Tsirkin [this message]
2010-11-17 2:03 ` [Qemu-devel] " Isaku Yamahata
2010-11-17 12:02 ` Michael S. Tsirkin
2010-11-18 2:08 ` Isaku Yamahata
2010-11-18 6:42 ` Michael S. Tsirkin
2010-11-16 8:26 ` [Qemu-devel] [PATCH v9 2/8] pci: fix accesses to pci status register Isaku Yamahata
2010-11-16 10:52 ` [Qemu-devel] " Michael S. Tsirkin
2010-11-17 4:17 ` Isaku Yamahata
2010-11-16 8:26 ` [Qemu-devel] [PATCH v9 3/8] pci: clean up of " Isaku Yamahata
2010-11-16 14:01 ` [Qemu-devel] " Michael S. Tsirkin
2010-11-16 8:26 ` [Qemu-devel] [PATCH v9 4/8] pcie_regs.h: more constants Isaku Yamahata
2010-11-16 8:26 ` [Qemu-devel] [PATCH v9 5/8] pcie/aer: helper functions for pcie aer capability Isaku Yamahata
2010-11-17 14:06 ` [Qemu-devel] [PATCH 0/2] " Michael S. Tsirkin
2010-11-17 14:06 ` [Qemu-devel] [PATCH 1/2] pcie_aer: get rid of recursion Michael S. Tsirkin
2010-11-17 14:06 ` [Qemu-devel] [PATCH 2/2] pcie_aer: complete unwinding recursion Michael S. Tsirkin
2010-11-18 8:11 ` [Qemu-devel] Re: [PATCH 0/2] Re: [PATCH v9 5/8] pcie/aer: helper functions for pcie aer capability Isaku Yamahata
2010-11-18 8:52 ` Michael S. Tsirkin
2010-11-19 9:42 ` Isaku Yamahata
2010-11-19 12:03 ` Michael S. Tsirkin
2010-11-16 8:26 ` [Qemu-devel] [PATCH v9 6/8] ioh3420: support aer Isaku Yamahata
2010-11-16 8:26 ` [Qemu-devel] [PATCH v9 7/8] x3130/upstream: " Isaku Yamahata
2010-11-16 8:26 ` [Qemu-devel] [PATCH v9 8/8] x3130/downstream: " Isaku Yamahata
[not found] ` <1289930315.27724.18.camel@etmartin-lnx>
2010-11-16 18:57 ` [Qemu-devel] " Etienne Martineau
2010-11-17 4:07 ` Isaku Yamahata
2010-11-17 5:31 ` Etienne Martineau
2010-11-18 2:19 ` Isaku Yamahata
2010-11-17 14:38 ` [Qemu-devel] Re: [PATCH v9 0/8] pcie port switch emulators Michael S. Tsirkin
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=20101116105019.GB19668@redhat.com \
--to=mst@redhat.com \
--cc=adnan@khaleel.us \
--cc=etmartin@cisco.com \
--cc=qemu-devel@nongnu.org \
--cc=skandasa@cisco.com \
--cc=wexu2@cisco.com \
--cc=yamahata@valinux.co.jp \
/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).