From: "Michael S. Tsirkin" <mst@redhat.com>
To: Isaku Yamahata <yamahata@valinux.co.jp>
Cc: skandasa@cisco.com, adhyas@gmail.com, etmartin@cisco.com,
qemu-devel@nongnu.org, wexu2@cisco.com
Subject: [Qemu-devel] Re: [PATCH v2 2/9] pcie: helper functions for pcie extended capability.
Date: Tue, 14 Sep 2010 14:23:18 +0200 [thread overview]
Message-ID: <20100914122318.GD703@redhat.com> (raw)
In-Reply-To: <20100914102915.GC29080@valinux.co.jp>
On Tue, Sep 14, 2010 at 07:29:15PM +0900, Isaku Yamahata wrote:
> On Wed, Sep 08, 2010 at 01:31:22PM +0300, Michael S. Tsirkin wrote:
> > > +/*
> > > + * RW1C: Write-1-to-clear
> > > + * regiger written val result
> > > + * 0 0 => 0
> > > + * 1 0 => 1
> > > + * 0 1 => 0
> > > + * 1 1 => 0
> > > + */
> > > +static inline void pcie_w1c_long(PCIDevice *d, uint32_t pos, uint32_t mask,
> > > + uint32_t addr, uint32_t val)
> > > +{
> > > + uint32_t written = pcie_written_val_long(addr, val, pos) & mask;
> > > + uint32_t reg = pci_get_long(d->config + pos);
> > > + reg &= ~written;
> > > + pci_set_long(d->config + pos, reg);
> > > +}
> > > +
> > > +static inline void pcie_w1c_word(PCIDevice *d, uint32_t pos, uint16_t mask,
> > > + uint32_t addr, uint32_t val)
> > > +{
> > > + uint16_t written = pcie_written_val_word(addr, val, pos) & mask;
> > > + uint16_t reg = pci_get_word(d->config + pos);
> > > + reg &= ~written;
> > > + pci_set_word(d->config + pos, reg);
> > > +}
> > > +
> >
> > So the SERR bit support IMO belongs in pci. And this means the W1C
> > inline functions need to move there.
> >
> > pci.c implemented this in a simpler way, by shifting
> > val by 8 bytes each time. Can we find a way to do it
> > in a similar way? I'll try to think about it.
>
> How about the following?
>
> diff --git a/hw/pci.c b/hw/pci.c
> index ceee291..6f1ce48 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -627,6 +627,7 @@ static void pci_config_alloc(PCIDevice *pci_dev)
> pci_dev->config = qemu_mallocz(config_size);
> pci_dev->cmask = qemu_mallocz(config_size);
> pci_dev->wmask = qemu_mallocz(config_size);
> + pci_dev->w1cmask = qemu_mallocz(config_size);
> pci_dev->used = qemu_mallocz(config_size);
> }
>
> @@ -635,6 +636,7 @@ static void pci_config_free(PCIDevice *pci_dev)
> qemu_free(pci_dev->config);
> qemu_free(pci_dev->cmask);
> qemu_free(pci_dev->wmask);
> + qemu_free(pci_dev->w1cmask);
> qemu_free(pci_dev->used);
> }
>
> @@ -997,7 +999,10 @@ void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int l)
>
> for (i = 0; i < l && addr + i < config_size; val >>= 8, ++i) {
> uint8_t wmask = d->wmask[addr + i];
> + uint8_t w1cmask = d->w1cmask[addr + i];
> + assert(!(wmask & w1cmask));
> d->config[addr + i] = (d->config[addr + i] & ~wmask) | (val & wmask);
> + d->config[addr + i] &= ~(val & w1cmask);
> }
> if (ranges_overlap(addr, l, PCI_BASE_ADDRESS_0, 24) ||
> ranges_overlap(addr, l, PCI_ROM_ADDRESS, 4) ||
> diff --git a/hw/pci.h b/hw/pci.h
> index e001f92..3509459 100644
> --- a/hw/pci.h
> +++ b/hw/pci.h
> @@ -132,6 +132,15 @@ struct PCIDevice {
> /* Used to implement R/W bytes */
> uint8_t *wmask;
>
> + /* Used to implement RW1C bytes
Just add (Write 1 to Clear) and that's clear enough
I think, the table in the comment is not really helpful.
> + * regiger written val result
regiger -> register :)
> + * 0 0 => 0
> + * 1 0 => 1
> + * 0 1 => 0
> + * 1 1 => 0
> + */
> + uint8_t *w1cmask;
> +
> /* Used to allocate config space for capabilities. */
> uint8_t *used;
It will definitely work. Does this help PCIE code as well?
If yes it's probably worth it. If no we could
do it just for SERR in a simple way like this:
for (i = 0; i < l && addr + i < config_size; val >>= 8, ++i) {
.... (existing code) ...
if (addr + i == PCI_COMMAND + 1 && (val & (PCI_COMMAND_SERR >> 8))) {
d->config[addr + i] &= ~(PCI_COMMAND_SERR >> 8);
}
}
> > > +int pci_pcie_cap_init(PCIDevice *dev,
> > > + uint8_t offset, uint8_t type, uint8_t port)
> >
> > I think we should have
> > pcie_init
> > that would init everything and be external,
> > and this one should be static, and this one
> > should be static.
>
> Ah, please take a look at Figure 7-10 if possible.
> Express capability structure is too complex to initialize
> by single function.
>
> So I introduce functions that applies to all devices,
> functions that applies to root complex,
> function that applies, ...
Sure, it's good to split to smaller functions,
but all these can be static so this would not affect
the external API, it can still be clean and simple.
--
MST
next prev parent reply other threads:[~2010-09-14 12:29 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-08 7:39 [Qemu-devel] [PATCH v2 0/9] pcie port switch emulators Isaku Yamahata
2010-09-08 7:39 ` [Qemu-devel] [PATCH v2 1/9] msi: implemented msi Isaku Yamahata
2010-09-08 9:13 ` [Qemu-devel] " Michael S. Tsirkin
2010-09-08 9:49 ` Isaku Yamahata
2010-09-08 7:39 ` [Qemu-devel] [PATCH v2 2/9] pcie: helper functions for pcie extended capability Isaku Yamahata
2010-09-08 10:31 ` [Qemu-devel] " Michael S. Tsirkin
2010-09-14 10:29 ` Isaku Yamahata
2010-09-14 12:23 ` Michael S. Tsirkin [this message]
2010-09-15 5:50 ` Isaku Yamahata
2010-09-15 13:05 ` Michael S. Tsirkin
2010-09-19 4:11 ` Isaku Yamahata
2010-09-19 11:51 ` Michael S. Tsirkin
2010-09-08 17:38 ` Wei Xu
2010-09-12 7:49 ` Blue Swirl
2010-09-12 13:26 ` Michael S. Tsirkin
2010-09-08 7:39 ` [Qemu-devel] [PATCH v2 3/9] pcie port: define struct PCIEPort/PCIESlot and helper functions Isaku Yamahata
2010-09-08 7:39 ` [Qemu-devel] [PATCH v2 4/9] pcie root port: implement pcie root port Isaku Yamahata
2010-09-08 7:39 ` [Qemu-devel] [PATCH v2 5/9] pcie upstream port: pci express switch upstream port Isaku Yamahata
2010-09-08 7:39 ` [Qemu-devel] [PATCH v2 6/9] pcie downstream port: pci express switch downstream port Isaku Yamahata
2010-09-08 7:39 ` [Qemu-devel] [PATCH v2 7/9] pcie/hotplug: glue pushing attention button command. pcie_abp Isaku Yamahata
2010-09-08 10:34 ` [Qemu-devel] " Michael S. Tsirkin
2010-09-09 3:43 ` Isaku Yamahata
2010-09-08 7:39 ` [Qemu-devel] [PATCH v2 8/9] pcie/aer: glue aer error injection into qemu monitor Isaku Yamahata
2010-09-08 7:39 ` [Qemu-devel] [PATCH v2 9/9] msix: clear not only INTA, but all INTx when MSI-X is enabled Isaku Yamahata
2010-09-08 10:33 ` [Qemu-devel] " 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=20100914122318.GD703@redhat.com \
--to=mst@redhat.com \
--cc=adhyas@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.