Received: by 2002:a17:907:c68a:b0:84d:2074:29bb with SMTP id ue10csp2588725ejc; Tue, 17 Jan 2023 09:57:40 -0800 (PST) X-Google-Smtp-Source: AMrXdXsAmDso3F3QdYCkihXPHCy0ZGT1svqVUUkiO2KcHYvBBZlkL8amumAdAuUtkd8Nh01Gq3k4 X-Received: by 2002:a0c:8dcf:0:b0:531:bea4:a9fd with SMTP id u15-20020a0c8dcf000000b00531bea4a9fdmr6127602qvb.28.1673978260216; Tue, 17 Jan 2023 09:57:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673978260; cv=none; d=google.com; s=arc-20160816; b=BlWyv9WZqww1b1qS2qYdCeNkoqL7VwDI/+4NuT7qb6NMVjGOCyTxzmHnGwcTA2IsBW jT38cDvgrRmwcg7NMuka4R4RdJVdPaarlXW3oJJyuz/cOjifmrz8KXpJJ4AkXlHQenk/ LX/JDo0slkTSL1GV3Ed9CX9IT7ptpAdj4aJzPhg/8W+IkTQQWNHzrRifsS2mHUVCzajl FJSril3YG4NlwtkKqS3KtCZfc32u9yo0J+q8NTK5u9myGmggusvULTYE+D+NGFzsuq9A xqwggmZ0ZvvvEGy6tu6NScC6mR5gqziUi/WkiUVv4r1CCfWdJ3BC8QBgrd+iMbsC/bi6 QB5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature:dkim-signature; bh=SSe3RROxRMxlwHPaOW/iYKDZdjjddXrZLRUBeCAvQ8w=; b=ot2W3BGz5tA2J6zs2a/SAdM0Nx9sMQwFnO3/p5ObysQOiIAMiuPabm9MF3m5vZZrF8 cCe95sngogPRtcXTMlIzqb8RpK/kBvPPMOmiQi3H7cx0XCXbbPBra5xDKgEtdd7JHjcr 3MMIVGAyhWxD63p1u72H88OSFdSfuWbAnMknPKC5k9UWCHR43FoBhaf0lmUMIYzL6mjJ Yx/z08RljuBIkwI9it3HypJIzImiR/wVR400ygU+dbRLlNOK1ztQtX8xB/xby7dMhwPK ewx1OPVGsg/dvHDz94o+tdHMBQrcRMw06hXB5MBhZRHl+uoTq6elp6vjOdqSXRTUYajS 4IaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@pjd.dev header.s=fm1 header.b=yfsM0D7S; dkim=fail header.i=@messagingengine.com header.s=fm3 header.b=h+4ER1F8; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v16-20020a05620a441000b00706b087a227si45028qkp.756.2023.01.17.09.57.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Jan 2023 09:57:40 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@pjd.dev header.s=fm1 header.b=yfsM0D7S; dkim=fail header.i=@messagingengine.com header.s=fm3 header.b=h+4ER1F8; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHqDJ-0007hn-Sl; Tue, 17 Jan 2023 12:57:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pHqDI-0007Xa-3x; Tue, 17 Jan 2023 12:57:36 -0500 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pHqDF-0006S7-UR; Tue, 17 Jan 2023 12:57:35 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 35E5B32007F0; Tue, 17 Jan 2023 12:57:31 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 17 Jan 2023 12:57:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pjd.dev; h=cc:cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1673978250; x= 1674064650; bh=SSe3RROxRMxlwHPaOW/iYKDZdjjddXrZLRUBeCAvQ8w=; b=y fsM0D7SugB6bOcNiFt37RvDzt7j7r9YSpDTqMKxVUSvEe77X8McNLPpSIj5tU1NP g9egwG6EIYsxiUHZQ4a1XrAMnVMQVy1yBxgzqfyLVD6uv2kQA647EznFgOcnAP0B 0UWJ8qwiYFzqLoqY4GqsrsupBre6+5y2cWHci1Idox6E9XTvdYnTS3vdMEVo7bHs 6JdnX9vaAMlEFKIBiqZB47lNJyGZO+4bN/22CM6WWvuiireS7VegE95WGcqLR9cu zqCh3fMugfDQevexpU3kHeU/aXww2wXOYahGOdfn/3fnyiDAs+1RVqdzuAq0XJA4 9G1iJQOqFsBexF2zbqT0Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1673978250; x= 1674064650; bh=SSe3RROxRMxlwHPaOW/iYKDZdjjddXrZLRUBeCAvQ8w=; b=h +4ER1F8jFxBotgYd+zET6/z5PIuBfO/A0o1rQ5gVxxr0z501YsnIi7MffNEhk4E/ ZZLJs1Ha8crcsT3qGXl1JJjLYnvvQMWhUUo9PGFH12j11USlHq6mwF//OEsVAH/o hDfpKxlC+RGR1HpbUkDl/LQS2aeZWzsLDVrXexfzItfva3Q7HbnmZ9SWhwgdkock /Qh1+ZSalWKz16aIVQkuegXGyW0gFLRiNqQtzhbCcp7GfsPzckqGUn9OBCxYw9M1 XZMR1MdiOam7bf+t0hRdRj0qyEdtJWkg/s9tnfuhVC3+7+SpI8y3cRjvcoWI8VsA A565SN9AtbaVYdBjc1Obg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedruddtiedguddtjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvfevuffkfhggtggugfgjse htkeertddttddunecuhfhrohhmpefrvghtvghrucffvghlvghvohhrhigrshcuoehpvght vghrsehpjhgurdguvghvqeenucggtffrrghtthgvrhhnpefhgeffvedufeevteegkeetie ejhffhudeujedvgedvheffheejveethffhffefueenucevlhhushhtvghrufhiiigvpedt necurfgrrhgrmhepmhgrihhlfhhrohhmpehpvghtvghrsehpjhgurdguvghv X-ME-Proxy: Feedback-ID: i9e814621:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 17 Jan 2023 12:57:29 -0500 (EST) Date: Tue, 17 Jan 2023 09:57:24 -0800 From: Peter Delevoryas To: =?iso-8859-1?Q?C=E9dric?= Le Goater Cc: peter.maydell@linaro.org, andrew@aj.id.au, joel@jms.id.au, hskinnemoen@google.com, kfting@nuvoton.com, qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: Re: [PATCH v2 3/5] hw/nvram/eeprom_at24c: Add init_rom field and at24c_eeprom_init_rom helper Message-ID: References: <20230116235604.55099-1-peter@pjd.dev> <20230116235604.55099-4-peter@pjd.dev> <351f520b-4690-ec08-ec90-008620fe1bee@kaod.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <351f520b-4690-ec08-ec90-008620fe1bee@kaod.org> Received-SPF: pass client-ip=64.147.123.20; envelope-from=peter@pjd.dev; helo=wout4-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org X-TUID: RTffDRs0EMkB On Tue, Jan 17, 2023 at 08:35:44AM +0100, Cédric Le Goater wrote: > On 1/17/23 00:56, Peter Delevoryas wrote: > > Allows users to specify binary data to initialize an EEPROM, allowing users to > > emulate data programmed at manufacturing time. > > > > - Added init_rom and init_rom_size attributes to TYPE_AT24C_EE > > - Added at24c_eeprom_init_rom helper function to initialize attributes > > > > Signed-off-by: Peter Delevoryas > > --- > > hw/nvram/eeprom_at24c.c | 37 ++++++++++++++++++++++++++++----- > > include/hw/nvram/eeprom_at24c.h | 2 ++ > > 2 files changed, 34 insertions(+), 5 deletions(-) > > > > diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c > > index 98857e3626b9..bb9ee75864fe 100644 > > --- a/hw/nvram/eeprom_at24c.c > > +++ b/hw/nvram/eeprom_at24c.c > > @@ -50,6 +50,9 @@ struct EEPROMState { > > uint8_t *mem; > > BlockBackend *blk; > > + > > + const uint8_t *init_rom; > > + uint32_t init_rom_size; > > }; > > static > > @@ -131,13 +134,26 @@ int at24c_eeprom_send(I2CSlave *s, uint8_t data) > > I2CSlave *at24c_eeprom_init(I2CBus *bus, uint8_t address, uint32_t rom_size) > > { > > - I2CSlave *i2c_dev = i2c_slave_new(TYPE_AT24C_EE, address); > > - DeviceState *dev = DEVICE(i2c_dev); > > + return at24c_eeprom_init_rom(bus, address, rom_size, NULL, 0); > > +} > > + > > +I2CSlave *at24c_eeprom_init_rom(I2CBus *bus, uint8_t address, uint32_t rom_size, > > + const uint8_t *init_rom, uint32_t init_rom_size) > > +{ > > + EEPROMState *s; > > + > > + s = AT24C_EE(qdev_new(TYPE_AT24C_EE)); > > + > > + qdev_prop_set_uint8(DEVICE(s), "address", address); > > + qdev_prop_set_uint32(DEVICE(s), "rom-size", rom_size); > > - qdev_prop_set_uint32(dev, "rom-size", rom_size); > > - i2c_slave_realize_and_unref(i2c_dev, bus, &error_abort); > > + /* TODO: Model init_rom with QOM properties. */ > > ok. This can be fixed with a property later when we have support. > > > + s->init_rom = init_rom; > > + s->init_rom_size = init_rom_size; > > - return i2c_dev; > > + i2c_slave_realize_and_unref(I2C_SLAVE(s), bus, &error_abort); > > + > > + return I2C_SLAVE(s); > > } > > static void at24c_eeprom_realize(DeviceState *dev, Error **errp) > > @@ -162,7 +178,14 @@ static void at24c_eeprom_realize(DeviceState *dev, Error **errp) > > } > > } > > + if (ee->init_rom_size > ee->rsize) { > > + error_setg(errp, "%s: init rom is larger than rom: %u > %u", > > + TYPE_AT24C_EE, ee->init_rom_size, ee->rsize); > > + return; > > + } > > + > > ee->mem = g_malloc0(ee->rsize); > > + > > } > > static > > @@ -185,6 +208,10 @@ void at24c_eeprom_reset(DeviceState *state) > > } > > DPRINTK("Reset read backing file\n"); > > } > > + > > + if (ee->init_rom) { > > + memcpy(ee->mem, ee->init_rom, MIN(ee->init_rom_size, ee->rsize)); > > + } > > I don't think we can have both an init_rom and a drive. The realize > handler should report an error in that case. +1, I'll include that in v3. > > > } > > static Property at24c_eeprom_props[] = { > > diff --git a/include/hw/nvram/eeprom_at24c.h b/include/hw/nvram/eeprom_at24c.h > > index 79a36b53ca87..e490826ab1d0 100644 > > --- a/include/hw/nvram/eeprom_at24c.h > > +++ b/include/hw/nvram/eeprom_at24c.h > > @@ -6,5 +6,7 @@ > > #include "hw/i2c/i2c.h" > > I2CSlave *at24c_eeprom_init(I2CBus *bus, uint8_t address, uint32_t rom_size); > > +I2CSlave *at24c_eeprom_init_rom(I2CBus *bus, uint8_t address, uint32_t rom_size, > > + const uint8_t *init_rom, uint32_t init_rom_size); > > #endif >