From nobody Tue Feb 10 23:55:32 2026 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1510589901912944.0635123692929; Mon, 13 Nov 2017 08:18:21 -0800 (PST) Received: from localhost ([::1]:55187 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEHR0-0006G3-3S for importer@patchew.org; Mon, 13 Nov 2017 11:18:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58570) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEHOC-0003wZ-Aq for qemu-devel@nongnu.org; Mon, 13 Nov 2017 11:15:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eEHO7-0008Vh-6O for qemu-devel@nongnu.org; Mon, 13 Nov 2017 11:15:12 -0500 Received: from relay2.gtri.gatech.edu ([130.207.199.168]:50339) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eEHO7-0008VF-1i for qemu-devel@nongnu.org; Mon, 13 Nov 2017 11:15:07 -0500 Received: from kiawah.core.gtri.org (kiawah.core.gtri.org [10.41.31.71]) by relay2.gtri.gatech.edu with ESMTP id JIPirF2xt3hlIDas (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=NO); Mon, 13 Nov 2017 11:15:04 -0500 (EST) Received: from tybee.core.gtri.org (10.41.1.49) by kiawah.core.gtri.org (10.41.31.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1034.26; Mon, 13 Nov 2017 11:15:04 -0500 Received: from tia-mxn-d01.ctisl.gtri.org (130.207.205.130) by tybee.core.gtri.org (10.41.1.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1034.26; Mon, 13 Nov 2017 11:15:04 -0500 X-ASG-Debug-ID: 1510589704-0768e41b30834e20001-jgbH7p X-Barracuda-Envelope-From: Michael.Nawrocki@gtri.gatech.edu From: Mike Nawrocki To: , Date: Mon, 13 Nov 2017 11:14:46 -0500 X-ASG-Orig-Subj: [PATCH v3 2/3] Enable 8-byte wide access to AMD CFI devices Message-ID: <20171113161446.2862-3-michael.nawrocki@gtri.gatech.edu> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171113161446.2862-1-michael.nawrocki@gtri.gatech.edu> References: <20171113161446.2862-1-michael.nawrocki@gtri.gatech.edu> MIME-Version: 1.0 X-Originating-IP: [130.207.205.130] X-ClientProxiedBy: apatlisdmfe4.core.gtri.org (10.41.47.104) To tybee.core.gtri.org (10.41.1.49) X-Barracuda-Connect: kiawah.core.gtri.org[10.41.31.71] X-Barracuda-Start-Time: 1510589704 X-Barracuda-Encrypted: ECDHE-RSA-AES128-SHA256 X-Barracuda-URL: https://130.207.199.168:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at gtri.gatech.edu X-Barracuda-Scan-Msg-Size: 8490 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=1000.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.44788 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 130.207.199.168 Subject: [Qemu-devel] [PATCH v3 2/3] Enable 8-byte wide access to AMD CFI devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, pbonzini@redhat.com, Mike Nawrocki , mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Mike Nawrocki --- hw/block/pflash_cfi02.c | 143 ++++++++++++++++++++++++++++++++++----------= ---- 1 file changed, 102 insertions(+), 41 deletions(-) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index a81df913f6..29eb0429a3 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -18,7 +18,7 @@ */ =20 /* - * For now, this code can emulate flashes of 1, 2 or 4 bytes width. + * For now, this code can emulate flashes of 1, 2, 4, or 8 bytes width. * Supported commands/modes are: * - flash read * - flash write @@ -138,11 +138,72 @@ static void pflash_timer (void *opaque) pfl->cmd =3D 0; } =20 +static uint64_t _flash_read(pflash_t *pfl, hwaddr offset, + int width, int be) +{ + /* Flash area read */ + uint64_t ret =3D 0; + uint8_t *p =3D pfl->storage; + + switch (width) { + case 1: + ret =3D p[offset]; + /* DPRINTF("%s: data offset %08x %02x\n", __func__, offset, ret); = */ + break; + case 2: + if (be) { + ret =3D p[offset] << 8; + ret |=3D p[offset + 1]; + } else { + ret =3D p[offset]; + ret |=3D p[offset + 1] << 8; + } + /* DPRINTF("%s: data offset %08x %04x\n", __func__, offset, ret); = */ + break; + case 4: + if (be) { + ret =3D p[offset] << 24; + ret |=3D p[offset + 1] << 16; + ret |=3D p[offset + 2] << 8; + ret |=3D p[offset + 3]; + } else { + ret =3D p[offset]; + ret |=3D p[offset + 1] << 8; + ret |=3D p[offset + 2] << 16; + ret |=3D p[offset + 3] << 24; + } + /* DPRINTF("%s: data offset %08x %08x\n", __func__, offset, ret); = */ + break; + case 8: + if (be) { + ret =3D (uint64_t)p[offset] << 56; + ret |=3D (uint64_t)p[offset + 1] << 48; + ret |=3D (uint64_t)p[offset + 2] << 40; + ret |=3D (uint64_t)p[offset + 3] << 32; + ret |=3D (uint64_t)p[offset + 4] << 24; + ret |=3D (uint64_t)p[offset + 5] << 16; + ret |=3D (uint64_t)p[offset + 6] << 8; + ret |=3D (uint64_t)p[offset + 7]; + } else { + ret =3D (uint64_t)p[offset]; + ret |=3D (uint64_t)p[offset + 1] << 8; + ret |=3D (uint64_t)p[offset + 2] << 16; + ret |=3D (uint64_t)p[offset + 3] << 24; + ret |=3D (uint64_t)p[offset + 4] << 32; + ret |=3D (uint64_t)p[offset + 5] << 40; + ret |=3D (uint64_t)p[offset + 6] << 48; + ret |=3D (uint64_t)p[offset + 7] << 56; + } + break; + } + + return ret; +} + static uint64_t pflash_read(pflash_t *pfl, hwaddr offset, int width, int be) { hwaddr boff; - uint8_t *p; uint64_t ret; =20 DPRINTF("%s: offset " TARGET_FMT_plx "\n", __func__, offset); @@ -158,6 +219,8 @@ static uint64_t pflash_read(pflash_t *pfl, hwaddr offse= t, boff =3D boff >> 1; else if (pfl->width =3D=3D 4) boff =3D boff >> 2; + else if (pfl->width =3D=3D 8) + boff =3D boff >> 3; switch (pfl->cmd) { default: /* This should never happen : reset state & treat it as a read*/ @@ -170,37 +233,7 @@ static uint64_t pflash_read(pflash_t *pfl, hwaddr offs= et, case 0x00: flash_read: /* Flash area read */ - p =3D pfl->storage; - switch (width) { - case 1: - ret =3D p[offset]; -// DPRINTF("%s: data offset %08x %02x\n", __func__, offset, ret= ); - break; - case 2: - if (be) { - ret =3D p[offset] << 8; - ret |=3D p[offset + 1]; - } else { - ret =3D p[offset]; - ret |=3D p[offset + 1] << 8; - } -// DPRINTF("%s: data offset %08x %04x\n", __func__, offset, ret= ); - break; - case 4: - if (be) { - ret =3D p[offset] << 24; - ret |=3D p[offset + 1] << 16; - ret |=3D p[offset + 2] << 8; - ret |=3D p[offset + 3]; - } else { - ret =3D p[offset]; - ret |=3D p[offset + 1] << 8; - ret |=3D p[offset + 2] << 16; - ret |=3D p[offset + 3] << 24; - } -// DPRINTF("%s: data offset %08x %08x\n", __func__, offset, ret= ); - break; - } + ret =3D _flash_read(pfl, offset, width, be); break; case 0x90: /* flash ID read */ @@ -260,8 +293,8 @@ static void pflash_update(pflash_t *pfl, int offset, } } =20 -static void pflash_write (pflash_t *pfl, hwaddr offset, - uint64_t value, int width, int be) +static void pflash_write(pflash_t *pfl, hwaddr offset, + uint64_t value, int width, int be) { hwaddr boff; uint8_t *p; @@ -275,17 +308,19 @@ static void pflash_write (pflash_t *pfl, hwaddr offse= t, #endif goto reset_flash; } - DPRINTF("%s: offset " TARGET_FMT_plx " %08x %d %d\n", __func__, - offset, value, width, pfl->wcycle); + DPRINTF("%s: offset " TARGET_FMT_plx " %08" PRIx64 " %d %d\n", + __func__, offset, value, width, pfl->wcycle); offset &=3D pfl->chip_len - 1; =20 - DPRINTF("%s: offset " TARGET_FMT_plx " %08x %d\n", __func__, - offset, value, width); + DPRINTF("%s: offset " TARGET_FMT_plx " %08" PRIx64 " %d\n", + __func__, offset, value, width); boff =3D offset & (pfl->sector_len - 1); if (pfl->width =3D=3D 2) boff =3D boff >> 1; else if (pfl->width =3D=3D 4) boff =3D boff >> 2; + else if (pfl->width =3D=3D 8) + boff =3D boff >> 3; switch (pfl->wcycle) { case 0: /* Set the device in I/O access mode if required */ @@ -346,8 +381,8 @@ static void pflash_write (pflash_t *pfl, hwaddr offset, /* We need another unlock sequence */ goto check_unlock0; case 0xA0: - DPRINTF("%s: write data offset " TARGET_FMT_plx " %08x %d\n", - __func__, offset, value, width); + DPRINTF("%s: write data offset " TARGET_FMT_plx + " %08" PRIx64 " %d\n", __func__, offset, value, width); p =3D pfl->storage; if (!pfl->ro) { switch (width) { @@ -379,6 +414,28 @@ static void pflash_write (pflash_t *pfl, hwaddr offset, } pflash_update(pfl, offset, 4); break; + case 8: + if (be) { + p[offset] &=3D value >> 56; + p[offset + 1] &=3D value >> 48; + p[offset + 2] &=3D value >> 40; + p[offset + 3] &=3D value >> 32; + p[offset + 4] &=3D value >> 24; + p[offset + 5] &=3D value >> 16; + p[offset + 6] &=3D value >> 8; + p[offset + 7] &=3D value; + } else { + p[offset] &=3D value; + p[offset + 1] &=3D value >> 8; + p[offset + 2] &=3D value >> 16; + p[offset + 3] &=3D value >> 24; + p[offset + 4] &=3D value >> 32; + p[offset + 5] &=3D value >> 40; + p[offset + 6] &=3D value >> 48; + p[offset + 7] &=3D value >> 56; + } + pflash_update(pfl, offset, 8); + break; } } pfl->status =3D 0x00 | ~(value & 0x80); @@ -524,12 +581,16 @@ static const MemoryRegionOps pflash_cfi02_ops_be =3D { .read =3D pflash_read_be, .write =3D pflash_write_be, .endianness =3D DEVICE_NATIVE_ENDIAN, + .valid.max_access_size =3D 8, + .impl.max_access_size =3D 8, }; =20 static const MemoryRegionOps pflash_cfi02_ops_le =3D { .read =3D pflash_read_le, .write =3D pflash_write_le, .endianness =3D DEVICE_NATIVE_ENDIAN, + .valid.max_access_size =3D 8, + .impl.max_access_size =3D 8, }; =20 static void pflash_cfi02_realize(DeviceState *dev, Error **errp) --=20 2.14.2