diff mbox

[32/61] pci: helper functions to access PCIDevice::config

Message ID 1254305917-14784-33-git-send-email-yamahata@valinux.co.jp
State Superseded
Headers show

Commit Message

Isaku Yamahata Sept. 30, 2009, 10:18 a.m. UTC
add helper functions to get/set PCIDevice::config
Those will be used later.

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

Comments

Michael S. Tsirkin Sept. 30, 2009, 10:47 a.m. UTC | #1
On Wed, Sep 30, 2009 at 07:18:08PM +0900, Isaku Yamahata wrote:
> add helper functions to get/set PCIDevice::config
> Those will be used later.
> 
> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
> ---
>  hw/pci.h |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 60 insertions(+), 0 deletions(-)
> 
> diff --git a/hw/pci.h b/hw/pci.h
> index 460a2b5..e3f5df8 100644
> --- a/hw/pci.h
> +++ b/hw/pci.h
> @@ -325,6 +325,18 @@ pci_get_long(uint8_t *config)
>  }
>  
>  static inline void
> +pci_set_quad(uint8_t *config, uint64_t val)
> +{
> +    cpu_to_le64w((uint64_t *)config, val);
> +}
> +
> +static inline uint64_t
> +pci_get_quad(uint8_t *config)
> +{
> +    return le64_to_cpup((uint64_t *)config);
> +}
> +
> +static inline void
>  pci_config_set_vendor_id(uint8_t *pci_config, uint16_t val)
>  {
>      pci_set_word(&pci_config[PCI_VENDOR_ID], val);

These look good, provided they are used.

> @@ -342,6 +354,54 @@ pci_config_set_class(uint8_t *pci_config, uint16_t val)
>      pci_set_word(&pci_config[PCI_CLASS_DEVICE], val);
>  }
>  
> +static inline void
> +pci_config_set_byte(PCIDevice *d, uint32_t addr, uint8_t val)
> +{
> +    pci_set_byte(&d->config[addr], val);
> +}
> +
> +static inline void
> +pci_config_set_word(PCIDevice *d, uint32_t addr, uint16_t val)
> +{
> +    pci_set_word(&d->config[addr], val);
> +}
> +
> +static inline void
> +pci_config_set_long(PCIDevice *d, uint32_t addr, uint32_t val)
> +{
> +    pci_set_long(&d->config[addr], val);
> +}
> +
> +static inline void
> +pci_config_set_quad(PCIDevice *d, uint32_t addr, uint64_t val)
> +{
> +    pci_set_quad(&d->config[addr], val);
> +}
> +
> +static inline uint8_t
> +pci_config_get_byte(PCIDevice *d, uint32_t addr)
> +{
> +    return pci_get_byte(&d->config[addr]);
> +}
> +
> +static inline uint16_t
> +pci_config_get_word(PCIDevice *d, uint32_t addr)
> +{
> +    return pci_get_word(&d->config[addr]);
> +}
> +
> +static inline uint32_t
> +pci_config_get_long(PCIDevice *d, uint32_t addr)
> +{
> +    return pci_get_long(&d->config[addr]);
> +}
> +
> +static inline uint64_t
> +pci_config_get_quad(PCIDevice *d, uint32_t addr)
> +{
> +    return pci_get_quad(&d->config[addr]);
> +}
> +

These seem like unnecessary wrappers. PCI is all little
endian: both memory and configuration.

>  typedef int (*pci_qdev_initfn)(PCIDevice *dev);
>  typedef struct {
>      DeviceInfo qdev;
> -- 
> 1.6.0.2
> 
>
diff mbox

Patch

diff --git a/hw/pci.h b/hw/pci.h
index 460a2b5..e3f5df8 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -325,6 +325,18 @@  pci_get_long(uint8_t *config)
 }
 
 static inline void
+pci_set_quad(uint8_t *config, uint64_t val)
+{
+    cpu_to_le64w((uint64_t *)config, val);
+}
+
+static inline uint64_t
+pci_get_quad(uint8_t *config)
+{
+    return le64_to_cpup((uint64_t *)config);
+}
+
+static inline void
 pci_config_set_vendor_id(uint8_t *pci_config, uint16_t val)
 {
     pci_set_word(&pci_config[PCI_VENDOR_ID], val);
@@ -342,6 +354,54 @@  pci_config_set_class(uint8_t *pci_config, uint16_t val)
     pci_set_word(&pci_config[PCI_CLASS_DEVICE], val);
 }
 
+static inline void
+pci_config_set_byte(PCIDevice *d, uint32_t addr, uint8_t val)
+{
+    pci_set_byte(&d->config[addr], val);
+}
+
+static inline void
+pci_config_set_word(PCIDevice *d, uint32_t addr, uint16_t val)
+{
+    pci_set_word(&d->config[addr], val);
+}
+
+static inline void
+pci_config_set_long(PCIDevice *d, uint32_t addr, uint32_t val)
+{
+    pci_set_long(&d->config[addr], val);
+}
+
+static inline void
+pci_config_set_quad(PCIDevice *d, uint32_t addr, uint64_t val)
+{
+    pci_set_quad(&d->config[addr], val);
+}
+
+static inline uint8_t
+pci_config_get_byte(PCIDevice *d, uint32_t addr)
+{
+    return pci_get_byte(&d->config[addr]);
+}
+
+static inline uint16_t
+pci_config_get_word(PCIDevice *d, uint32_t addr)
+{
+    return pci_get_word(&d->config[addr]);
+}
+
+static inline uint32_t
+pci_config_get_long(PCIDevice *d, uint32_t addr)
+{
+    return pci_get_long(&d->config[addr]);
+}
+
+static inline uint64_t
+pci_config_get_quad(PCIDevice *d, uint32_t addr)
+{
+    return pci_get_quad(&d->config[addr]);
+}
+
 typedef int (*pci_qdev_initfn)(PCIDevice *dev);
 typedef struct {
     DeviceInfo qdev;