diff mbox

[v4,02/15] pci: introduce helper functions to clear/set bits in configuration space

Message ID a1909c1c84166be63b37e2c8bd733cf40fe0e014.1287371107.git.yamahata@valinux.co.jp
State New
Headers show

Commit Message

Isaku Yamahata Oct. 18, 2010, 3:17 a.m. UTC
This patch introduces helper functions to clear/set bits in configuration
space. pci_{clear_set, clear, set}_bit_{byte, word, long, quad}().
They will be used later.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
 hw/pci.h |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 72 insertions(+), 0 deletions(-)

Comments

Michael S. Tsirkin Oct. 18, 2010, 5:42 a.m. UTC | #1
On Mon, Oct 18, 2010 at 12:17:43PM +0900, Isaku Yamahata wrote:
> This patch introduces helper functions to clear/set bits in configuration
> space. pci_{clear_set, clear, set}_bit_{byte, word, long, quad}().
> They will be used later.
> 
> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>

I don't think we want clear_set variant.
It is just confusing, simply calling
clear and then set will be better.


> ---
>  hw/pci.h |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 72 insertions(+), 0 deletions(-)
> 
> diff --git a/hw/pci.h b/hw/pci.h
> index d8b399f..eafa9f3 100644
> --- a/hw/pci.h
> +++ b/hw/pci.h
> @@ -323,6 +323,78 @@ pci_config_set_interrupt_pin(uint8_t *pci_config, uint8_t val)
>      pci_set_byte(&pci_config[PCI_INTERRUPT_PIN], val);
>  }
>  
> +static inline void
> +pci_clear_set_bit_byte(uint8_t *config, uint8_t clear, uint8_t set)
> +{
> +    pci_set_byte(config, (pci_get_byte(config) & ~clear) | set);
> +}
> +

Let's just open-code this.

> +static inline void
> +pci_clear_bit_byte(uint8_t *config, uint8_t clear)
> +{
> +    pci_clear_set_bit_byte(config, clear, 0);
> +}
> +
> +static inline void
> +pci_set_bit_byte(uint8_t *config, uint8_t set)
> +{
> +    pci_clear_set_bit_byte(config, 0, set);
> +}
> +
> +static inline void
> +pci_clear_set_bit_word(uint8_t *config, uint16_t clear, uint16_t set)
> +{
> +    pci_set_word(config, (pci_get_word(config) & ~clear) | set);
> +}
> +

and this

> +static inline void
> +pci_clear_bit_word(uint8_t *config, uint16_t clear)
> +{
> +    pci_clear_set_bit_word(config, clear, 0);
> +}
> +
> +static inline void
> +pci_set_bit_word(uint8_t *config, uint16_t set)
> +{
> +    pci_clear_set_bit_word(config, 0, set);
> +}
> +
> +static inline void
> +pci_clear_set_bit_long(uint8_t *config, uint32_t clear, uint32_t set)
> +{
> +    pci_set_long(config, (pci_get_long(config) & ~clear) | set);
> +}
> +

and this.

> +static inline void
> +pci_clear_bit_long(uint8_t *config, uint32_t clear)
> +{
> +    pci_clear_set_bit_long(config, clear, 0);
> +}
> +
> +static inline void
> +pci_set_bit_long(uint8_t *config, uint32_t set)
> +{
> +    pci_clear_set_bit_long(config, 0, set);
> +}
> +
> +static inline void
> +pci_clear_set_bit_quad(uint8_t *config, uint64_t clear, uint64_t set)
> +{
> +    pci_set_quad(config, (pci_get_quad(config) & ~clear) | set);
> +}
> +
> +static inline void
> +pci_clear_bit_quad(uint8_t *config, uint64_t clear)
> +{
> +    pci_clear_set_bit_quad(config, clear, 0);
> +}
> +
> +static inline void
> +pci_set_bit_quad(uint8_t *config, uint64_t set)
> +{
> +    pci_clear_set_bit_quad(config, 0, set);
> +}
> +
>  typedef int (*pci_qdev_initfn)(PCIDevice *dev);
>  typedef struct {
>      DeviceInfo qdev;
> -- 
> 1.7.1.1
Michael S. Tsirkin Oct. 18, 2010, 6:32 a.m. UTC | #2
On Mon, Oct 18, 2010 at 12:17:43PM +0900, Isaku Yamahata wrote:
> This patch introduces helper functions to clear/set bits in configuration
> space. pci_{clear_set, clear, set}_bit_{byte, word, long, quad}().
> They will be used later.
> 
> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>

I am not very happy with the names we came up with.
pci_clear_bit_byte - it sounds like this clears bit *and* byte.
Also, this gets a mask, not a bit number as the name implies.

How about
	pci_word_set_mask
	pci_word_clear_mask
Other ideas?

> ---
>  hw/pci.h |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 72 insertions(+), 0 deletions(-)
> 
> diff --git a/hw/pci.h b/hw/pci.h
> index d8b399f..eafa9f3 100644
> --- a/hw/pci.h
> +++ b/hw/pci.h
> @@ -323,6 +323,78 @@ pci_config_set_interrupt_pin(uint8_t *pci_config, uint8_t val)
>      pci_set_byte(&pci_config[PCI_INTERRUPT_PIN], val);
>  }
>  
> +static inline void
> +pci_clear_set_bit_byte(uint8_t *config, uint8_t clear, uint8_t set)
> +{
> +    pci_set_byte(config, (pci_get_byte(config) & ~clear) | set);
> +}
> +
> +static inline void
> +pci_clear_bit_byte(uint8_t *config, uint8_t clear)
> +{
> +    pci_clear_set_bit_byte(config, clear, 0);
> +}
> +
> +static inline void
> +pci_set_bit_byte(uint8_t *config, uint8_t set)
> +{
> +    pci_clear_set_bit_byte(config, 0, set);
> +}
> +
> +static inline void
> +pci_clear_set_bit_word(uint8_t *config, uint16_t clear, uint16_t set)
> +{
> +    pci_set_word(config, (pci_get_word(config) & ~clear) | set);
> +}
> +
> +static inline void
> +pci_clear_bit_word(uint8_t *config, uint16_t clear)
> +{
> +    pci_clear_set_bit_word(config, clear, 0);
> +}
> +
> +static inline void
> +pci_set_bit_word(uint8_t *config, uint16_t set)
> +{
> +    pci_clear_set_bit_word(config, 0, set);
> +}
> +
> +static inline void
> +pci_clear_set_bit_long(uint8_t *config, uint32_t clear, uint32_t set)
> +{
> +    pci_set_long(config, (pci_get_long(config) & ~clear) | set);
> +}
> +
> +static inline void
> +pci_clear_bit_long(uint8_t *config, uint32_t clear)
> +{
> +    pci_clear_set_bit_long(config, clear, 0);
> +}
> +
> +static inline void
> +pci_set_bit_long(uint8_t *config, uint32_t set)
> +{
> +    pci_clear_set_bit_long(config, 0, set);
> +}
> +
> +static inline void
> +pci_clear_set_bit_quad(uint8_t *config, uint64_t clear, uint64_t set)
> +{
> +    pci_set_quad(config, (pci_get_quad(config) & ~clear) | set);
> +}
> +
> +static inline void
> +pci_clear_bit_quad(uint8_t *config, uint64_t clear)
> +{
> +    pci_clear_set_bit_quad(config, clear, 0);
> +}
> +
> +static inline void
> +pci_set_bit_quad(uint8_t *config, uint64_t set)
> +{
> +    pci_clear_set_bit_quad(config, 0, set);
> +}
> +
>  typedef int (*pci_qdev_initfn)(PCIDevice *dev);
>  typedef struct {
>      DeviceInfo qdev;
> -- 
> 1.7.1.1
diff mbox

Patch

diff --git a/hw/pci.h b/hw/pci.h
index d8b399f..eafa9f3 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -323,6 +323,78 @@  pci_config_set_interrupt_pin(uint8_t *pci_config, uint8_t val)
     pci_set_byte(&pci_config[PCI_INTERRUPT_PIN], val);
 }
 
+static inline void
+pci_clear_set_bit_byte(uint8_t *config, uint8_t clear, uint8_t set)
+{
+    pci_set_byte(config, (pci_get_byte(config) & ~clear) | set);
+}
+
+static inline void
+pci_clear_bit_byte(uint8_t *config, uint8_t clear)
+{
+    pci_clear_set_bit_byte(config, clear, 0);
+}
+
+static inline void
+pci_set_bit_byte(uint8_t *config, uint8_t set)
+{
+    pci_clear_set_bit_byte(config, 0, set);
+}
+
+static inline void
+pci_clear_set_bit_word(uint8_t *config, uint16_t clear, uint16_t set)
+{
+    pci_set_word(config, (pci_get_word(config) & ~clear) | set);
+}
+
+static inline void
+pci_clear_bit_word(uint8_t *config, uint16_t clear)
+{
+    pci_clear_set_bit_word(config, clear, 0);
+}
+
+static inline void
+pci_set_bit_word(uint8_t *config, uint16_t set)
+{
+    pci_clear_set_bit_word(config, 0, set);
+}
+
+static inline void
+pci_clear_set_bit_long(uint8_t *config, uint32_t clear, uint32_t set)
+{
+    pci_set_long(config, (pci_get_long(config) & ~clear) | set);
+}
+
+static inline void
+pci_clear_bit_long(uint8_t *config, uint32_t clear)
+{
+    pci_clear_set_bit_long(config, clear, 0);
+}
+
+static inline void
+pci_set_bit_long(uint8_t *config, uint32_t set)
+{
+    pci_clear_set_bit_long(config, 0, set);
+}
+
+static inline void
+pci_clear_set_bit_quad(uint8_t *config, uint64_t clear, uint64_t set)
+{
+    pci_set_quad(config, (pci_get_quad(config) & ~clear) | set);
+}
+
+static inline void
+pci_clear_bit_quad(uint8_t *config, uint64_t clear)
+{
+    pci_clear_set_bit_quad(config, clear, 0);
+}
+
+static inline void
+pci_set_bit_quad(uint8_t *config, uint64_t set)
+{
+    pci_clear_set_bit_quad(config, 0, set);
+}
+
 typedef int (*pci_qdev_initfn)(PCIDevice *dev);
 typedef struct {
     DeviceInfo qdev;