From nobody Sun Nov 24 09:35:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1725379975; cv=none; d=zohomail.com; s=zohoarc; b=ZVrPe/on87DO5fCI6iWZ3UALuRc2u1O8x0lbV8FbHHZN1zseYo5rKMGABu28XOunzLxtjJ3jAJLO+hy2QOdhm4B9k/5vsruJJv+lUKsTihAFB0An3c3EZDZ6OS6kIe3Z2p/OcthhCM5ZXSJ3IzF/7MKtnDK4FfZ/88laL7WGlJ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725379975; h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=S5c89sKQbPl5fIjq2ETHtRbYiVtxAIAEgqCXSPrAcUc=; b=MAKa1A/7IY3gV+paqKrMMxuOndYh6qTF0XMI2pyyf+84v54mj+N8y/4Tpn8JO8Dne8jMXUUIdpKXcBCpMFkJx75PNgAygI74EVGBtW0/zEEe4k2a2KG6tOm9vvUjMZoDnURfUzrpR2AEK4XIZ20SgtdqbbE93LoR3vj14QzV6AA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1725379975412355.312000053554; Tue, 3 Sep 2024 09:12:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1slW5N-0000I4-0R; Tue, 03 Sep 2024 12:08:53 -0400 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 1slW5L-00009A-Hf for qemu-devel@nongnu.org; Tue, 03 Sep 2024 12:08:51 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1slW5A-0002re-Jm for qemu-devel@nongnu.org; Tue, 03 Sep 2024 12:08:51 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-42bb81e795bso45462325e9.1 for ; Tue, 03 Sep 2024 09:08:40 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6df1066sm175123065e9.18.2024.09.03.09.08.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 09:08:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725379719; x=1725984519; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=S5c89sKQbPl5fIjq2ETHtRbYiVtxAIAEgqCXSPrAcUc=; b=jokZzNrO+JscMvRcnK5JitShQX3hPpE/RJWz+ogHGQH4MuAFcMeIZN5EsTjOpGQVCO aeRH+C59aPenYW9ay/VuZsr7e5FpLnZIsvJV0wuhQ7vTpGNUXJZfO+HTIxngRsXZ0+cX t07/OwHFbY08NLfKwDt2SvPbpiX5at/6IdvnMx64N9CJF3s+ww2qsHIlTBgEHQMhiPyF qLk3BSxnoGdSyIcHyW/8k5DsYJd60BK5FsF/LX/9+ThDqdMx/oYU9115kJ0WyitaBeAt iISIpkz9SHm1/6Ya8ds5xMcNwxzgPwqj6lBzqIbwsTdI5lmrWWuGgTfblXCxkeO3v731 HSQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725379719; x=1725984519; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S5c89sKQbPl5fIjq2ETHtRbYiVtxAIAEgqCXSPrAcUc=; b=C3eXMOLezY0qwclwfq+PC/9As5HXbMPOYx4MA9ik+IB06rcczQfG3bl2itSOu3MzSa qtaO0Mc26PMV55b9PehZlL2SG0jUVycJVTLjymvmeWXXuwsjVfSBpQIAn4b9n/X+MMeX 25A6DdhCMOfr4kkYbFy2xs0Il9Z6MEJFO2EJvlulBEkw86pDw5EUphdf+BYH48Iu2/gO v2FYOPNLERx1ZebJLvniroOWdJ1O6P0TATiAk1YQ7AV9w4fl97cxt+581idUNKPVuaT8 nBVkK4LTW6ctG99AjfWafBaZjjTzNvWN5nbCo+qqgq8nqJRYQb8+GYwe1uM1dfAnSS5d hHIQ== X-Forwarded-Encrypted: i=1; AJvYcCVfMZewueOwIqtYikrYoOcH2zeqQcRLoMj3uKy3BpctRHaTLBRjRTGpw6AvVguLrQ74ZOJ11XTq2Ulx@nongnu.org X-Gm-Message-State: AOJu0YxSZXPXJVWrkydO+3A+5Rk+KGGzs8cRSp9nCxwtQn3+jD7PEQeM Ymw9epWoUB9hrlPkh8goSlLQwYYCs17bCwfYmruU6+o1aJXsyZjaQxzve9G4h5Q= X-Google-Smtp-Source: AGHT+IFnHNAinU8LWdvnumAIbNjCiYLk8Sa5IgPfNMJOHjRqsx0Rcw8VYEKqQIb734+Q2+JXTAHhEg== X-Received: by 2002:a05:600c:1914:b0:426:647b:1bfc with SMTP id 5b1f17b1804b1-42bbb440222mr89442075e9.30.1725379718888; Tue, 03 Sep 2024 09:08:38 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH for-9.2 32/53] hw/block: Remove OneNAND device Date: Tue, 3 Sep 2024 17:07:30 +0100 Message-Id: <20240903160751.4100218-33-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903160751.4100218-1-peter.maydell@linaro.org> References: <20240903160751.4100218-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x332.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@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-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1725379976023116600 Content-Type: text/plain; charset="utf-8" The OneNAND devices were only used by n800/n810, so they can be removed now. Signed-off-by: Peter Maydell Reviewed-by: Thomas Huth --- include/hw/block/flash.h | 3 - hw/block/onenand.c | 872 --------------------------------------- hw/block/Kconfig | 3 - hw/block/meson.build | 1 - 4 files changed, 879 deletions(-) delete mode 100644 hw/block/onenand.c diff --git a/include/hw/block/flash.h b/include/hw/block/flash.h index 2b5ccd92f46..b985c825a01 100644 --- a/include/hw/block/flash.h +++ b/include/hw/block/flash.h @@ -62,9 +62,6 @@ uint32_t nand_getbuswidth(DeviceState *dev); #define NAND_MFR_HYNIX 0xad #define NAND_MFR_MICRON 0x2c =20 -/* onenand.c */ -void *onenand_raw_otp(DeviceState *onenand_device); - /* ecc.c */ typedef struct { uint8_t cp; /* Column parity */ diff --git a/hw/block/onenand.c b/hw/block/onenand.c deleted file mode 100644 index d8a6944027a..00000000000 --- a/hw/block/onenand.c +++ /dev/null @@ -1,872 +0,0 @@ -/* - * OneNAND flash memories emulation. - * - * Copyright (C) 2008 Nokia Corporation - * Written by Andrzej Zaborowski - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, see . - */ - -#include "qemu/osdep.h" -#include "qapi/error.h" -#include "hw/hw.h" -#include "hw/block/flash.h" -#include "hw/irq.h" -#include "hw/qdev-properties.h" -#include "hw/qdev-properties-system.h" -#include "sysemu/block-backend.h" -#include "exec/memory.h" -#include "hw/sysbus.h" -#include "migration/vmstate.h" -#include "qemu/error-report.h" -#include "qemu/log.h" -#include "qemu/module.h" -#include "qom/object.h" - -/* 11 for 2kB-page OneNAND ("2nd generation") and 10 for 1kB-page chips */ -#define PAGE_SHIFT 11 - -/* Fixed */ -#define BLOCK_SHIFT (PAGE_SHIFT + 6) - -#define TYPE_ONE_NAND "onenand" -OBJECT_DECLARE_SIMPLE_TYPE(OneNANDState, ONE_NAND) - -struct OneNANDState { - SysBusDevice parent_obj; - - struct { - uint16_t man; - uint16_t dev; - uint16_t ver; - } id; - int shift; - hwaddr base; - qemu_irq intr; - qemu_irq rdy; - BlockBackend *blk; - BlockBackend *blk_cur; - uint8_t *image; - uint8_t *otp; - uint8_t *current; - MemoryRegion ram; - MemoryRegion mapped_ram; - uint8_t current_direction; - uint8_t *boot[2]; - uint8_t *data[2][2]; - MemoryRegion iomem; - MemoryRegion container; - int cycle; - int otpmode; - - uint16_t addr[8]; - uint16_t unladdr[8]; - int bufaddr; - int count; - uint16_t command; - uint16_t config[2]; - uint16_t status; - uint16_t intstatus; - uint16_t wpstatus; - - ECCState ecc; - - int density_mask; - int secs; - int secs_cur; - int blocks; - uint8_t *blockwp; -}; - -enum { - ONEN_BUF_BLOCK =3D 0, - ONEN_BUF_BLOCK2 =3D 1, - ONEN_BUF_DEST_BLOCK =3D 2, - ONEN_BUF_DEST_PAGE =3D 3, - ONEN_BUF_PAGE =3D 7, -}; - -enum { - ONEN_ERR_CMD =3D 1 << 10, - ONEN_ERR_ERASE =3D 1 << 11, - ONEN_ERR_PROG =3D 1 << 12, - ONEN_ERR_LOAD =3D 1 << 13, -}; - -enum { - ONEN_INT_RESET =3D 1 << 4, - ONEN_INT_ERASE =3D 1 << 5, - ONEN_INT_PROG =3D 1 << 6, - ONEN_INT_LOAD =3D 1 << 7, - ONEN_INT =3D 1 << 15, -}; - -enum { - ONEN_LOCK_LOCKTIGHTEN =3D 1 << 0, - ONEN_LOCK_LOCKED =3D 1 << 1, - ONEN_LOCK_UNLOCKED =3D 1 << 2, -}; - -static void onenand_mem_setup(OneNANDState *s) -{ - /* XXX: We should use IO_MEM_ROMD but we broke it earlier... - * Both 0x0000 ... 0x01ff and 0x8000 ... 0x800f can be used to - * write boot commands. Also take note of the BWPS bit. */ - memory_region_init(&s->container, OBJECT(s), "onenand", - 0x10000 << s->shift); - memory_region_add_subregion(&s->container, 0, &s->iomem); - memory_region_init_alias(&s->mapped_ram, OBJECT(s), "onenand-mapped-ra= m", - &s->ram, 0x0200 << s->shift, - 0xbe00 << s->shift); - memory_region_add_subregion_overlap(&s->container, - 0x0200 << s->shift, - &s->mapped_ram, - 1); -} - -static void onenand_intr_update(OneNANDState *s) -{ - qemu_set_irq(s->intr, ((s->intstatus >> 15) ^ (~s->config[0] >> 6)) & = 1); -} - -static int onenand_pre_save(void *opaque) -{ - OneNANDState *s =3D opaque; - if (s->current =3D=3D s->otp) { - s->current_direction =3D 1; - } else if (s->current =3D=3D s->image) { - s->current_direction =3D 2; - } else { - s->current_direction =3D 0; - } - - return 0; -} - -static int onenand_post_load(void *opaque, int version_id) -{ - OneNANDState *s =3D opaque; - switch (s->current_direction) { - case 0: - break; - case 1: - s->current =3D s->otp; - break; - case 2: - s->current =3D s->image; - break; - default: - return -1; - } - onenand_intr_update(s); - return 0; -} - -static const VMStateDescription vmstate_onenand =3D { - .name =3D "onenand", - .version_id =3D 1, - .minimum_version_id =3D 1, - .pre_save =3D onenand_pre_save, - .post_load =3D onenand_post_load, - .fields =3D (const VMStateField[]) { - VMSTATE_UINT8(current_direction, OneNANDState), - VMSTATE_INT32(cycle, OneNANDState), - VMSTATE_INT32(otpmode, OneNANDState), - VMSTATE_UINT16_ARRAY(addr, OneNANDState, 8), - VMSTATE_UINT16_ARRAY(unladdr, OneNANDState, 8), - VMSTATE_INT32(bufaddr, OneNANDState), - VMSTATE_INT32(count, OneNANDState), - VMSTATE_UINT16(command, OneNANDState), - VMSTATE_UINT16_ARRAY(config, OneNANDState, 2), - VMSTATE_UINT16(status, OneNANDState), - VMSTATE_UINT16(intstatus, OneNANDState), - VMSTATE_UINT16(wpstatus, OneNANDState), - VMSTATE_INT32(secs_cur, OneNANDState), - VMSTATE_PARTIAL_VBUFFER(blockwp, OneNANDState, blocks), - VMSTATE_UINT8(ecc.cp, OneNANDState), - VMSTATE_UINT16_ARRAY(ecc.lp, OneNANDState, 2), - VMSTATE_UINT16(ecc.count, OneNANDState), - VMSTATE_BUFFER_POINTER_UNSAFE(otp, OneNANDState, 0, - ((64 + 2) << PAGE_SHIFT)), - VMSTATE_END_OF_LIST() - } -}; - -/* Hot reset (Reset OneNAND command) or warm reset (RP pin low) */ -static void onenand_reset(OneNANDState *s, int cold) -{ - memset(&s->addr, 0, sizeof(s->addr)); - s->command =3D 0; - s->count =3D 1; - s->bufaddr =3D 0; - s->config[0] =3D 0x40c0; - s->config[1] =3D 0x0000; - onenand_intr_update(s); - qemu_irq_raise(s->rdy); - s->status =3D 0x0000; - s->intstatus =3D cold ? 0x8080 : 0x8010; - s->unladdr[0] =3D 0; - s->unladdr[1] =3D 0; - s->wpstatus =3D 0x0002; - s->cycle =3D 0; - s->otpmode =3D 0; - s->blk_cur =3D s->blk; - s->current =3D s->image; - s->secs_cur =3D s->secs; - - if (cold) { - /* Lock the whole flash */ - memset(s->blockwp, ONEN_LOCK_LOCKED, s->blocks); - - if (s->blk_cur && blk_pread(s->blk_cur, 0, 8 << BDRV_SECTOR_BITS, - s->boot[0], 0) < 0) { - hw_error("%s: Loading the BootRAM failed.\n", __func__); - } - } -} - -static void onenand_system_reset(DeviceState *dev) -{ - OneNANDState *s =3D ONE_NAND(dev); - - onenand_reset(s, 1); -} - -static inline int onenand_load_main(OneNANDState *s, int sec, int secn, - void *dest) -{ - assert(UINT32_MAX >> BDRV_SECTOR_BITS > sec); - assert(UINT32_MAX >> BDRV_SECTOR_BITS > secn); - if (s->blk_cur) { - return blk_pread(s->blk_cur, sec << BDRV_SECTOR_BITS, - secn << BDRV_SECTOR_BITS, dest, 0) < 0; - } else if (sec + secn > s->secs_cur) { - return 1; - } - - memcpy(dest, s->current + (sec << 9), secn << 9); - - return 0; -} - -static inline int onenand_prog_main(OneNANDState *s, int sec, int secn, - void *src) -{ - int result =3D 0; - - if (secn > 0) { - uint32_t size =3D secn << BDRV_SECTOR_BITS; - uint32_t offset =3D sec << BDRV_SECTOR_BITS; - assert(UINT32_MAX >> BDRV_SECTOR_BITS > sec); - assert(UINT32_MAX >> BDRV_SECTOR_BITS > secn); - const uint8_t *sp =3D (const uint8_t *)src; - uint8_t *dp =3D 0; - if (s->blk_cur) { - dp =3D g_malloc(size); - if (!dp || blk_pread(s->blk_cur, offset, size, dp, 0) < 0) { - result =3D 1; - } - } else { - if (sec + secn > s->secs_cur) { - result =3D 1; - } else { - dp =3D (uint8_t *)s->current + offset; - } - } - if (!result) { - uint32_t i; - for (i =3D 0; i < size; i++) { - dp[i] &=3D sp[i]; - } - if (s->blk_cur) { - result =3D blk_pwrite(s->blk_cur, offset, size, dp, 0) < 0; - } - } - if (dp && s->blk_cur) { - g_free(dp); - } - } - - return result; -} - -static inline int onenand_load_spare(OneNANDState *s, int sec, int secn, - void *dest) -{ - uint8_t buf[512]; - - if (s->blk_cur) { - uint32_t offset =3D (s->secs_cur + (sec >> 5)) << BDRV_SECTOR_BITS; - if (blk_pread(s->blk_cur, offset, BDRV_SECTOR_SIZE, buf, 0) < 0) { - return 1; - } - memcpy(dest, buf + ((sec & 31) << 4), secn << 4); - } else if (sec + secn > s->secs_cur) { - return 1; - } else { - memcpy(dest, s->current + (s->secs_cur << 9) + (sec << 4), secn <<= 4); - } - - return 0; -} - -static inline int onenand_prog_spare(OneNANDState *s, int sec, int secn, - void *src) -{ - int result =3D 0; - if (secn > 0) { - const uint8_t *sp =3D (const uint8_t *)src; - uint8_t *dp =3D 0, *dpp =3D 0; - uint32_t offset =3D (s->secs_cur + (sec >> 5)) << BDRV_SECTOR_BITS; - assert(UINT32_MAX >> BDRV_SECTOR_BITS > s->secs_cur + (sec >> 5)); - if (s->blk_cur) { - dp =3D g_malloc(512); - if (!dp - || blk_pread(s->blk_cur, offset, BDRV_SECTOR_SIZE, dp, 0) = < 0) { - result =3D 1; - } else { - dpp =3D dp + ((sec & 31) << 4); - } - } else { - if (sec + secn > s->secs_cur) { - result =3D 1; - } else { - dpp =3D s->current + (s->secs_cur << 9) + (sec << 4); - } - } - if (!result) { - uint32_t i; - for (i =3D 0; i < (secn << 4); i++) { - dpp[i] &=3D sp[i]; - } - if (s->blk_cur) { - result =3D blk_pwrite(s->blk_cur, offset, BDRV_SECTOR_SIZE= , dp, - 0) < 0; - } - } - g_free(dp); - } - return result; -} - -static inline int onenand_erase(OneNANDState *s, int sec, int num) -{ - uint8_t *blankbuf, *tmpbuf; - - blankbuf =3D g_malloc(512); - tmpbuf =3D g_malloc(512); - memset(blankbuf, 0xff, 512); - for (; num > 0; num--, sec++) { - if (s->blk_cur) { - int erasesec =3D s->secs_cur + (sec >> 5); - if (blk_pwrite(s->blk_cur, sec << BDRV_SECTOR_BITS, - BDRV_SECTOR_SIZE, blankbuf, 0) < 0) { - goto fail; - } - if (blk_pread(s->blk_cur, erasesec << BDRV_SECTOR_BITS, - BDRV_SECTOR_SIZE, tmpbuf, 0) < 0) { - goto fail; - } - memcpy(tmpbuf + ((sec & 31) << 4), blankbuf, 1 << 4); - if (blk_pwrite(s->blk_cur, erasesec << BDRV_SECTOR_BITS, - BDRV_SECTOR_SIZE, tmpbuf, 0) < 0) { - goto fail; - } - } else { - if (sec + 1 > s->secs_cur) { - goto fail; - } - memcpy(s->current + (sec << 9), blankbuf, 512); - memcpy(s->current + (s->secs_cur << 9) + (sec << 4), - blankbuf, 1 << 4); - } - } - - g_free(tmpbuf); - g_free(blankbuf); - return 0; - -fail: - g_free(tmpbuf); - g_free(blankbuf); - return 1; -} - -static void onenand_command(OneNANDState *s) -{ - int b; - int sec; - void *buf; -#define SETADDR(block, page) \ - sec =3D (s->addr[page] & 3) + \ - ((((s->addr[page] >> 2) & 0x3f) + \ - (((s->addr[block] & 0xfff) | \ - (s->addr[block] >> 15 ? s->density_mask : 0)) \ - << 6)) \ - << (PAGE_SHIFT - 9)); -#define SETBUF_M() = \ - buf =3D (s->bufaddr & 8) ? s->data[(s->bufaddr >> 2) & 1][0] : s->boot= [0]; \ - buf +=3D (s->bufaddr & 3) << 9; -#define SETBUF_S() \ - buf =3D (s->bufaddr & 8) ? \ - s->data[(s->bufaddr >> 2) & 1][1] : s->boot[1]; \ - buf +=3D (s->bufaddr & 3) << 4; - - switch (s->command) { - case 0x00: /* Load single/multiple sector data unit into buffer */ - SETADDR(ONEN_BUF_BLOCK, ONEN_BUF_PAGE) - - SETBUF_M() - if (onenand_load_main(s, sec, s->count, buf)) - s->status |=3D ONEN_ERR_CMD | ONEN_ERR_LOAD; - -#if 0 - SETBUF_S() - if (onenand_load_spare(s, sec, s->count, buf)) - s->status |=3D ONEN_ERR_CMD | ONEN_ERR_LOAD; -#endif - - /* TODO: if (s->bufaddr & 3) + s->count was > 4 (2k-pages) - * or if (s->bufaddr & 1) + s->count was > 2 (1k-pages) - * then we need two split the read/write into two chunks. - */ - s->intstatus |=3D ONEN_INT | ONEN_INT_LOAD; - break; - case 0x13: /* Load single/multiple spare sector into buffer */ - SETADDR(ONEN_BUF_BLOCK, ONEN_BUF_PAGE) - - SETBUF_S() - if (onenand_load_spare(s, sec, s->count, buf)) - s->status |=3D ONEN_ERR_CMD | ONEN_ERR_LOAD; - - /* TODO: if (s->bufaddr & 3) + s->count was > 4 (2k-pages) - * or if (s->bufaddr & 1) + s->count was > 2 (1k-pages) - * then we need two split the read/write into two chunks. - */ - s->intstatus |=3D ONEN_INT | ONEN_INT_LOAD; - break; - case 0x80: /* Program single/multiple sector data unit from buffer */ - SETADDR(ONEN_BUF_BLOCK, ONEN_BUF_PAGE) - - SETBUF_M() - if (onenand_prog_main(s, sec, s->count, buf)) - s->status |=3D ONEN_ERR_CMD | ONEN_ERR_PROG; - -#if 0 - SETBUF_S() - if (onenand_prog_spare(s, sec, s->count, buf)) - s->status |=3D ONEN_ERR_CMD | ONEN_ERR_PROG; -#endif - - /* TODO: if (s->bufaddr & 3) + s->count was > 4 (2k-pages) - * or if (s->bufaddr & 1) + s->count was > 2 (1k-pages) - * then we need two split the read/write into two chunks. - */ - s->intstatus |=3D ONEN_INT | ONEN_INT_PROG; - break; - case 0x1a: /* Program single/multiple spare area sector from buffer */ - SETADDR(ONEN_BUF_BLOCK, ONEN_BUF_PAGE) - - SETBUF_S() - if (onenand_prog_spare(s, sec, s->count, buf)) - s->status |=3D ONEN_ERR_CMD | ONEN_ERR_PROG; - - /* TODO: if (s->bufaddr & 3) + s->count was > 4 (2k-pages) - * or if (s->bufaddr & 1) + s->count was > 2 (1k-pages) - * then we need two split the read/write into two chunks. - */ - s->intstatus |=3D ONEN_INT | ONEN_INT_PROG; - break; - case 0x1b: /* Copy-back program */ - SETBUF_S() - - SETADDR(ONEN_BUF_BLOCK, ONEN_BUF_PAGE) - if (onenand_load_main(s, sec, s->count, buf)) - s->status |=3D ONEN_ERR_CMD | ONEN_ERR_PROG; - - SETADDR(ONEN_BUF_DEST_BLOCK, ONEN_BUF_DEST_PAGE) - if (onenand_prog_main(s, sec, s->count, buf)) - s->status |=3D ONEN_ERR_CMD | ONEN_ERR_PROG; - - /* TODO: spare areas */ - - s->intstatus |=3D ONEN_INT | ONEN_INT_PROG; - break; - - case 0x23: /* Unlock NAND array block(s) */ - s->intstatus |=3D ONEN_INT; - - /* XXX the previous (?) area should be locked automatically */ - for (b =3D s->unladdr[0]; b <=3D s->unladdr[1]; b ++) { - if (b >=3D s->blocks) { - s->status |=3D ONEN_ERR_CMD; - break; - } - if (s->blockwp[b] =3D=3D ONEN_LOCK_LOCKTIGHTEN) - break; - - s->wpstatus =3D s->blockwp[b] =3D ONEN_LOCK_UNLOCKED; - } - break; - case 0x27: /* Unlock All NAND array blocks */ - s->intstatus |=3D ONEN_INT; - - for (b =3D 0; b < s->blocks; b ++) { - if (s->blockwp[b] =3D=3D ONEN_LOCK_LOCKTIGHTEN) - break; - - s->wpstatus =3D s->blockwp[b] =3D ONEN_LOCK_UNLOCKED; - } - break; - - case 0x2a: /* Lock NAND array block(s) */ - s->intstatus |=3D ONEN_INT; - - for (b =3D s->unladdr[0]; b <=3D s->unladdr[1]; b ++) { - if (b >=3D s->blocks) { - s->status |=3D ONEN_ERR_CMD; - break; - } - if (s->blockwp[b] =3D=3D ONEN_LOCK_LOCKTIGHTEN) - break; - - s->wpstatus =3D s->blockwp[b] =3D ONEN_LOCK_LOCKED; - } - break; - case 0x2c: /* Lock-tight NAND array block(s) */ - s->intstatus |=3D ONEN_INT; - - for (b =3D s->unladdr[0]; b <=3D s->unladdr[1]; b ++) { - if (b >=3D s->blocks) { - s->status |=3D ONEN_ERR_CMD; - break; - } - if (s->blockwp[b] =3D=3D ONEN_LOCK_UNLOCKED) - continue; - - s->wpstatus =3D s->blockwp[b] =3D ONEN_LOCK_LOCKTIGHTEN; - } - break; - - case 0x71: /* Erase-Verify-Read */ - s->intstatus |=3D ONEN_INT; - break; - case 0x95: /* Multi-block erase */ - qemu_irq_pulse(s->intr); - /* Fall through. */ - case 0x94: /* Block erase */ - sec =3D ((s->addr[ONEN_BUF_BLOCK] & 0xfff) | - (s->addr[ONEN_BUF_BLOCK] >> 15 ? s->density_mask := 0)) - << (BLOCK_SHIFT - 9); - if (onenand_erase(s, sec, 1 << (BLOCK_SHIFT - 9))) - s->status |=3D ONEN_ERR_CMD | ONEN_ERR_ERASE; - - s->intstatus |=3D ONEN_INT | ONEN_INT_ERASE; - break; - case 0xb0: /* Erase suspend */ - break; - case 0x30: /* Erase resume */ - s->intstatus |=3D ONEN_INT | ONEN_INT_ERASE; - break; - - case 0xf0: /* Reset NAND Flash core */ - onenand_reset(s, 0); - break; - case 0xf3: /* Reset OneNAND */ - onenand_reset(s, 0); - break; - - case 0x65: /* OTP Access */ - s->intstatus |=3D ONEN_INT; - s->blk_cur =3D NULL; - s->current =3D s->otp; - s->secs_cur =3D 1 << (BLOCK_SHIFT - 9); - s->addr[ONEN_BUF_BLOCK] =3D 0; - s->otpmode =3D 1; - break; - - default: - s->status |=3D ONEN_ERR_CMD; - s->intstatus |=3D ONEN_INT; - qemu_log_mask(LOG_GUEST_ERROR, "unknown OneNAND command %x\n", - s->command); - } - - onenand_intr_update(s); -} - -static uint64_t onenand_read(void *opaque, hwaddr addr, - unsigned size) -{ - OneNANDState *s =3D (OneNANDState *) opaque; - int offset =3D addr >> s->shift; - - switch (offset) { - case 0x0000 ... 0xbffe: - return lduw_le_p(s->boot[0] + addr); - - case 0xf000: /* Manufacturer ID */ - return s->id.man; - case 0xf001: /* Device ID */ - return s->id.dev; - case 0xf002: /* Version ID */ - return s->id.ver; - /* TODO: get the following values from a real chip! */ - case 0xf003: /* Data Buffer size */ - return 1 << PAGE_SHIFT; - case 0xf004: /* Boot Buffer size */ - return 0x200; - case 0xf005: /* Amount of buffers */ - return 1 | (2 << 8); - case 0xf006: /* Technology */ - return 0; - - case 0xf100 ... 0xf107: /* Start addresses */ - return s->addr[offset - 0xf100]; - - case 0xf200: /* Start buffer */ - return (s->bufaddr << 8) | ((s->count - 1) & (1 << (PAGE_SHIFT - 1= 0))); - - case 0xf220: /* Command */ - return s->command; - case 0xf221: /* System Configuration 1 */ - return s->config[0] & 0xffe0; - case 0xf222: /* System Configuration 2 */ - return s->config[1]; - - case 0xf240: /* Controller Status */ - return s->status; - case 0xf241: /* Interrupt */ - return s->intstatus; - case 0xf24c: /* Unlock Start Block Address */ - return s->unladdr[0]; - case 0xf24d: /* Unlock End Block Address */ - return s->unladdr[1]; - case 0xf24e: /* Write Protection Status */ - return s->wpstatus; - - case 0xff00: /* ECC Status */ - return 0x00; - case 0xff01: /* ECC Result of main area data */ - case 0xff02: /* ECC Result of spare area data */ - case 0xff03: /* ECC Result of main area data */ - case 0xff04: /* ECC Result of spare area data */ - qemu_log_mask(LOG_UNIMP, - "onenand: ECC result registers unimplemented\n"); - return 0x0000; - } - - qemu_log_mask(LOG_GUEST_ERROR, "read of unknown OneNAND register 0x%x\= n", - offset); - return 0; -} - -static void onenand_write(void *opaque, hwaddr addr, - uint64_t value, unsigned size) -{ - OneNANDState *s =3D (OneNANDState *) opaque; - int offset =3D addr >> s->shift; - int sec; - - switch (offset) { - case 0x0000 ... 0x01ff: - case 0x8000 ... 0x800f: - if (s->cycle) { - s->cycle =3D 0; - - if (value =3D=3D 0x0000) { - SETADDR(ONEN_BUF_BLOCK, ONEN_BUF_PAGE) - onenand_load_main(s, sec, - 1 << (PAGE_SHIFT - 9), s->data[0][0]); - s->addr[ONEN_BUF_PAGE] +=3D 4; - s->addr[ONEN_BUF_PAGE] &=3D 0xff; - } - break; - } - - switch (value) { - case 0x00f0: /* Reset OneNAND */ - onenand_reset(s, 0); - break; - - case 0x00e0: /* Load Data into Buffer */ - s->cycle =3D 1; - break; - - case 0x0090: /* Read Identification Data */ - memset(s->boot[0], 0, 3 << s->shift); - s->boot[0][0 << s->shift] =3D s->id.man & 0xff; - s->boot[0][1 << s->shift] =3D s->id.dev & 0xff; - s->boot[0][2 << s->shift] =3D s->wpstatus & 0xff; - break; - - default: - qemu_log_mask(LOG_GUEST_ERROR, - "unknown OneNAND boot command %" PRIx64 "\n", - value); - } - break; - - case 0xf100 ... 0xf107: /* Start addresses */ - s->addr[offset - 0xf100] =3D value; - break; - - case 0xf200: /* Start buffer */ - s->bufaddr =3D (value >> 8) & 0xf; - if (PAGE_SHIFT =3D=3D 11) - s->count =3D (value & 3) ?: 4; - else if (PAGE_SHIFT =3D=3D 10) - s->count =3D (value & 1) ?: 2; - break; - - case 0xf220: /* Command */ - if (s->intstatus & (1 << 15)) - break; - s->command =3D value; - onenand_command(s); - break; - case 0xf221: /* System Configuration 1 */ - s->config[0] =3D value; - onenand_intr_update(s); - qemu_set_irq(s->rdy, (s->config[0] >> 7) & 1); - break; - case 0xf222: /* System Configuration 2 */ - s->config[1] =3D value; - break; - - case 0xf241: /* Interrupt */ - s->intstatus &=3D value; - if ((1 << 15) & ~s->intstatus) - s->status &=3D ~(ONEN_ERR_CMD | ONEN_ERR_ERASE | - ONEN_ERR_PROG | ONEN_ERR_LOAD); - onenand_intr_update(s); - break; - case 0xf24c: /* Unlock Start Block Address */ - s->unladdr[0] =3D value & (s->blocks - 1); - /* For some reason we have to set the end address to by default - * be same as start because the software forgets to write anything - * in there. */ - s->unladdr[1] =3D value & (s->blocks - 1); - break; - case 0xf24d: /* Unlock End Block Address */ - s->unladdr[1] =3D value & (s->blocks - 1); - break; - - default: - qemu_log_mask(LOG_GUEST_ERROR, - "write to unknown OneNAND register 0x%x\n", - offset); - } -} - -static const MemoryRegionOps onenand_ops =3D { - .read =3D onenand_read, - .write =3D onenand_write, - .endianness =3D DEVICE_NATIVE_ENDIAN, -}; - -static void onenand_realize(DeviceState *dev, Error **errp) -{ - SysBusDevice *sbd =3D SYS_BUS_DEVICE(dev); - OneNANDState *s =3D ONE_NAND(dev); - uint32_t size =3D 1 << (24 + ((s->id.dev >> 4) & 7)); - void *ram; - Error *local_err =3D NULL; - - s->base =3D (hwaddr)-1; - s->rdy =3D NULL; - s->blocks =3D size >> BLOCK_SHIFT; - s->secs =3D size >> 9; - s->blockwp =3D g_malloc(s->blocks); - s->density_mask =3D (s->id.dev & 0x08) - ? (1 << (6 + ((s->id.dev >> 4) & 7))) : 0; - memory_region_init_io(&s->iomem, OBJECT(s), &onenand_ops, s, "onenand", - 0x10000 << s->shift); - if (!s->blk) { - s->image =3D memset(g_malloc(size + (size >> 5)), - 0xff, size + (size >> 5)); - } else { - if (!blk_supports_write_perm(s->blk)) { - error_setg(errp, "Can't use a read-only drive"); - return; - } - blk_set_perm(s->blk, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE, - BLK_PERM_ALL, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } - s->blk_cur =3D s->blk; - } - s->otp =3D memset(g_malloc((64 + 2) << PAGE_SHIFT), - 0xff, (64 + 2) << PAGE_SHIFT); - memory_region_init_ram_nomigrate(&s->ram, OBJECT(s), "onenand.ram", - 0xc000 << s->shift, &error_fatal); - vmstate_register_ram_global(&s->ram); - ram =3D memory_region_get_ram_ptr(&s->ram); - s->boot[0] =3D ram + (0x0000 << s->shift); - s->boot[1] =3D ram + (0x8000 << s->shift); - s->data[0][0] =3D ram + ((0x0200 + (0 << (PAGE_SHIFT - 1))) << s->shif= t); - s->data[0][1] =3D ram + ((0x8010 + (0 << (PAGE_SHIFT - 6))) << s->shif= t); - s->data[1][0] =3D ram + ((0x0200 + (1 << (PAGE_SHIFT - 1))) << s->shif= t); - s->data[1][1] =3D ram + ((0x8010 + (1 << (PAGE_SHIFT - 6))) << s->shif= t); - onenand_mem_setup(s); - sysbus_init_irq(sbd, &s->intr); - sysbus_init_mmio(sbd, &s->container); - vmstate_register(VMSTATE_IF(dev), - ((s->shift & 0x7f) << 24) - | ((s->id.man & 0xff) << 16) - | ((s->id.dev & 0xff) << 8) - | (s->id.ver & 0xff), - &vmstate_onenand, s); -} - -static Property onenand_properties[] =3D { - DEFINE_PROP_UINT16("manufacturer_id", OneNANDState, id.man, 0), - DEFINE_PROP_UINT16("device_id", OneNANDState, id.dev, 0), - DEFINE_PROP_UINT16("version_id", OneNANDState, id.ver, 0), - DEFINE_PROP_INT32("shift", OneNANDState, shift, 0), - DEFINE_PROP_DRIVE("drive", OneNANDState, blk), - DEFINE_PROP_END_OF_LIST(), -}; - -static void onenand_class_init(ObjectClass *klass, void *data) -{ - DeviceClass *dc =3D DEVICE_CLASS(klass); - - dc->realize =3D onenand_realize; - dc->reset =3D onenand_system_reset; - device_class_set_props(dc, onenand_properties); -} - -static const TypeInfo onenand_info =3D { - .name =3D TYPE_ONE_NAND, - .parent =3D TYPE_SYS_BUS_DEVICE, - .instance_size =3D sizeof(OneNANDState), - .class_init =3D onenand_class_init, -}; - -static void onenand_register_types(void) -{ - type_register_static(&onenand_info); -} - -void *onenand_raw_otp(DeviceState *onenand_device) -{ - OneNANDState *s =3D ONE_NAND(onenand_device); - - return s->otp; -} - -type_init(onenand_register_types) diff --git a/hw/block/Kconfig b/hw/block/Kconfig index 9e8f28f9824..002d255dced 100644 --- a/hw/block/Kconfig +++ b/hw/block/Kconfig @@ -25,9 +25,6 @@ config PFLASH_CFI02 config ECC bool =20 -config ONENAND - bool - config TC58128 bool =20 diff --git a/hw/block/meson.build b/hw/block/meson.build index 8aa4dc3893c..74c8eb9e735 100644 --- a/hw/block/meson.build +++ b/hw/block/meson.build @@ -8,7 +8,6 @@ system_ss.add(when: 'CONFIG_FDC', if_true: files('fdc.c')) system_ss.add(when: 'CONFIG_FDC_ISA', if_true: files('fdc-isa.c')) system_ss.add(when: 'CONFIG_FDC_SYSBUS', if_true: files('fdc-sysbus.c')) system_ss.add(when: 'CONFIG_NAND', if_true: files('nand.c')) -system_ss.add(when: 'CONFIG_ONENAND', if_true: files('onenand.c')) system_ss.add(when: 'CONFIG_PFLASH_CFI01', if_true: files('pflash_cfi01.c'= )) system_ss.add(when: 'CONFIG_PFLASH_CFI02', if_true: files('pflash_cfi02.c'= )) system_ss.add(when: 'CONFIG_SSI_M25P80', if_true: files('m25p80.c')) --=20 2.34.1