qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] smbus_eeprom: consolidate smbus eeprom creation oc pc_piix, mips_mapta, mips_fulong
@ 2011-04-05  2:07 Isaku Yamahata
  2011-04-09 21:53 ` Aurelien Jarno
  0 siblings, 1 reply; 2+ messages in thread
From: Isaku Yamahata @ 2011-04-05  2:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: yamahata, aurelien, Huacai Chen

consolidate smbus initialization for pc_piix, mips_malta and mips_fulong.

Cc: Aurelien Jarno <aurelien@aurel32.net>
Cc: Huacai Chen <zltjiangshi@gmail.com>
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>
---
 hw/mips_fulong2e.c |    9 +--------
 hw/mips_malta.c    |   12 ++----------
 hw/pc_piix.c       |   10 ++--------
 hw/smbus.h         |    3 +++
 hw/smbus_eeprom.c  |   22 ++++++++++++++++++++--
 5 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/hw/mips_fulong2e.c b/hw/mips_fulong2e.c
index 0e90d68..420fada 100644
--- a/hw/mips_fulong2e.c
+++ b/hw/mips_fulong2e.c
@@ -263,11 +263,9 @@ static void mips_fulong2e_init(ram_addr_t ram_size, const char *boot_device,
     qemu_irq *cpu_exit_irq;
     int via_devfn;
     PCIBus *pci_bus;
-    uint8_t *eeprom_buf;
     i2c_bus *smbus;
     int i;
     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
-    DeviceState *eeprom;
     CPUState *env;
 
     /* init CPUs */
@@ -353,13 +351,8 @@ static void mips_fulong2e_init(ram_addr_t ram_size, const char *boot_device,
 
     smbus = vt82c686b_pm_init(pci_bus, PCI_DEVFN(FULONG2E_VIA_SLOT, 4),
                               0xeee1, NULL);
-    eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
-    memcpy(eeprom_buf, eeprom_spd, sizeof(eeprom_spd));
     /* TODO: Populate SPD eeprom data.  */
-    eeprom = qdev_create((BusState *)smbus, "smbus-eeprom");
-    qdev_prop_set_uint8(eeprom, "address", 0x50);
-    qdev_prop_set_ptr(eeprom, "data", eeprom_buf);
-    qdev_init_nofail(eeprom);
+    smbus_eeprom_init(smbus, 1, eeprom_spd, sizeof(eeprom_spd));
 
     /* init other devices */
     pit = pit_init(0x40, 0);
diff --git a/hw/mips_malta.c b/hw/mips_malta.c
index bf0d76d..ed2a483 100644
--- a/hw/mips_malta.c
+++ b/hw/mips_malta.c
@@ -770,7 +770,6 @@ void mips_malta_init (ram_addr_t ram_size,
     qemu_irq *i8259;
     qemu_irq *cpu_exit_irq;
     int piix4_devfn;
-    uint8_t *eeprom_buf;
     i2c_bus *smbus;
     int i;
     DriveInfo *dinfo;
@@ -913,15 +912,8 @@ void mips_malta_init (ram_addr_t ram_size,
     usb_uhci_piix4_init(pci_bus, piix4_devfn + 2);
     smbus = piix4_pm_init(pci_bus, piix4_devfn + 3, 0x1100, isa_get_irq(9),
                           NULL, NULL, 0);
-    eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
-    for (i = 0; i < 8; i++) {
-        /* TODO: Populate SPD eeprom data.  */
-        DeviceState *eeprom;
-        eeprom = qdev_create((BusState *)smbus, "smbus-eeprom");
-        qdev_prop_set_uint8(eeprom, "address", 0x50 + i);
-        qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256));
-        qdev_init_nofail(eeprom);
-    }
+    /* TODO: Populate SPD eeprom data.  */
+    smbus_eeprom_init(smbus, 8, NULL, 0);
     pit = pit_init(0x40, 0);
     cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1);
     DMA_init(0, cpu_exit_irq);
diff --git a/hw/pc_piix.c b/hw/pc_piix.c
index 4d54ca1..a85214b 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -37,6 +37,7 @@
 #include "sysbus.h"
 #include "arch_init.h"
 #include "blockdev.h"
+#include "smbus.h"
 
 #define MAX_IDE_BUS 2
 
@@ -154,7 +155,6 @@ static void pc_init1(ram_addr_t ram_size,
     }
 
     if (pci_enabled && acpi_enabled) {
-        uint8_t *eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
         i2c_bus *smbus;
 
         cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1);
@@ -163,13 +163,7 @@ static void pc_init1(ram_addr_t ram_size,
         smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
                               isa_get_irq(9), *cmos_s3, *smi_irq,
                               kvm_enabled());
-        for (i = 0; i < 8; i++) {
-            DeviceState *eeprom;
-            eeprom = qdev_create((BusState *)smbus, "smbus-eeprom");
-            qdev_prop_set_uint8(eeprom, "address", 0x50 + i);
-            qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256));
-            qdev_init_nofail(eeprom);
-        }
+        smbus_eeprom_init(smbus, 8, NULL, 0);
     }
 
     if (i440fx_state) {
diff --git a/hw/smbus.h b/hw/smbus.h
index 571c52d..a398715 100644
--- a/hw/smbus.h
+++ b/hw/smbus.h
@@ -66,3 +66,6 @@ void smbus_write_word(i2c_bus *bus, uint8_t addr, uint8_t command, uint16_t data
 int smbus_read_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data);
 void smbus_write_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data,
                        int len);
+
+void smbus_eeprom_init(i2c_bus *smbus, int nb_eeprom,
+                       const uint8_t *eeprom_spd, int size);
diff --git a/hw/smbus_eeprom.c b/hw/smbus_eeprom.c
index 52463e0..3634754 100644
--- a/hw/smbus_eeprom.c
+++ b/hw/smbus_eeprom.c
@@ -96,7 +96,7 @@ static uint8_t eeprom_read_data(SMBusDevice *dev, uint8_t cmd, int n)
     return eeprom_receive_byte(dev);
 }
 
-static int smbus_eeprom_init(SMBusDevice *dev)
+static int smbus_eeprom_initfn(SMBusDevice *dev)
 {
     SMBusEEPROMDevice *eeprom = (SMBusEEPROMDevice *)dev;
 
@@ -111,7 +111,7 @@ static SMBusDeviceInfo smbus_eeprom_info = {
         DEFINE_PROP_PTR("data", SMBusEEPROMDevice, data),
         DEFINE_PROP_END_OF_LIST(),
     },
-    .init = smbus_eeprom_init,
+    .init = smbus_eeprom_initfn,
     .quick_cmd = eeprom_quick_cmd,
     .send_byte = eeprom_send_byte,
     .receive_byte = eeprom_receive_byte,
@@ -125,3 +125,21 @@ static void smbus_eeprom_register_devices(void)
 }
 
 device_init(smbus_eeprom_register_devices)
+
+void smbus_eeprom_init(i2c_bus *smbus, int nb_eeprom,
+                       const uint8_t *eeprom_spd, int eeprom_spd_size)
+{
+    int i;
+    uint8_t *eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
+    if (eeprom_spd_size > 0) {
+        memcpy(eeprom_buf, eeprom_spd, eeprom_spd_size);
+    }
+
+    for (i = 0; i < nb_eeprom; i++) {
+        DeviceState *eeprom;
+        eeprom = qdev_create((BusState *)smbus, "smbus-eeprom");
+        qdev_prop_set_uint8(eeprom, "address", 0x50 + i);
+        qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256));
+        qdev_init_nofail(eeprom);
+    }
+}
-- 
1.7.1.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] smbus_eeprom: consolidate smbus eeprom creation oc pc_piix, mips_mapta, mips_fulong
  2011-04-05  2:07 [Qemu-devel] [PATCH] smbus_eeprom: consolidate smbus eeprom creation oc pc_piix, mips_mapta, mips_fulong Isaku Yamahata
@ 2011-04-09 21:53 ` Aurelien Jarno
  0 siblings, 0 replies; 2+ messages in thread
From: Aurelien Jarno @ 2011-04-09 21:53 UTC (permalink / raw)
  To: Isaku Yamahata; +Cc: Huacai Chen, qemu-devel

On Tue, Apr 05, 2011 at 11:07:06AM +0900, Isaku Yamahata wrote:
> consolidate smbus initialization for pc_piix, mips_malta and mips_fulong.
> 
> Cc: Aurelien Jarno <aurelien@aurel32.net>
> Cc: Huacai Chen <zltjiangshi@gmail.com>
> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
> Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>
> ---
>  hw/mips_fulong2e.c |    9 +--------
>  hw/mips_malta.c    |   12 ++----------
>  hw/pc_piix.c       |   10 ++--------
>  hw/smbus.h         |    3 +++
>  hw/smbus_eeprom.c  |   22 ++++++++++++++++++++--
>  5 files changed, 28 insertions(+), 28 deletions(-)

Thanks, applied.

> diff --git a/hw/mips_fulong2e.c b/hw/mips_fulong2e.c
> index 0e90d68..420fada 100644
> --- a/hw/mips_fulong2e.c
> +++ b/hw/mips_fulong2e.c
> @@ -263,11 +263,9 @@ static void mips_fulong2e_init(ram_addr_t ram_size, const char *boot_device,
>      qemu_irq *cpu_exit_irq;
>      int via_devfn;
>      PCIBus *pci_bus;
> -    uint8_t *eeprom_buf;
>      i2c_bus *smbus;
>      int i;
>      DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
> -    DeviceState *eeprom;
>      CPUState *env;
>  
>      /* init CPUs */
> @@ -353,13 +351,8 @@ static void mips_fulong2e_init(ram_addr_t ram_size, const char *boot_device,
>  
>      smbus = vt82c686b_pm_init(pci_bus, PCI_DEVFN(FULONG2E_VIA_SLOT, 4),
>                                0xeee1, NULL);
> -    eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
> -    memcpy(eeprom_buf, eeprom_spd, sizeof(eeprom_spd));
>      /* TODO: Populate SPD eeprom data.  */
> -    eeprom = qdev_create((BusState *)smbus, "smbus-eeprom");
> -    qdev_prop_set_uint8(eeprom, "address", 0x50);
> -    qdev_prop_set_ptr(eeprom, "data", eeprom_buf);
> -    qdev_init_nofail(eeprom);
> +    smbus_eeprom_init(smbus, 1, eeprom_spd, sizeof(eeprom_spd));
>  
>      /* init other devices */
>      pit = pit_init(0x40, 0);
> diff --git a/hw/mips_malta.c b/hw/mips_malta.c
> index bf0d76d..ed2a483 100644
> --- a/hw/mips_malta.c
> +++ b/hw/mips_malta.c
> @@ -770,7 +770,6 @@ void mips_malta_init (ram_addr_t ram_size,
>      qemu_irq *i8259;
>      qemu_irq *cpu_exit_irq;
>      int piix4_devfn;
> -    uint8_t *eeprom_buf;
>      i2c_bus *smbus;
>      int i;
>      DriveInfo *dinfo;
> @@ -913,15 +912,8 @@ void mips_malta_init (ram_addr_t ram_size,
>      usb_uhci_piix4_init(pci_bus, piix4_devfn + 2);
>      smbus = piix4_pm_init(pci_bus, piix4_devfn + 3, 0x1100, isa_get_irq(9),
>                            NULL, NULL, 0);
> -    eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
> -    for (i = 0; i < 8; i++) {
> -        /* TODO: Populate SPD eeprom data.  */
> -        DeviceState *eeprom;
> -        eeprom = qdev_create((BusState *)smbus, "smbus-eeprom");
> -        qdev_prop_set_uint8(eeprom, "address", 0x50 + i);
> -        qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256));
> -        qdev_init_nofail(eeprom);
> -    }
> +    /* TODO: Populate SPD eeprom data.  */
> +    smbus_eeprom_init(smbus, 8, NULL, 0);
>      pit = pit_init(0x40, 0);
>      cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1);
>      DMA_init(0, cpu_exit_irq);
> diff --git a/hw/pc_piix.c b/hw/pc_piix.c
> index 4d54ca1..a85214b 100644
> --- a/hw/pc_piix.c
> +++ b/hw/pc_piix.c
> @@ -37,6 +37,7 @@
>  #include "sysbus.h"
>  #include "arch_init.h"
>  #include "blockdev.h"
> +#include "smbus.h"
>  
>  #define MAX_IDE_BUS 2
>  
> @@ -154,7 +155,6 @@ static void pc_init1(ram_addr_t ram_size,
>      }
>  
>      if (pci_enabled && acpi_enabled) {
> -        uint8_t *eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
>          i2c_bus *smbus;
>  
>          cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1);
> @@ -163,13 +163,7 @@ static void pc_init1(ram_addr_t ram_size,
>          smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
>                                isa_get_irq(9), *cmos_s3, *smi_irq,
>                                kvm_enabled());
> -        for (i = 0; i < 8; i++) {
> -            DeviceState *eeprom;
> -            eeprom = qdev_create((BusState *)smbus, "smbus-eeprom");
> -            qdev_prop_set_uint8(eeprom, "address", 0x50 + i);
> -            qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256));
> -            qdev_init_nofail(eeprom);
> -        }
> +        smbus_eeprom_init(smbus, 8, NULL, 0);
>      }
>  
>      if (i440fx_state) {
> diff --git a/hw/smbus.h b/hw/smbus.h
> index 571c52d..a398715 100644
> --- a/hw/smbus.h
> +++ b/hw/smbus.h
> @@ -66,3 +66,6 @@ void smbus_write_word(i2c_bus *bus, uint8_t addr, uint8_t command, uint16_t data
>  int smbus_read_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data);
>  void smbus_write_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data,
>                         int len);
> +
> +void smbus_eeprom_init(i2c_bus *smbus, int nb_eeprom,
> +                       const uint8_t *eeprom_spd, int size);
> diff --git a/hw/smbus_eeprom.c b/hw/smbus_eeprom.c
> index 52463e0..3634754 100644
> --- a/hw/smbus_eeprom.c
> +++ b/hw/smbus_eeprom.c
> @@ -96,7 +96,7 @@ static uint8_t eeprom_read_data(SMBusDevice *dev, uint8_t cmd, int n)
>      return eeprom_receive_byte(dev);
>  }
>  
> -static int smbus_eeprom_init(SMBusDevice *dev)
> +static int smbus_eeprom_initfn(SMBusDevice *dev)
>  {
>      SMBusEEPROMDevice *eeprom = (SMBusEEPROMDevice *)dev;
>  
> @@ -111,7 +111,7 @@ static SMBusDeviceInfo smbus_eeprom_info = {
>          DEFINE_PROP_PTR("data", SMBusEEPROMDevice, data),
>          DEFINE_PROP_END_OF_LIST(),
>      },
> -    .init = smbus_eeprom_init,
> +    .init = smbus_eeprom_initfn,
>      .quick_cmd = eeprom_quick_cmd,
>      .send_byte = eeprom_send_byte,
>      .receive_byte = eeprom_receive_byte,
> @@ -125,3 +125,21 @@ static void smbus_eeprom_register_devices(void)
>  }
>  
>  device_init(smbus_eeprom_register_devices)
> +
> +void smbus_eeprom_init(i2c_bus *smbus, int nb_eeprom,
> +                       const uint8_t *eeprom_spd, int eeprom_spd_size)
> +{
> +    int i;
> +    uint8_t *eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
> +    if (eeprom_spd_size > 0) {
> +        memcpy(eeprom_buf, eeprom_spd, eeprom_spd_size);
> +    }
> +
> +    for (i = 0; i < nb_eeprom; i++) {
> +        DeviceState *eeprom;
> +        eeprom = qdev_create((BusState *)smbus, "smbus-eeprom");
> +        qdev_prop_set_uint8(eeprom, "address", 0x50 + i);
> +        qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256));
> +        qdev_init_nofail(eeprom);
> +    }
> +}
> -- 
> 1.7.1.1
> 
> 
> 

-- 
Aurelien Jarno                          GPG: 1024D/F1BCDB73
aurelien@aurel32.net                 http://www.aurel32.net

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-04-09 21:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-05  2:07 [Qemu-devel] [PATCH] smbus_eeprom: consolidate smbus eeprom creation oc pc_piix, mips_mapta, mips_fulong Isaku Yamahata
2011-04-09 21:53 ` Aurelien Jarno

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).