diff mbox

[2/2] eepro100: convert to new capability API

Message ID fff22f778ff616caeba02553734b710c6dc77ba8.1270627361.git.mst@redhat.com
State New
Headers show

Commit Message

Michael S. Tsirkin April 7, 2010, 8:04 a.m. UTC
Using new pci_add_capability_at_offset makes
eepro100 code cleaner.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/eepro100.c |   22 +++++++++-------------
 1 files changed, 9 insertions(+), 13 deletions(-)

Comments

Stefan Weil April 7, 2010, 8:42 a.m. UTC | #1
Michael S. Tsirkin schrieb:
> Using new pci_add_capability_at_offset makes
> eepro100 code cleaner.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> hw/eepro100.c | 22 +++++++++-------------
> 1 files changed, 9 insertions(+), 13 deletions(-)
>
> diff --git a/hw/eepro100.c b/hw/eepro100.c
> index 785a7da..a74d834 100644
> --- a/hw/eepro100.c
> +++ b/hw/eepro100.c
> @@ -539,21 +539,17 @@ static void e100_pci_reset(EEPRO100State * s,
> E100PCIDeviceInfo *e100_device)
>
> if (e100_device->power_management) {
> /* Power Management Capabilities */
> - int cfg_offset;
> - pci_reserve_capability(&s->dev, PCI_CONFIG_HEADER_SIZE,
> - 0xdc - PCI_CONFIG_HEADER_SIZE);
> - cfg_offset = pci_add_capability(&s->dev, PCI_CAP_ID_PM, PCI_PM_SIZEOF);
> - assert(cfg_offset == 0xdc);
> - if (cfg_offset > 0) {
> - /* Power Management Capabilities */
> - pci_set_word(pci_conf + cfg_offset + PCI_PM_PMC, 0x7e21);
> + int cfg_offset = 0xdc;

Suggestion:

uint8_t cfg_offset = 0xdc;
> + int r = pci_add_capability_at_offset(&s->dev, PCI_CAP_ID_PM,
> + cfg_offset, PCI_PM_SIZEOF);
> + assert(r >= 0);
> + pci_set_word(pci_conf + cfg_offset + PCI_PM_PMC, 0x7e21);
> #if 0 /* TODO: replace dummy code for power management emulation. */
> - /* TODO: Power Management Control / Status. */
> - pci_set_word(pci_conf + cfg_offset + PCI_PM_CTRL, 0x0000);
> - /* TODO: Ethernet Power Consumption Registers (i82559 and later). */
> - pci_set_byte(pci_conf + cfg_offset + PCI_PM_PPB_EXTENSIONS, 0x0000);
> + /* TODO: Power Management Control / Status. */
> + pci_set_word(pci_conf + cfg_offset + PCI_PM_CTRL, 0x0000);
> + /* TODO: Ethernet Power Consumption Registers (i82559 and later). */
> + pci_set_byte(pci_conf + cfg_offset + PCI_PM_PPB_EXTENSIONS, 0x0000);
> #endif
> - }
> }
>
> #if EEPROM_SIZE > 0

Acked-by: Stefan Weil <weil@mail.berlios.de>
Michael S. Tsirkin April 7, 2010, 11:04 a.m. UTC | #2
On Wed, Apr 07, 2010 at 10:42:07AM +0200, Stefan Weil wrote:
> Michael S. Tsirkin schrieb:
> > Using new pci_add_capability_at_offset makes
> > eepro100 code cleaner.
> >
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> > hw/eepro100.c | 22 +++++++++-------------
> > 1 files changed, 9 insertions(+), 13 deletions(-)
> >
> > diff --git a/hw/eepro100.c b/hw/eepro100.c
> > index 785a7da..a74d834 100644
> > --- a/hw/eepro100.c
> > +++ b/hw/eepro100.c
> > @@ -539,21 +539,17 @@ static void e100_pci_reset(EEPRO100State * s,
> > E100PCIDeviceInfo *e100_device)
> >
> > if (e100_device->power_management) {
> > /* Power Management Capabilities */
> > - int cfg_offset;
> > - pci_reserve_capability(&s->dev, PCI_CONFIG_HEADER_SIZE,
> > - 0xdc - PCI_CONFIG_HEADER_SIZE);
> > - cfg_offset = pci_add_capability(&s->dev, PCI_CAP_ID_PM, PCI_PM_SIZEOF);
> > - assert(cfg_offset == 0xdc);
> > - if (cfg_offset > 0) {
> > - /* Power Management Capabilities */
> > - pci_set_word(pci_conf + cfg_offset + PCI_PM_PMC, 0x7e21);
> > + int cfg_offset = 0xdc;
> 
> Suggestion:
> 
> uint8_t cfg_offset = 0xdc;

I don't think it matters as there's no chance of overflow or anything,
all math is on small constants.

> > + int r = pci_add_capability_at_offset(&s->dev, PCI_CAP_ID_PM,
> > + cfg_offset, PCI_PM_SIZEOF);
> > + assert(r >= 0);
> > + pci_set_word(pci_conf + cfg_offset + PCI_PM_PMC, 0x7e21);
> > #if 0 /* TODO: replace dummy code for power management emulation. */
> > - /* TODO: Power Management Control / Status. */
> > - pci_set_word(pci_conf + cfg_offset + PCI_PM_CTRL, 0x0000);
> > - /* TODO: Ethernet Power Consumption Registers (i82559 and later). */
> > - pci_set_byte(pci_conf + cfg_offset + PCI_PM_PPB_EXTENSIONS, 0x0000);
> > + /* TODO: Power Management Control / Status. */
> > + pci_set_word(pci_conf + cfg_offset + PCI_PM_CTRL, 0x0000);
> > + /* TODO: Ethernet Power Consumption Registers (i82559 and later). */
> > + pci_set_byte(pci_conf + cfg_offset + PCI_PM_PPB_EXTENSIONS, 0x0000);
> > #endif
> > - }
> > }
> >
> > #if EEPROM_SIZE > 0
> 
> Acked-by: Stefan Weil <weil@mail.berlios.de>
diff mbox

Patch

diff --git a/hw/eepro100.c b/hw/eepro100.c
index 785a7da..a74d834 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -539,21 +539,17 @@  static void e100_pci_reset(EEPRO100State * s, E100PCIDeviceInfo *e100_device)
 
     if (e100_device->power_management) {
         /* Power Management Capabilities */
-        int cfg_offset;
-        pci_reserve_capability(&s->dev, PCI_CONFIG_HEADER_SIZE,
-                               0xdc - PCI_CONFIG_HEADER_SIZE);
-        cfg_offset = pci_add_capability(&s->dev, PCI_CAP_ID_PM, PCI_PM_SIZEOF);
-        assert(cfg_offset == 0xdc);
-        if (cfg_offset > 0) {
-            /* Power Management Capabilities */
-            pci_set_word(pci_conf + cfg_offset + PCI_PM_PMC, 0x7e21);
+        int cfg_offset = 0xdc;
+        int r = pci_add_capability_at_offset(&s->dev, PCI_CAP_ID_PM,
+                                             cfg_offset, PCI_PM_SIZEOF);
+        assert(r >= 0);
+        pci_set_word(pci_conf + cfg_offset + PCI_PM_PMC, 0x7e21);
 #if 0 /* TODO: replace dummy code for power management emulation. */
-            /* TODO: Power Management Control / Status. */
-            pci_set_word(pci_conf + cfg_offset + PCI_PM_CTRL, 0x0000);
-            /* TODO: Ethernet Power Consumption Registers (i82559 and later). */
-            pci_set_byte(pci_conf + cfg_offset + PCI_PM_PPB_EXTENSIONS, 0x0000);
+        /* TODO: Power Management Control / Status. */
+        pci_set_word(pci_conf + cfg_offset + PCI_PM_CTRL, 0x0000);
+        /* TODO: Ethernet Power Consumption Registers (i82559 and later). */
+        pci_set_byte(pci_conf + cfg_offset + PCI_PM_PPB_EXTENSIONS, 0x0000);
 #endif
-        }
     }
 
 #if EEPROM_SIZE > 0