From patchwork Sat Feb 4 08:03:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 139551 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4A8F1104796 for ; Sat, 4 Feb 2012 20:01:13 +1100 (EST) Received: from localhost ([::1]:51819 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RtbUd-0001rr-6r for incoming@patchwork.ozlabs.org; Sat, 04 Feb 2012 04:01:11 -0500 Received: from eggs.gnu.org ([140.186.70.92]:35007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rtaaw-0002ET-Nb for qemu-devel@nongnu.org; Sat, 04 Feb 2012 03:03:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rtaau-0005N1-Mo for qemu-devel@nongnu.org; Sat, 04 Feb 2012 03:03:38 -0500 Received: from mail-ww0-f53.google.com ([74.125.82.53]:63252) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rtaau-00059M-FR for qemu-devel@nongnu.org; Sat, 04 Feb 2012 03:03:36 -0500 Received: by mail-ww0-f53.google.com with SMTP id dr12so4470350wgb.10 for ; Sat, 04 Feb 2012 00:03:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=GNac7jnaPUGy4RlNAY/32K187FblGMNoVVz0Mw41ECM=; b=FXa5T1npi+vKxEB+kBoof2LF65kVaL1ZOYclngyLaKADHKjqwulppYjDzGRCuY39KC bRjagFTTlewSuYhP/uZI4I2doGtVbMJdZL1CJPnOVySqYkFcD54gAxrvCk9vi/l6f9RI +prOXOHM+0ZanRxyTgeIgw2rZwHalVzxOqs6A= Received: by 10.180.97.166 with SMTP id eb6mr16443630wib.5.1328342616104; Sat, 04 Feb 2012 00:03:36 -0800 (PST) Received: from yakj.usersys.redhat.com.ACCOR.COM (218.104-246-81.adsl-static.isp.belgacom.be. [81.246.104.218]) by mx.google.com with ESMTPS id dw7sm11508313wib.4.2012.02.04.00.03.35 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 04 Feb 2012 00:03:35 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Sat, 4 Feb 2012 09:03:31 +0100 Message-Id: <1328342612-25826-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1328342612-25826-1-git-send-email-pbonzini@redhat.com> References: <1328342612-25826-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.125.82.53 Subject: [Qemu-devel] [PATCH 2/3] smbus_eeprom: remove PTR property X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Paolo Bonzini --- hw/smbus.c | 4 ++-- hw/smbus.h | 4 ++-- hw/smbus_eeprom.c | 39 +++++++++++++++++++++------------------ 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/hw/smbus.c b/hw/smbus.c index 4ff2342..969d46d 100644 --- a/hw/smbus.c +++ b/hw/smbus.c @@ -295,8 +295,8 @@ int smbus_read_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data) return len; } -void smbus_write_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data, - int len) +void smbus_write_block(i2c_bus *bus, uint8_t addr, uint8_t command, + const uint8_t *data, int len) { int i; diff --git a/hw/smbus.h b/hw/smbus.h index 6ed45bd..3dee2d1 100644 --- a/hw/smbus.h +++ b/hw/smbus.h @@ -74,8 +74,8 @@ void smbus_write_byte(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t data) uint16_t smbus_read_word(i2c_bus *bus, uint8_t addr, uint8_t command); 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_write_block(i2c_bus *bus, uint8_t addr, uint8_t command, + const 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 9d96cbe..8e42c41 100644 --- a/hw/smbus_eeprom.c +++ b/hw/smbus_eeprom.c @@ -27,10 +27,11 @@ #include "smbus.h" //#define DEBUG +#define SMBUS_EEPROM_SIZE 256 typedef struct SMBusEEPROMDevice { SMBusDevice smbusdev; - void *data; + uint8_t data[SMBUS_EEPROM_SIZE]; uint8_t offset; } SMBusEEPROMDevice; @@ -54,8 +55,7 @@ static void eeprom_send_byte(SMBusDevice *dev, uint8_t val) static uint8_t eeprom_receive_byte(SMBusDevice *dev) { SMBusEEPROMDevice *eeprom = (SMBusEEPROMDevice *) dev; - uint8_t *data = eeprom->data; - uint8_t val = data[eeprom->offset++]; + uint8_t val = eeprom->data[eeprom->offset++]; #ifdef DEBUG printf("eeprom_receive_byte: addr=0x%02x val=0x%02x\n", dev->i2c.address, val); @@ -75,8 +75,8 @@ static void eeprom_write_data(SMBusDevice *dev, uint8_t cmd, uint8_t *buf, int l It is a block write without a length byte. Fortunately we get the full block anyway. */ /* TODO: Should this set the current location? */ - if (cmd + len > 256) - n = 256 - cmd; + if (cmd + len > SMBUS_EEPROM_SIZE) + n = SMBUS_EEPROM_SIZE - cmd; else n = len; memcpy(eeprom->data + cmd, buf, n); @@ -104,14 +104,8 @@ static int smbus_eeprom_initfn(SMBusDevice *dev) return 0; } -static Property smbus_eeprom_properties[] = { - DEFINE_PROP_PTR("data", SMBusEEPROMDevice, data), - DEFINE_PROP_END_OF_LIST(), -}; - static void smbus_eeprom_class_initfn(ObjectClass *klass, void *data) { - DeviceClass *dc = DEVICE_CLASS(klass); SMBusDeviceClass *sc = SMBUS_DEVICE_CLASS(klass); sc->init = smbus_eeprom_initfn; @@ -120,7 +114,6 @@ static void smbus_eeprom_class_initfn(ObjectClass *klass, void *data) sc->receive_byte = eeprom_receive_byte; sc->write_data = eeprom_write_data; sc->read_data = eeprom_read_data; - dc->props = smbus_eeprom_properties; } static TypeInfo smbus_eeprom_info = { @@ -141,16 +134,26 @@ 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 = g_malloc0(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; + int address = 0x50 + i; + 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_prop_set_uint8(eeprom, "address", address); qdev_init_nofail(eeprom); + + if (eeprom_spd_size > 0) { + int len = MIN(eeprom_spd_size, SMBUS_EEPROM_SIZE); + int offset = 0; + while (len > 0) { + int xfer_len = MIN(len, 32); + smbus_write_block(smbus, address, offset, eeprom_spd, xfer_len); + len -= xfer_len; + eeprom_spd_size -= xfer_len; + eeprom_spd += xfer_len; + offset += xfer_len; + } + } } }