From nobody Sun Nov 24 00:31:05 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=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1728350687; cv=none; d=zohomail.com; s=zohoarc; b=dR8jg6Ishq5Xq1+Bn6FW3sbI4V36UXcM1p0pO7E5u4dTJjTRA4nuN3qV/HiGCJW15HxbhYl0TTF4lCG9v0c5e1UL/ISEWnqwG31P997FAgRh3uJs2WjqQW05Rp1caTmlU+53KZ9Pu9BbqTjx9kSh1K9FBlI087l00OPj9Fr71B8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350687; h=Content-Type:Cc:Cc: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; bh=0eZ20KWycrpoAWSK7v7xZhJPuQ4t9+MXTd5omboFwxE=; b=inePymip/eh0aSLJdi6oKCY6T1FT+IKiSUhbn0S8FXvIyPn5fzIYTKOG5ahrbsyzKxVVRsdggIdKSU6riaOPP4nexisSmIW+ktqeJLOJMJq3mZvLUJpAW86KEqyWKL+pz93B9NmE8vlYWPQBLj5VQ86dsR8sRe/QQL0YlvDZ5/Y= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728350687718925.1168324978638; Mon, 7 Oct 2024 18:24:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxyt5-0000Sy-MY; Mon, 07 Oct 2024 21:19:44 -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 <3kYgEZwUKCvInUpcjaiiafY.WigkYgo-XYpYfhihaho.ila@flex--tavip.bounces.google.com>) id 1sxysi-0007rU-TT for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:21 -0400 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3kYgEZwUKCvInUpcjaiiafY.WigkYgo-XYpYfhihaho.ila@flex--tavip.bounces.google.com>) id 1sxyse-0000AH-3C for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:20 -0400 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-e28690bc290so7535228276.1 for ; Mon, 07 Oct 2024 18:19:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350354; x=1728955154; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=0eZ20KWycrpoAWSK7v7xZhJPuQ4t9+MXTd5omboFwxE=; b=ayqP1iztqATkPL7eEDLYvjwruRwu8EIZADTsb8Uu3uppQUfSasSdSx/U007jqitfgg F470M+sif/tftqGUB7EBgHTBpEgO/sBDAmqns+quTtDsdyYqiM677VUAoLKVRXP6RYUc VSho5mQ5ocVB29boFRnMe+1hGQkGxaORyKluhGeh1e9+xm14+7Dh22cnWvYdHnqo1JL0 kqPhngvF6q5a7Wkd9+yMadV1/b4UZYzFzq7PKdU0ufb7ywX504WVUDun0GOiSGJ1R4y5 voL/fRGalzNp9zcK5qJ5B0u5tQdlYQPN0m9oEZ69piqKTr1VKylEouEUKk/fomRr+bV7 tFpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350354; x=1728955154; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0eZ20KWycrpoAWSK7v7xZhJPuQ4t9+MXTd5omboFwxE=; b=P7+me+SYRX7LFkJPQqZIwTiJnXT3zI7H22Htz8Q+u8xCQjbVs9oSgwcCQFNIp1Ax9f thG9pgXBtjfkYKqdINdFug2Mw0UiukEJpZd77WAEHwmG3lbGQ7hcyM5ONwgoErCkTFYZ CI6r6+cs4jsJtk5eZqpZec6A5FC0nMScHIa/t4KqrZ155M8P/q/hTGz3PGoWPoIxJ0SD BQRoPfcZcRRoZ1+Ka3A4rFuG4BITAZjmAfv8RueUJWgq9/PSJX/aSsqQsB6M//Vff3Gr r1ecSWUZ+iyddGMfoIO1zD9UENO99M1Vhbe/TqUZufm58mXBkRBfLSzR6bAnVwc+ow9R 7BTA== X-Gm-Message-State: AOJu0YyG1BBNSplQs526F/+ewEPL0WvDdhQWq6TSpKacVnnWjujp018B JC49nEN3ZEtfMbILVPLG+3L0Ja0F/ACp7vuGizjkews4Xbrku6MhjlU7lTxiNoC7KlsTM529dar bXx/LIc2iLwc9fVgQAgD+Gmoy2IMRQGq5NE9O0Cg6+w9bxpAAnohnVb8dgwxvgW+MjtOsv59md3 +k+sa6asmWZBMI9rqKCO8BSzXH2w== X-Google-Smtp-Source: AGHT+IHSUmcJnw1C/+86tM9pY+DBOVdB9rYfekCN7zWgSpmD4h6ImtNtH8wO9EKcNCt9vM3jVhBUP7duBg== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a25:a444:0:b0:e13:e11c:507 with SMTP id 3f1490d57ef6-e28936d614bmr11062276.3.1728350353966; Mon, 07 Oct 2024 18:19:13 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:37 -0700 In-Reply-To: <20241008011852.1439154-1-tavip@google.com> Mime-Version: 1.0 References: <20241008011852.1439154-1-tavip@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Message-ID: <20241008011852.1439154-12-tavip@google.com> Subject: [PATCH v2 11/25] hw/ssi: add support for flexspi From: Octavian Purdila To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, stefanst@google.com, pbonzini@redhat.com, peter.maydell@linaro.org, marcandre.lureau@redhat.com, berrange@redhat.com, eduardo@habkost.net, luc@lmichel.fr, damien.hedde@dahe.fr, alistair@alistair23.me, thuth@redhat.com, philmd@linaro.org, jsnow@redhat.com, crosa@redhat.com, lvivier@redhat.com 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=2607:f8b0:4864:20::b49; envelope-from=3kYgEZwUKCvInUpcjaiiafY.WigkYgo-XYpYfhihaho.ila@flex--tavip.bounces.google.com; helo=mail-yb1-xb49.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.024, 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, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham 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 @google.com) X-ZM-MESSAGEID: 1728350688691116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This is mostly a stub which completes SPI transactions as noops by masking out the error interrupts and never clearing the IPCMDDONE interrupt. Although incomplete, this allows software that uses NXP's mcuxpresso SDK to run the SDK board initialization functions. It also supports AHB memory access, aka XIP, for now as simple RAM memory regions. The patch includes an automatically generated header which contains the register layout and helpers. The header can be regenerated with the svd-flexspi target when the build is configured with --enable-mcux-soc-svd. Signed-off-by: Octavian Purdila --- include/hw/arm/svd/flexspi.h | 1085 ++++++++++++++++++++++++++++++++++ include/hw/ssi/flexspi.h | 31 + hw/ssi/flexspi.c | 181 ++++++ hw/arm/svd/meson.build | 4 + hw/ssi/Kconfig | 4 + hw/ssi/meson.build | 1 + hw/ssi/trace-events | 4 + 7 files changed, 1310 insertions(+) create mode 100644 include/hw/arm/svd/flexspi.h create mode 100644 include/hw/ssi/flexspi.h create mode 100644 hw/ssi/flexspi.c diff --git a/include/hw/arm/svd/flexspi.h b/include/hw/arm/svd/flexspi.h new file mode 100644 index 0000000000..6e7e715d51 --- /dev/null +++ b/include/hw/arm/svd/flexspi.h @@ -0,0 +1,1085 @@ +/* + * Copyright 2016-2023 NXP SPDX-License-Identifier: BSD-3-Clause + * + * Automatically generated by svd-gen-header.py from MIMXRT595S_cm33.xml + */ +#pragma once + +#include "hw/register.h" + +/* FlexSPI */ +#define FLEXSPI_REGS_NO (267) + +/* Module Control Register 0 */ +REG32(FLEXSPI_MCR0, 0x0); +/* Software Reset */ +FIELD(FLEXSPI_MCR0, SWRESET, 0, 1); + +/* Interrupt Register */ +REG32(FLEXSPI_INTR, 0x14); +/* + * IP triggered Command Sequences Execution finished interrupt. This inter= rupt + * is also generated when there is IPCMDGE or IPCMDERR interrupt generated. + */ +FIELD(FLEXSPI_INTR, IPCMDDONE, 0, 1); + +/* Status Register 0 */ +REG32(FLEXSPI_STS0, 0xE0); +/* + * This status bit indicates the state machine in SEQ_CTL is idle and ther= e is + * command sequence executing on FlexSPI interface. + */ +FIELD(FLEXSPI_STS0, SEQIDLE, 0, 1); + + +#define FLEXSPI_REGISTER_ACCESS_INFO_ARRAY(_name) \ + struct RegisterAccessInfo _name[FLEXSPI_REGS_NO] =3D { \ + [0 ... FLEXSPI_REGS_NO - 1] =3D { \ + .name =3D "", \ + .addr =3D -1, \ + }, \ + [0x0] =3D { \ + .name =3D "MCR0", \ + .addr =3D 0x0, \ + .ro =3D 0x20CC, \ + .reset =3D 0xFFFF80C2, \ + }, \ + [0x1] =3D { \ + .name =3D "MCR1", \ + .addr =3D 0x4, \ + .ro =3D 0x0, \ + .reset =3D 0xFFFFFFFF, \ + }, \ + [0x2] =3D { \ + .name =3D "MCR2", \ + .addr =3D 0x8, \ + .ro =3D 0xFF37FF, \ + .reset =3D 0x200081F7, \ + }, \ + [0x3] =3D { \ + .name =3D "AHBCR", \ + .addr =3D 0xC, \ + .ro =3D 0xFFFFFB02, \ + .reset =3D 0x18, \ + }, \ + [0x4] =3D { \ + .name =3D "INTEN", \ + .addr =3D 0x10, \ + .ro =3D 0xFFFFC000, \ + .reset =3D 0x0, \ + }, \ + [0x5] =3D { \ + .name =3D "INTR", \ + .addr =3D 0x14, \ + .ro =3D 0xFFFFE000, \ + .reset =3D 0x0, \ + }, \ + [0x6] =3D { \ + .name =3D "LUTKEY", \ + .addr =3D 0x18, \ + .ro =3D 0x0, \ + .reset =3D 0x5AF05AF0, \ + }, \ + [0x7] =3D { \ + .name =3D "LUTCR", \ + .addr =3D 0x1C, \ + .ro =3D 0xFFFFFFFC, \ + .reset =3D 0x2, \ + }, \ + [0x8] =3D { \ + .name =3D "AHBRXBUF0CR0", \ + .addr =3D 0x20, \ + .ro =3D 0x78F0FF00, \ + .reset =3D 0x80000010, \ + }, \ + [0x9] =3D { \ + .name =3D "AHBRXBUF1CR0", \ + .addr =3D 0x24, \ + .ro =3D 0x78F0FF00, \ + .reset =3D 0x80010010, \ + }, \ + [0xA] =3D { \ + .name =3D "AHBRXBUF2CR0", \ + .addr =3D 0x28, \ + .ro =3D 0x78F0FF00, \ + .reset =3D 0x80020010, \ + }, \ + [0xB] =3D { \ + .name =3D "AHBRXBUF3CR0", \ + .addr =3D 0x2C, \ + .ro =3D 0x78F0FF00, \ + .reset =3D 0x80030010, \ + }, \ + [0xC] =3D { \ + .name =3D "AHBRXBUF4CR0", \ + .addr =3D 0x30, \ + .ro =3D 0x78F0FF00, \ + .reset =3D 0x80040010, \ + }, \ + [0xD] =3D { \ + .name =3D "AHBRXBUF5CR0", \ + .addr =3D 0x34, \ + .ro =3D 0x78F0FF00, \ + .reset =3D 0x80050010, \ + }, \ + [0xE] =3D { \ + .name =3D "AHBRXBUF6CR0", \ + .addr =3D 0x38, \ + .ro =3D 0x78F0FF00, \ + .reset =3D 0x80060010, \ + }, \ + [0xF] =3D { \ + .name =3D "AHBRXBUF7CR0", \ + .addr =3D 0x3C, \ + .ro =3D 0x78F0FF00, \ + .reset =3D 0x80070010, \ + }, \ + [0x18] =3D { \ + .name =3D "FLSHA1CR0", \ + .addr =3D 0x60, \ + .ro =3D 0xFF800000, \ + .reset =3D 0x10000, \ + }, \ + [0x19] =3D { \ + .name =3D "FLSHA2CR0", \ + .addr =3D 0x64, \ + .ro =3D 0xFF800000, \ + .reset =3D 0x10000, \ + }, \ + [0x1A] =3D { \ + .name =3D "FLSHB1CR0", \ + .addr =3D 0x68, \ + .ro =3D 0xFF800000, \ + .reset =3D 0x10000, \ + }, \ + [0x1B] =3D { \ + .name =3D "FLSHB2CR0", \ + .addr =3D 0x6C, \ + .ro =3D 0xFF800000, \ + .reset =3D 0x10000, \ + }, \ + [0x1C] =3D { \ + .name =3D "FLSHCR1A1", \ + .addr =3D 0x70, \ + .ro =3D 0x0, \ + .reset =3D 0x63, \ + }, \ + [0x1D] =3D { \ + .name =3D "FLSHCR1A2", \ + .addr =3D 0x74, \ + .ro =3D 0x0, \ + .reset =3D 0x63, \ + }, \ + [0x1E] =3D { \ + .name =3D "FLSHCR1B1", \ + .addr =3D 0x78, \ + .ro =3D 0x0, \ + .reset =3D 0x63, \ + }, \ + [0x1F] =3D { \ + .name =3D "FLSHCR1B2", \ + .addr =3D 0x7C, \ + .ro =3D 0x0, \ + .reset =3D 0x63, \ + }, \ + [0x20] =3D { \ + .name =3D "FLSHCR2A1", \ + .addr =3D 0x80, \ + .ro =3D 0x1010, \ + .reset =3D 0x0, \ + }, \ + [0x21] =3D { \ + .name =3D "FLSHCR2A2", \ + .addr =3D 0x84, \ + .ro =3D 0x1010, \ + .reset =3D 0x0, \ + }, \ + [0x22] =3D { \ + .name =3D "FLSHCR2B1", \ + .addr =3D 0x88, \ + .ro =3D 0x1010, \ + .reset =3D 0x0, \ + }, \ + [0x23] =3D { \ + .name =3D "FLSHCR2B2", \ + .addr =3D 0x8C, \ + .ro =3D 0x1010, \ + .reset =3D 0x0, \ + }, \ + [0x25] =3D { \ + .name =3D "FLSHCR4", \ + .addr =3D 0x94, \ + .ro =3D 0xFFFFFFFA, \ + .reset =3D 0x0, \ + }, \ + [0x28] =3D { \ + .name =3D "IPCR0", \ + .addr =3D 0xA0, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x29] =3D { \ + .name =3D "IPCR1", \ + .addr =3D 0xA4, \ + .ro =3D 0x78F00000, \ + .reset =3D 0x0, \ + }, \ + [0x2C] =3D { \ + .name =3D "IPCMD", \ + .addr =3D 0xB0, \ + .ro =3D 0xFFFFFFFE, \ + .reset =3D 0x0, \ + }, \ + [0x2D] =3D { \ + .name =3D "DLPR", \ + .addr =3D 0xB4, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x2E] =3D { \ + .name =3D "IPRXFCR", \ + .addr =3D 0xB8, \ + .ro =3D 0xFFFFFE00, \ + .reset =3D 0x0, \ + }, \ + [0x2F] =3D { \ + .name =3D "IPTXFCR", \ + .addr =3D 0xBC, \ + .ro =3D 0xFFFFFE00, \ + .reset =3D 0x0, \ + }, \ + [0x30] =3D { \ + .name =3D "DLLCRA", \ + .addr =3D 0xC0, \ + .ro =3D 0xFFFF8084, \ + .reset =3D 0x100, \ + }, \ + [0x31] =3D { \ + .name =3D "DLLCRB", \ + .addr =3D 0xC4, \ + .ro =3D 0xFFFF8084, \ + .reset =3D 0x100, \ + }, \ + [0x38] =3D { \ + .name =3D "STS0", \ + .addr =3D 0xE0, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x2, \ + }, \ + [0x39] =3D { \ + .name =3D "STS1", \ + .addr =3D 0xE4, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x3A] =3D { \ + .name =3D "STS2", \ + .addr =3D 0xE8, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x1000100, \ + }, \ + [0x3B] =3D { \ + .name =3D "AHBSPNDSTS", \ + .addr =3D 0xEC, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x3C] =3D { \ + .name =3D "IPRXFSTS", \ + .addr =3D 0xF0, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x3D] =3D { \ + .name =3D "IPTXFSTS", \ + .addr =3D 0xF4, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x40] =3D { \ + .name =3D "RFDR0", \ + .addr =3D 0x100, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x41] =3D { \ + .name =3D "RFDR1", \ + .addr =3D 0x104, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x42] =3D { \ + .name =3D "RFDR2", \ + .addr =3D 0x108, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x43] =3D { \ + .name =3D "RFDR3", \ + .addr =3D 0x10C, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x44] =3D { \ + .name =3D "RFDR4", \ + .addr =3D 0x110, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x45] =3D { \ + .name =3D "RFDR5", \ + .addr =3D 0x114, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x46] =3D { \ + .name =3D "RFDR6", \ + .addr =3D 0x118, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x47] =3D { \ + .name =3D "RFDR7", \ + .addr =3D 0x11C, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x48] =3D { \ + .name =3D "RFDR8", \ + .addr =3D 0x120, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x49] =3D { \ + .name =3D "RFDR9", \ + .addr =3D 0x124, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x4A] =3D { \ + .name =3D "RFDR10", \ + .addr =3D 0x128, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x4B] =3D { \ + .name =3D "RFDR11", \ + .addr =3D 0x12C, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x4C] =3D { \ + .name =3D "RFDR12", \ + .addr =3D 0x130, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x4D] =3D { \ + .name =3D "RFDR13", \ + .addr =3D 0x134, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x4E] =3D { \ + .name =3D "RFDR14", \ + .addr =3D 0x138, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x4F] =3D { \ + .name =3D "RFDR15", \ + .addr =3D 0x13C, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x50] =3D { \ + .name =3D "RFDR16", \ + .addr =3D 0x140, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x51] =3D { \ + .name =3D "RFDR17", \ + .addr =3D 0x144, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x52] =3D { \ + .name =3D "RFDR18", \ + .addr =3D 0x148, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x53] =3D { \ + .name =3D "RFDR19", \ + .addr =3D 0x14C, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x54] =3D { \ + .name =3D "RFDR20", \ + .addr =3D 0x150, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x55] =3D { \ + .name =3D "RFDR21", \ + .addr =3D 0x154, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x56] =3D { \ + .name =3D "RFDR22", \ + .addr =3D 0x158, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x57] =3D { \ + .name =3D "RFDR23", \ + .addr =3D 0x15C, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x58] =3D { \ + .name =3D "RFDR24", \ + .addr =3D 0x160, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x59] =3D { \ + .name =3D "RFDR25", \ + .addr =3D 0x164, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x5A] =3D { \ + .name =3D "RFDR26", \ + .addr =3D 0x168, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x5B] =3D { \ + .name =3D "RFDR27", \ + .addr =3D 0x16C, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x5C] =3D { \ + .name =3D "RFDR28", \ + .addr =3D 0x170, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x5D] =3D { \ + .name =3D "RFDR29", \ + .addr =3D 0x174, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x5E] =3D { \ + .name =3D "RFDR30", \ + .addr =3D 0x178, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x5F] =3D { \ + .name =3D "RFDR31", \ + .addr =3D 0x17C, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x60] =3D { \ + .name =3D "TFDR0", \ + .addr =3D 0x180, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x61] =3D { \ + .name =3D "TFDR1", \ + .addr =3D 0x184, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x62] =3D { \ + .name =3D "TFDR2", \ + .addr =3D 0x188, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x63] =3D { \ + .name =3D "TFDR3", \ + .addr =3D 0x18C, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x64] =3D { \ + .name =3D "TFDR4", \ + .addr =3D 0x190, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x65] =3D { \ + .name =3D "TFDR5", \ + .addr =3D 0x194, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x66] =3D { \ + .name =3D "TFDR6", \ + .addr =3D 0x198, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x67] =3D { \ + .name =3D "TFDR7", \ + .addr =3D 0x19C, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x68] =3D { \ + .name =3D "TFDR8", \ + .addr =3D 0x1A0, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x69] =3D { \ + .name =3D "TFDR9", \ + .addr =3D 0x1A4, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x6A] =3D { \ + .name =3D "TFDR10", \ + .addr =3D 0x1A8, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x6B] =3D { \ + .name =3D "TFDR11", \ + .addr =3D 0x1AC, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x6C] =3D { \ + .name =3D "TFDR12", \ + .addr =3D 0x1B0, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x6D] =3D { \ + .name =3D "TFDR13", \ + .addr =3D 0x1B4, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x6E] =3D { \ + .name =3D "TFDR14", \ + .addr =3D 0x1B8, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x6F] =3D { \ + .name =3D "TFDR15", \ + .addr =3D 0x1BC, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x70] =3D { \ + .name =3D "TFDR16", \ + .addr =3D 0x1C0, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x71] =3D { \ + .name =3D "TFDR17", \ + .addr =3D 0x1C4, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x72] =3D { \ + .name =3D "TFDR18", \ + .addr =3D 0x1C8, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x73] =3D { \ + .name =3D "TFDR19", \ + .addr =3D 0x1CC, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x74] =3D { \ + .name =3D "TFDR20", \ + .addr =3D 0x1D0, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x75] =3D { \ + .name =3D "TFDR21", \ + .addr =3D 0x1D4, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x76] =3D { \ + .name =3D "TFDR22", \ + .addr =3D 0x1D8, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x77] =3D { \ + .name =3D "TFDR23", \ + .addr =3D 0x1DC, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x78] =3D { \ + .name =3D "TFDR24", \ + .addr =3D 0x1E0, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x79] =3D { \ + .name =3D "TFDR25", \ + .addr =3D 0x1E4, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x7A] =3D { \ + .name =3D "TFDR26", \ + .addr =3D 0x1E8, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x7B] =3D { \ + .name =3D "TFDR27", \ + .addr =3D 0x1EC, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x7C] =3D { \ + .name =3D "TFDR28", \ + .addr =3D 0x1F0, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x7D] =3D { \ + .name =3D "TFDR29", \ + .addr =3D 0x1F4, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x7E] =3D { \ + .name =3D "TFDR30", \ + .addr =3D 0x1F8, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x7F] =3D { \ + .name =3D "TFDR31", \ + .addr =3D 0x1FC, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x80] =3D { \ + .name =3D "LUT0", \ + .addr =3D 0x200, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x81] =3D { \ + .name =3D "LUT1", \ + .addr =3D 0x204, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x82] =3D { \ + .name =3D "LUT2", \ + .addr =3D 0x208, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x83] =3D { \ + .name =3D "LUT3", \ + .addr =3D 0x20C, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x84] =3D { \ + .name =3D "LUT4", \ + .addr =3D 0x210, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x85] =3D { \ + .name =3D "LUT5", \ + .addr =3D 0x214, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x86] =3D { \ + .name =3D "LUT6", \ + .addr =3D 0x218, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x87] =3D { \ + .name =3D "LUT7", \ + .addr =3D 0x21C, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x88] =3D { \ + .name =3D "LUT8", \ + .addr =3D 0x220, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x89] =3D { \ + .name =3D "LUT9", \ + .addr =3D 0x224, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x8A] =3D { \ + .name =3D "LUT10", \ + .addr =3D 0x228, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x8B] =3D { \ + .name =3D "LUT11", \ + .addr =3D 0x22C, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x8C] =3D { \ + .name =3D "LUT12", \ + .addr =3D 0x230, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x8D] =3D { \ + .name =3D "LUT13", \ + .addr =3D 0x234, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x8E] =3D { \ + .name =3D "LUT14", \ + .addr =3D 0x238, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x8F] =3D { \ + .name =3D "LUT15", \ + .addr =3D 0x23C, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x90] =3D { \ + .name =3D "LUT16", \ + .addr =3D 0x240, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x91] =3D { \ + .name =3D "LUT17", \ + .addr =3D 0x244, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x92] =3D { \ + .name =3D "LUT18", \ + .addr =3D 0x248, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x93] =3D { \ + .name =3D "LUT19", \ + .addr =3D 0x24C, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x94] =3D { \ + .name =3D "LUT20", \ + .addr =3D 0x250, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x95] =3D { \ + .name =3D "LUT21", \ + .addr =3D 0x254, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x96] =3D { \ + .name =3D "LUT22", \ + .addr =3D 0x258, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x97] =3D { \ + .name =3D "LUT23", \ + .addr =3D 0x25C, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x98] =3D { \ + .name =3D "LUT24", \ + .addr =3D 0x260, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x99] =3D { \ + .name =3D "LUT25", \ + .addr =3D 0x264, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x9A] =3D { \ + .name =3D "LUT26", \ + .addr =3D 0x268, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x9B] =3D { \ + .name =3D "LUT27", \ + .addr =3D 0x26C, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x9C] =3D { \ + .name =3D "LUT28", \ + .addr =3D 0x270, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x9D] =3D { \ + .name =3D "LUT29", \ + .addr =3D 0x274, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x9E] =3D { \ + .name =3D "LUT30", \ + .addr =3D 0x278, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x9F] =3D { \ + .name =3D "LUT31", \ + .addr =3D 0x27C, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xA0] =3D { \ + .name =3D "LUT32", \ + .addr =3D 0x280, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xA1] =3D { \ + .name =3D "LUT33", \ + .addr =3D 0x284, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xA2] =3D { \ + .name =3D "LUT34", \ + .addr =3D 0x288, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xA3] =3D { \ + .name =3D "LUT35", \ + .addr =3D 0x28C, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xA4] =3D { \ + .name =3D "LUT36", \ + .addr =3D 0x290, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xA5] =3D { \ + .name =3D "LUT37", \ + .addr =3D 0x294, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xA6] =3D { \ + .name =3D "LUT38", \ + .addr =3D 0x298, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xA7] =3D { \ + .name =3D "LUT39", \ + .addr =3D 0x29C, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xA8] =3D { \ + .name =3D "LUT40", \ + .addr =3D 0x2A0, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xA9] =3D { \ + .name =3D "LUT41", \ + .addr =3D 0x2A4, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xAA] =3D { \ + .name =3D "LUT42", \ + .addr =3D 0x2A8, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xAB] =3D { \ + .name =3D "LUT43", \ + .addr =3D 0x2AC, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xAC] =3D { \ + .name =3D "LUT44", \ + .addr =3D 0x2B0, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xAD] =3D { \ + .name =3D "LUT45", \ + .addr =3D 0x2B4, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xAE] =3D { \ + .name =3D "LUT46", \ + .addr =3D 0x2B8, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xAF] =3D { \ + .name =3D "LUT47", \ + .addr =3D 0x2BC, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xB0] =3D { \ + .name =3D "LUT48", \ + .addr =3D 0x2C0, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xB1] =3D { \ + .name =3D "LUT49", \ + .addr =3D 0x2C4, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xB2] =3D { \ + .name =3D "LUT50", \ + .addr =3D 0x2C8, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xB3] =3D { \ + .name =3D "LUT51", \ + .addr =3D 0x2CC, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xB4] =3D { \ + .name =3D "LUT52", \ + .addr =3D 0x2D0, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xB5] =3D { \ + .name =3D "LUT53", \ + .addr =3D 0x2D4, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xB6] =3D { \ + .name =3D "LUT54", \ + .addr =3D 0x2D8, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xB7] =3D { \ + .name =3D "LUT55", \ + .addr =3D 0x2DC, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xB8] =3D { \ + .name =3D "LUT56", \ + .addr =3D 0x2E0, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xB9] =3D { \ + .name =3D "LUT57", \ + .addr =3D 0x2E4, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xBA] =3D { \ + .name =3D "LUT58", \ + .addr =3D 0x2E8, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xBB] =3D { \ + .name =3D "LUT59", \ + .addr =3D 0x2EC, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xBC] =3D { \ + .name =3D "LUT60", \ + .addr =3D 0x2F0, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xBD] =3D { \ + .name =3D "LUT61", \ + .addr =3D 0x2F4, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xBE] =3D { \ + .name =3D "LUT62", \ + .addr =3D 0x2F8, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0xBF] =3D { \ + .name =3D "LUT63", \ + .addr =3D 0x2FC, \ + .ro =3D 0x0, \ + .reset =3D 0x0, \ + }, \ + [0x108] =3D { \ + .name =3D "HADDRSTART", \ + .addr =3D 0x420, \ + .ro =3D 0xFFE, \ + .reset =3D 0x0, \ + }, \ + [0x109] =3D { \ + .name =3D "HADDREND", \ + .addr =3D 0x424, \ + .ro =3D 0xFFF, \ + .reset =3D 0x0, \ + }, \ + [0x10A] =3D { \ + .name =3D "HADDROFFSET", \ + .addr =3D 0x428, \ + .ro =3D 0xFFF, \ + .reset =3D 0x0, \ + }, \ + } diff --git a/include/hw/ssi/flexspi.h b/include/hw/ssi/flexspi.h new file mode 100644 index 0000000000..51699e1ceb --- /dev/null +++ b/include/hw/ssi/flexspi.h @@ -0,0 +1,31 @@ +/* + * QEMU model for FLEXSPI + * + * Copyright (c) 2024 Google LLC + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#ifndef HW_RT500_FLEXSPI_H +#define HW_RT500_FLEXSPI_H + +#include "hw/sysbus.h" +#include "hw/ssi/ssi.h" +#include "hw/arm/svd/flexspi.h" + +#define TYPE_FLEXSPI "flexspi" +#define FLEXSPI(obj) OBJECT_CHECK(FlexSpiState, (obj), TYPE_FLEXSPI) + +typedef struct { + SysBusDevice parent_obj; + + MemoryRegion mmio; + uint32_t regs[FLEXSPI_REGS_NO]; + MemoryRegion mem; + uint64_t mmap_size; +} FlexSpiState; + +#endif /* HW_RT500_FLEXSPI_H */ diff --git a/hw/ssi/flexspi.c b/hw/ssi/flexspi.c new file mode 100644 index 0000000000..d5d9e4f098 --- /dev/null +++ b/hw/ssi/flexspi.c @@ -0,0 +1,181 @@ +/* + * QEMU model for FLEXSPI + * + * Copyright (c) 2024 Google LLC + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/mmap-alloc.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/units.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" +#include "hw/qdev-properties-system.h" +#include "migration/vmstate.h" +#include "exec/address-spaces.h" +#include "hw/ssi/flexspi.h" +#include "hw/arm/svd/flexspi.h" + +#include "trace.h" + +#define REG(s, reg) (s->regs[R_FLEXSPI_##reg]) +#define RF_WR(s, reg, field, val) \ + ARRAY_FIELD_DP32(s->regs, FLEXSPI_##reg, field, val) +#define RF_RD(s, reg, field) \ + ARRAY_FIELD_EX32(s->regs, FLEXSPI_##reg, field) + +static FLEXSPI_REGISTER_ACCESS_INFO_ARRAY(reg_info); + +static void flexspi_reset_enter(Object *obj, ResetType type) +{ + FlexSpiState *s =3D FLEXSPI(obj); + + for (int i =3D 0; i < FLEXSPI_REGS_NO; i++) { + hwaddr addr =3D reg_info[i].addr; + + if (addr !=3D -1) { + struct RegisterInfo ri =3D { + .data =3D &s->regs[addr / 4], + .data_size =3D 4, + .access =3D ®_info[i], + }; + + register_reset(&ri); + } + } + + /* idle immediately after reset */ + RF_WR(s, STS0, SEQIDLE, 1); +} + +static MemTxResult flexspi_read(void *opaque, hwaddr addr, + uint64_t *data, unsigned size, + MemTxAttrs attrs) +{ + FlexSpiState *s =3D opaque; + const struct RegisterAccessInfo *rai =3D ®_info[addr / 4]; + MemTxResult ret =3D MEMTX_OK; + + switch (addr) { + default: + *data =3D s->regs[addr / 4]; + break; + } + + trace_flexspi_reg_read(DEVICE(s)->id, rai->name, addr, *data); + return ret; +} + + +static MemTxResult flexspi_write(void *opaque, hwaddr addr, + uint64_t value, unsigned size, + MemTxAttrs attrs) +{ + FlexSpiState *s =3D opaque; + const struct RegisterAccessInfo *rai =3D ®_info[addr / 4]; + struct RegisterInfo ri =3D { + .data =3D &s->regs[addr / 4], + .data_size =3D 4, + .access =3D rai, + }; + + trace_flexspi_reg_write(DEVICE(s)->id, rai->name, addr, value); + + switch (addr) { + case A_FLEXSPI_MCR0: + { + register_write(&ri, value, ~0, NULL, false); + + if (RF_RD(s, MCR0, SWRESET)) { + RF_WR(s, MCR0, SWRESET, 0); + } + break; + } + case A_FLEXSPI_INTR: + { + /* fake SPI transfer completion */ + RF_WR(s, INTR, IPCMDDONE, 1); + break; + } + default: + register_write(&ri, value, ~0, NULL, false); + break; + } + + return MEMTX_OK; +} + +static const MemoryRegionOps flexspi_ops =3D { + .read_with_attrs =3D flexspi_read, + .write_with_attrs =3D flexspi_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .valid =3D { + .min_access_size =3D 1, + .max_access_size =3D 4, + .unaligned =3D false, + }, +}; + +static Property flexspi_properties[] =3D { + DEFINE_PROP_UINT64("mmap_size", FlexSpiState, mmap_size, 0), + DEFINE_PROP_END_OF_LIST(), +}; + +static void flexspi_init(Object *obj) +{ + FlexSpiState *s =3D FLEXSPI(obj); + + memory_region_init_io(&s->mmio, obj, &flexspi_ops, s, TYPE_FLEXSPI, + sizeof(s->regs)); + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); +} + +static void flexspi_realize(DeviceState *dev, Error **errp) +{ + FlexSpiState *s =3D FLEXSPI(dev); + + if (s->mmap_size) { + memory_region_init_ram(&s->mem, OBJECT(s), DEVICE(s)->id, s->mmap_= size, + NULL); + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->mem); + } +} + +static const VMStateDescription vmstate_flexspi =3D { + .name =3D "flexspi", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT32_ARRAY(regs, FlexSpiState, FLEXSPI_REGS_NO), + VMSTATE_END_OF_LIST() + } +}; + +static void flexspi_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + + rc->phases.enter =3D flexspi_reset_enter; + dc->realize =3D flexspi_realize; + dc->vmsd =3D &vmstate_flexspi; + device_class_set_props(dc, flexspi_properties); +} + +static const TypeInfo flexspi_types[] =3D { + { + .name =3D TYPE_FLEXSPI, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(FlexSpiState), + .instance_init =3D flexspi_init, + .class_init =3D flexspi_class_init, + }, +}; + +DEFINE_TYPES(flexspi_types); diff --git a/hw/arm/svd/meson.build b/hw/arm/svd/meson.build index 9c458b314c..adf0f8327a 100644 --- a/hw/arm/svd/meson.build +++ b/hw/arm/svd/meson.build @@ -24,4 +24,8 @@ if get_option('mcux-soc-svd') [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/rt500_clkctl1.h= ', '-p', 'CLKCTL1', '-t', 'RT500_CLKCTL1', '--fields', 'PSCCTL*:FlexIO AUDIOPLL0PFD OSEVENTTFCLKSEL']) + run_target('svd-flexspi', command: svd_gen_header + + [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/flexspi.h', + '-p', 'FLEXSPI0', '-t', 'FLEXSPI', + '--fields', 'STS0:SEQIDLE MCR0:SWRESET INTR:IPCMDDONE']) endif diff --git a/hw/ssi/Kconfig b/hw/ssi/Kconfig index 8d180de7cf..e3de40e6b6 100644 --- a/hw/ssi/Kconfig +++ b/hw/ssi/Kconfig @@ -28,3 +28,7 @@ config BCM2835_SPI config PNV_SPI bool select SSI + +config FLEXSPI + bool + select SSI diff --git a/hw/ssi/meson.build b/hw/ssi/meson.build index 58e0d14b37..31a2618d52 100644 --- a/hw/ssi/meson.build +++ b/hw/ssi/meson.build @@ -13,3 +13,4 @@ system_ss.add(when: 'CONFIG_IBEX', if_true: files('ibex_s= pi_host.c')) system_ss.add(when: 'CONFIG_BCM2835_SPI', if_true: files('bcm2835_spi.c')) system_ss.add(when: 'CONFIG_PNV_SPI', if_true: files('pnv_spi.c')) system_ss.add(when: 'CONFIG_FLEXCOMM', if_true: files('flexcomm_spi.c')) +system_ss.add(when: 'CONFIG_FLEXSPI', if_true: files('flexspi.c')) diff --git a/hw/ssi/trace-events b/hw/ssi/trace-events index f849f1f8be..dd2f04cb22 100644 --- a/hw/ssi/trace-events +++ b/hw/ssi/trace-events @@ -58,3 +58,7 @@ pnv_spi_RDR_match(const char* result) "%s" flexcomm_spi_reg_read(const char *id, const char *reg_name, uint32_t addr,= uint32_t val) " %s: %s[0x%04x] -> 0x%08x" flexcomm_spi_reg_write(const char *id, const char *reg_name, uint32_t addr= , uint32_t val) "%s: %s[0x%04x] <- 0x%08x" flexcomm_spi_irq(const char *id, bool irq, bool fifoirqs, bool perirqs, bo= ol enabled) "%s: %d %d %d %d" + +# flexspi.c +flexspi_reg_read(const char *id, const char *reg_name, uint32_t addr, uint= 32_t val) " %s: %s[0x%04x] -> 0x%08x" +flexspi_reg_write(const char *id, const char *reg_name, uint32_t addr, uin= t32_t val) "%s: %s[0x%04x] <- 0x%08x" --=20 2.47.0.rc0.187.ge670bccf7e-goog