From: Anthony Liguori <anthony@codemonkey.ws>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: yamahata@valinux.co.jp, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] pci: add accessors to get/set registers by mask
Date: Wed, 22 Feb 2012 12:46:46 -0600 [thread overview]
Message-ID: <4F453816.2020305@codemonkey.ws> (raw)
In-Reply-To: <20120221134128.GA7930@redhat.com>
On 02/21/2012 07:41 AM, Michael S. Tsirkin wrote:
> pci_regs.h specifies many registers by mask +
> shifted register values.
> There's always some duplication when using such:
> for example to override device type, we would need:
>
> pci_word_test_and_clear_mask(cap + PCI_EXP_FLAGS,
> PCI_EXP_FLAGS_TYPE);
> pci_word_test_and_set_mask(cap + PCI_EXP_FLAGS,
> PCI_EXP_TYPE_ENDPOINT<< (ffs(PCI_EXP_FLAGS_TYPE) - 1));
>
> Getting such registers also uses some duplication:
>
> word = pci_get_word(cap + PCI_EXP_FLAGS)& PCI_EXP_FLAGS_TYPE;
> if ((word>> ffs((PCI_EXP_FLAGS_TYPE) - 1)) == PCI_EXP_TYPE_ENDPOINT)
>
> Add API to access such registers in one line:
> pci_set_word_by_mask(cap + PCI_EXP_FLAGS, PCI_EXP_FLAGS_TYPE,
> PCI_EXP_TYPE_ENDPOINT)
>
> and
> word = pci_get_word_by_mask(cap + PCI_EXP_FLAGS, PCI_EXP_FLAGS_TYPE)
> if (word == PCI_EXP_TYPE_ENDPOINT)
>
> Signed-off-by: Michael S. Tsirkin<mst@redhat.com>
Applied. Thanks.
Regards,
Anthony Liguori
> ---
> hw/pci.h | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 61 insertions(+), 0 deletions(-)
>
> diff --git a/hw/pci.h b/hw/pci.h
> index 448c44e..1103838 100644
> --- a/hw/pci.h
> +++ b/hw/pci.h
> @@ -469,6 +469,67 @@ pci_quad_test_and_set_mask(uint8_t *config, uint64_t mask)
> return val& mask;
> }
>
> +/* Access a register specified by a mask */
> +static inline void
> +pci_set_byte_by_mask(uint8_t *config, uint8_t mask, uint8_t reg)
> +{
> + uint8_t val = pci_get_byte(config);
> + uint8_t rval = reg<< (ffs(mask) - 1);
> + pci_set_byte(config, (~mask& val) | (mask& rval));
> +}
> +
> +static inline uint8_t
> +pci_get_byte_by_mask(uint8_t *config, uint8_t mask)
> +{
> + uint8_t val = pci_get_byte(config);
> + return (val& mask)>> (ffs(mask) - 1);
> +}
> +
> +static inline void
> +pci_set_word_by_mask(uint8_t *config, uint16_t mask, uint16_t reg)
> +{
> + uint16_t val = pci_get_word(config);
> + uint16_t rval = reg<< (ffs(mask) - 1);
> + pci_set_word(config, (~mask& val) | (mask& rval));
> +}
> +
> +static inline uint16_t
> +pci_get_word_by_mask(uint8_t *config, uint16_t mask)
> +{
> + uint16_t val = pci_get_word(config);
> + return (val& mask)>> (ffs(mask) - 1);
> +}
> +
> +static inline void
> +pci_set_long_by_mask(uint8_t *config, uint32_t mask, uint32_t reg)
> +{
> + uint32_t val = pci_get_long(config);
> + uint32_t rval = reg<< (ffs(mask) - 1);
> + pci_set_long(config, (~mask& val) | (mask& rval));
> +}
> +
> +static inline uint32_t
> +pci_get_long_by_mask(uint8_t *config, uint32_t mask)
> +{
> + uint32_t val = pci_get_long(config);
> + return (val& mask)>> (ffs(mask) - 1);
> +}
> +
> +static inline void
> +pci_set_quad_by_mask(uint8_t *config, uint64_t mask, uint64_t reg)
> +{
> + uint64_t val = pci_get_quad(config);
> + uint64_t rval = reg<< (ffs(mask) - 1);
> + pci_set_quad(config, (~mask& val) | (mask& rval));
> +}
> +
> +static inline uint64_t
> +pci_get_quad_by_mask(uint8_t *config, uint64_t mask)
> +{
> + uint64_t val = pci_get_quad(config);
> + return (val& mask)>> (ffs(mask) - 1);
> +}
> +
> PCIDevice *pci_create_multifunction(PCIBus *bus, int devfn, bool multifunction,
> const char *name);
> PCIDevice *pci_create_simple_multifunction(PCIBus *bus, int devfn,
prev parent reply other threads:[~2012-02-22 18:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-21 13:41 [Qemu-devel] [PATCH] pci: add accessors to get/set registers by mask Michael S. Tsirkin
2012-02-22 15:58 ` Isaku Yamahata
2012-02-22 18:46 ` Anthony Liguori [this message]
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=4F453816.2020305@codemonkey.ws \
--to=anthony@codemonkey.ws \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--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).