smbus_eeprom: consolidate smbus eeprom creation oc pc_piix, mips_mapta, mips_fulong
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> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
This commit is contained in:
		
							parent
							
								
									a0313c00fc
								
							
						
					
					
						commit
						a88df0b9b5
					
				| 
						 | 
					@ -263,11 +263,9 @@ static void mips_fulong2e_init(ram_addr_t ram_size, const char *boot_device,
 | 
				
			||||||
    qemu_irq *cpu_exit_irq;
 | 
					    qemu_irq *cpu_exit_irq;
 | 
				
			||||||
    int via_devfn;
 | 
					    int via_devfn;
 | 
				
			||||||
    PCIBus *pci_bus;
 | 
					    PCIBus *pci_bus;
 | 
				
			||||||
    uint8_t *eeprom_buf;
 | 
					 | 
				
			||||||
    i2c_bus *smbus;
 | 
					    i2c_bus *smbus;
 | 
				
			||||||
    int i;
 | 
					    int i;
 | 
				
			||||||
    DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
 | 
					    DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
 | 
				
			||||||
    DeviceState *eeprom;
 | 
					 | 
				
			||||||
    CPUState *env;
 | 
					    CPUState *env;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* init CPUs */
 | 
					    /* 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),
 | 
					    smbus = vt82c686b_pm_init(pci_bus, PCI_DEVFN(FULONG2E_VIA_SLOT, 4),
 | 
				
			||||||
                              0xeee1, NULL);
 | 
					                              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.  */
 | 
					    /* TODO: Populate SPD eeprom data.  */
 | 
				
			||||||
    eeprom = qdev_create((BusState *)smbus, "smbus-eeprom");
 | 
					    smbus_eeprom_init(smbus, 1, eeprom_spd, sizeof(eeprom_spd));
 | 
				
			||||||
    qdev_prop_set_uint8(eeprom, "address", 0x50);
 | 
					 | 
				
			||||||
    qdev_prop_set_ptr(eeprom, "data", eeprom_buf);
 | 
					 | 
				
			||||||
    qdev_init_nofail(eeprom);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* init other devices */
 | 
					    /* init other devices */
 | 
				
			||||||
    pit = pit_init(0x40, 0);
 | 
					    pit = pit_init(0x40, 0);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -770,7 +770,6 @@ void mips_malta_init (ram_addr_t ram_size,
 | 
				
			||||||
    qemu_irq *i8259;
 | 
					    qemu_irq *i8259;
 | 
				
			||||||
    qemu_irq *cpu_exit_irq;
 | 
					    qemu_irq *cpu_exit_irq;
 | 
				
			||||||
    int piix4_devfn;
 | 
					    int piix4_devfn;
 | 
				
			||||||
    uint8_t *eeprom_buf;
 | 
					 | 
				
			||||||
    i2c_bus *smbus;
 | 
					    i2c_bus *smbus;
 | 
				
			||||||
    int i;
 | 
					    int i;
 | 
				
			||||||
    DriveInfo *dinfo;
 | 
					    DriveInfo *dinfo;
 | 
				
			||||||
| 
						 | 
					@ -913,15 +912,8 @@ void mips_malta_init (ram_addr_t ram_size,
 | 
				
			||||||
    usb_uhci_piix4_init(pci_bus, piix4_devfn + 2);
 | 
					    usb_uhci_piix4_init(pci_bus, piix4_devfn + 2);
 | 
				
			||||||
    smbus = piix4_pm_init(pci_bus, piix4_devfn + 3, 0x1100, isa_get_irq(9),
 | 
					    smbus = piix4_pm_init(pci_bus, piix4_devfn + 3, 0x1100, isa_get_irq(9),
 | 
				
			||||||
                          NULL, NULL, 0);
 | 
					                          NULL, NULL, 0);
 | 
				
			||||||
    eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
 | 
					    /* TODO: Populate SPD eeprom data.  */
 | 
				
			||||||
    for (i = 0; i < 8; i++) {
 | 
					    smbus_eeprom_init(smbus, 8, NULL, 0);
 | 
				
			||||||
        /* 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);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    pit = pit_init(0x40, 0);
 | 
					    pit = pit_init(0x40, 0);
 | 
				
			||||||
    cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1);
 | 
					    cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1);
 | 
				
			||||||
    DMA_init(0, cpu_exit_irq);
 | 
					    DMA_init(0, cpu_exit_irq);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										10
									
								
								hw/pc_piix.c
								
								
								
								
							
							
						
						
									
										10
									
								
								hw/pc_piix.c
								
								
								
								
							| 
						 | 
					@ -37,6 +37,7 @@
 | 
				
			||||||
#include "sysbus.h"
 | 
					#include "sysbus.h"
 | 
				
			||||||
#include "arch_init.h"
 | 
					#include "arch_init.h"
 | 
				
			||||||
#include "blockdev.h"
 | 
					#include "blockdev.h"
 | 
				
			||||||
 | 
					#include "smbus.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define MAX_IDE_BUS 2
 | 
					#define MAX_IDE_BUS 2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -154,7 +155,6 @@ static void pc_init1(ram_addr_t ram_size,
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (pci_enabled && acpi_enabled) {
 | 
					    if (pci_enabled && acpi_enabled) {
 | 
				
			||||||
        uint8_t *eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
 | 
					 | 
				
			||||||
        i2c_bus *smbus;
 | 
					        i2c_bus *smbus;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1);
 | 
					        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,
 | 
					        smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
 | 
				
			||||||
                              isa_get_irq(9), *cmos_s3, *smi_irq,
 | 
					                              isa_get_irq(9), *cmos_s3, *smi_irq,
 | 
				
			||||||
                              kvm_enabled());
 | 
					                              kvm_enabled());
 | 
				
			||||||
        for (i = 0; i < 8; i++) {
 | 
					        smbus_eeprom_init(smbus, 8, NULL, 0);
 | 
				
			||||||
            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);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (i440fx_state) {
 | 
					    if (i440fx_state) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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);
 | 
					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,
 | 
					void smbus_write_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data,
 | 
				
			||||||
                       int len);
 | 
					                       int len);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void smbus_eeprom_init(i2c_bus *smbus, int nb_eeprom,
 | 
				
			||||||
 | 
					                       const uint8_t *eeprom_spd, int size);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -96,7 +96,7 @@ static uint8_t eeprom_read_data(SMBusDevice *dev, uint8_t cmd, int n)
 | 
				
			||||||
    return eeprom_receive_byte(dev);
 | 
					    return eeprom_receive_byte(dev);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int smbus_eeprom_init(SMBusDevice *dev)
 | 
					static int smbus_eeprom_initfn(SMBusDevice *dev)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    SMBusEEPROMDevice *eeprom = (SMBusEEPROMDevice *)dev;
 | 
					    SMBusEEPROMDevice *eeprom = (SMBusEEPROMDevice *)dev;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -111,7 +111,7 @@ static SMBusDeviceInfo smbus_eeprom_info = {
 | 
				
			||||||
        DEFINE_PROP_PTR("data", SMBusEEPROMDevice, data),
 | 
					        DEFINE_PROP_PTR("data", SMBusEEPROMDevice, data),
 | 
				
			||||||
        DEFINE_PROP_END_OF_LIST(),
 | 
					        DEFINE_PROP_END_OF_LIST(),
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    .init = smbus_eeprom_init,
 | 
					    .init = smbus_eeprom_initfn,
 | 
				
			||||||
    .quick_cmd = eeprom_quick_cmd,
 | 
					    .quick_cmd = eeprom_quick_cmd,
 | 
				
			||||||
    .send_byte = eeprom_send_byte,
 | 
					    .send_byte = eeprom_send_byte,
 | 
				
			||||||
    .receive_byte = eeprom_receive_byte,
 | 
					    .receive_byte = eeprom_receive_byte,
 | 
				
			||||||
| 
						 | 
					@ -125,3 +125,21 @@ static void smbus_eeprom_register_devices(void)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
device_init(smbus_eeprom_register_devices)
 | 
					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);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue