From nobody Sat Nov 23 21:39:54 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=1728350387; cv=none; d=zohomail.com; s=zohoarc; b=SWVz3Mk2Ql5H1Ge1jjuwf/KYlCvGiV1myArDma4qDAAqQL3g70nxsq5gARFLG3TRPPDhZRbj3FGky6GQfx0ewhXBcc89FxjXUToA3lq57DcsC9tSdpGkrppDQiq0yWY3fZydXxXLoLCruk6u172mAwTnWbVDZmE3HSi1lcsc85U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350387; 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=tX+6Z1PHnYxk320Y4l1d37qXLvaekBWmUkrZNyFnhQ0=; b=fTixJFLaBXe7mEbUvKeiajbauIWbI1zjHo03Zs6CJTqPtbgO76NTk/fphTKuAijc+fXBGTPhzkDETKkV3P96ULSYcy5aVDT9U7ulfUHG8sO0XQtfg8jct6/+t+ovFw2DrfaNYC4THu5gLTW/wDovHWdXCGAHGIOlpXi+5NZVGKo= 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 1728350387294821.5200353650923; Mon, 7 Oct 2024 18:19:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxysn-0007tC-Ru; Mon, 07 Oct 2024 21:19:29 -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 <3f4gEZwUKCuAVCXKRIQQING.EQOSGOW-FGXGNPQPIPW.QTI@flex--tavip.bounces.google.com>) id 1sxysQ-0007cD-FO for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:03 -0400 Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3f4gEZwUKCuAVCXKRIQQING.EQOSGOW-FGXGNPQPIPW.QTI@flex--tavip.bounces.google.com>) id 1sxysO-00006p-NB for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:02 -0400 Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-71dfa361499so2100210b3a.0 for ; Mon, 07 Oct 2024 18:18:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350337; x=1728955137; 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=tX+6Z1PHnYxk320Y4l1d37qXLvaekBWmUkrZNyFnhQ0=; b=dbmY/ZCjpBKcnfie7FHk5Q4XREW4d0AptJVY+ZUQHuTYy8ax5kwtpdbdpBrfT/dPto gCfL4xLURjBI/XGpHdnv3uEX5IwoEzycP1/LqTI6U26Igs36HmvpOnDjpaf9JHN2jooj 4aNs2TswgWE/VnRHisRqPUxe2hKhV7q/0SaE7DBPV3SuzwyvHjlN4u8awvcosoz3ANSx 9uk9ARuHIvWSMKb0HBUZfmQQb03EqyY8o+0McglPlOk9LbWwwuhFSg8hswt12VdSXUGw TVt293mW22HU4nMSxC7jDDR11CGZ/5Qi0teN1rXk5Bx1PwmdODtYsUQhqP9UFxUFp98D QD5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350337; x=1728955137; 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=tX+6Z1PHnYxk320Y4l1d37qXLvaekBWmUkrZNyFnhQ0=; b=iDnRWt0/rvv/2mJvpxDCDzkD4gRmX8jHeuHUWJsv0Oj75bAQV2fBAWkUjwCxddlA1d uvlvH37QjR5tbqlrKRLxPgMr8c7TU9x9W1O0tjhtNJNte+k8tvortSItOJGyTTOmIbmE nNDB2ok3laoFtzC1Mffjnr2JVEqxsd/hh54IM9sciwSwXyvI/BNAvXgGETo+CRsuN4cX o8QjYr4a8lmo/BWH1T2qiWOJ+JGyuso9myFgzIiCC4yeyHKuqBMMYyYtlnjbXH2mS8SF zqmKPQxTIC/hLoNBbQilbU4CdwLo/0aCfTxlBJ4vIRCw9o4SXYOLa9b4Gt+dU8v4d6+O vk5w== X-Gm-Message-State: AOJu0Yzg3BkTAWy3Sejd495u5jVKR/GNeHLcfVNir9uCVtl/MeoG/VHX tdFqMjEU76U5BxGJFN64Hxz47KLvmbZGquEONES9BqtTAg1tBWT2GHS2pDDNO0sl6q5kM8xPJ6V 86bkCB9QEBz4wlp43PNSK5zx6ISH6MLknVc5SS9A7zEQK0VhXKWzJV8eq1xwHgfQe0r7D3gsV7r zKJ83JcqbRoy24wBWgiYtjh2CyrQ== X-Google-Smtp-Source: AGHT+IFcS0b2L6CwNcAuaaxIJ0yPVF1XIP3tgzQU+rGCAQO+Un5l5gv5AKJ7m2pQ1hJxX6pAHEEMx7pv1Q== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a05:6a00:8c0b:b0:71d:ef26:2c6f with SMTP id d2e1a72fcca58-71def262d76mr15806b3a.1.1728350335998; Mon, 07 Oct 2024 18:18:55 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:27 -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-2-tavip@google.com> Subject: [PATCH v2 01/25] fifo32: add peek function 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::44a; envelope-from=3f4gEZwUKCuAVCXKRIQQING.EQOSGOW-FGXGNPQPIPW.QTI@flex--tavip.bounces.google.com; helo=mail-pf1-x44a.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=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 @google.com) X-ZM-MESSAGEID: 1728350388943116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add fifo32_peek() that returns the first element from the queue without popping it. Signed-off-by: Octavian Purdila --- include/qemu/fifo32.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/qemu/fifo32.h b/include/qemu/fifo32.h index 4e9fd1b5ef..9de1807375 100644 --- a/include/qemu/fifo32.h +++ b/include/qemu/fifo32.h @@ -140,6 +140,34 @@ static inline uint32_t fifo32_pop(Fifo32 *fifo) return ret; } =20 +/** + * fifo32_peek: + * @fifo: fifo to peek at + * + * Returns the value from the FIFO's head without poping it. Behaviour + * is undefined if the FIFO is empty. Clients are responsible for + * checking for emptiness using fifo32_is_empty(). + * + * Returns: the value from the FIFO's head + */ + +static inline uint32_t fifo32_peek(Fifo32 *fifo) +{ + uint32_t ret =3D 0, num; + const uint8_t *buf; + + buf =3D fifo8_peek_bufptr(&fifo->fifo, 4, &num); + if (num !=3D 4) { + return ret; + } + + for (int i =3D 0; i < sizeof(uint32_t); i++) { + ret |=3D buf[i] << (i * 8); + } + + return ret; +} + /** * There is no fifo32_pop_buf() because the data is not stored in the buff= er * as a set of native-order words. --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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=1728350635; cv=none; d=zohomail.com; s=zohoarc; b=KaPW20cKbkI5AozpoSpNtW0++xfc9JEna/Ut3ZrBEGq7Fhy90JneOyN082SBjfh2MvcNURoGIUICieWWfdA9B6LkmTmN/4npq4OT/J+b1JHY2Ihcv3E/2BA5NCGfk7GSz3RmX7gNCuB9AzsM/pi0Ilea/k7pAg9YOYUdOd+WN5s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350635; 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=wyZg7kxpkNCds2EZflCHxHMwXfcdXxrO/ZcaHcLL39s=; b=fuHmF9Wffn2E5eqR7Ysorcya8dNPOqiCsncHIktSLVY76l8hBTiCelN8cRlluKB+0bpthvegsnzoYBC9Y+IcMlzF9W3Fnxcdx+HtdTixNho86P0BS7DwPNSJH8ewduA+KKWdxUdQ3DORhG9lLfo0Zc+dHiFUXN2N7rb13GxeSjQ= 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 1728350635487584.0102617159191; Mon, 7 Oct 2024 18:23:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxysy-0008Cd-Kj; Mon, 07 Oct 2024 21:19:36 -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 <3gYgEZwUKCuIXEZMTKSSKPI.GSQUIQY-HIZIPRSRKRY.SVK@flex--tavip.bounces.google.com>) id 1sxysQ-0007br-5l for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:03 -0400 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3gYgEZwUKCuIXEZMTKSSKPI.GSQUIQY-HIZIPRSRKRY.SVK@flex--tavip.bounces.google.com>) id 1sxysO-00006w-FD for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:01 -0400 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6e30cf0cf1bso16065357b3.0 for ; Mon, 07 Oct 2024 18:18:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350338; x=1728955138; 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=wyZg7kxpkNCds2EZflCHxHMwXfcdXxrO/ZcaHcLL39s=; b=sUmZs6x50LQ/pe4Gez4ZK7t8kjzZvn/cx2qAoJC/7Y4F68dzQ2xvg5k45/wjdGXgo3 hFQf/wA/gJMDCEmbwjZvVkLT1pCF9CcYNQz50G99FM2uXCZx57Db8ZQLDjWvdLu9qFQT ovBzXs1neqv3tzxBZce9oLOY7tmfUHv2RgCc3RbJlZH4rsWqQLF/aT7ccrIFGNrnYufX jIMQ9zzLKMsc57TWkNSR/qvyorhy+F9gQ3Jj93KlQJzgiVw2qwdwNDlQzNIpd1ps0MaM ZfsQsRSiBCoTu1ogZkiFizMVw9hIB36Ew55tHEq013wHhq03py+2Mj/uno8nxwVXKBIa ueKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350338; x=1728955138; 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=wyZg7kxpkNCds2EZflCHxHMwXfcdXxrO/ZcaHcLL39s=; b=oiE3LkJ3p75jGNwaF01xmFwjh718Hq5GsvpSZnLxLlwlLE0xCEt/7nbKSJSAA1IiiV EArxJDTWfmJKQ76KHEXLGw4awBb62z0T+94EYgwyQKhOR8IIEVMUIlkKjmcYSKeH4U9M gc9M30CMyq+HrPVAATxUw/hp8cIZ7Alqo51EjjW++W6jKy7BKzUKAUCwylfZlspmGEBZ JbI6XtKkXZJgi2CGR+BcvuimcswVN40kHl8pRtwMxU5PD3fHFVaoEs7P6OfSVigj/EP9 nYUgCB7W/1TG1cCJSKO0qD2ILJFN6TkE0IpCoCuoquNRaYkUVjKCPWeYPXzCBVk/m4EG gOTw== X-Gm-Message-State: AOJu0YymgggF4pwxu9UxSNvjHATwKkv4aLitwurhwsJ3lQluZN1sZrDd 8RjrgHoiWQ/LUmNnwiAWr70n4jx/VODidx0RG+iprZCM+GQnsn3Skfbx9rjfleLKVlk9RBZ/jbI vlMzmxV+xkRBItm+BxTJ4ITe/bb4X8liu5qsGB+cDgcsku26pGwK3Qav+55vnLT8ZgEQs1xwbNI T3tBHS28fJpxNz9cX8PL7cjwuIKw== X-Google-Smtp-Source: AGHT+IE3/W9CgSMU393ZW56+VU+vEEAMQd6ttBYHzgtNP0gr2mWHRr9OJi2xXWSJjWwG7FxSWygOJf1nyg== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a81:b513:0:b0:6e3:eab:18b1 with SMTP id 00721157ae682-6e30eab1934mr52557b3.1.1728350337999; Mon, 07 Oct 2024 18:18:57 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:28 -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-3-tavip@google.com> Subject: [PATCH v2 02/25] tests/unit: add fifo32 tests 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::114a; envelope-from=3gYgEZwUKCuIXEZMTKSSKPI.GSQUIQY-HIZIPRSRKRY.SVK@flex--tavip.bounces.google.com; helo=mail-yw1-x114a.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: 1728350636471116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add push/pop and peek tests for fifo32. Signed-off-by: Octavian Purdila --- tests/unit/test-fifo.c | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/unit/test-fifo.c b/tests/unit/test-fifo.c index 14153c41fa..d0e05ba95c 100644 --- a/tests/unit/test-fifo.c +++ b/tests/unit/test-fifo.c @@ -13,6 +13,7 @@ #include "qemu/osdep.h" #include "migration/vmstate.h" #include "qemu/fifo8.h" +#include "qemu/fifo32.h" =20 const VMStateInfo vmstate_info_uint32; const VMStateInfo vmstate_info_buffer; @@ -432,6 +433,53 @@ static void test_fifo8_pushpop(void) fifo8_destroy(&fifo); } =20 +static void test_fifo32_pushpop(void) +{ + Fifo32 fifo; + uint32_t e; + + fifo32_create(&fifo, 2); + fifo32_push(&fifo, 0x11121314); + fifo32_push(&fifo, 0x21222324); + g_assert(fifo32_num_used(&fifo) =3D=3D 2); + + e =3D fifo32_pop(&fifo); + g_assert(e =3D=3D 0x11121314); + g_assert(fifo32_num_used(&fifo) =3D=3D 1); + + e =3D fifo32_peek(&fifo); + g_assert(e =3D=3D 0x21222324); + + g_assert(fifo32_num_used(&fifo) =3D=3D 1); + fifo32_destroy(&fifo); +} + +static void test_fifo32_peek(void) +{ + Fifo32 fifo; + uint32_t e; + + fifo32_create(&fifo, 2); + fifo32_push(&fifo, 0x11121314); + fifo32_push(&fifo, 0x21222324); + g_assert(fifo32_num_used(&fifo) =3D=3D 2); + + e =3D fifo32_peek(&fifo); + g_assert(e =3D=3D 0x11121314); + g_assert(fifo32_num_used(&fifo) =3D=3D 2); + + e =3D fifo32_pop(&fifo); + g_assert(e =3D=3D 0x11121314); + g_assert(fifo32_num_used(&fifo) =3D=3D 1); + + e =3D fifo32_peek(&fifo); + g_assert(e =3D=3D 0x21222324); + g_assert(fifo32_num_used(&fifo) =3D=3D 1); + + fifo32_destroy(&fifo); +} + + int main(int argc, char *argv[]) { g_test_init(&argc, &argv, NULL); @@ -445,5 +493,7 @@ int main(int argc, char *argv[]) g_test_add_func("/fifo8/peek_bufptr_wrap", test_fifo8_peek_bufptr_wrap= ); g_test_add_func("/fifo8/pop_bufptr", test_fifo8_pop_bufptr); g_test_add_func("/fifo8/pop_bufptr_wrap", test_fifo8_pop_bufptr_wrap); + g_test_add_func("/fifo32/pushpop", test_fifo32_pushpop); + g_test_add_func("/fifo32/peek", test_fifo32_peek); return g_test_run(); } --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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=1728350637; cv=none; d=zohomail.com; s=zohoarc; b=PklqvXYF24DntTm2BpuU/L6ryy/Nk0pxSAhWzRMaUARyQho/c4NM2RpOGFzZro3G+lUE0figwIGARJFcQb6SjLwcbgsuKZJrMkBDospTOSLQrcpd2PQPVNudrQP2FmAMbSZ7+6OedHQ+Cyzr7MDypNMtepvArrsqcZXYORoztso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350637; 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=mOjYfJjVDbekrSS0dJ0e0WrdZI53XB9lrt52zwVXgdE=; b=VGF3r5hiqQEpkf15LtyzK/lVeYzokFy97OXtgjaaHecybskWkOAkpEbsL44RwcRiH6prSjbXm48l/e0GqkPnO7QxLFGTf4uQMB+qI+hqaSa8rEig6ZNbiDxugqTf0q0dOZC1/TRdjFG+cSPaGTtObYK5qFugbWIIFdsXpn/cfyE= 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 1728350637584267.45082838450367; Mon, 7 Oct 2024 18:23:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxyt0-0008PT-Ui; Mon, 07 Oct 2024 21:19:39 -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 <3g4gEZwUKCuQZGbOVMUUMRK.IUSWKSa-JKbKRTUTMTa.UXM@flex--tavip.bounces.google.com>) id 1sxysT-0007ho-MG for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:06 -0400 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3g4gEZwUKCuQZGbOVMUUMRK.IUSWKSa-JKbKRTUTMTa.UXM@flex--tavip.bounces.google.com>) id 1sxysR-00007M-8F for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:05 -0400 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-690404fd230so29853237b3.3 for ; Mon, 07 Oct 2024 18:19:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350340; x=1728955140; 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=mOjYfJjVDbekrSS0dJ0e0WrdZI53XB9lrt52zwVXgdE=; b=sGyscZBvjMn8mHYUvroZ7MhL/wGAbDcDA8xQP0KsuzCzGssc8MWlpeZuqCyR68uh4r R3S0cJ8GYlzqbXdMFuNTtvOhUIwfFEZrYxV2yiNhHTG62qBdDCwspzAczEpotJPYjh7/ 0N7Bmss8EDN4AO9sdWPgVWFd52g+LQsZkMIGhoWvjYnddexxcfMit2A/jzdzrQ1+XW5M W86TRatIO5v3B97PpGLn8Ah85vb53O8+//MCYIGr7iRSvLQsIx8HWG7QGFusvS6b9C5j 8o1fxuiGAyvcHreJuhBpk3ePcPAwxpDbmNm5sWMWzzZUfTCUU3YmclQp5L5PzIiJmYms X2VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350340; x=1728955140; 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=mOjYfJjVDbekrSS0dJ0e0WrdZI53XB9lrt52zwVXgdE=; b=TWF8zr2/Xq2SrYMYOPoXYoXiqqKWfKrX14BZaKvqu0i3IE3GE7cLHY6iBnzSuNkK1O EIIPRlNw1gYrFB5iuLPsKnWzrdPNCUKW3abB0YH8ijRpO+jRmLRjtVUTMK9z7v87ekCv oW1GIvP1+Au6GtbzwiBMt3HlGtZ7xMBEJU2iLuN7MOviNsUtkjTJg2H0EMmw/rk5w7bp sP0yxO7mwnY70BYlDFQVU5HXX1husETpnRq5mXlWcqCHzP6qERfgUekwVrk0hnjX2nrM cP+N9AV46amOP5CBeI1DBfgIYJ70Ey8Ry3im3xjuwT1aKJe3eXRIAvZKkQ16f/xEPt7p 0/sQ== X-Gm-Message-State: AOJu0YwitT7ibLwZyJB6kgVDfrg99W3SWSb110ChW2gw4MtGP3MEQvIG Usoil5FpyFmG7A2fYqLWn+wIIF6vvpVuxcZ9yc+Kld8NfjnMNdW6tauqmRZg4etCfiCN7ymEYbF av6uvTSTYFE9yUIdeIXUAlX9yexFvtGo/5M66pciynHeUPLdSEUdhg0WcLhp5talBun5VlQ1Eb4 SjLRzmns/cTwA2l7QZSE+QRWGIYA== X-Google-Smtp-Source: AGHT+IFXNoRKMbcr5g2Ch81E0fEb4jgg81eW3pnVWasxIKvPPjCZ2FzJEeKEMLdRIVBw6AvbjS4oRQIz9g== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a25:68ca:0:b0:e28:8f2c:73e6 with SMTP id 3f1490d57ef6-e289391ea39mr8605276.7.1728350339603; Mon, 07 Oct 2024 18:18:59 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:29 -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-4-tavip@google.com> Subject: [PATCH v2 03/25] scripts: add script to generate C header files from SVD XML files 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::114a; envelope-from=3g4gEZwUKCuQZGbOVMUUMRK.IUSWKSa-JKbKRTUTMTa.UXM@flex--tavip.bounces.google.com; helo=mail-yw1-x114a.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=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 @google.com) X-ZM-MESSAGEID: 1728350638552116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Stefan Stanacar The CMSIS System View Description format(CMSIS-SVD) is an XML based description of Arm Cortex-M microcontrollers provided and maintained by sillicon vendors. It includes details such as peripherals registers (down to bitfields), peripheral register block addresses, reset values, etc. This script uses this information to create header files that makes it easier to emulate peripherals. The script can be used to create either peripheral specific headers or board / system specific information. Peripheral specific headers contains information such as register layout (using the qemu register fields infrastructure), register names, register write masks and register reset values, the latter using RegisterAccessInfo. Here is an excerpt from a generated header: #pragma once #include "hw/registerfields.h" /* Flexcomm */ #define FLEXCOMM_REGS_NO (1024) /* Peripheral Select and Flexcomm module ID */ REG32(FLEXCOMM_PSELID, 4088); /* Peripheral Select */ FIELD(FLEXCOMM_PSELID, PERSEL, 0, 3); /* No peripheral selected. */ #define FLEXCOMM_PSELID_PERSEL_NO_PERIPH_SELECTED 0 /* USART function selected */ #define FLEXCOMM_PSELID_PERSEL_USART 1 /* SPI function selected */ #define FLEXCOMM_PSELID_PERSEL_SPI 2 /* I2C */ #define FLEXCOMM_PSELID_PERSEL_I2C 3 /* I2S Transmit */ #define FLEXCOMM_PSELID_PERSEL_I2S_TRANSMIT 4 /* I2S Receive */ #define FLEXCOMM_PSELID_PERSEL_I2S_RECEIVE 5 ... #define FLEXCOMM_REGISTER_ACCESS_INFO_ARRAY(_name) \ struct RegisterAccessInfo _name[FLEXCOMM_REGS_NO] =3D { \ [0 ... FLEXCOMM_REGS_NO -1] =3D { \ .name =3D "", \ .addr =3D -1, \ }, \ [0x3FE] =3D { \ .name =3D "PSELID", \ .addr =3D 0xFF8, \ .ro =3D 0xFFFFFFF0, \ .reset =3D 0x101000, \ }, \ [0x3FF] =3D { \ .name =3D "PID", \ .addr =3D 0xFFC, \ .ro =3D 0xFFFFFFFF, \ .reset =3D 0x0, \ }, \ } The script has options to control which registers and fields should be generated. Board specific headers contains information about peripheral base register addresses. Signed-off-by: Stefan Stanacar [tavip: pylint fixes, generate layout with qemu register fields instead of bitfields, generate register names, romask and reset values, add options to control which register and fields are generated] Signed-off-by: Octavian Purdila --- meson.build | 4 + scripts/svd-gen-header.py | 415 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 419 insertions(+) create mode 100755 scripts/svd-gen-header.py diff --git a/meson.build b/meson.build index 33954b3eba..5127e67d93 100644 --- a/meson.build +++ b/meson.build @@ -3330,6 +3330,10 @@ tracetool_depends =3D files( 'scripts/tracetool/__init__.py', ) =20 +svd_gen_header =3D [ + python, files('scripts/svd-gen-header.py') +] + qemu_version_cmd =3D [find_program('scripts/qemu-version.sh'), meson.current_source_dir(), get_option('pkgversion'), meson.project_version()] diff --git a/scripts/svd-gen-header.py b/scripts/svd-gen-header.py new file mode 100755 index 0000000000..7befa75421 --- /dev/null +++ b/scripts/svd-gen-header.py @@ -0,0 +1,415 @@ +#!/usr/bin/env python3 + +# Copyright 2024 Google LLC +# +# This work is licensed under the terms of the GNU GPL, version 2 or later. +# See the COPYING file in the top-level directory. +# +# Use this script to generate a C header file from an SVD xml +# +# Two mode of operations are supported: peripheral and system. +# +# When running in peripheral mode a header for a specific peripheral +# is going to be generated. It will define a type and structure with +# all of the available registers at the bitfield level. An array that +# contains the reigster names indexed by address is also going to be +# generated as well as a function to initialize registers to their +# reset values. +# +# Invocation example: +# +# svd_gen_header -i MIMXRT595S_cm33.xml -o flexcomm.h -p FLEXCOMM0 -t FLEX= COMM +# +# When running in system mode a header for a specific system / +# platform will be generated. It will define register base addresses +# and interrupt numbers for selected peripherals. +# +# Invocation example: +# +# svd_gen_header -i MIMXRT595S_cm33.xml -o rt500.h -s RT500 -p FLEXCOMM0 \ +# -p CLKCTL0 -p CLKCTL1 +# + +import argparse +import fnmatch +import re +import os +import sys +import xml.etree.ElementTree +import pysvd + +data_type_by_bits =3D { + 8: "uint8_t", + 16: "uint16_t", + 32: "uint32_t", +} + + +def get_register_array_name_and_size(reg): + """Return register name and register array size. + + The SVD can define register arrays and pysvd encodes the whole set + as as regular register with their name prepended by []. + + Returns a tuple with the register name and the size of the array or + zero if this is not a register set. + + """ + + split =3D re.split(r"[\[\]]", reg.name) + return (split[0], int(split[1]) if len(split) > 1 else 0) + + +def generate_comment(indent, text): + """Generate a comment block with for the given text with the given + indentation level. + + If possible, use a single line /* */ comment block, otherwise use + a multiline comment block. + + Newlines are preseved but tabs are not. + + """ + + # preserve new lines + text =3D text.replace("\n", " \n ") + text =3D text.replace(" ", " ") + + if len(text) + len("/* */") + len(" " * indent) <=3D 80 and "\n" not = in text: + return f"{' '* indent}/* {text} */\n" + + out =3D " " * indent + "/*\n" + line =3D " " * indent + " *" + for word in re.split(r"[ ]", text): + if len(line) + len(word) >=3D 79 or word =3D=3D "\n": + out +=3D line + "\n" + line =3D " " * indent + " *" + if word !=3D "\n": + line +=3D " " + word + else: + line +=3D " " + word + + out +=3D line + "\n" + + out +=3D " " * indent + " */\n" + return out + + +def get_fields(reg, dictionary): + """Return a list of fields from a register indexed dictionary. + + The dictionary keys may contain wildcards. + + """ + + for key in dictionary.keys(): + if fnmatch.fnmatch(reg, key): + return dictionary[key] + return None + + +def generate_reg(reg, dictionary): + """Check if the register should be generated""" + + if get_fields(reg, dictionary): + return True + return False + + +def skip_reg(reg, dictionary): + """Check if the register should be skipped""" + + for key in dictionary.keys(): + if fnmatch.fnmatch(reg, key) and dictionary[key] is None: + return True + return False + + +def match_field(reg, field, dictionary): + """Match a register and field in a dictionary indexed by registers + that contains a list of fields. + + Both the dictionary keys and the list of fields may contain wildcards. + + """ + fields =3D get_fields(reg, dictionary) + if not fields: + return False + for f in fields: + if fnmatch.fnmatch(field, f): + return True + return False + + +def generate_field(name, reg_name, field, shared): + """Generate register field.""" + + out =3D generate_comment(0, field.description) + if shared: + out +=3D "SHARED_" + out +=3D f"FIELD({name}_{reg_name}, {field.name}, " + out +=3D f"{field.bitOffset}, {field.bitWidth});\n" + if hasattr(field, "enumeratedValues") and field.bitWidth > 1: + for enum in field.enumeratedValues.enumeratedValues: + enum_name =3D f"{name}_{reg_name}_{field.name}_{enum.name}" + out +=3D generate_comment(0, enum.description) + out +=3D f"#define {enum_name} {enum.value}\n" + return out + + +def generate_registers(name, periph, generate, skip): + """Generate register offsets and fields + + Use registerfield macros to define register offsets and fields for + a given peripheral. + + """ + + regs =3D sorted(periph.registers, key=3Dlambda reg: reg.addressOffset) + out =3D generate_comment(0, periph.description) + out +=3D f"#define {name}_REGS_NO ({regs[-1].addressOffset // 4 + 1})\= n\n" + for reg in regs: + reg_name, reg_array_size =3D get_register_array_name_and_size(reg) + if not generate_reg(reg_name, generate): + continue + if skip_reg(reg_name, skip): + continue + out +=3D generate_comment(0, reg.description) + if reg_array_size > 1: + for idx in range(0, reg_array_size): + addr =3D reg.addressOffset + idx * reg.size // 8 + out +=3D f"REG32({name}_{reg_name}{idx}, 0x{addr:X});\n" + else: + addr =3D reg.addressOffset + out +=3D f"REG32({name}_{reg_name}, 0x{addr:X});\n" + for field in reg.fields: + if not match_field(reg_name, field.name, generate): + continue + if match_field(reg_name, field.name, skip): + continue + out +=3D generate_field( + name, reg_name, field, True if reg_array_size > 1 else Fal= se + ) + out +=3D "\n" + + return out + + +def create_wmask(reg): + """Generate write mask for a register. + + Generate a mask with all bits that are writable set to 1 + """ + + wmask =3D 0 + fields =3D sorted(reg.fields, key=3Dlambda field: field.bitOffset) + if len(fields) > 0: + for field in fields: + if field.access !=3D pysvd.type.access.read_only: + wmask |=3D ((1 << field.bitWidth) - 1) << field.bitOffset + else: + if reg.access !=3D pysvd.type.access.read_only: + wmask =3D 0xFFFFFFFF + return wmask + + +def create_romask(reg): + """Generate write mask for a register. + + Generate a mask with all bits that are readonly set to 1 + """ + + return ~create_wmask(reg) & 0xFFFFFFFF + + +def generate_register_access_info(name, periph): + """Generate RegisterAccessInfo array macro""" + + out =3D f"\n#define {name}_REGISTER_ACCESS_INFO_ARRAY(_name) \\\n" + out +=3D f" struct RegisterAccessInfo _name[{name}_REGS_NO] =3D {{ = \\\n" + out +=3D f" [0 ... {name}_REGS_NO - 1] =3D {{ \\\n" + out +=3D ' .name =3D "", \\\n' + out +=3D " .addr =3D -1, \\\n" + out +=3D " }, \\\n" + for reg in periph.registers: + reg_name, reg_array_size =3D get_register_array_name_and_size(reg) + if reg_array_size > 1: + for idx in range(0, reg_array_size): + addr =3D reg.addressOffset + idx * reg.size // 8 + out +=3D f" [0x{addr // 4:X}] =3D {{ \\\n" + out +=3D f' .name =3D "{reg_name}{idx}", \\\n' + out +=3D f" .addr =3D 0x{addr:X}, \\\n" + out +=3D f" .ro =3D 0x{create_romask(reg):X}, \= \\n" + out +=3D f" .reset =3D 0x{reg.resetValue:X}, \\= \n" + out +=3D " }, \\\n" + else: + out +=3D f" [0x{reg.addressOffset // 4:X}] =3D {{ \\\n" + out +=3D f' .name =3D "{reg_name}", \\\n' + out +=3D f" .addr =3D 0x{reg.addressOffset:X}, \\\n" + out +=3D f" .ro =3D 0x{create_romask(reg):X}, \\\n" + out +=3D f" .reset =3D 0x{reg.resetValue:X}, \\\n" + out +=3D " }, \\\n" + out +=3D " }\n" + + return out + + +def generate_peripheral_header(periph, name, args): + """Generate peripheral header + + The following information is generated: + + * typedef with all of the available registers and register fields, + position and mask defines for register fields. + + * enum values that encode register fields options. + + * a macro that defines the register names indexed by the relative + address of the register. + + * a function that sets the registers to their reset values + + """ + + generate =3D {} + for reg in args.fields.split(): + if reg.find(":") > 0: + reg, fields =3D reg.split(":") + generate[reg] =3D fields.split(",") + else: + generate[reg] =3D ["*"] + + skip =3D {} + for reg in args.no_fields.split(): + if reg.find(":") > 0: + reg, fields =3D reg.split(":") + skip[reg] =3D fields.split(",") + else: + skip[reg] =3D None + + out =3D generate_registers(name, periph, generate, skip) + + out +=3D generate_register_access_info(name, periph) + + return out + + +def get_same_class_peripherals(svd, periph): + """Get a list of peripherals that are instances of the same class.""" + + return [periph] + [ + p + for p in svd.peripherals + if p.derivedFrom and p.derivedFrom.name =3D=3D periph.name + ] + + +def generate_system_header(system, svd, periph): + """Generate base and irq defines for given list of peripherals""" + + out =3D "" + + for p in get_same_class_peripherals(svd, periph): + out +=3D f"#define {system}_{p.name}_BASE 0x{p.baseAddress:X}UL\n" + out +=3D "\n" + + for p in get_same_class_peripherals(svd, periph): + for irq in p.interrupts: + out +=3D f"#define {system}_{irq.name}_IRQn 0x{irq.value}UL\n" + out +=3D "\n" + + return out + + +def main(): + """Script to generate C header file from an SVD file""" + + parser =3D argparse.ArgumentParser() + parser.add_argument( + "-i", "--input", type=3Dstr, help=3D"Input SVD file", required=3DT= rue + ) + parser.add_argument( + "-o", "--output", type=3Dstr, help=3D"Output .h file", required=3D= True + ) + parser.add_argument( + "-p", + "--peripheral", + action=3D"append", + help=3D"peripheral name from the SVD file", + required=3DTrue, + ) + parser.add_argument( + "-t", + "--type-name", + type=3Dstr, + help=3D"name to be used for peripheral definitions", + required=3DFalse, + ) + parser.add_argument( + "-s", + "--system", + type=3Dstr, + help=3D"name to be used for the system definitions", + required=3DFalse, + ) + parser.add_argument( + "--fields", + help=3D"list of registers and fields that should be generated " + "in the following format 'REG[:FIELDS] ...' " + "where FIELDS is a list of comma separated fields that can be " + "empty; both regsiters and fields can be matched with wildcards; " + "'REG' is an alias for 'REG:*';", + required=3DFalse, + default=3D"*:*", + ) + parser.add_argument( + "--no-fields", + type=3Dstr, + help=3D"list of register and fields that should not be generated " + "in the following format 'REG[:FIELDS] ...' " + "where FIELDS is a list of comma separated fields that can be " + "empty; both regsiters and fields can be matched with wildcards; " + "note that 'REG' will not generate neither the register nor its " + "fields while REG: will generate the register but none of its fiel= ds", + required=3DFalse, + default=3D":", + ) + + args =3D parser.parse_args() + + node =3D xml.etree.ElementTree.parse(args.input).getroot() + svd =3D pysvd.element.Device(node) + + # Write license header + header =3D svd.licenseText.strip() + header +=3D f"\n\nAutomatically generated by {os.path.basename(__file_= _)} " + header +=3D f"from {os.path.basename(args.input)}" + out =3D generate_comment(0, header) + + # Write some generic defines + out +=3D "#pragma once\n\n" + + for name in args.peripheral: + periph =3D svd.find(name) + if periph: + if args.system: + out +=3D generate_system_header(args.system, svd, periph) + else: + out +=3D '#include "hw/register.h"\n\n' + out +=3D generate_peripheral_header( + periph, + args.type_name if args.type_name else periph.name, + args, + ) + else: + print(f"No such peripheral: {name}") + return 1 + + with open(args.output, "w", encoding=3D"ascii") as output: + output.write(out) + + return 0 + + +if __name__ =3D=3D "__main__": + sys.exit(main()) --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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=1728350496; cv=none; d=zohomail.com; s=zohoarc; b=UmryoFLhhsTkZ7hQNMpWcIEv016spvmZEXE4XsM518BmKEJj0mOUn+N0LVLGH7r0i79JxsQ74DVIj8rPE/DHRE8/2BdAbzFfOvI9557DqRfStAGU00CJ08EUpddOp48HRoG9PGC1g29vF/pVOgelk96oiKzsTxZTjuhC54Lex3Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350496; 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=SRJtDmmyu0p+iYadPI5KNYfcB0hfVULXlSFU/u3kO34=; b=IFXFrMBmQ60VdkW89IIQzh8tHIQuTs11cw0qZUzTJ8pMwKQipE9QhxOBjJIEZch/oW2YL8AT7q68pAezuI59wsUgACNFWqLttdbVnoJ2/9341/3erPMzuOir1IfiTp08qUOHLBaX4nRf/oWnPeDKccnnoK11Ks0yel4g4Wv6aXI= 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 1728350496467426.0541786837671; Mon, 7 Oct 2024 18:21:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxyt9-00013Z-W7; Mon, 07 Oct 2024 21:19:48 -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 <3hYgEZwUKCuYbIdQXOWWOTM.KWUYMUc-LMdMTVWVOVc.WZO@flex--tavip.bounces.google.com>) id 1sxysU-0007hr-11 for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:07 -0400 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3hYgEZwUKCuYbIdQXOWWOTM.KWUYMUc-LMdMTVWVOVc.WZO@flex--tavip.bounces.google.com>) id 1sxysR-00007l-QG for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:05 -0400 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-e24b43799e9so4992183276.2 for ; Mon, 07 Oct 2024 18:19:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350341; x=1728955141; 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=SRJtDmmyu0p+iYadPI5KNYfcB0hfVULXlSFU/u3kO34=; b=QB1Wmc+uxm4GciIa68XIdQEZga91s+QCkalN+t2ZsDq6kZPP/3APN6A9O35CBayjUO zodkORkCzApKvGhjUoTHEWi2Z9iLze4ed4d6dJ7r1xcRUgjoPgXfOnENCDGoJI/0rupg QgHU1/N4H0L2BVYwSbZ6amS6bBozwQpVvHxE0YhE7BSMqH95yVRl88GmzC5C0peExo25 9LnHwK0IMKMFVHksjYs/n37V3HyKmTmXJb/KLSXwkt7fsmetA1w5109D5WJdRtcWmxkV NNjIQmWaR03yITJ9pccw1P+LiiS5Qx3iUWP+Mt9pv+5M7MdXK1SUA3AJIUWLcyPt5QCI SH2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350341; x=1728955141; 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=SRJtDmmyu0p+iYadPI5KNYfcB0hfVULXlSFU/u3kO34=; b=HwJQnXpOrxdg1SFgnYV0BIf77L6IvxwY3UWhK+Ql6/unQoQrhlAJKNx62PGPN4NRwS AZpFqO2+HchZ+ZIh2S31Oackp7tYMp3BIrgz2j7EZrpdofw0ofu0+0x25FAyCtkTbe1N OWn9yYAyZRVaV+tSsoeEocbyW1snxfokiqCfBmh9RxCyXqMSyVcxn4y94GFg58F2vZAb XBkEfA2KUvsD/QgN4QKczEaL5yVgXjyMjd1RAwSBJS41ULvax/wYNN5lR8F9iPuArhPs UkFio5/7UMJt4uOvMyciGgYXMlEzsHBvZxqv4w6VQXKP0yED/SfAmDgqj2vhje3LYGwY ZmAw== X-Gm-Message-State: AOJu0Yw5KZdhgc8CeQ/bOGuBNa0TYRELjUvc9uIPORD9NkMvdOCRGS0y 98I7A/Zy6JiZPPZWaXEOsG/vVGPU5G8AOEIxc+fa1Bw0B5vzIMyZYwJzPu6UlxLe5GXwcRo1U04 Sr9bfIdsQxSBxtaVlx1OSunq29JIiwcWM6NNsPsY/oUU14e1xNST+j+5i0vqCeWZ9Kx8wAtt8m6 MV/Q+ByD7pvPiXj8b6q1VgwmqoCQ== X-Google-Smtp-Source: AGHT+IGwqe4AUonStZiddHG8zloPnHdUO/i4be9rIUYNtKyu6KDWl1Kh9fMZKqdIY53NIoUzTLTHblLNEg== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a05:6902:d49:b0:e05:6532:166 with SMTP id 3f1490d57ef6-e28936c0dabmr30058276.1.1728350341057; Mon, 07 Oct 2024 18:19:01 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:30 -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-5-tavip@google.com> Subject: [PATCH v2 04/25] Add mcux-soc-svd subproject 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::b4a; envelope-from=3hYgEZwUKCuYbIdQXOWWOTM.KWUYMUc-LMdMTVWVOVc.WZO@flex--tavip.bounces.google.com; helo=mail-yb1-xb4a.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=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 @google.com) X-ZM-MESSAGEID: 1728350498275116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add mcux-soc-svd subproject that contains SVD files that are going to be used to generate C header with register layout definitions and other helpers to create device models. Guard the subproject by a configuration option since it is rarely going to be used - whenever new headers will be generated. It is unlikely that already generated headers will be updated, with the exception of minor hardware revisions. Also export the rt595 SVD file which is going to be used by subsequent patches. TBD: switch to a qemu gitlab fork before merge Signed-off-by: Octavian Purdila --- hw/arm/svd/meson.build | 4 ++++ meson_options.txt | 3 +++ scripts/meson-buildoptions.sh | 4 ++++ subprojects/.gitignore | 1 + subprojects/mcux-soc-svd.wrap | 5 +++++ subprojects/packagefiles/mcux-soc-svd/meson.build | 5 +++++ 6 files changed, 22 insertions(+) create mode 100644 hw/arm/svd/meson.build create mode 100644 subprojects/mcux-soc-svd.wrap create mode 100644 subprojects/packagefiles/mcux-soc-svd/meson.build diff --git a/hw/arm/svd/meson.build b/hw/arm/svd/meson.build new file mode 100644 index 0000000000..7d83d2ccbc --- /dev/null +++ b/hw/arm/svd/meson.build @@ -0,0 +1,4 @@ +if get_option('mcux-soc-svd') + mcux_soc_svd =3D subproject('mcux-soc-svd') + rt595 =3D mcux_soc_svd.get_variable('rt595') +endif diff --git a/meson_options.txt b/meson_options.txt index 5ee1d95c9c..87a412194c 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -373,3 +373,6 @@ option('hexagon_idef_parser', type : 'boolean', value := true, =20 option('x86_version', type : 'combo', choices : ['0', '1', '2', '3', '4'],= value: '1', description: 'tweak required x86_64 architecture version beyond com= piler default') + +option('mcux-soc-svd', type : 'boolean', value : false, + description: 'enable targets to generate C headers from mcux-soc-sv= d') diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh index 3bee1c56df..0918eb1ab2 100644 --- a/scripts/meson-buildoptions.sh +++ b/scripts/meson-buildoptions.sh @@ -41,6 +41,8 @@ meson_options_help() { printf "%s\n" ' --enable-lto Use link time optimization' printf "%s\n" ' --enable-malloc=3DCHOICE choose memory allocator to u= se [system] (choices:' printf "%s\n" ' jemalloc/system/tcmalloc)' + printf "%s\n" ' --enable-mcux-soc-svd enable targets to generate C h= eaders from mcux-' + printf "%s\n" ' soc-svd' printf "%s\n" ' --enable-module-upgrades try to load modules from alter= nate paths for' printf "%s\n" ' upgrades' printf "%s\n" ' --enable-rng-none dummy RNG, avoid using /dev/(u= )random and' @@ -393,6 +395,8 @@ _meson_option_parse() { --enable-malloc-trim) printf "%s" -Dmalloc_trim=3Denabled ;; --disable-malloc-trim) printf "%s" -Dmalloc_trim=3Ddisabled ;; --mandir=3D*) quote_sh "-Dmandir=3D$2" ;; + --enable-mcux-soc-svd) printf "%s" -Dmcux-soc-svd=3Dtrue ;; + --disable-mcux-soc-svd) printf "%s" -Dmcux-soc-svd=3Dfalse ;; --enable-membarrier) printf "%s" -Dmembarrier=3Denabled ;; --disable-membarrier) printf "%s" -Dmembarrier=3Ddisabled ;; --enable-module-upgrades) printf "%s" -Dmodule_upgrades=3Dtrue ;; diff --git a/subprojects/.gitignore b/subprojects/.gitignore index adca0266be..bca8693ef4 100644 --- a/subprojects/.gitignore +++ b/subprojects/.gitignore @@ -6,3 +6,4 @@ /keycodemapdb /libvfio-user /slirp +/mcux-soc-svd diff --git a/subprojects/mcux-soc-svd.wrap b/subprojects/mcux-soc-svd.wrap new file mode 100644 index 0000000000..80d18e8561 --- /dev/null +++ b/subprojects/mcux-soc-svd.wrap @@ -0,0 +1,5 @@ +[wrap-git] +url =3D https://github.com/nxp-mcuxpresso/mcux-soc-svd/ +revision =3D 7f6f9ef7420144fe14cd9bc4d8e0e3523232da04 +patch_directory =3D mcux-soc-svd +depth =3D 1 diff --git a/subprojects/packagefiles/mcux-soc-svd/meson.build b/subproject= s/packagefiles/mcux-soc-svd/meson.build new file mode 100644 index 0000000000..37c537d040 --- /dev/null +++ b/subprojects/packagefiles/mcux-soc-svd/meson.build @@ -0,0 +1,5 @@ +project('mcux-soc-svd') + +fs =3D import('fs') + +rt595 =3D fs.copyfile('MIMXRT595S/MIMXRT595S_cm33.xml') --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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=1728350744; cv=none; d=zohomail.com; s=zohoarc; b=aBF1M38FIYpFpU4WCGfnlc91Ln5IfMecc+M5d4K3aPdYXv/FAiyWcuQrvZPJhTQv43Ql6ALgy0dAlRGeOgERaW7+LrTjpeX+QGqWdUf5Tk7fxCN9SNHnSc4Xy8mMTyVey/Ys9bxcZLC/2b59uXqGtQyLyZd/SxHRQBlhL5IVLAU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350744; 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=ALEsA5QASCJbactGuKnulwp5BQq6AgOVeo/aeexBENk=; b=TPNSET5YvlYxzL86oEw12TEsiIuYuky9f3HYbXSL7mZNtHsHst9JM7RYUotiDqyF9/6OhH8AMEjmZKuCgJEVXMdHkr/7Kz8/VSFrQDAN9vgbdtJF/28kI8J5uYoYh12AmC+0uO8/qjBJEh2D3kqDHLQaVI5YTR7fR/vgHcBsSOw= 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 1728350744668137.89781971953448; Mon, 7 Oct 2024 18:25:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxytK-0002Hd-4R; Mon, 07 Oct 2024 21:19:59 -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 <3h4gEZwUKCugdKfSZQYYQVO.MYWaOWe-NOfOVXYXQXe.YbQ@flex--tavip.bounces.google.com>) id 1sxysY-0007mG-7s for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:13 -0400 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3h4gEZwUKCugdKfSZQYYQVO.MYWaOWe-NOfOVXYXQXe.YbQ@flex--tavip.bounces.google.com>) id 1sxysT-000087-Au for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:09 -0400 Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-7163489149fso5904197a12.3 for ; Mon, 07 Oct 2024 18:19:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350343; x=1728955143; 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=ALEsA5QASCJbactGuKnulwp5BQq6AgOVeo/aeexBENk=; b=e7tZ1XECUozXLGNiUWhFPet0tCpnnNe4TjTrZva0sseGYa1yDePdCx/8blRokeuQXf vOC+GRt7fk83nlzYBMbqIARPL92MLVKBpsL/wSh6wxjb88uZkMicD4Jhfr/yAI6f8zeC BDR1z68GD1KM5TCfTNbZ3zpv4ycCcfqrEo4Rx7f2lev1IyUMnkDpEZbEGsYtDszQVul4 2BnsvvgDFK1R/6lXDLjUBAWt0zlp+8512+66KHNQB3KtR5p07a+/T8NCJA1OUQMH3ut3 d+OIIVfLdH2V6NG+T4uAiR9zko1g/JlzcfYCRotWKoFFLAzv+cF5GAhCNm2jnQPDg4/2 68qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350343; x=1728955143; 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=ALEsA5QASCJbactGuKnulwp5BQq6AgOVeo/aeexBENk=; b=bj7M27z+kSLXh6fv73gkqEAUCeOoU1hiZYEb+9+JF78oGzXU8UYIzHnoeMs2c9FktG vtlm2SYoBcjm5ZhYLepRfd1dGPJBH797coSY3CWegkGeDiq+eLsgKuEKk+GZWVYOqmO5 s9b8g9U1RcwyO7eBqQQCOkFdQ7Blt1FTZDpA5oasG0YzQ4iKAZC1CCYIEAa3/JfYP7+D p8URZo7FHxNgnDjbjRtJ/BOYYzNBk+toEFYLfTNTY6korcCQn8crW6mbDo746cAQHF3D /zCQCUdCF2DnZItC9Yj5X8yyXoNyKPYDm4CRxzSFrGr/BoKUP/HZy2jNfHeWBoZ0Tbai ZAVg== X-Gm-Message-State: AOJu0Ywy+7DQnANjLAwPXcUNeUP4X6beaKsu0moX7L2eS9w0WF6fDl2p doctJF2GYn8EEct1Zc1Cq6ynthzkYoqxWeQL/U6Ud/+gnc4ckQEr8ro4XEGgC9tuSToP276NbgO k3jT9tZwmUf9xYJnZ2TWLfZgTJD4Lwe8eFpBsmtSaxmgJ4WszFkBQd3lsjrLm5dT0+FxXKVx9mX 91imyIv2Vocq2BfFanw3ZIYeqL9w== X-Google-Smtp-Source: AGHT+IEIb4sVVYf9Xihwanz1RHGbXZOTJR1mNeoEZMZVFcJC0mbKsFiasSizbGv4idJ/j2UV04Srj0a4VA== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a63:d147:0:b0:7d8:449f:1319 with SMTP id 41be03b00d2f7-7e9e5779f24mr20071a12.0.1728350343119; Mon, 07 Oct 2024 18:19:03 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:31 -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-6-tavip@google.com> Subject: [PATCH v2 05/25] hw/misc: add support for flexcomm 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::54a; envelope-from=3h4gEZwUKCugdKfSZQYYQVO.MYWaOWe-NOfOVXYXQXe.YbQ@flex--tavip.bounces.google.com; helo=mail-pg1-x54a.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=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 @google.com) X-ZM-MESSAGEID: 1728350744894116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for NXP's FLEXCOMM device model. FLEXCOMM is a generic serial communication module which support multiple functions: UART, SPI and I2C. These are configurable at runtime. An abstract FlexcomFunction class is created that will be extended for specific functions. Each function has a dedicated overlapped MemoryRegion that it is going to be activated when that particular function is selected. A generic MemoryRegion is used to map generic registers (PSELID, PID) that is always active but has a lower priority. The function memory region is trimed to not include the generic registers. The FlexcommFunction object also gets access to the (non-concurrently) shared register backstore. The patch includes an automatically generated header which contains the register layout and helpers. The header can be regenerated with the svd-flexcomm target when the build is configured with --enable-mcux-soc-svd. Signed-off-by: Octavian Purdila --- include/hw/arm/svd/flexcomm.h | 70 ++++++ include/hw/misc/flexcomm.h | 49 +++++ include/hw/misc/flexcomm_function.h | 47 ++++ hw/misc/flexcomm.c | 319 ++++++++++++++++++++++++++++ hw/arm/meson.build | 2 + hw/arm/svd/meson.build | 3 + hw/misc/Kconfig | 3 + hw/misc/meson.build | 2 + hw/misc/trace-events | 5 + 9 files changed, 500 insertions(+) create mode 100644 include/hw/arm/svd/flexcomm.h create mode 100644 include/hw/misc/flexcomm.h create mode 100644 include/hw/misc/flexcomm_function.h create mode 100644 hw/misc/flexcomm.c diff --git a/include/hw/arm/svd/flexcomm.h b/include/hw/arm/svd/flexcomm.h new file mode 100644 index 0000000000..564180bd02 --- /dev/null +++ b/include/hw/arm/svd/flexcomm.h @@ -0,0 +1,70 @@ +/* + * 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" + +/* Flexcomm */ +#define FLEXCOMM_REGS_NO (1024) + +/* Peripheral Select and Flexcomm module ID */ +REG32(FLEXCOMM_PSELID, 0xFF8); +/* Peripheral Select */ +FIELD(FLEXCOMM_PSELID, PERSEL, 0, 3); +/* No peripheral selected. */ +#define FLEXCOMM_PSELID_PERSEL_NO_PERIPH_SELECTED 0 +/* USART function selected */ +#define FLEXCOMM_PSELID_PERSEL_USART 1 +/* SPI function selected */ +#define FLEXCOMM_PSELID_PERSEL_SPI 2 +/* I2C */ +#define FLEXCOMM_PSELID_PERSEL_I2C 3 +/* I2S Transmit */ +#define FLEXCOMM_PSELID_PERSEL_I2S_TRANSMIT 4 +/* I2S Receive */ +#define FLEXCOMM_PSELID_PERSEL_I2S_RECEIVE 5 +/* Lock the peripheral select */ +FIELD(FLEXCOMM_PSELID, LOCK, 3, 1); +/* USART present indicator */ +FIELD(FLEXCOMM_PSELID, USARTPRESENT, 4, 1); +/* SPI present indicator */ +FIELD(FLEXCOMM_PSELID, SPIPRESENT, 5, 1); +/* I2C present indicator */ +FIELD(FLEXCOMM_PSELID, I2CPRESENT, 6, 1); +/* I2S Present */ +FIELD(FLEXCOMM_PSELID, I2SPRESENT, 7, 1); +/* Flexcomm ID */ +FIELD(FLEXCOMM_PSELID, ID, 12, 20); + +/* Peripheral Identification */ +REG32(FLEXCOMM_PID, 0xFFC); +/* Minor revision of module implementation */ +FIELD(FLEXCOMM_PID, Minor_Rev, 8, 4); +/* Major revision of module implementation */ +FIELD(FLEXCOMM_PID, Major_Rev, 12, 4); +/* Module identifier for the selected function */ +FIELD(FLEXCOMM_PID, ID, 16, 16); + + +#define FLEXCOMM_REGISTER_ACCESS_INFO_ARRAY(_name) \ + struct RegisterAccessInfo _name[FLEXCOMM_REGS_NO] =3D { \ + [0 ... FLEXCOMM_REGS_NO - 1] =3D { \ + .name =3D "", \ + .addr =3D -1, \ + }, \ + [0x3FE] =3D { \ + .name =3D "PSELID", \ + .addr =3D 0xFF8, \ + .ro =3D 0xFFFFFFF0, \ + .reset =3D 0x101000, \ + }, \ + [0x3FF] =3D { \ + .name =3D "PID", \ + .addr =3D 0xFFC, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + } diff --git a/include/hw/misc/flexcomm.h b/include/hw/misc/flexcomm.h new file mode 100644 index 0000000000..ea0fe77f26 --- /dev/null +++ b/include/hw/misc/flexcomm.h @@ -0,0 +1,49 @@ +/* + * QEMU model for NXP's FLEXCOMM + * + * 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_FLEXCOMM_H +#define HW_FLEXCOMM_H + +#include "hw/sysbus.h" +#include "hw/arm/svd/flexcomm.h" +#include "qemu/fifo32.h" + +#define FLEXCOMM_FUNC_USART 0 +#define FLEXCOMM_FUNC_SPI 1 +#define FLEXCOMM_FUNC_I2C 2 +#define FLEXCOMM_FUNC_I2S 3 +#define FLEXCOMM_FUNCTIONS 4 + +#define FLEXCOMM_FULL 0xF +#define FLEXCOMM_HSSPI (1 << FLEXCOMM_FUNC_SPI) +#define FLEXCOMM_PMICI2C (1 << FLEXCOMM_FUNC_I2C) + +#define FLEXCOMM_PERSEL_USART 1 +#define FLEXCOMM_PERSEL_SPI 2 +#define FLEXCOMM_PERSEL_I2C 3 +#define FLEXCOMM_PERSEL_I2S_TX 4 +#define FLEXCOMM_PERSEL_I2S_RX 5 + +#define TYPE_FLEXCOMM "flexcomm" +OBJECT_DECLARE_SIMPLE_TYPE(FlexcommState, FLEXCOMM); + +struct FlexcommState { + SysBusDevice parent_obj; + + MemoryRegion container; + MemoryRegion mmio; + uint32_t regs[FLEXCOMM_REGS_NO]; + uint32_t functions; + qemu_irq irq; + bool irq_state; +}; + +#endif /* HW_FLEXCOMM_H */ diff --git a/include/hw/misc/flexcomm_function.h b/include/hw/misc/flexcomm= _function.h new file mode 100644 index 0000000000..e498976927 --- /dev/null +++ b/include/hw/misc/flexcomm_function.h @@ -0,0 +1,47 @@ +/* + * QEMU model for NXP's FLEXCOMM + * + * 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_FLEXCOMM_FUNCTION_H +#define HW_FLEXCOMM_FUNCTION_H + +#include "qemu/fifo32.h" +#include "hw/sysbus.h" + +#define TYPE_FLEXCOMM_FUNCTION "flexcomm-function" +OBJECT_DECLARE_TYPE(FlexcommFunction, FlexcommFunctionClass, FLEXCOMM_FUNC= TION); + +struct FlexcommFunction { + SysBusDevice parent_obj; + + MemoryRegion mmio; + uint32_t *regs; +}; + +typedef void (*FlexcommFunctionSelect)(FlexcommFunction *f, bool selected); + +struct FlexcommFunctionClass { + SysBusDeviceClass parent_class; + + const MemoryRegionOps *mmio_ops; + const char *name; + FlexcommFunctionSelect select; +}; + +static inline void flexcomm_select(FlexcommFunction *obj, bool selected) +{ + FlexcommFunctionClass *klass =3D FLEXCOMM_FUNCTION_GET_CLASS(obj); + + klass->select(obj, selected); +} + +void flexcomm_set_irq(FlexcommFunction *f, bool irq); + +#endif /* HW_FLEXCOMM_FUNCTION_H */ diff --git a/hw/misc/flexcomm.c b/hw/misc/flexcomm.c new file mode 100644 index 0000000000..2337fb814c --- /dev/null +++ b/hw/misc/flexcomm.c @@ -0,0 +1,319 @@ +/* + * QEMU model for NXP's FLEXCOMM + * + * 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 "hw/irq.h" +#include "hw/qdev-properties.h" +#include "hw/qdev-properties-system.h" +#include "migration/vmstate.h" +#include "exec/address-spaces.h" +#include "qapi/error.h" +#include "trace.h" +#include "migration/vmstate.h" +#include "hw/misc/flexcomm.h" + +#define REG(s, reg) (s->regs[R_FLEXCOMM_##reg]) +#define RF_WR(s, reg, field, val) \ + ARRAY_FIELD_DP32(s->regs, FLEXCOMM_##reg, field, val) +#define RF_RD(s, reg, field) \ + ARRAY_FIELD_EX32(s->regs, FLEXCOMM_##reg, field) + +#define modname "FLEXCOMM" + +#define FLEXCOMM_FUNC_MMIO_SIZE \ + ((FLEXCOMM_REGS_NO - 2) * sizeof(uint32_t)) + +static const FLEXCOMM_REGISTER_ACCESS_INFO_ARRAY(reg_info); + +static inline bool has_function(FlexcommState *s, int function) +{ + return s->functions & (1 << function); +} + +static inline int persel_to_function(FlexcommState *s) +{ + switch (RF_RD(s, PSELID, PERSEL)) { + case FLEXCOMM_PERSEL_USART: + return FLEXCOMM_FUNC_USART; + case FLEXCOMM_PERSEL_SPI: + return FLEXCOMM_FUNC_SPI; + case FLEXCOMM_PERSEL_I2C: + return FLEXCOMM_FUNC_I2C; + case FLEXCOMM_PERSEL_I2S_TX: + case FLEXCOMM_PERSEL_I2S_RX: + return FLEXCOMM_FUNC_I2S; + default: + return -1; + } +} + +static void flexcomm_func_select(FlexcommState *s, bool selected) +{ + FlexcommFunction *obj[] =3D { + FLEXCOMM_FUNCTION(&s->usart), + FLEXCOMM_FUNCTION(&s->spi), + FLEXCOMM_FUNCTION(&s->i2c), + }; + int f =3D persel_to_function(s); + + if (f >=3D 0 && f < ARRAY_SIZE(obj)) { + flexcomm_select(obj[f], selected); + } +} + +static void flexcomm_reset_enter(Object *o, ResetType type) +{ + FlexcommState *s =3D FLEXCOMM(o); + + trace_flexcomm_reset(); + + flexcomm_func_select(s, false); + + for (int i =3D 0; i < FLEXCOMM_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); + } + } + + RF_WR(s, PSELID, USARTPRESENT, has_function(s, FLEXCOMM_FUNC_USART)); + RF_WR(s, PSELID, SPIPRESENT, has_function(s, FLEXCOMM_FUNC_SPI)); + RF_WR(s, PSELID, I2CPRESENT, has_function(s, FLEXCOMM_FUNC_I2C)); + RF_WR(s, PSELID, I2SPRESENT, has_function(s, FLEXCOMM_FUNC_I2S)); + + s->irq_state =3D false; +} + +static void flexcomm_reset_exit(Object *o, ResetType type) +{ + FlexcommState *s =3D FLEXCOMM(o); + + qemu_set_irq(s->irq, s->irq_state); +} + + +static MemTxResult flexcomm_reg_read(void *opaque, hwaddr addr, + uint64_t *data, unsigned size, + MemTxAttrs attrs) +{ + FlexcommState *s =3D opaque; + MemTxResult ret =3D MEMTX_OK; + const struct RegisterAccessInfo *rai =3D ®_info[addr / 4]; + + switch (addr) { + case A_FLEXCOMM_PSELID: + case A_FLEXCOMM_PID: + { + *data =3D s->regs[addr / 4]; + break; + } + default: + return MEMTX_ERROR; + } + + trace_flexcomm_reg_read(DEVICE(s)->id, rai->name, addr, *data); + return ret; +} + +static int flexcomm_check_function(FlexcommState *s) +{ + int f =3D persel_to_function(s); + + if (f < 0 || !has_function(s, f)) { + return -1; + } + + return f; +} + +static MemTxResult flexcomm_reg_write(void *opaque, hwaddr addr, + uint64_t value, unsigned size, + MemTxAttrs attrs) +{ + FlexcommState *s =3D opaque; + MemTxResult ret =3D MEMTX_OK; + 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_flexcomm_reg_write(DEVICE(s)->id, rai->name, addr, value); + + switch (addr) { + case A_FLEXCOMM_PID: + /* RO register, nothing do to */ + break; + case A_FLEXCOMM_PSELID: + { + if (RF_RD(s, PSELID, LOCK)) { + break; + } + + flexcomm_func_select(s, false); + + register_write(&ri, value, ~0, modname, false); + + if (flexcomm_check_function(s) < 0) { + RF_WR(s, PSELID, PERSEL, 0); + break; + } + + flexcomm_func_select(s, true); + break; + } + default: + return MEMTX_ERROR; + } + + return ret; +} + + +static const MemoryRegionOps flexcomm_ops =3D { + .read_with_attrs =3D flexcomm_reg_read, + .write_with_attrs =3D flexcomm_reg_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + .unaligned =3D false, + }, +}; + +static Property flexcomm_properties[] =3D { + DEFINE_PROP_UINT32("functions", FlexcommState, functions, + FLEXCOMM_FULL), + DEFINE_PROP_END_OF_LIST(), +}; + +static void flexcomm_init(Object *obj) +{ + FlexcommState *s =3D FLEXCOMM(obj); + DeviceState *dev =3D DEVICE(obj); + SysBusDevice *sbd =3D SYS_BUS_DEVICE(dev); + + memory_region_init(&s->container, obj, "container", sizeof(s->regs)); + memory_region_init_io(&s->mmio, obj, &flexcomm_ops, s, + TYPE_FLEXCOMM, sizeof(s->regs)); + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->container); + sysbus_init_irq(sbd, &s->irq); +} + +static void flexcomm_func_realize_and_unref(FlexcommFunction *f, Error **e= rrp) +{ + FlexcommState *s =3D FLEXCOMM(OBJECT(f)->parent); + FlexcommFunctionClass *fc =3D FLEXCOMM_FUNCTION_GET_CLASS(f); + + f->regs =3D s->regs; + memory_region_add_subregion_overlap(&s->container, 0, &f->mmio, 0); + DEVICE(f)->id =3D g_strdup_printf("%s-%s", DEVICE(s)->id, fc->name); + sysbus_realize_and_unref(SYS_BUS_DEVICE(f), errp); + memory_region_set_enabled(&f->mmio, false); +} + +static void flexcomm_realize(DeviceState *dev, Error **errp) +{ + FlexcommState *s =3D FLEXCOMM(dev); + + memory_region_add_subregion_overlap(&s->container, 0, &s->mmio, -1); +} + +static const VMStateDescription vmstate_flexcomm =3D { + .name =3D "flexcomm", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT32_ARRAY(regs, FlexcommState, FLEXCOMM_REGS_NO), + VMSTATE_BOOL(irq_state, FlexcommState), + VMSTATE_FIFO32(rx_fifo, FlexcommState), + VMSTATE_FIFO32(tx_fifo, FlexcommState), + VMSTATE_END_OF_LIST() + } +}; + +static void flexcomm_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + + rc->phases.enter =3D flexcomm_reset_enter; + rc->phases.exit =3D flexcomm_reset_exit; + device_class_set_props(dc, flexcomm_properties); + dc->realize =3D flexcomm_realize; + dc->vmsd =3D &vmstate_flexcomm; +} + +void flexcomm_set_irq(FlexcommFunction *f, bool irq) +{ + FlexcommState *s =3D FLEXCOMM(OBJECT(f)->parent); + + if (s->irq_state !=3D irq) { + trace_flexcomm_irq(DEVICE(s)->id, irq); + qemu_set_irq(s->irq, irq); + s->irq_state =3D irq; + } +} + +static void flexcomm_function_select(FlexcommFunction *f, bool selected) +{ + FlexcommFunctionClass *fc =3D FLEXCOMM_FUNCTION_GET_CLASS(f); + + memory_region_set_enabled(&f->mmio, selected); +} + +static void flexcomm_function_init(Object *obj) +{ + FlexcommFunctionClass *fc =3D FLEXCOMM_FUNCTION_GET_CLASS(obj); + FlexcommFunction *f =3D FLEXCOMM_FUNCTION(obj); + + memory_region_init_io(&f->mmio, obj, fc->mmio_ops, obj, fc->name, + FLEXCOMM_FUNC_MMIO_SIZE); +} + +static void flexcomm_function_class_init(ObjectClass *klass, void *data) +{ + FlexcommFunctionClass *fc =3D FLEXCOMM_FUNCTION_CLASS(klass); + + fc->select =3D flexcomm_function_select; +} + +static const TypeInfo flexcomm_types[] =3D { + { + .name =3D TYPE_FLEXCOMM, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(FlexcommState), + .instance_init =3D flexcomm_init, + .class_init =3D flexcomm_class_init, + }, + { + .name =3D TYPE_FLEXCOMM_FUNCTION, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(FlexcommFunction), + .abstract =3D true, + .class_size =3D sizeof(FlexcommFunctionClass), + .instance_init =3D flexcomm_function_init, + .class_init =3D flexcomm_function_class_init, + }, +}; + +DEFINE_TYPES(flexcomm_types); diff --git a/hw/arm/meson.build b/hw/arm/meson.build index 490234b3b8..83e4aea10e 100644 --- a/hw/arm/meson.build +++ b/hw/arm/meson.build @@ -73,3 +73,5 @@ system_ss.add(when: 'CONFIG_VERSATILE', if_true: files('v= ersatilepb.c')) system_ss.add(when: 'CONFIG_VEXPRESS', if_true: files('vexpress.c')) =20 hw_arch +=3D {'arm': arm_ss} + +subdir('svd') diff --git a/hw/arm/svd/meson.build b/hw/arm/svd/meson.build index 7d83d2ccbc..4b0bbbbbdc 100644 --- a/hw/arm/svd/meson.build +++ b/hw/arm/svd/meson.build @@ -1,4 +1,7 @@ if get_option('mcux-soc-svd') mcux_soc_svd =3D subproject('mcux-soc-svd') rt595 =3D mcux_soc_svd.get_variable('rt595') + run_target('svd-flexcomm', command: svd_gen_header + + [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/flexcomm.h', + '-p', 'FLEXCOMM0', '-t', 'FLEXCOMM']) endif diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig index 1e08785b83..14167ae9e8 100644 --- a/hw/misc/Kconfig +++ b/hw/misc/Kconfig @@ -213,4 +213,7 @@ config IOSB config XLNX_VERSAL_TRNG bool =20 +config FLEXCOMM + bool + source macio/Kconfig diff --git a/hw/misc/meson.build b/hw/misc/meson.build index a2951951b5..0d901b9c65 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -151,3 +151,5 @@ system_ss.add(when: 'CONFIG_SBSA_REF', if_true: files('= sbsa_ec.c')) =20 # HPPA devices system_ss.add(when: 'CONFIG_LASI', if_true: files('lasi.c')) + +system_ss.add(when: 'CONFIG_FLEXCOMM', if_true: files('flexcomm.c')) diff --git a/hw/misc/trace-events b/hw/misc/trace-events index 1be0717c0c..419879fd65 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -362,3 +362,8 @@ aspeed_sli_read(uint64_t offset, unsigned int size, uin= t32_t data) "To 0x%" PRIx aspeed_sliio_write(uint64_t offset, unsigned int size, uint32_t data) "To = 0x%" PRIx64 " of size %u: 0x%" PRIx32 aspeed_sliio_read(uint64_t offset, unsigned int size, uint32_t data) "To 0= x%" PRIx64 " of size %u: 0x%" PRIx32 =20 +# flexcomm +flexcomm_reset(void) "" +flexcomm_irq(const char *id, uint8_t irq) "%s %d" +flexcomm_reg_read(const char *devname, const char *regname, uint32_t addr,= uint32_t val) "%s: %s[0x%04x] -> 0x%08x" +flexcomm_reg_write(const char *dename, const char *regname, uint32_t addr,= uint32_t val) "%s: %s[0x%04x] <- 0x%08x" --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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=1728350632; cv=none; d=zohomail.com; s=zohoarc; b=T4p9ixrxzvAxNV+zvVAV4PTyNjhLwNn4e9QTDk8y9hWbUdjkw6qKARe6k4O5p2m0HapI4wruKmmD5ndahfvvV+OCBdulaDGApZTqp1TnzC2Bgk8q/3O3hoqgwRKm/bWbjLxF+F5bpLwc6CrhPlT7u4TnlZug+D1mv0g0IT+6hfg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350632; 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=mYb8OnCeZQrVX3cX0gw+0rgqxbLbcVi8KOrSlVTkt1w=; b=La+VqrLbI+alAQ0KwSUnAwVgjcM4B1VjvjLX3+OdJlE140dYFU7dYRQjhC6GWxYBQeWmKn8H9Rb3oY3W3P2T2dbizNjSA1QtXETHDz9lztd1qowX9BG8rU6vPBWf+SCQ4Mqb3+RE6xhJx/PlxDdd8Ho8qDjxph5kCwqlmB0ypJk= 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 1728350632472904.9955342028156; Mon, 7 Oct 2024 18:23:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxytB-0001Gu-JQ; Mon, 07 Oct 2024 21:19:49 -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 <3iIgEZwUKCukeLgTaRZZRWP.NZXbPXf-OPgPWYZYRYf.ZcR@flex--tavip.bounces.google.com>) id 1sxysY-0007mH-8C for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:15 -0400 Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3iIgEZwUKCukeLgTaRZZRWP.NZXbPXf-OPgPWYZYRYf.ZcR@flex--tavip.bounces.google.com>) id 1sxysV-00008Z-4u for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:08 -0400 Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-71e11abb22aso517563b3a.1 for ; Mon, 07 Oct 2024 18:19:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350345; x=1728955145; 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=mYb8OnCeZQrVX3cX0gw+0rgqxbLbcVi8KOrSlVTkt1w=; b=R+dbq+lYPKBxoShJVGaECVHtrXWjZzyeL7InCQCZ+Qj0EgFmQTkodR+QRqOUAowVa8 ZbH9shwsQ4mThB9EgjYZrslSSBTb+ZlCdlJdCuSB9I3DizhOELaSwNaTGkSZ1L40cDGi S63PVlsC3lgMjRypOkldSc8DqSvKFpMDdkmIbXHAl9yoTPbj9almi8UE/cxV5LxdBiO0 /Wy/HsA3EhJV8YFaNXLwrYqnjE5CMuAjeIOIkTnY//xeRfuTV5YrEl2pQGl13LmZjlxc u8nel40foteYKxO7WdJN7JDd3MFtUfPux72NbhYSZaIIW3dZU1KMB7wdb9C6FRpkGLgi H58A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350345; x=1728955145; 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=mYb8OnCeZQrVX3cX0gw+0rgqxbLbcVi8KOrSlVTkt1w=; b=GHjD8GiqGS9oF0jg7sb99hk0yRlt/ojKP1rSgPo4Sfbfc3vP9HO/feXKer+iZH6eg3 W2VVQwvvumvd9xRSRnJsF7plMGiA0WGB32OzTZTl8ykGdS8PH9zoU53AMbw1R8ZvLjve NhUrkcmPA6sSie+d7nNaput2BA59j3ymEW8eWJpN/xWxT8kXfmF2c1JCjNJPcOkvtJs6 vpUOhiB5a8HMnUv9e20u6n0u60OsaodSw9eQnVsMAwk1k12GFTxmzeIQTYZDuu8iGT4g jlNstYOa/XriuF6tpLd+FYxiwtxzK4PYg0bR0SkHFReo76xUYNr6OPVkSReSqgE640jv h04A== X-Gm-Message-State: AOJu0YyfgC2Q743aF0Enq6syaEsHkQq+jPVTw7gcwY++y/xIgxuFV2wS rnaszC5IO1eVYp+imUXnlmoXfhddb6+omN3KIiqeK2Wr/yDw7BlFUA1/6bmdPq043MmKDVcg2x+ X4jeRNaWo+L53rTnqSCuFwa/hk//C/JzfKEGph+T7NLr/ofGb43dYOKzJHnLZpVNPf277mRYlzH bP/jg3JfG6OGER2MMFBMhZwB15ow== X-Google-Smtp-Source: AGHT+IGFgJf3vbj7kBTLVjfPMhdKIVaWnTkGtp63eWEPIqhdYAUDElv58c3jqoWBOfsVGgkeJlZGsISX+w== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a62:ae17:0:b0:71d:ef29:82b2 with SMTP id d2e1a72fcca58-71def2984ddmr23497b3a.0.1728350344733; Mon, 07 Oct 2024 18:19:04 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:32 -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-7-tavip@google.com> Subject: [PATCH v2 06/25] hw/misc/flexcomm.c: add common fifo functionality 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::449; envelope-from=3iIgEZwUKCukeLgTaRZZRWP.NZXbPXf-OPgPWYZYRYf.ZcR@flex--tavip.bounces.google.com; helo=mail-pf1-x449.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=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 @google.com) X-ZM-MESSAGEID: 1728350634509116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" FLEXCOMM SPI and USART share FIFO functionality. Add common helper functions to avoid code duplication. Signed-off-by: Octavian Purdila --- include/hw/misc/flexcomm.h | 2 + include/hw/misc/flexcomm_function.h | 8 +++ hw/misc/flexcomm.c | 83 +++++++++++++++++++++++++++++ hw/misc/trace-events | 1 + 4 files changed, 94 insertions(+) diff --git a/include/hw/misc/flexcomm.h b/include/hw/misc/flexcomm.h index ea0fe77f26..832d4cd29d 100644 --- a/include/hw/misc/flexcomm.h +++ b/include/hw/misc/flexcomm.h @@ -44,6 +44,8 @@ struct FlexcommState { uint32_t functions; qemu_irq irq; bool irq_state; + Fifo32 rx_fifo; + Fifo32 tx_fifo; }; =20 #endif /* HW_FLEXCOMM_H */ diff --git a/include/hw/misc/flexcomm_function.h b/include/hw/misc/flexcomm= _function.h index e498976927..3ff1677ff6 100644 --- a/include/hw/misc/flexcomm_function.h +++ b/include/hw/misc/flexcomm_function.h @@ -23,6 +23,8 @@ struct FlexcommFunction { =20 MemoryRegion mmio; uint32_t *regs; + Fifo32 *tx_fifo; + Fifo32 *rx_fifo; }; =20 typedef void (*FlexcommFunctionSelect)(FlexcommFunction *f, bool selected); @@ -32,6 +34,7 @@ struct FlexcommFunctionClass { =20 const MemoryRegionOps *mmio_ops; const char *name; + bool has_fifos; FlexcommFunctionSelect select; }; =20 @@ -43,5 +46,10 @@ static inline void flexcomm_select(FlexcommFunction *obj= , bool selected) } =20 void flexcomm_set_irq(FlexcommFunction *f, bool irq); +void flexcomm_update_fifostat(FlexcommFunction *f); +void flexcomm_clear_fifostat(FlexcommFunction *f, uint64_t value); +void flexcomm_init_fifos(FlexcommFunction *f, unsigned num); +void flexcomm_cleanup_fifos(FlexcommFunction *f); +void flexcomm_reset_fifos(FlexcommFunction *f); =20 #endif /* HW_FLEXCOMM_FUNCTION_H */ diff --git a/hw/misc/flexcomm.c b/hw/misc/flexcomm.c index 2337fb814c..a98d8845aa 100644 --- a/hw/misc/flexcomm.c +++ b/hw/misc/flexcomm.c @@ -22,6 +22,7 @@ #include "trace.h" #include "migration/vmstate.h" #include "hw/misc/flexcomm.h" +#include "hw/arm/svd/flexcomm_usart.h" =20 #define REG(s, reg) (s->regs[R_FLEXCOMM_##reg]) #define RF_WR(s, reg, field, val) \ @@ -219,12 +220,22 @@ static void flexcomm_init(Object *obj) sysbus_init_irq(sbd, &s->irq); } =20 +static void flexcomm_finalize(Object *obj) +{ + FlexcommState *s =3D FLEXCOMM(obj); + + /* release resources allocated by the function select (e.g. fifos) */ + flexcomm_func_select(s, false); +} + static void flexcomm_func_realize_and_unref(FlexcommFunction *f, Error **e= rrp) { FlexcommState *s =3D FLEXCOMM(OBJECT(f)->parent); FlexcommFunctionClass *fc =3D FLEXCOMM_FUNCTION_GET_CLASS(f); =20 f->regs =3D s->regs; + f->tx_fifo =3D &s->tx_fifo; + f->rx_fifo =3D &s->rx_fifo; memory_region_add_subregion_overlap(&s->container, 0, &f->mmio, 0); DEVICE(f)->id =3D g_strdup_printf("%s-%s", DEVICE(s)->id, fc->name); sysbus_realize_and_unref(SYS_BUS_DEVICE(f), errp); @@ -274,11 +285,82 @@ void flexcomm_set_irq(FlexcommFunction *f, bool irq) } } =20 +/* FIFO is shared between USART and SPI, provide common functions here */ +#define FIFO_REG(s, reg) (s->regs[R_FLEXCOMM_USART_FIFO##reg]) +#define FIFO_WR(s, reg, field, val) \ + ARRAY_FIELD_DP32(s->regs, FLEXCOMM_USART_FIFO##reg, field, val) +#define FIFO_RD(s, reg, field) \ + ARRAY_FIELD_EX32(s->regs, FLEXCOMM_USART_FIFO##reg, field) + +void flexcomm_update_fifostat(FlexcommFunction *f) +{ + int rxlvl =3D fifo32_num_used(f->rx_fifo); + int txlvl =3D fifo32_num_used(f->tx_fifo); + + FIFO_WR(f, STAT, RXLVL, rxlvl); + FIFO_WR(f, STAT, TXLVL, txlvl); + FIFO_WR(f, STAT, RXFULL, fifo32_is_full(f->rx_fifo) ? 1 : 0); + FIFO_WR(f, STAT, RXNOTEMPTY, !fifo32_is_empty(f->rx_fifo) ? 1 : 0); + FIFO_WR(f, STAT, TXNOTFULL, !fifo32_is_full(f->tx_fifo) ? 1 : 0); + FIFO_WR(f, STAT, TXEMPTY, fifo32_is_empty(f->tx_fifo) ? 1 : 0); + + if (FIFO_RD(f, TRIG, RXLVLENA) && (rxlvl > FIFO_RD(f, TRIG, RXLVL))) { + FIFO_WR(f, INTSTAT, RXLVL, 1); + } else { + FIFO_WR(f, INTSTAT, RXLVL, 0); + } + + if (FIFO_RD(f, TRIG, TXLVLENA) && (txlvl <=3D FIFO_RD(f, TRIG, TXLVL))= ) { + FIFO_WR(f, INTSTAT, TXLVL, 1); + } else { + FIFO_WR(f, INTSTAT, TXLVL, 0); + } + + trace_flexcomm_fifostat(DEVICE(f)->id, FIFO_REG(f, STAT), + FIFO_REG(f, INTSTAT)); +} + +void flexcomm_reset_fifos(FlexcommFunction *f) +{ + if (FIFO_RD(f, CFG, EMPTYRX)) { + FIFO_WR(f, CFG, EMPTYRX, 0); + fifo32_reset(f->rx_fifo); + } + if (FIFO_RD(f, CFG, EMPTYTX)) { + FIFO_WR(f, CFG, EMPTYTX, 0); + fifo32_reset(f->tx_fifo); + } +} + +void flexcomm_clear_fifostat(FlexcommFunction *f, uint64_t value) +{ + bool rxerr =3D FIELD_EX32(value, FLEXCOMM_USART_FIFOSTAT, RXERR); + bool txerr =3D FIELD_EX32(value, FLEXCOMM_USART_FIFOSTAT, TXERR); + + if (rxerr) { + FIFO_WR(f, STAT, RXERR, 0); + } + if (txerr) { + FIFO_WR(f, STAT, TXERR, 0); + } +} + static void flexcomm_function_select(FlexcommFunction *f, bool selected) { FlexcommFunctionClass *fc =3D FLEXCOMM_FUNCTION_GET_CLASS(f); =20 memory_region_set_enabled(&f->mmio, selected); + if (fc->has_fifos) { + if (selected) { + unsigned num =3D FIFO_RD(f, SIZE, FIFOSIZE); + + fifo32_create(f->tx_fifo, num); + fifo32_create(f->rx_fifo, num); + } else { + fifo32_destroy(f->tx_fifo); + fifo32_destroy(f->rx_fifo); + } + } } =20 static void flexcomm_function_init(Object *obj) @@ -303,6 +385,7 @@ static const TypeInfo flexcomm_types[] =3D { .parent =3D TYPE_SYS_BUS_DEVICE, .instance_size =3D sizeof(FlexcommState), .instance_init =3D flexcomm_init, + .instance_finalize =3D flexcomm_finalize, .class_init =3D flexcomm_class_init, }, { diff --git a/hw/misc/trace-events b/hw/misc/trace-events index 419879fd65..dc245905dc 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -367,3 +367,4 @@ flexcomm_reset(void) "" flexcomm_irq(const char *id, uint8_t irq) "%s %d" flexcomm_reg_read(const char *devname, const char *regname, uint32_t addr,= uint32_t val) "%s: %s[0x%04x] -> 0x%08x" flexcomm_reg_write(const char *dename, const char *regname, uint32_t addr,= uint32_t val) "%s: %s[0x%04x] <- 0x%08x" +flexcomm_fifostat(const char *id, uint32_t fifostat, uint32_t fifoinstat) = "%s: %08x %08x" --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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=1728350507; cv=none; d=zohomail.com; s=zohoarc; b=Okxf+DR14B/vUQxHWT33WUsa7/L2NGsd5BmrFI+wm75I34y2C0Zur7aF7zj4B9GiFoAfwq9Muby/EROP9+70nT1WOF0eYe8SJMVDnhHzkzJvnfEf2q0JTi6q+zh07IjPXRo5f/gdZ+n892JA949dONxIacDHcupA9hWra6cKss8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350507; 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=Vzupf3vt9+CjqF4zkzgvZPteAeoMK9Pq2w9EB8vbI+s=; b=W1yv4qDyeLwPHzvCanT0M6WTLRrNOuiaJrfASgBn3MDxE1yD7ZnsfZ3l0TyyI6tcys/WKKpmOq1yALV3T40fwVrCGSnCglHNyQs48Rq1XliTRuWP/UFf7IKnYYd7q+63S19KoKpIcI+ARhRiV49fyxeqR20Z+CH6uRnGt7id+To= 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 1728350506996375.43308641341787; Mon, 7 Oct 2024 18:21:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxytG-0001lq-BO; Mon, 07 Oct 2024 21:19:54 -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 <3iogEZwUKCusgNiVcTbbTYR.PbZdRZh-QRiRYabaTah.beT@flex--tavip.bounces.google.com>) id 1sxysa-0007nM-Nn for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:17 -0400 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3iogEZwUKCusgNiVcTbbTYR.PbZdRZh-QRiRYabaTah.beT@flex--tavip.bounces.google.com>) id 1sxysX-00008v-Vp for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:12 -0400 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-e28690bc290so7535132276.1 for ; Mon, 07 Oct 2024 18:19:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350347; x=1728955147; 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=Vzupf3vt9+CjqF4zkzgvZPteAeoMK9Pq2w9EB8vbI+s=; b=odlR4mOhxesowE5PMylvU9UJ79+ssGRuruZ3GrwUZkjNrxN3tY1V8IEYghq0EjuQgH HNmv+iNkohMwsN8+Q58RZGNHi4TX6Epn4x1n4bvMJlC5aOwk9AGUqfq56yWkMVmJqh3M WzU4pHNr0KZLgellApQnOGYxsWHAd8ZrOOsIzWFc51Qa1HsXd+zhvMHFQ9yPCXKnMbA5 pbrgoTFDVWRGNJBLWO3n4cWxV4x0Lw/qzK8yLFFXrmPOEo81Do8l45mmOj+RHbb6SbAc dVaUtiLoOYeqv/h1ru7GGbmExlBz9Wi+ckgayOm92f+uAxnU4AbnNbNv09uGuOwWN6xa LrcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350347; x=1728955147; 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=Vzupf3vt9+CjqF4zkzgvZPteAeoMK9Pq2w9EB8vbI+s=; b=g4dQ9aHjRMxTs2FJ98aEZCl7YsJ6Ipx9tcygYO25NTBMHEow5OwCJIFW+jD+iwq79b XLYli5/apL92uQ+etdHiZoZzWJXv9zXGPcbb+JX9raAcUiOPVPXLLv3RVU2g2hKD9NdH 8l/meP4iqh1pTX/+RKvlN2SLLw0wMMj7Y1+RGPZNsQjckVR6iH8FHtKx6Qs0/w29LVEp mRmZukAZhj3LhokQS3OGFkjM5e+AgQXSzrGHptdku1AUT7tM84Zu4iwbk9syTptR+YeM MvM2HHee6eTnIyeLLGbjFOUkmUtzrfdaPZIH1FtTwtZ+ubufP2GTfo20FARScVo70Upw cFYg== X-Gm-Message-State: AOJu0Yw3XhfqXl0DdEMsw3O5CTtTWa9rIrQ1CZqdlunBFpRjVdKaA6GP EtZRxOajWZ0Q7oFQagiJoHsOvbGOcnR0gOW1tklqbD4IgfY2rljwdGHFup/WsmeDhuWSXgL3294 r4gRQUkHpp5hrsDX0KgeDYmJ54/GinIWZBhH7Bhidw/ikfzw5fNA1e3u+ke+lCSEfA1Et7mLoJ9 ePebs3H8CrLLhQTsVk67m70aFI1Q== X-Google-Smtp-Source: AGHT+IF8b+KwDkEfdHpiw3avdhoIJWRKXiRbTxfcFuMGtw+4XiGc6GeHNYWj3ZNVznRFO2FNXD2xTlVYVw== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a25:6b4b:0:b0:e1a:44fa:f09 with SMTP id 3f1490d57ef6-e28936c0e5amr9284276.2.1728350346664; Mon, 07 Oct 2024 18:19:06 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:33 -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-8-tavip@google.com> Subject: [PATCH v2 07/25] hw/char: add support for flexcomm usart 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::b4a; envelope-from=3iogEZwUKCusgNiVcTbbTYR.PbZdRZh-QRiRYabaTah.beT@flex--tavip.bounces.google.com; helo=mail-yb1-xb4a.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=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 @google.com) X-ZM-MESSAGEID: 1728350508093116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for NXP's flexcomm usart. It supports interupts and FIFO access but no DMA. The patch includes an automatically generated header which contains the register layout and helpers. The header can be regenerated with the svd-flexcomm-usart target when the build is configured with --enable-mcux-soc-svd. Signed-off-by: Octavian Purdila --- include/hw/arm/svd/flexcomm_usart.h | 294 ++++++++++++++++++++++++++++ include/hw/char/flexcomm_usart.h | 33 ++++ include/hw/misc/flexcomm.h | 2 + hw/char/flexcomm_usart.c | 288 +++++++++++++++++++++++++++ hw/misc/flexcomm.c | 3 + hw/arm/svd/meson.build | 4 + hw/char/meson.build | 1 + hw/char/trace-events | 8 + 8 files changed, 633 insertions(+) create mode 100644 include/hw/arm/svd/flexcomm_usart.h create mode 100644 include/hw/char/flexcomm_usart.h create mode 100644 hw/char/flexcomm_usart.c diff --git a/include/hw/arm/svd/flexcomm_usart.h b/include/hw/arm/svd/flexc= omm_usart.h new file mode 100644 index 0000000000..a226917182 --- /dev/null +++ b/include/hw/arm/svd/flexcomm_usart.h @@ -0,0 +1,294 @@ +/* + * 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" + +/* Flexcomm USART */ +#define FLEXCOMM_USART_REGS_NO (1024) + +/* USART Configuration */ +REG32(FLEXCOMM_USART_CFG, 0x0); +/* USART Enable */ +FIELD(FLEXCOMM_USART_CFG, ENABLE, 0, 1); + +/* USART Control */ +REG32(FLEXCOMM_USART_CTL, 0x4); + +/* USART Status */ +REG32(FLEXCOMM_USART_STAT, 0x8); + +/* Interrupt Enable Read and Set for USART (not FIFO) Status */ +REG32(FLEXCOMM_USART_INTENSET, 0xC); + +/* Interrupt Enable Clear */ +REG32(FLEXCOMM_USART_INTENCLR, 0x10); + +/* Baud Rate Generator */ +REG32(FLEXCOMM_USART_BRG, 0x20); + +/* Interrupt Status */ +REG32(FLEXCOMM_USART_INTSTAT, 0x24); + +/* Oversample Selection Register for Asynchronous Communication */ +REG32(FLEXCOMM_USART_OSR, 0x28); + +/* Address Register for Automatic Address Matching */ +REG32(FLEXCOMM_USART_ADDR, 0x2C); + +/* FIFO Configuration */ +REG32(FLEXCOMM_USART_FIFOCFG, 0xE00); +/* Enable the Transmit FIFO. */ +FIELD(FLEXCOMM_USART_FIFOCFG, ENABLETX, 0, 1); +/* Enable the Receive FIFO */ +FIELD(FLEXCOMM_USART_FIFOCFG, ENABLERX, 1, 1); +/* Empty Command for the Transmit FIFO */ +FIELD(FLEXCOMM_USART_FIFOCFG, EMPTYTX, 16, 1); +/* Empty Command for the Receive FIFO */ +FIELD(FLEXCOMM_USART_FIFOCFG, EMPTYRX, 17, 1); + +/* FIFO Status */ +REG32(FLEXCOMM_USART_FIFOSTAT, 0xE04); +/* TX FIFO Error */ +FIELD(FLEXCOMM_USART_FIFOSTAT, TXERR, 0, 1); +/* RX FIFO Error */ +FIELD(FLEXCOMM_USART_FIFOSTAT, RXERR, 1, 1); +/* Peripheral Interrupt */ +FIELD(FLEXCOMM_USART_FIFOSTAT, PERINT, 3, 1); +/* Transmit FIFO Empty */ +FIELD(FLEXCOMM_USART_FIFOSTAT, TXEMPTY, 4, 1); +/* Transmit FIFO is Not Full */ +FIELD(FLEXCOMM_USART_FIFOSTAT, TXNOTFULL, 5, 1); +/* Receive FIFO is Not Empty */ +FIELD(FLEXCOMM_USART_FIFOSTAT, RXNOTEMPTY, 6, 1); +/* Receive FIFO is Full */ +FIELD(FLEXCOMM_USART_FIFOSTAT, RXFULL, 7, 1); +/* Transmit FIFO Current Level */ +FIELD(FLEXCOMM_USART_FIFOSTAT, TXLVL, 8, 5); +/* Receive FIFO Current Level */ +FIELD(FLEXCOMM_USART_FIFOSTAT, RXLVL, 16, 5); + +/* FIFO Trigger Settings for Interrupt and DMA Request */ +REG32(FLEXCOMM_USART_FIFOTRIG, 0xE08); +/* Transmit FIFO Level Trigger Enable. */ +FIELD(FLEXCOMM_USART_FIFOTRIG, TXLVLENA, 0, 1); +/* Receive FIFO Level Trigger Enable */ +FIELD(FLEXCOMM_USART_FIFOTRIG, RXLVLENA, 1, 1); +/* Transmit FIFO Level Trigger Point */ +FIELD(FLEXCOMM_USART_FIFOTRIG, TXLVL, 8, 4); +/* Trigger when the TX FIFO becomes empty */ +#define FLEXCOMM_USART_FIFOTRIG_TXLVL_TXLVL0 0 +/* Trigger when the TX FIFO level decreases to 1 entry */ +#define FLEXCOMM_USART_FIFOTRIG_TXLVL_TXLVL1 1 +/* Trigger when the TX FIFO level decreases to 15 entries (is no longer fu= ll) */ +#define FLEXCOMM_USART_FIFOTRIG_TXLVL_TXLVL15 15 +/* Receive FIFO Level Trigger Point */ +FIELD(FLEXCOMM_USART_FIFOTRIG, RXLVL, 16, 4); +/* Trigger when the RX FIFO has received 1 entry (is no longer empty) */ +#define FLEXCOMM_USART_FIFOTRIG_RXLVL_RXLVL1 0 +/* Trigger when the RX FIFO has received 2 entries */ +#define FLEXCOMM_USART_FIFOTRIG_RXLVL_RXLVL2 1 +/* Trigger when the RX FIFO has received 16 entries (has become full) */ +#define FLEXCOMM_USART_FIFOTRIG_RXLVL_RXLVL15 15 + +/* FIFO Interrupt Enable */ +REG32(FLEXCOMM_USART_FIFOINTENSET, 0xE10); +/* Transmit Error Interrupt Enable */ +FIELD(FLEXCOMM_USART_FIFOINTENSET, TXERR, 0, 1); +/* Receive Error Interrupt Enable */ +FIELD(FLEXCOMM_USART_FIFOINTENSET, RXERR, 1, 1); +/* Transmit FIFO Level Interrupt Enable */ +FIELD(FLEXCOMM_USART_FIFOINTENSET, TXLVL, 2, 1); +/* Receive FIFO Level Interrupt Enable */ +FIELD(FLEXCOMM_USART_FIFOINTENSET, RXLVL, 3, 1); + +/* FIFO Interrupt Enable Clear */ +REG32(FLEXCOMM_USART_FIFOINTENCLR, 0xE14); +/* Transmit Error Interrupt Enable */ +FIELD(FLEXCOMM_USART_FIFOINTENCLR, TXERR, 0, 1); +/* Receive Error Interrupt Enable */ +FIELD(FLEXCOMM_USART_FIFOINTENCLR, RXERR, 1, 1); +/* Transmit FIFO Level Interrupt Enable */ +FIELD(FLEXCOMM_USART_FIFOINTENCLR, TXLVL, 2, 1); +/* Receive FIFO Level Interrupt Enable */ +FIELD(FLEXCOMM_USART_FIFOINTENCLR, RXLVL, 3, 1); + +/* FIFO Interrupt Status */ +REG32(FLEXCOMM_USART_FIFOINTSTAT, 0xE18); +/* TX FIFO Error Interrupt Status */ +FIELD(FLEXCOMM_USART_FIFOINTSTAT, TXERR, 0, 1); +/* RX FIFO Error Interrupt Status */ +FIELD(FLEXCOMM_USART_FIFOINTSTAT, RXERR, 1, 1); +/* Transmit FIFO Level Interrupt Status */ +FIELD(FLEXCOMM_USART_FIFOINTSTAT, TXLVL, 2, 1); +/* Receive FIFO Level Interrupt Status */ +FIELD(FLEXCOMM_USART_FIFOINTSTAT, RXLVL, 3, 1); +/* Peripheral Interrupt Status */ +FIELD(FLEXCOMM_USART_FIFOINTSTAT, PERINT, 4, 1); + +/* FIFO Write Data */ +REG32(FLEXCOMM_USART_FIFOWR, 0xE20); +/* Transmit data to the FIFO */ +FIELD(FLEXCOMM_USART_FIFOWR, TXDATA, 0, 9); + +/* FIFO Read Data */ +REG32(FLEXCOMM_USART_FIFORD, 0xE30); +/* Received Data from the FIFO */ +FIELD(FLEXCOMM_USART_FIFORD, RXDATA, 0, 9); +/* Framing Error Status Flag */ +FIELD(FLEXCOMM_USART_FIFORD, FRAMERR, 13, 1); +/* Parity Error Status Flag */ +FIELD(FLEXCOMM_USART_FIFORD, PARITYERR, 14, 1); +/* Received Noise Flag */ +FIELD(FLEXCOMM_USART_FIFORD, RXNOISE, 15, 1); + +/* FIFO Data Read with No FIFO Pop */ +REG32(FLEXCOMM_USART_FIFORDNOPOP, 0xE40); +/* Received Data from the FIFO */ +FIELD(FLEXCOMM_USART_FIFORDNOPOP, RXDATA, 0, 9); +/* Framing Error Status Flag */ +FIELD(FLEXCOMM_USART_FIFORDNOPOP, FRAMERR, 13, 1); +/* Parity Error Status Flag */ +FIELD(FLEXCOMM_USART_FIFORDNOPOP, PARITYERR, 14, 1); +/* Received Noise Flag */ +FIELD(FLEXCOMM_USART_FIFORDNOPOP, RXNOISE, 15, 1); + +/* FIFO Size */ +REG32(FLEXCOMM_USART_FIFOSIZE, 0xE48); +/* FIFO Size */ +FIELD(FLEXCOMM_USART_FIFOSIZE, FIFOSIZE, 0, 5); + +/* Peripheral Identification */ +REG32(FLEXCOMM_USART_ID, 0xFFC); + + +#define FLEXCOMM_USART_REGISTER_ACCESS_INFO_ARRAY(_name) \ + struct RegisterAccessInfo _name[FLEXCOMM_USART_REGS_NO] =3D { \ + [0 ... FLEXCOMM_USART_REGS_NO - 1] =3D { \ + .name =3D "", \ + .addr =3D -1, \ + }, \ + [0x0] =3D { \ + .name =3D "CFG", \ + .addr =3D 0x0, \ + .ro =3D 0xFF032402, \ + .reset =3D 0x0, \ + }, \ + [0x1] =3D { \ + .name =3D "CTL", \ + .addr =3D 0x4, \ + .ro =3D 0xFFFEFCB9, \ + .reset =3D 0x0, \ + }, \ + [0x2] =3D { \ + .name =3D "STAT", \ + .addr =3D 0x8, \ + .ro =3D 0xFFFE07DF, \ + .reset =3D 0xA, \ + }, \ + [0x3] =3D { \ + .name =3D "INTENSET", \ + .addr =3D 0xC, \ + .ro =3D 0xFFFE0797, \ + .reset =3D 0x0, \ + }, \ + [0x4] =3D { \ + .name =3D "INTENCLR", \ + .addr =3D 0x10, \ + .ro =3D 0xFFFE0797, \ + .reset =3D 0x0, \ + }, \ + [0x8] =3D { \ + .name =3D "BRG", \ + .addr =3D 0x20, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0x0, \ + }, \ + [0x9] =3D { \ + .name =3D "INTSTAT", \ + .addr =3D 0x24, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0xA] =3D { \ + .name =3D "OSR", \ + .addr =3D 0x28, \ + .ro =3D 0xFFFFFFF0, \ + .reset =3D 0xF, \ + }, \ + [0xB] =3D { \ + .name =3D "ADDR", \ + .addr =3D 0x2C, \ + .ro =3D 0xFFFFFF00, \ + .reset =3D 0x0, \ + }, \ + [0x380] =3D { \ + .name =3D "FIFOCFG", \ + .addr =3D 0xE00, \ + .ro =3D 0xFFF80FFC, \ + .reset =3D 0x0, \ + }, \ + [0x381] =3D { \ + .name =3D "FIFOSTAT", \ + .addr =3D 0xE04, \ + .ro =3D 0xFFFFFFFC, \ + .reset =3D 0x30, \ + }, \ + [0x382] =3D { \ + .name =3D "FIFOTRIG", \ + .addr =3D 0xE08, \ + .ro =3D 0xFFF0F0FC, \ + .reset =3D 0x0, \ + }, \ + [0x384] =3D { \ + .name =3D "FIFOINTENSET", \ + .addr =3D 0xE10, \ + .ro =3D 0xFFFFFFF0, \ + .reset =3D 0x0, \ + }, \ + [0x385] =3D { \ + .name =3D "FIFOINTENCLR", \ + .addr =3D 0xE14, \ + .ro =3D 0xFFFFFFF0, \ + .reset =3D 0x0, \ + }, \ + [0x386] =3D { \ + .name =3D "FIFOINTSTAT", \ + .addr =3D 0xE18, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x388] =3D { \ + .name =3D "FIFOWR", \ + .addr =3D 0xE20, \ + .ro =3D 0xFFFFFE00, \ + .reset =3D 0x0, \ + }, \ + [0x38C] =3D { \ + .name =3D "FIFORD", \ + .addr =3D 0xE30, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x390] =3D { \ + .name =3D "FIFORDNOPOP", \ + .addr =3D 0xE40, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x392] =3D { \ + .name =3D "FIFOSIZE", \ + .addr =3D 0xE48, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x10, \ + }, \ + [0x3FF] =3D { \ + .name =3D "ID", \ + .addr =3D 0xFFC, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0xE0102100, \ + }, \ + } diff --git a/include/hw/char/flexcomm_usart.h b/include/hw/char/flexcomm_us= art.h new file mode 100644 index 0000000000..e67b15208f --- /dev/null +++ b/include/hw/char/flexcomm_usart.h @@ -0,0 +1,33 @@ +/* + * QEMU model for NXP's FLEXCOMM USART + * + * 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_FLEXCOMM_USART_H +#define HW_FLEXCOMM_USART_H + +#include "hw/misc/flexcomm_function.h" +#include "chardev/char-fe.h" + +#define TYPE_FLEXCOMM_USART "flexcomm-usart" +OBJECT_DECLARE_TYPE(FlexcommUsartState, FlexcommUsartClass, FLEXCOMM_USART= ); + +struct FlexcommUsartState { + FlexcommFunction parent_obj; + + CharBackend chr; +}; + +struct FlexcommUsartClass { + FlexcommFunctionClass parent_obj; + + FlexcommFunctionSelect select; +}; + +#endif /* HW_FLEXCOMM_USART_H */ diff --git a/include/hw/misc/flexcomm.h b/include/hw/misc/flexcomm.h index 832d4cd29d..679b7ea64d 100644 --- a/include/hw/misc/flexcomm.h +++ b/include/hw/misc/flexcomm.h @@ -15,6 +15,7 @@ #include "hw/sysbus.h" #include "hw/arm/svd/flexcomm.h" #include "qemu/fifo32.h" +#include "hw/char/flexcomm_usart.h" =20 #define FLEXCOMM_FUNC_USART 0 #define FLEXCOMM_FUNC_SPI 1 @@ -46,6 +47,7 @@ struct FlexcommState { bool irq_state; Fifo32 rx_fifo; Fifo32 tx_fifo; + FlexcommUsartState usart; }; =20 #endif /* HW_FLEXCOMM_H */ diff --git a/hw/char/flexcomm_usart.c b/hw/char/flexcomm_usart.c new file mode 100644 index 0000000000..53ab5d8379 --- /dev/null +++ b/hw/char/flexcomm_usart.c @@ -0,0 +1,288 @@ +/* + * QEMU model for NXP's FLEXCOMM USART + * + * 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/cutils.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" +#include "hw/qdev-properties-system.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "exec/address-spaces.h" +#include "qapi/error.h" +#include "trace.h" +#include "hw/misc/flexcomm.h" +#include "hw/char/flexcomm_usart.h" +#include "hw/arm/svd/flexcomm_usart.h" + +#define REG(s, reg) (s->regs[R_FLEXCOMM_USART_##reg]) +/* register field write helper macro */ +#define RF_RD(s, reg, field, val) \ + ARRAY_FIELD_DP32(s->regs, FLEXCOMM_USART_##reg, field, val) +/* register field read helper macro */ +#define RF_WR(s, reg, field) \ + ARRAY_FIELD_EX32(s->regs, FLEXCOMM_USART_##reg, field) + +static FLEXCOMM_USART_REGISTER_ACCESS_INFO_ARRAY(reg_info); + +static void flexcomm_usart_reset(FlexcommFunction *f) +{ + for (int i =3D 0; i < FLEXCOMM_USART_REGS_NO; i++) { + hwaddr addr =3D reg_info[i].addr; + + if (addr !=3D -1) { + struct RegisterInfo ri =3D { + .data =3D &f->regs[addr / 4], + .data_size =3D 4, + .access =3D ®_info[i], + }; + + register_reset(&ri); + } + } +} + +static void flexcomm_usart_irq_update(FlexcommFunction *f) +{ + bool irq, per_irqs, fifo_irqs, enabled =3D RF_WR(f, CFG, ENABLE); + + flexcomm_update_fifostat(f); + fifo_irqs =3D REG(f, FIFOINTSTAT) & REG(f, FIFOINTENSET); + + REG(f, INTSTAT) =3D REG(f, STAT) & REG(f, INTENSET); + per_irqs =3D REG(f, INTSTAT) !=3D 0; + + irq =3D enabled && (fifo_irqs || per_irqs); + + trace_flexcomm_usart_irq(DEVICE(f)->id, irq, fifo_irqs, per_irqs, enab= led); + flexcomm_set_irq(f, irq); +} + +static int flexcomm_usart_rx_space(void *opaque) +{ + FlexcommUsartState *s =3D FLEXCOMM_USART(opaque); + FlexcommFunction *f =3D FLEXCOMM_FUNCTION(opaque); + + uint32_t ret =3D fifo32_num_free(f->rx_fifo); + + if (!RF_WR(f, CFG, ENABLE) || !RF_WR(f, FIFOCFG, ENABLERX)) { + ret =3D 0; + } + + trace_flexcomm_usart_rx_space(DEVICE(s)->id, ret); + + return ret; +} + +static void flexcomm_usart_rx(void *opaque, const uint8_t *buf, int size) +{ + FlexcommFunction *f =3D FLEXCOMM_FUNCTION(opaque); + + if (!RF_WR(f, CFG, ENABLE) || !RF_WR(f, FIFOCFG, ENABLERX)) { + return; + } + + trace_flexcomm_usart_rx(DEVICE(f)->id); + + while (!fifo32_is_full(f->rx_fifo) && size) { + fifo32_push(f->rx_fifo, *buf++); + size--; + } + + flexcomm_usart_irq_update(f); +} + +static MemTxResult flexcomm_usart_reg_read(void *opaque, hwaddr addr, + uint64_t *data, unsigned size, + MemTxAttrs attrs) +{ + FlexcommFunction *f =3D FLEXCOMM_FUNCTION(opaque); + FlexcommUsartState *s =3D FLEXCOMM_USART(opaque); + const struct RegisterAccessInfo *rai =3D ®_info[addr / 4]; + MemTxResult ret =3D MEMTX_OK; + + if (size !=3D 4) { + ret =3D MEMTX_ERROR; + goto out; + } + + switch (addr) { + case A_FLEXCOMM_USART_FIFORD: + { + if (!fifo32_is_empty(f->rx_fifo)) { + *data =3D fifo32_pop(f->rx_fifo); + qemu_chr_fe_accept_input(&s->chr); + } + break; + } + case A_FLEXCOMM_USART_FIFORDNOPOP: + { + if (!fifo32_is_empty(f->rx_fifo)) { + *data =3D fifo32_peek(f->rx_fifo); + } + break; + } + default: + *data =3D f->regs[addr / 4]; + break; + } + + flexcomm_usart_irq_update(f); + +out: + trace_flexcomm_usart_reg_read(DEVICE(f)->id, rai->name, addr, *data); + return ret; +} + +static MemTxResult flexcomm_usart_reg_write(void *opaque, hwaddr addr, + uint64_t value, unsigned size, + MemTxAttrs attrs) +{ + FlexcommFunction *f =3D FLEXCOMM_FUNCTION(opaque); + FlexcommUsartState *s =3D FLEXCOMM_USART(opaque); + const struct RegisterAccessInfo *rai =3D ®_info[addr / 4]; + struct RegisterInfo ri =3D { + .data =3D &f->regs[addr / 4], + .data_size =3D 4, + .access =3D rai, + }; + + trace_flexcomm_usart_reg_write(DEVICE(f)->id, rai->name, addr, value); + + switch (addr) { + case A_FLEXCOMM_USART_INTENCLR: + { + register_write(&ri, value, ~0, NULL, false); + REG(f, INTENSET) &=3D ~REG(f, INTENCLR); + break; + } + case A_FLEXCOMM_USART_FIFOCFG: + { + register_write(&ri, value, ~0, NULL, false); + flexcomm_reset_fifos(f); + break; + } + case A_FLEXCOMM_USART_FIFOSTAT: + { + flexcomm_clear_fifostat(f, value); + break; + } + case A_FLEXCOMM_USART_FIFOINTENSET: + { + REG(f, FIFOINTENSET) |=3D value; + break; + } + case A_FLEXCOMM_USART_FIFOINTENCLR: + { + register_write(&ri, value, ~0, NULL, false); + REG(f, FIFOINTENSET) &=3D ~value; + break; + } + case A_FLEXCOMM_USART_FIFOWR: + { + register_write(&ri, value, ~0, NULL, false); + + if (!fifo32_is_full(f->tx_fifo)) { + fifo32_push(f->tx_fifo, REG(f, FIFOWR)); + } + + if (!RF_WR(f, CFG, ENABLE) || !RF_WR(f, FIFOCFG, ENABLETX)) { + break; + } + + while (!fifo32_is_empty(f->tx_fifo)) { + uint32_t val32 =3D fifo32_pop(f->tx_fifo); + uint8_t val8 =3D val32 & 0xff; + + trace_flexcomm_usart_tx(DEVICE(f)->id); + qemu_chr_fe_write_all(&s->chr, &val8, sizeof(val8)); + } + break; + } + case A_FLEXCOMM_USART_CFG: + { + register_write(&ri, value, ~0, NULL, false); + break; + } + default: + register_write(&ri, value, ~0, NULL, false); + break; + } + + flexcomm_usart_irq_update(f); + + return MEMTX_OK; +} + +static void flexcomm_usart_select(FlexcommFunction *f, bool selected) +{ + FlexcommUsartState *s =3D FLEXCOMM_USART(f); + FlexcommUsartClass *uc =3D FLEXCOMM_USART_GET_CLASS(f); + + if (selected) { + qemu_chr_fe_set_handlers(&s->chr, flexcomm_usart_rx_space, + flexcomm_usart_rx, NULL, NULL, + s, NULL, true); + flexcomm_usart_reset(f); + } else { + qemu_chr_fe_set_handlers(&s->chr, NULL, NULL, NULL, NULL, NULL, NU= LL, + false); + } + uc->select(f, selected); +} + +static const MemoryRegionOps flexcomm_usart_ops =3D { + .read_with_attrs =3D flexcomm_usart_reg_read, + .write_with_attrs =3D flexcomm_usart_reg_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + .unaligned =3D false, + }, +}; + +static Property flexcomm_usart_properties[] =3D { + DEFINE_PROP_CHR("chardev", FlexcommUsartState, chr), + DEFINE_PROP_END_OF_LIST(), +}; + +static void flexcomm_usart_realize(DeviceState *dev, Error **errp) +{ + qdev_prop_set_chr(dev, "chardev", qemu_chr_find(dev->id)); +} + +static void flexcomm_usart_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + FlexcommFunctionClass *fc =3D FLEXCOMM_FUNCTION_CLASS(klass); + FlexcommUsartClass *uc =3D FLEXCOMM_USART_CLASS(klass); + + device_class_set_props(dc, flexcomm_usart_properties); + dc->realize =3D flexcomm_usart_realize; + uc->select =3D fc->select; + fc->select =3D flexcomm_usart_select; + fc->name =3D "usart"; + fc->has_fifos =3D true; + fc->mmio_ops =3D &flexcomm_usart_ops; +} + +static const TypeInfo flexcomm_usart_types[] =3D { + { + .name =3D TYPE_FLEXCOMM_USART, + .parent =3D TYPE_FLEXCOMM_FUNCTION, + .instance_size =3D sizeof(FlexcommUsartState), + .class_init =3D flexcomm_usart_class_init, + .class_size =3D sizeof(FlexcommUsartClass), + }, +}; + +DEFINE_TYPES(flexcomm_usart_types); diff --git a/hw/misc/flexcomm.c b/hw/misc/flexcomm.c index a98d8845aa..a291148f27 100644 --- a/hw/misc/flexcomm.c +++ b/hw/misc/flexcomm.c @@ -23,6 +23,7 @@ #include "migration/vmstate.h" #include "hw/misc/flexcomm.h" #include "hw/arm/svd/flexcomm_usart.h" +#include "hw/char/flexcomm_usart.h" =20 #define REG(s, reg) (s->regs[R_FLEXCOMM_##reg]) #define RF_WR(s, reg, field, val) \ @@ -218,6 +219,7 @@ static void flexcomm_init(Object *obj) TYPE_FLEXCOMM, sizeof(s->regs)); sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->container); sysbus_init_irq(sbd, &s->irq); + object_initialize_child(obj, "usart", &s->usart, TYPE_FLEXCOMM_USART); } =20 static void flexcomm_finalize(Object *obj) @@ -247,6 +249,7 @@ static void flexcomm_realize(DeviceState *dev, Error **= errp) FlexcommState *s =3D FLEXCOMM(dev); =20 memory_region_add_subregion_overlap(&s->container, 0, &s->mmio, -1); + flexcomm_func_realize_and_unref(FLEXCOMM_FUNCTION(&s->usart), errp); } =20 static const VMStateDescription vmstate_flexcomm =3D { diff --git a/hw/arm/svd/meson.build b/hw/arm/svd/meson.build index 4b0bbbbbdc..3bff90bcbd 100644 --- a/hw/arm/svd/meson.build +++ b/hw/arm/svd/meson.build @@ -4,4 +4,8 @@ if get_option('mcux-soc-svd') run_target('svd-flexcomm', command: svd_gen_header + [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/flexcomm.h', '-p', 'FLEXCOMM0', '-t', 'FLEXCOMM']) + run_target('svd-flexcomm-usart', command: svd_gen_header + + [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/flexcomm_usart.= h', + '-p', 'USART0', '-t', 'FLEXCOMM_USART', + '--fields', 'CFG:ENABLE FIFOCFG:ENABLE*,EMPTY* FIFO*:* *:']) endif diff --git a/hw/char/meson.build b/hw/char/meson.build index 1750834385..5c6aaf8309 100644 --- a/hw/char/meson.build +++ b/hw/char/meson.build @@ -39,3 +39,4 @@ system_ss.add(when: 'CONFIG_GOLDFISH_TTY', if_true: files= ('goldfish_tty.c')) specific_ss.add(when: 'CONFIG_TERMINAL3270', if_true: files('terminal3270.= c')) specific_ss.add(when: 'CONFIG_VIRTIO', if_true: files('virtio-serial-bus.c= ')) specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_vty.c')) +system_ss.add(when: 'CONFIG_FLEXCOMM', if_true: files('flexcomm_usart.c')) diff --git a/hw/char/trace-events b/hw/char/trace-events index 59e1f734a7..578551b388 100644 --- a/hw/char/trace-events +++ b/hw/char/trace-events @@ -125,3 +125,11 @@ xen_console_unrealize(unsigned int idx) "idx %u" xen_console_realize(unsigned int idx, const char *chrdev) "idx %u chrdev %= s" xen_console_device_create(unsigned int idx) "idx %u" xen_console_device_destroy(unsigned int idx) "idx %u" + +# flexcomm_usart.c +flexcomm_usart_reg_read(const char *id, const char *reg_name, uint32_t add= r, uint32_t val) " %s: %s[0x%04x] -> 0x%08x" +flexcomm_usart_reg_write(const char *id, const char *reg_name, uint32_t ad= dr, uint32_t val) "%s: %s[0x%04x] <- 0x%08x" +flexcomm_usart_rx_space(const char *id, uint32_t rx) "%s: %d" +flexcomm_usart_rx(const char *id) "%s" +flexcomm_usart_tx(const char *id) "%s" +flexcomm_usart_irq(const char *id, bool irq, bool fifoirqs, bool perirqs, = bool enabled) "%s: %d %d %d %d" --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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=1728350790; cv=none; d=zohomail.com; s=zohoarc; b=hLePc/latbuPqGg7mYB641e0PzfVz6gXnO050SDvRxaD/BFYOemY7t+nIqHNRh/IaaZDInYevA3BbiOw9ZxT7wBsrG2pSf7/mgGH+tJLdpG71q/HFnM6rkOR8TmnYnhlko/HzJ5NRD6nENzJ8VnUvrbqkWeo0nnOCaYDD/6jejQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350790; 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=8QRkphhXNdsPFrr6+C1WirROoZs1K34T9oRkyUJP42U=; b=JfbDdsxbqn25Ob0ta0Cb7e+nrKbYOmLKcDwug0F2drxsek9MI+W9uFYwdxCZgRYlDlAZfVi0hAaIEeUpN9yXrkRCGUly44xblewPRgI81w7XLU9FQQwSUFh0av2mLK7qzwl1IBaZCuYdMhmDz1cXK74UKZzgtlVvR8onGz4UokA= 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 1728350790650134.2742062888201; Mon, 7 Oct 2024 18:26:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxytI-00024Q-Fi; Mon, 07 Oct 2024 21:19:56 -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 <3jIgEZwUKCu0iPkXeVddVaT.RdbfTbj-STkTacdcVcj.dgV@flex--tavip.bounces.google.com>) id 1sxysc-0007pC-VG for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:18 -0400 Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3jIgEZwUKCu0iPkXeVddVaT.RdbfTbj-STkTacdcVcj.dgV@flex--tavip.bounces.google.com>) id 1sxysa-00009V-84 for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:14 -0400 Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-20c531e38a5so2135035ad.0 for ; Mon, 07 Oct 2024 18:19:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350350; x=1728955150; 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=8QRkphhXNdsPFrr6+C1WirROoZs1K34T9oRkyUJP42U=; b=aKIT0UZADk6D1kbWMMQNAEmdgkvQ82SV224drSOD1h5Zb/fjD8Tk4dpeQBuVtnUCHP IxJo9XOU0wd7GWDtKmLKyPQYBKCQ8/S0qgNJiKkh9+4ieAVgCa9geZCJ0SlcU67DWrzU 5DD7rEQpUeGZHi020DWAFg0+N/GwtrXjpC5nkWfcsFQg6ESB/+W/bVfZ0h5B1tRwRICF syr1lyk5GeoJpjssvGKIIk3G407EZiMAQRFjs+qFJSZetaLsRinoXdOrDs8pB+VWyipf tyuo2YxLLprqglQHHI/eY3RLA4fTPeHP9phasntiVlkbxZwf50geSZT7Tm79K9b0ZtQl ZeBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350350; x=1728955150; 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=8QRkphhXNdsPFrr6+C1WirROoZs1K34T9oRkyUJP42U=; b=tcbmIoH6vBSlP8XKrQG+DzrDkEiT6IdXViWVNaqcfMbOhf8WPZBHEPliUZ6/8yBzLm VCwBfUfzaXif1Zns+qLhRx6xGLbb1ou4eH90No1V/AZBkE8RRpH7C9zcder4FMpOqPKz UFajzdQmKPcdsWzpp+v7MBQj29MrGY8mDVJEHM2d0r2jfkqLweIqbqavPHVDz2VDmfFe 8wEXrEt/Odu0kChPICC8eDKPzxLKPpC5NGmBQhX9o6elEi7fogx9ZKqP5bcisE5QHk57 K0MHFtvCcfuQzC/J0ecaH4VlMIie2im5RPTJzFzHWRaxsl0imVu5l7ksMDWZS3vnPgBz q13Q== X-Gm-Message-State: AOJu0Yzk9FZDqj3Nu1zE+DHaaVhlAvE8fJ0X6Uih1YWDpws+sIiVNZAX UUgYz00sw+ZSleXqziQXe2hwDPMUsU/qhg0VLZpJmFOCH3YTZ/G6cIbeZSM/GgF0VJKFxJOeimx 5IA0AOa7VW+anZowAiyXa5aIp1FMzq0DwOSu7/lRim5STfkTYm+h8H/+nGwEkR54nw/NcU32mng PloV5hs70NMQjl1kf7OVbOhoSgQw== X-Google-Smtp-Source: AGHT+IFV4ejJ05aZUkbHio21LY8L4/lVckYz35q8sBuQeMqIuRtHuEY0pU+3zodaECEAI/wCW3eOByzZlA== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a17:902:e80c:b0:20b:9df1:54a3 with SMTP id d9443c01a7336-20bff1dfc9fmr779915ad.8.1728350348483; Mon, 07 Oct 2024 18:19:08 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:34 -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-9-tavip@google.com> Subject: [PATCH v2 08/25] hw/i2c: add support for flexcomm i2c 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::649; envelope-from=3jIgEZwUKCu0iPkXeVddVaT.RdbfTbj-STkTacdcVcj.dgV@flex--tavip.bounces.google.com; helo=mail-pl1-x649.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: 1728350791051116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for NXP's flexcomm i2c. It does not support slave mode or DMA. The patch includes an automatically generated header which contains the register layout and helpers. The header can be regenerated with the svd-flexcomm-i2c target when the build is configured with --enable-mcux-soc-svd. Signed-off-by: Octavian Purdila --- include/hw/arm/svd/flexcomm_i2c.h | 229 +++++++++++++++++++++++++++ include/hw/i2c/flexcomm_i2c.h | 40 +++++ include/hw/misc/flexcomm.h | 2 + hw/i2c/flexcomm_i2c.c | 250 ++++++++++++++++++++++++++++++ hw/misc/flexcomm.c | 3 + hw/arm/svd/meson.build | 4 + hw/i2c/meson.build | 1 + hw/i2c/trace-events | 10 ++ hw/misc/Kconfig | 1 + 9 files changed, 540 insertions(+) create mode 100644 include/hw/arm/svd/flexcomm_i2c.h create mode 100644 include/hw/i2c/flexcomm_i2c.h create mode 100644 hw/i2c/flexcomm_i2c.c diff --git a/include/hw/arm/svd/flexcomm_i2c.h b/include/hw/arm/svd/flexcom= m_i2c.h new file mode 100644 index 0000000000..bd1dec16f3 --- /dev/null +++ b/include/hw/arm/svd/flexcomm_i2c.h @@ -0,0 +1,229 @@ +/* + * 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" + +/* I2C Bus Interface */ +#define FLEXCOMM_I2C_REGS_NO (1024) + +/* Configuration Register */ +REG32(FLEXCOMM_I2C_CFG, 0x800); +/* Master Enable */ +FIELD(FLEXCOMM_I2C_CFG, MSTEN, 0, 1); +/* Slave Enable */ +FIELD(FLEXCOMM_I2C_CFG, SLVEN, 1, 1); +/* Monitor Enable */ +FIELD(FLEXCOMM_I2C_CFG, MONEN, 2, 1); +/* I2C bus Time-out Enable */ +FIELD(FLEXCOMM_I2C_CFG, TIMEOUTEN, 3, 1); +/* Monitor function Clock Stretching */ +FIELD(FLEXCOMM_I2C_CFG, MONCLKSTR, 4, 1); +/* High Speed mode Capable enable */ +FIELD(FLEXCOMM_I2C_CFG, HSCAPABLE, 5, 1); + +/* Status Register */ +REG32(FLEXCOMM_I2C_STAT, 0x804); +/* Master Pending */ +FIELD(FLEXCOMM_I2C_STAT, MSTPENDING, 0, 1); +/* Master State code */ +FIELD(FLEXCOMM_I2C_STAT, MSTSTATE, 1, 3); +/* Idle. The Master function is available to be used for a new transaction= . */ +#define FLEXCOMM_I2C_STAT_MSTSTATE_IDLE 0 +/* + * Receive ready. Received data is available (in Master Receiver mode). Ad= dress + * plus Read was previously sent and Acknowledged by a slave. + */ +#define FLEXCOMM_I2C_STAT_MSTSTATE_RECEIVE_READY 1 +/* + * Transmit ready. Data can be transmitted (in Master Transmitter mode). + * Address plus Write was previously sent and Acknowledged by a slave. + */ +#define FLEXCOMM_I2C_STAT_MSTSTATE_TRANSMIT_READY 2 +/* NACK Address. Slave NACKed address. */ +#define FLEXCOMM_I2C_STAT_MSTSTATE_NACK_ADDRESS 3 +/* NACK Data. Slave NACKed transmitted data. */ +#define FLEXCOMM_I2C_STAT_MSTSTATE_NACK_DATA 4 + +/* Interrupt Enable Set Register */ +REG32(FLEXCOMM_I2C_INTENSET, 0x808); +/* Master Pending interrupt Enable */ +FIELD(FLEXCOMM_I2C_INTENSET, MSTPENDINGEN, 0, 1); + +/* Interrupt Enable Clear Register */ +REG32(FLEXCOMM_I2C_INTENCLR, 0x80C); +/* Master Pending interrupt clear */ +FIELD(FLEXCOMM_I2C_INTENCLR, MSTPENDINGCLR, 0, 1); + +/* Time-out Register */ +REG32(FLEXCOMM_I2C_TIMEOUT, 0x810); +/* Time-out time value, the bottom 4 bits */ +FIELD(FLEXCOMM_I2C_TIMEOUT, TOMIN, 0, 4); + +/* Interrupt Status Register */ +REG32(FLEXCOMM_I2C_INTSTAT, 0x818); +/* Master Pending */ +FIELD(FLEXCOMM_I2C_INTSTAT, MSTPENDING, 0, 1); + +/* Master Control Register */ +REG32(FLEXCOMM_I2C_MSTCTL, 0x820); +/* Master Continue(write-only) */ +FIELD(FLEXCOMM_I2C_MSTCTL, MSTCONTINUE, 0, 1); +/* Master Start control(write-only) */ +FIELD(FLEXCOMM_I2C_MSTCTL, MSTSTART, 1, 1); +/* Master Stop control(write-only) */ +FIELD(FLEXCOMM_I2C_MSTCTL, MSTSTOP, 2, 1); +/* Master DMA enable */ +FIELD(FLEXCOMM_I2C_MSTCTL, MSTDMA, 3, 1); + +/* Master Data Register */ +REG32(FLEXCOMM_I2C_MSTDAT, 0x828); +/* Master function data register */ +FIELD(FLEXCOMM_I2C_MSTDAT, DATA, 0, 8); + +/* Slave Control Register */ +REG32(FLEXCOMM_I2C_SLVCTL, 0x840); + +/* Slave Data Register */ +REG32(FLEXCOMM_I2C_SLVDAT, 0x844); + +/* Slave Address Register */ +REG32(FLEXCOMM_I2C_SLVADR0, 0x848); + +/* Slave Address Register */ +REG32(FLEXCOMM_I2C_SLVADR1, 0x84C); + +/* Slave Address Register */ +REG32(FLEXCOMM_I2C_SLVADR2, 0x850); + +/* Slave Address Register */ +REG32(FLEXCOMM_I2C_SLVADR3, 0x854); + +/* Slave Qualification for Address 0 Register */ +REG32(FLEXCOMM_I2C_SLVQUAL0, 0x858); + + +#define FLEXCOMM_I2C_REGISTER_ACCESS_INFO_ARRAY(_name) \ + struct RegisterAccessInfo _name[FLEXCOMM_I2C_REGS_NO] =3D { \ + [0 ... FLEXCOMM_I2C_REGS_NO - 1] =3D { \ + .name =3D "", \ + .addr =3D -1, \ + }, \ + [0x200] =3D { \ + .name =3D "CFG", \ + .addr =3D 0x800, \ + .ro =3D 0xFFFFFFC0, \ + .reset =3D 0x0, \ + }, \ + [0x201] =3D { \ + .name =3D "STAT", \ + .addr =3D 0x804, \ + .ro =3D 0xFCF57FAF, \ + .reset =3D 0x801, \ + }, \ + [0x202] =3D { \ + .name =3D "INTENSET", \ + .addr =3D 0x808, \ + .ro =3D 0xFCF476AE, \ + .reset =3D 0x0, \ + }, \ + [0x203] =3D { \ + .name =3D "INTENCLR", \ + .addr =3D 0x80C, \ + .ro =3D 0xFCF476AE, \ + .reset =3D 0x0, \ + }, \ + [0x204] =3D { \ + .name =3D "TIMEOUT", \ + .addr =3D 0x810, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0xFFFF, \ + }, \ + [0x205] =3D { \ + .name =3D "CLKDIV", \ + .addr =3D 0x814, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0x0, \ + }, \ + [0x206] =3D { \ + .name =3D "INTSTAT", \ + .addr =3D 0x818, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x801, \ + }, \ + [0x208] =3D { \ + .name =3D "MSTCTL", \ + .addr =3D 0x820, \ + .ro =3D 0xFFFFFFF0, \ + .reset =3D 0x0, \ + }, \ + [0x209] =3D { \ + .name =3D "MSTTIME", \ + .addr =3D 0x824, \ + .ro =3D 0xFFFFFF88, \ + .reset =3D 0x77, \ + }, \ + [0x20A] =3D { \ + .name =3D "MSTDAT", \ + .addr =3D 0x828, \ + .ro =3D 0xFFFFFF00, \ + .reset =3D 0x0, \ + }, \ + [0x210] =3D { \ + .name =3D "SLVCTL", \ + .addr =3D 0x840, \ + .ro =3D 0xFFFFFCF4, \ + .reset =3D 0x0, \ + }, \ + [0x211] =3D { \ + .name =3D "SLVDAT", \ + .addr =3D 0x844, \ + .ro =3D 0xFFFFFF00, \ + .reset =3D 0x0, \ + }, \ + [0x212] =3D { \ + .name =3D "SLVADR0", \ + .addr =3D 0x848, \ + .ro =3D 0xFFFF7F00, \ + .reset =3D 0x1, \ + }, \ + [0x213] =3D { \ + .name =3D "SLVADR1", \ + .addr =3D 0x84C, \ + .ro =3D 0xFFFF7F00, \ + .reset =3D 0x1, \ + }, \ + [0x214] =3D { \ + .name =3D "SLVADR2", \ + .addr =3D 0x850, \ + .ro =3D 0xFFFF7F00, \ + .reset =3D 0x1, \ + }, \ + [0x215] =3D { \ + .name =3D "SLVADR3", \ + .addr =3D 0x854, \ + .ro =3D 0xFFFF7F00, \ + .reset =3D 0x1, \ + }, \ + [0x216] =3D { \ + .name =3D "SLVQUAL0", \ + .addr =3D 0x858, \ + .ro =3D 0xFFFFFF00, \ + .reset =3D 0x0, \ + }, \ + [0x220] =3D { \ + .name =3D "MONRXDAT", \ + .addr =3D 0x880, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x3FF] =3D { \ + .name =3D "ID", \ + .addr =3D 0xFFC, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0xE0301300, \ + }, \ + } diff --git a/include/hw/i2c/flexcomm_i2c.h b/include/hw/i2c/flexcomm_i2c.h new file mode 100644 index 0000000000..7b27e333d7 --- /dev/null +++ b/include/hw/i2c/flexcomm_i2c.h @@ -0,0 +1,40 @@ +/* + * QEMU model for NXP's FLEXCOMM I2C + * + * 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_FLEXCOMM_I2C_H +#define HW_FLEXCOMM_I2C_H + +#include "hw/i2c/i2c.h" +#include "hw/misc/flexcomm_function.h" + +#define TYPE_FLEXCOMM_I2C "flexcomm-i2c" +OBJECT_DECLARE_TYPE(FlexcommI2cState, FlexcommI2cClass, FLEXCOMM_I2C); + +struct FlexcommI2cState { + FlexcommFunction parent_obj; + + I2CBus *bus; +}; + +struct FlexcommI2cClass { + FlexcommFunctionClass parent_obj; + + FlexcommFunctionSelect select; +}; + +#define MSTSTATE_IDLE 0 +#define MSTSTATE_RXRDY 1 +#define MSTSTATE_TXRDY 2 +#define MSTSTATE_NAKADR 3 +#define MSTSTATE_NAKDAT 4 + + +#endif /* HW_FLEXCOMM_I2C_H */ diff --git a/include/hw/misc/flexcomm.h b/include/hw/misc/flexcomm.h index 679b7ea64d..c9f1cd3890 100644 --- a/include/hw/misc/flexcomm.h +++ b/include/hw/misc/flexcomm.h @@ -16,6 +16,7 @@ #include "hw/arm/svd/flexcomm.h" #include "qemu/fifo32.h" #include "hw/char/flexcomm_usart.h" +#include "hw/i2c/flexcomm_i2c.h" =20 #define FLEXCOMM_FUNC_USART 0 #define FLEXCOMM_FUNC_SPI 1 @@ -48,6 +49,7 @@ struct FlexcommState { Fifo32 rx_fifo; Fifo32 tx_fifo; FlexcommUsartState usart; + FlexcommI2cState i2c; }; =20 #endif /* HW_FLEXCOMM_H */ diff --git a/hw/i2c/flexcomm_i2c.c b/hw/i2c/flexcomm_i2c.c new file mode 100644 index 0000000000..e5341ec241 --- /dev/null +++ b/hw/i2c/flexcomm_i2c.c @@ -0,0 +1,250 @@ +/* + * QEMU model for NXP's FLEXCOMM I2C + * + * 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/cutils.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "exec/address-spaces.h" +#include "qapi/error.h" +#include "trace.h" +#include "hw/i2c/flexcomm_i2c.h" +#include "hw/arm/svd/flexcomm_i2c.h" + +#define REG(s, reg) (s->regs[R_FLEXCOMM_I2C_##reg]) +#define RF_WR(s, reg, field, val) \ + ARRAY_FIELD_DP32(s->regs, FLEXCOMM_I2C_##reg, field, val) +#define RF_RD(s, reg, field) \ + ARRAY_FIELD_EX32(s->regs, FLEXCOMM_I2C_##reg, field) + +static FLEXCOMM_I2C_REGISTER_ACCESS_INFO_ARRAY(reg_info); + +static void flexcomm_i2c_reset(FlexcommFunction *f) +{ + for (int i =3D 0; i < FLEXCOMM_I2C_REGS_NO; i++) { + hwaddr addr =3D reg_info[i].addr; + + if (addr !=3D -1) { + struct RegisterInfo ri =3D { + .data =3D &f->regs[addr / 4], + .data_size =3D 4, + .access =3D ®_info[i], + }; + + register_reset(&ri); + } + } +} + +static void flexcomm_i2c_irq_update(FlexcommFunction *f) +{ + bool enabled =3D RF_RD(f, CFG, MSTEN); + bool irq, per_irqs; + + REG(f, INTSTAT) =3D REG(f, STAT) & REG(f, INTENSET); + per_irqs =3D REG(f, INTSTAT) !=3D 0; + + irq =3D enabled && per_irqs; + + trace_flexcomm_i2c_irq(DEVICE(f)->id, irq, per_irqs, enabled); + flexcomm_set_irq(f, irq); +} + +static MemTxResult flexcomm_i2c_reg_read(void *opaque, hwaddr addr, + uint64_t *data, unsigned size, + MemTxAttrs attrs) +{ + FlexcommFunction *f =3D FLEXCOMM_FUNCTION(opaque); + MemTxResult ret =3D MEMTX_OK; + const struct RegisterAccessInfo *rai =3D ®_info[addr / 4]; + + if (size !=3D 4) { + ret =3D MEMTX_ERROR; + goto out; + } + + *data =3D f->regs[addr / 4]; + + flexcomm_i2c_irq_update(f); + +out: + trace_flexcomm_i2c_reg_read(DEVICE(f)->id, rai->name, addr, *data); + return ret; +} + +static MemTxResult flexcomm_i2c_reg_write(void *opaque, hwaddr addr, + uint64_t value, unsigned size, + MemTxAttrs attrs) +{ + FlexcommFunction *f =3D FLEXCOMM_FUNCTION(opaque); + FlexcommI2cState *s =3D FLEXCOMM_I2C(opaque); + const struct RegisterAccessInfo *rai =3D ®_info[addr / 4]; + struct RegisterInfo ri =3D { + .data =3D &f->regs[addr / 4], + .data_size =3D 4, + .access =3D rai, + }; + + trace_flexcomm_i2c_reg_write(DEVICE(f)->id, rai->name, addr, value); + + if (size !=3D 4) { + return MEMTX_ERROR; + } + + switch (addr) { + case A_FLEXCOMM_I2C_CFG: + { + register_write(&ri, value, ~0, NULL, false); + if (RF_RD(f, CFG, SLVEN)) { + qemu_log_mask(LOG_GUEST_ERROR, "I2C slave not supported"); + } + if (RF_RD(f, CFG, MONEN)) { + qemu_log_mask(LOG_GUEST_ERROR, "I2C monitoring not supported"); + } + break; + } + case A_FLEXCOMM_I2C_INTENCLR: + { + REG(f, INTENSET) &=3D ~value; + break; + } + case A_FLEXCOMM_I2C_TIMEOUT: + { + register_write(&ri, value, ~0, NULL, false); + /* The bottom 4 bits are hard-wired to 0xF */ + RF_WR(f, TIMEOUT, TOMIN, 0xf); + break; + } + case A_FLEXCOMM_I2C_MSTCTL: + { + register_write(&ri, value, ~0, NULL, false); + if (RF_RD(f, MSTCTL, MSTSTART)) { + uint8_t i2c_addr =3D RF_RD(f, MSTDAT, DATA); + bool recv =3D i2c_addr & 1; + + trace_flexcomm_i2c_start(DEVICE(s)->id, i2c_addr, recv); + if (i2c_start_transfer(s->bus, i2c_addr, recv)) { + RF_WR(f, STAT, MSTSTATE, MSTSTATE_NAKADR); + trace_flexcomm_i2c_nak(DEVICE(s)->id); + } else { + if (recv) { + uint8_t data =3D i2c_recv(s->bus); + + RF_WR(f, MSTDAT, DATA, data); + trace_flexcomm_i2c_rx(DEVICE(s)->id, data); + RF_WR(f, STAT, MSTSTATE, MSTSTATE_RXRDY); + } else { + RF_WR(f, STAT, MSTSTATE, MSTSTATE_TXRDY); + } + } + } + if (RF_RD(f, MSTCTL, MSTSTOP)) { + RF_WR(f, STAT, MSTSTATE, MSTSTATE_IDLE); + i2c_end_transfer(s->bus); + } + if (RF_RD(f, MSTCTL, MSTCONTINUE)) { + if (RF_RD(f, STAT, MSTSTATE) =3D=3D MSTSTATE_TXRDY) { + uint8_t data =3D RF_RD(f, MSTDAT, DATA); + + trace_flexcomm_i2c_tx(DEVICE(s)->id, data); + if (i2c_send(s->bus, data)) { + RF_WR(f, STAT, MSTSTATE, MSTSTATE_NAKDAT); + } + } else if (RF_RD(f, STAT, MSTSTATE) =3D=3D MSTSTATE_RXRDY) { + uint8_t data =3D i2c_recv(s->bus); + + RF_WR(f, MSTDAT, DATA, data); + trace_flexcomm_i2c_rx(DEVICE(s)->id, data); + } + } + break; + } + case A_FLEXCOMM_I2C_STAT: + { + /* write 1 to clear bits */ + REG(f, STAT) &=3D ~value; + break; + } + case A_FLEXCOMM_I2C_SLVCTL: + case A_FLEXCOMM_I2C_SLVDAT: + case A_FLEXCOMM_I2C_SLVADR0: + case A_FLEXCOMM_I2C_SLVADR1: + case A_FLEXCOMM_I2C_SLVADR2: + case A_FLEXCOMM_I2C_SLVADR3: + case A_FLEXCOMM_I2C_SLVQUAL0: + { + qemu_log_mask(LOG_GUEST_ERROR, "I2C slave not supported\n"); + break; + } + default: + register_write(&ri, value, ~0, NULL, false); + break; + } + + flexcomm_i2c_irq_update(f); + + return MEMTX_OK; +} + +static void flexcomm_i2c_select(FlexcommFunction *f, bool selected) +{ + FlexcommI2cClass *ic =3D FLEXCOMM_I2C_GET_CLASS(f); + + if (selected) { + flexcomm_i2c_reset(f); + } + ic->select(f, selected); +} + +static const MemoryRegionOps flexcomm_i2c_ops =3D { + .read_with_attrs =3D flexcomm_i2c_reg_read, + .write_with_attrs =3D flexcomm_i2c_reg_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + .unaligned =3D false, + }, +}; + +static void flexcomm_i2c_realize(DeviceState *dev, Error **errp) +{ + FlexcommI2cState *s =3D FLEXCOMM_I2C(dev); + + s->bus =3D i2c_init_bus(DEVICE(s), "bus"); +} + +static void flexcomm_i2c_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + FlexcommFunctionClass *fc =3D FLEXCOMM_FUNCTION_CLASS(klass); + FlexcommI2cClass *ic =3D FLEXCOMM_I2C_CLASS(klass); + + dc->realize =3D flexcomm_i2c_realize; + ic->select =3D fc->select; + fc->select =3D flexcomm_i2c_select; + fc->name =3D "i2c"; + fc->mmio_ops =3D &flexcomm_i2c_ops; +} + +static const TypeInfo flexcomm_i2c_types[] =3D { + { + .name =3D TYPE_FLEXCOMM_I2C, + .parent =3D TYPE_FLEXCOMM_FUNCTION, + .instance_size =3D sizeof(FlexcommI2cState), + .class_init =3D flexcomm_i2c_class_init, + .class_size =3D sizeof(FlexcommI2cClass), + }, +}; + +DEFINE_TYPES(flexcomm_i2c_types); diff --git a/hw/misc/flexcomm.c b/hw/misc/flexcomm.c index a291148f27..b1a2f01acf 100644 --- a/hw/misc/flexcomm.c +++ b/hw/misc/flexcomm.c @@ -24,6 +24,7 @@ #include "hw/misc/flexcomm.h" #include "hw/arm/svd/flexcomm_usart.h" #include "hw/char/flexcomm_usart.h" +#include "hw/i2c/flexcomm_i2c.h" =20 #define REG(s, reg) (s->regs[R_FLEXCOMM_##reg]) #define RF_WR(s, reg, field, val) \ @@ -220,6 +221,7 @@ static void flexcomm_init(Object *obj) sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->container); sysbus_init_irq(sbd, &s->irq); object_initialize_child(obj, "usart", &s->usart, TYPE_FLEXCOMM_USART); + object_initialize_child(obj, "i2c", &s->i2c, TYPE_FLEXCOMM_I2C); } =20 static void flexcomm_finalize(Object *obj) @@ -250,6 +252,7 @@ static void flexcomm_realize(DeviceState *dev, Error **= errp) =20 memory_region_add_subregion_overlap(&s->container, 0, &s->mmio, -1); flexcomm_func_realize_and_unref(FLEXCOMM_FUNCTION(&s->usart), errp); + flexcomm_func_realize_and_unref(FLEXCOMM_FUNCTION(&s->i2c), errp); } =20 static const VMStateDescription vmstate_flexcomm =3D { diff --git a/hw/arm/svd/meson.build b/hw/arm/svd/meson.build index 3bff90bcbd..2542b56294 100644 --- a/hw/arm/svd/meson.build +++ b/hw/arm/svd/meson.build @@ -8,4 +8,8 @@ if get_option('mcux-soc-svd') [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/flexcomm_usart.= h', '-p', 'USART0', '-t', 'FLEXCOMM_USART', '--fields', 'CFG:ENABLE FIFOCFG:ENABLE*,EMPTY* FIFO*:* *:']) + run_target('svd-flexcomm-i2c', command: svd_gen_header + + [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/flexcomm_i2c.h', + '-p', 'I2C0', '-t', 'FLEXCOMM_I2C', + '--fields', 'CFG TIMEOUT:TOMIN MSTCTL MSTDAT STAT:MSTPENDING,MSTSTAT= E INT*:MSTPENDING* SLV*:']) endif diff --git a/hw/i2c/meson.build b/hw/i2c/meson.build index c459adcb59..e7d79e6938 100644 --- a/hw/i2c/meson.build +++ b/hw/i2c/meson.build @@ -18,4 +18,5 @@ i2c_ss.add(when: 'CONFIG_PPC4XX', if_true: files('ppc4xx_= i2c.c')) i2c_ss.add(when: 'CONFIG_PCA954X', if_true: files('i2c_mux_pca954x.c')) i2c_ss.add(when: 'CONFIG_PMBUS', if_true: files('pmbus_device.c')) i2c_ss.add(when: 'CONFIG_BCM2835_I2C', if_true: files('bcm2835_i2c.c')) +i2c_ss.add(when: 'CONFIG_FLEXCOMM', if_true: files('flexcomm_i2c.c')) system_ss.add_all(when: 'CONFIG_I2C', if_true: i2c_ss) diff --git a/hw/i2c/trace-events b/hw/i2c/trace-events index 6900e06eda..9f0175fab7 100644 --- a/hw/i2c/trace-events +++ b/hw/i2c/trace-events @@ -51,3 +51,13 @@ npcm7xx_smbus_recv_fifo(const char *id, uint8_t received= , uint8_t expected) "%s =20 pca954x_write_bytes(uint8_t value) "PCA954X write data: 0x%02x" pca954x_read_data(uint8_t value) "PCA954X read data: 0x%02x" + +# flexcomm_i2c.c + +flexcomm_i2c_reg_read(const char *id, const char *reg_name, uint32_t addr,= uint32_t val) " %s: %s[0x%04x] -> 0x%08x" +flexcomm_i2c_reg_write(const char *id, const char *reg_name, uint32_t addr= , uint32_t val) "%s: %s[0x%04x] <- 0x%08x" +flexcomm_i2c_start(const char *id, uint8_t addr, uint8_t recv) "%s: 0x%02x= %d" +flexcomm_i2c_rx(const char *id, uint8_t data) "%s: <- 0x%02x" +flexcomm_i2c_tx(const char *id, uint8_t data) "%s: -> 0x%02x" +flexcomm_i2c_nak(const char *id) "%s: <- nak" +flexcomm_i2c_irq(const char *id, bool irq, bool perirqs, bool enabled) "%s= : %d %d %d" diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig index 14167ae9e8..9a244fa01d 100644 --- a/hw/misc/Kconfig +++ b/hw/misc/Kconfig @@ -215,5 +215,6 @@ config XLNX_VERSAL_TRNG =20 config FLEXCOMM bool + select I2C =20 source macio/Kconfig --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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=1728350710; cv=none; d=zohomail.com; s=zohoarc; b=XC39JhE2i/NKZY3ExUMzkPAR8vfp0Hhdn/jBWuWe15kug5plxXFU507QrFp6kNIYmAv6uaPF1bNeRt+Jo9Fxc3tfBw9h0dwrytZfXZFAtASEuC16CLGE4A+YoHzxCSLdSU2+KTwS9GqPW15TUJsmOP+tsWXrJKz/yyqw2Ek3wI8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350710; 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=bFIqfrB60fzUJwtasXiqxuXbxvJUBaZy8yqqf9RYqyc=; b=c+122Re565PbOE/jCdqCBj7d2cAuSddI7WMJzq9cShvppxrSHfJSWJzkp1vvrkQFkgXJnBPdDM/cj9TyPCxdQw1fXdDkh2spip2pEIGLpUQddYQT2r31nD4NaFKu9O4IkGQOKp9VVb3KFDvWIAOCQ8zJmgyW+FDOui8REMTHiQw= 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 1728350710929267.0791792219097; Mon, 7 Oct 2024 18:25:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxytN-0002Wa-L6; Mon, 07 Oct 2024 21:20:02 -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 <3jogEZwUKCu8kRmZgXffXcV.TfdhVdl-UVmVcefeXel.fiX@flex--tavip.bounces.google.com>) id 1sxysg-0007qG-3U for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:21 -0400 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3jogEZwUKCu8kRmZgXffXcV.TfdhVdl-UVmVcefeXel.fiX@flex--tavip.bounces.google.com>) id 1sxysa-00009c-T4 for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:16 -0400 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6e2b049b64aso81156477b3.3 for ; Mon, 07 Oct 2024 18:19:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350351; x=1728955151; 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=bFIqfrB60fzUJwtasXiqxuXbxvJUBaZy8yqqf9RYqyc=; b=x1peIlfIAg5KUmhXJxqFRQ2JwbyBiiA2MOZrzbRJn+dFSPPF2i+C7+DLYaupQuDwq9 E2Rt72z3rC2arKSNOc9xO0BhWpTPGwh9UKOSxFsf4UEqCwLoNWlchCN/j/2xcephNA2f n9Xwmg1EkwIaG9Qn3hsDrevPPgRz+a7r67koCKG9uGVmdWh/e+MqXxLB3l+whqcDF+OI AJJ9hzzs1wqOKz8vAg7mdgh98iTGqZdOngksyrbtw2kq1SWKevKLxbfBq2k0HhFd6MsU ZSoHkDuYSQjMF5y+KCEFjnjAfhXHNRPE2so2NEbfAku6dh0T+06gQfkap1BS4bQVP1WU Elxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350351; x=1728955151; 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=bFIqfrB60fzUJwtasXiqxuXbxvJUBaZy8yqqf9RYqyc=; b=CcxDY6DrkVmFXOvBqHwwpaOcsxfDOstM4MunzEqeWI/LOEgcJPz4UUyCrWCvyyfSC3 rsXUdKHZPJplydD/YHQMennAb2M11DR0tw5HO58MqztnNBYkCgQoxMbH5g8pxGBoX5yc E8NOubH+3fIehav7Imew4TC8Nezu8EKOMtNCMe+Ij5UPzkjg6yzDrldWpKVgn3LZ5evx N80N41JhMF+LipH3RUbQLuIuzchLmwtaU3lduRwTW6bFNC3ZM74YKI3T0lNNICHg3LsT GBfdjkJC59kjc6MpiSdfcSJ49Y36AnvaeStBWhfnwlYDJYABNZI/e1nMTCgTa4Vl8Rxw GniA== X-Gm-Message-State: AOJu0YwH4QN0fndhBvGHjC9m1ngrUb2VIU98tTLbUZ/mh7wsPihKKZmR TqNEHHPSjUFMZg5Ik/ZrxRK/I649yr+9pxm9GRC7f2YzC18NHImFGAcc3R05L2CyVG+sioxxvzE dSj45GHj1sQs16E8106w3MNXIXiPtLtnuQWNyk7yCViGGGYRnlTlFJjfbe2yU0gLTVc0vJl0Mbg ZfyfGwV3+WiGYFL4fFZsK8+L963Q== X-Google-Smtp-Source: AGHT+IGkuD7TbREcq6U/rFFH7/EYiI9O0MyX/NGirkYsV/sq33w1AV5NrldGAUI8PuBzb2XtTF0vKNw1DQ== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a05:690c:945:b0:6db:7b3d:b414 with SMTP id 00721157ae682-6e2c6e9b946mr1970347b3.0.1728350350652; Mon, 07 Oct 2024 18:19:10 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:35 -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-10-tavip@google.com> Subject: [PATCH v2 09/25] hw/ssi: add support for flexcomm spi 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::114a; envelope-from=3jogEZwUKCu8kRmZgXffXcV.TfdhVdl-UVmVcefeXel.fiX@flex--tavip.bounces.google.com; helo=mail-yw1-x114a.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=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 @google.com) X-ZM-MESSAGEID: 1728350712765116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Sebastian Ene Add support for NXP's flexcomm spi. It supports FIFO access, interrupts and master mode only. It does not support DMA. The patch includes an automatically generated header which contains the register layout and helpers. The header can be regenerated with the svd-flexcomm-spi target when the build is configured with --enable-mcux-soc-svd. Signed-off-by: Sebastian Ene [tavip: add suport for CFG.SPOL, CFG.LSBF, TX control flags per FIFO entry and 8/16 bit access to FIFORD and FIFOWR, convert to Resettable interface, add support for migration] Signed-off-by: Octavian Purdila --- include/hw/arm/svd/flexcomm_spi.h | 327 +++++++++++++++++++++++ include/hw/misc/flexcomm.h | 2 + include/hw/ssi/flexcomm_spi.h | 36 +++ hw/misc/flexcomm.c | 3 + hw/ssi/flexcomm_spi.c | 422 ++++++++++++++++++++++++++++++ hw/arm/svd/meson.build | 4 + hw/misc/Kconfig | 1 + hw/ssi/meson.build | 1 + hw/ssi/trace-events | 5 + 9 files changed, 801 insertions(+) create mode 100644 include/hw/arm/svd/flexcomm_spi.h create mode 100644 include/hw/ssi/flexcomm_spi.h create mode 100644 hw/ssi/flexcomm_spi.c diff --git a/include/hw/arm/svd/flexcomm_spi.h b/include/hw/arm/svd/flexcom= m_spi.h new file mode 100644 index 0000000000..c9ab2c661a --- /dev/null +++ b/include/hw/arm/svd/flexcomm_spi.h @@ -0,0 +1,327 @@ +/* + * 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" + +/* Serial Peripheral Interfaces (SPI) */ +#define FLEXCOMM_SPI_REGS_NO (1024) + +/* Configuration Register */ +REG32(FLEXCOMM_SPI_CFG, 0x400); +/* SPI Enable */ +FIELD(FLEXCOMM_SPI_CFG, ENABLE, 0, 1); +/* Master Mode Select */ +FIELD(FLEXCOMM_SPI_CFG, MASTER, 2, 1); +/* LSB First Mode Enable */ +FIELD(FLEXCOMM_SPI_CFG, LSBF, 3, 1); +/* Clock Phase Select */ +FIELD(FLEXCOMM_SPI_CFG, CPHA, 4, 1); +/* Clock Polarity Select */ +FIELD(FLEXCOMM_SPI_CFG, CPOL, 5, 1); +/* Loopback Mode Enable */ +FIELD(FLEXCOMM_SPI_CFG, LOOP, 7, 1); +/* SSEL0 Polarity Select */ +FIELD(FLEXCOMM_SPI_CFG, SPOL0, 8, 1); +/* SSEL1 Polarity Select */ +FIELD(FLEXCOMM_SPI_CFG, SPOL1, 9, 1); +/* SSEL2 Polarity Select */ +FIELD(FLEXCOMM_SPI_CFG, SPOL2, 10, 1); +/* SSEL3 Polarity Select */ +FIELD(FLEXCOMM_SPI_CFG, SPOL3, 11, 1); + +/* Status Register */ +REG32(FLEXCOMM_SPI_STAT, 0x408); +/* Slave Select Assert */ +FIELD(FLEXCOMM_SPI_STAT, SSA, 4, 1); +/* Slave Select Deassert */ +FIELD(FLEXCOMM_SPI_STAT, SSD, 5, 1); +/* Stalled Status Flag */ +FIELD(FLEXCOMM_SPI_STAT, STALLED, 6, 1); +/* End Transfer Control */ +FIELD(FLEXCOMM_SPI_STAT, ENDTRANSFER, 7, 1); +/* Master Idle Status Flag */ +FIELD(FLEXCOMM_SPI_STAT, MSTIDLE, 8, 1); + +/* Interrupt Enable Register */ +REG32(FLEXCOMM_SPI_INTENSET, 0x40C); + +/* Interrupt Enable Clear Register */ +REG32(FLEXCOMM_SPI_INTENCLR, 0x410); + +/* Interrupt Status Register */ +REG32(FLEXCOMM_SPI_INTSTAT, 0x428); + +/* FIFO Configuration Register */ +REG32(FLEXCOMM_SPI_FIFOCFG, 0xE00); +/* Enable the Transmit FIFO */ +FIELD(FLEXCOMM_SPI_FIFOCFG, ENABLETX, 0, 1); +/* Enable the Receive FIFO */ +FIELD(FLEXCOMM_SPI_FIFOCFG, ENABLERX, 1, 1); +/* Empty Command for the Transmit FIFO */ +FIELD(FLEXCOMM_SPI_FIFOCFG, EMPTYTX, 16, 1); +/* Empty Command for the Receive FIFO */ +FIELD(FLEXCOMM_SPI_FIFOCFG, EMPTYRX, 17, 1); + +/* FIFO Status Register */ +REG32(FLEXCOMM_SPI_FIFOSTAT, 0xE04); +/* TX FIFO Error */ +FIELD(FLEXCOMM_SPI_FIFOSTAT, TXERR, 0, 1); +/* RX FIFO Error */ +FIELD(FLEXCOMM_SPI_FIFOSTAT, RXERR, 1, 1); +/* Peripheral Interrupt */ +FIELD(FLEXCOMM_SPI_FIFOSTAT, PERINT, 3, 1); +/* Transmit FIFO Empty */ +FIELD(FLEXCOMM_SPI_FIFOSTAT, TXEMPTY, 4, 1); +/* Transmit FIFO is Not Full */ +FIELD(FLEXCOMM_SPI_FIFOSTAT, TXNOTFULL, 5, 1); +/* Receive FIFO is Not Empty */ +FIELD(FLEXCOMM_SPI_FIFOSTAT, RXNOTEMPTY, 6, 1); +/* Receive FIFO is Full */ +FIELD(FLEXCOMM_SPI_FIFOSTAT, RXFULL, 7, 1); +/* Transmit FIFO Current Level */ +FIELD(FLEXCOMM_SPI_FIFOSTAT, TXLVL, 8, 5); +/* Receive FIFO Current Level */ +FIELD(FLEXCOMM_SPI_FIFOSTAT, RXLVL, 16, 5); + +/* FIFO Trigger Register */ +REG32(FLEXCOMM_SPI_FIFOTRIG, 0xE08); +/* Transmit FIFO Level Trigger Enable */ +FIELD(FLEXCOMM_SPI_FIFOTRIG, TXLVLENA, 0, 1); +/* Receive FIFO Level Trigger Enable */ +FIELD(FLEXCOMM_SPI_FIFOTRIG, RXLVLENA, 1, 1); +/* Transmit FIFO Level Trigger Point */ +FIELD(FLEXCOMM_SPI_FIFOTRIG, TXLVL, 8, 4); +/* Trigger when the TX FIFO becomes empty */ +#define FLEXCOMM_SPI_FIFOTRIG_TXLVL_TXLVL0 0 +/* Trigger when the TX FIFO level decreases to 1 entry */ +#define FLEXCOMM_SPI_FIFOTRIG_TXLVL_TXLVL1 1 +/* Trigger when the TX FIFO level decreases to 15 entries (is no longer fu= ll) */ +#define FLEXCOMM_SPI_FIFOTRIG_TXLVL_TXLVL15 15 +/* Receive FIFO Level Trigger Point */ +FIELD(FLEXCOMM_SPI_FIFOTRIG, RXLVL, 16, 4); +/* Trigger when the RX FIFO has received 1 entry (is no longer empty) */ +#define FLEXCOMM_SPI_FIFOTRIG_RXLVL_RXLVL1 0 +/* Trigger when the RX FIFO has received 2 entries */ +#define FLEXCOMM_SPI_FIFOTRIG_RXLVL_RXLVL2 1 +/* Trigger when the RX FIFO has received 16 entries (has become full) */ +#define FLEXCOMM_SPI_FIFOTRIG_RXLVL_RXLVL15 15 + +/* FIFO Interrupt Enable Register */ +REG32(FLEXCOMM_SPI_FIFOINTENSET, 0xE10); +/* TX Error Interrupt Enable */ +FIELD(FLEXCOMM_SPI_FIFOINTENSET, TXERR, 0, 1); +/* Receive Error Interrupt Enable */ +FIELD(FLEXCOMM_SPI_FIFOINTENSET, RXERR, 1, 1); +/* Transmit FIFO Level Interrupt Enable */ +FIELD(FLEXCOMM_SPI_FIFOINTENSET, TXLVL, 2, 1); +/* Receive FIFO Level Interrupt Enable */ +FIELD(FLEXCOMM_SPI_FIFOINTENSET, RXLVL, 3, 1); + +/* FIFO Interrupt Enable Clear Register */ +REG32(FLEXCOMM_SPI_FIFOINTENCLR, 0xE14); +/* TX Error Interrupt Enable */ +FIELD(FLEXCOMM_SPI_FIFOINTENCLR, TXERR, 0, 1); +/* Receive Error Interrupt Enable */ +FIELD(FLEXCOMM_SPI_FIFOINTENCLR, RXERR, 1, 1); +/* Transmit FIFO Level Interrupt Enable */ +FIELD(FLEXCOMM_SPI_FIFOINTENCLR, TXLVL, 2, 1); +/* Receive FIFO Level Interrupt Enable */ +FIELD(FLEXCOMM_SPI_FIFOINTENCLR, RXLVL, 3, 1); + +/* FIFO Interrupt Status Register */ +REG32(FLEXCOMM_SPI_FIFOINTSTAT, 0xE18); +/* TX FIFO Error Interrupt Status */ +FIELD(FLEXCOMM_SPI_FIFOINTSTAT, TXERR, 0, 1); +/* RX FIFO Error Interrupt Status */ +FIELD(FLEXCOMM_SPI_FIFOINTSTAT, RXERR, 1, 1); +/* Transmit FIFO Level Interrupt Status */ +FIELD(FLEXCOMM_SPI_FIFOINTSTAT, TXLVL, 2, 1); +/* Receive FIFO Level Interrupt Status */ +FIELD(FLEXCOMM_SPI_FIFOINTSTAT, RXLVL, 3, 1); +/* Peripheral Interrupt Status */ +FIELD(FLEXCOMM_SPI_FIFOINTSTAT, PERINT, 4, 1); + +/* FIFO Write Data Register */ +REG32(FLEXCOMM_SPI_FIFOWR, 0xE20); +/* Transmit Data to the FIFO */ +FIELD(FLEXCOMM_SPI_FIFOWR, TXDATA, 0, 16); +/* Transmit Slave Select 0 */ +FIELD(FLEXCOMM_SPI_FIFOWR, TXSSEL0_N, 16, 1); +/* Transmit Slave Select 1 */ +FIELD(FLEXCOMM_SPI_FIFOWR, TXSSEL1_N, 17, 1); +/* Transmit Slave Select 2 */ +FIELD(FLEXCOMM_SPI_FIFOWR, TXSSEL2_N, 18, 1); +/* Transmit Slave Select 3 */ +FIELD(FLEXCOMM_SPI_FIFOWR, TXSSEL3_N, 19, 1); +/* End of Transfer */ +FIELD(FLEXCOMM_SPI_FIFOWR, EOT, 20, 1); +/* End of Frame */ +FIELD(FLEXCOMM_SPI_FIFOWR, EOF, 21, 1); +/* Receive Ignore */ +FIELD(FLEXCOMM_SPI_FIFOWR, RXIGNORE, 22, 1); +/* Transmit Ignore */ +FIELD(FLEXCOMM_SPI_FIFOWR, TXIGNORE, 23, 1); +/* Data Length */ +FIELD(FLEXCOMM_SPI_FIFOWR, LEN, 24, 4); +/* Data transfer is 4 bits in length */ +#define FLEXCOMM_SPI_FIFOWR_LEN_LEN_4BITS 3 +/* Data transfer is 5 bits in length */ +#define FLEXCOMM_SPI_FIFOWR_LEN_LEN_5BITS 4 +/* Data transfer is 16 bits in length */ +#define FLEXCOMM_SPI_FIFOWR_LEN_LEN_16BITS 15 + +/* FIFO Read Data Register */ +REG32(FLEXCOMM_SPI_FIFORD, 0xE30); +/* Received Data from the FIFO */ +FIELD(FLEXCOMM_SPI_FIFORD, RXDATA, 0, 16); +/* Slave Select 0 for Receive */ +FIELD(FLEXCOMM_SPI_FIFORD, RXSSEL0_N, 16, 1); +/* Slave Select 1 for Receive */ +FIELD(FLEXCOMM_SPI_FIFORD, RXSSEL1_N, 17, 1); +/* Slave Select 2 for Receive */ +FIELD(FLEXCOMM_SPI_FIFORD, RXSSEL2_N, 18, 1); +/* Slave Select 3 for Receive */ +FIELD(FLEXCOMM_SPI_FIFORD, RXSSEL3_N, 19, 1); +/* Start of Transfer Flag */ +FIELD(FLEXCOMM_SPI_FIFORD, SOT, 20, 1); + +/* FIFO Data Read with no FIFO Pop Register */ +REG32(FLEXCOMM_SPI_FIFORDNOPOP, 0xE40); +/* Received Data from the FIFO */ +FIELD(FLEXCOMM_SPI_FIFORDNOPOP, RXDATA, 0, 16); +/* Slave Select 0 for Receive */ +FIELD(FLEXCOMM_SPI_FIFORDNOPOP, RXSSEL0_N, 16, 1); +/* Slave Select 1 for Receive */ +FIELD(FLEXCOMM_SPI_FIFORDNOPOP, RXSSEL1_N, 17, 1); +/* Slave Select 2 for Receive */ +FIELD(FLEXCOMM_SPI_FIFORDNOPOP, RXSSEL2_N, 18, 1); +/* Slave Select 3 for Receive */ +FIELD(FLEXCOMM_SPI_FIFORDNOPOP, RXSSEL3_N, 19, 1); +/* Start of Transfer Flag */ +FIELD(FLEXCOMM_SPI_FIFORDNOPOP, SOT, 20, 1); + +/* FIFO Size Register */ +REG32(FLEXCOMM_SPI_FIFOSIZE, 0xE48); +/* FIFO Size */ +FIELD(FLEXCOMM_SPI_FIFOSIZE, FIFOSIZE, 0, 5); + + +#define FLEXCOMM_SPI_REGISTER_ACCESS_INFO_ARRAY(_name) \ + struct RegisterAccessInfo _name[FLEXCOMM_SPI_REGS_NO] =3D { \ + [0 ... FLEXCOMM_SPI_REGS_NO - 1] =3D { \ + .name =3D "", \ + .addr =3D -1, \ + }, \ + [0x100] =3D { \ + .name =3D "CFG", \ + .addr =3D 0x400, \ + .ro =3D 0xFFFFF042, \ + .reset =3D 0x0, \ + }, \ + [0x101] =3D { \ + .name =3D "DLY", \ + .addr =3D 0x404, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0x0, \ + }, \ + [0x102] =3D { \ + .name =3D "STAT", \ + .addr =3D 0x408, \ + .ro =3D 0xFFFFFF4F, \ + .reset =3D 0x100, \ + }, \ + [0x103] =3D { \ + .name =3D "INTENSET", \ + .addr =3D 0x40C, \ + .ro =3D 0xFFFFFECF, \ + .reset =3D 0x0, \ + }, \ + [0x104] =3D { \ + .name =3D "INTENCLR", \ + .addr =3D 0x410, \ + .ro =3D 0xFFFFFECF, \ + .reset =3D 0x0, \ + }, \ + [0x109] =3D { \ + .name =3D "DIV", \ + .addr =3D 0x424, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0x0, \ + }, \ + [0x10A] =3D { \ + .name =3D "INTSTAT", \ + .addr =3D 0x428, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x380] =3D { \ + .name =3D "FIFOCFG", \ + .addr =3D 0xE00, \ + .ro =3D 0xFFF80FFC, \ + .reset =3D 0x0, \ + }, \ + [0x381] =3D { \ + .name =3D "FIFOSTAT", \ + .addr =3D 0xE04, \ + .ro =3D 0xFFFFFFFC, \ + .reset =3D 0x30, \ + }, \ + [0x382] =3D { \ + .name =3D "FIFOTRIG", \ + .addr =3D 0xE08, \ + .ro =3D 0xFFF0F0FC, \ + .reset =3D 0x0, \ + }, \ + [0x384] =3D { \ + .name =3D "FIFOINTENSET", \ + .addr =3D 0xE10, \ + .ro =3D 0xFFFFFFF0, \ + .reset =3D 0x0, \ + }, \ + [0x385] =3D { \ + .name =3D "FIFOINTENCLR", \ + .addr =3D 0xE14, \ + .ro =3D 0xFFFFFFF0, \ + .reset =3D 0x0, \ + }, \ + [0x386] =3D { \ + .name =3D "FIFOINTSTAT", \ + .addr =3D 0xE18, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x388] =3D { \ + .name =3D "FIFOWR", \ + .addr =3D 0xE20, \ + .ro =3D 0xF0000000, \ + .reset =3D 0x0, \ + }, \ + [0x38C] =3D { \ + .name =3D "FIFORD", \ + .addr =3D 0xE30, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x390] =3D { \ + .name =3D "FIFORDNOPOP", \ + .addr =3D 0xE40, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x392] =3D { \ + .name =3D "FIFOSIZE", \ + .addr =3D 0xE48, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x3FF] =3D { \ + .name =3D "ID", \ + .addr =3D 0xFFC, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0xE0201200, \ + }, \ + } diff --git a/include/hw/misc/flexcomm.h b/include/hw/misc/flexcomm.h index c9f1cd3890..757453df97 100644 --- a/include/hw/misc/flexcomm.h +++ b/include/hw/misc/flexcomm.h @@ -17,6 +17,7 @@ #include "qemu/fifo32.h" #include "hw/char/flexcomm_usart.h" #include "hw/i2c/flexcomm_i2c.h" +#include "hw/ssi/flexcomm_spi.h" =20 #define FLEXCOMM_FUNC_USART 0 #define FLEXCOMM_FUNC_SPI 1 @@ -50,6 +51,7 @@ struct FlexcommState { Fifo32 tx_fifo; FlexcommUsartState usart; FlexcommI2cState i2c; + FlexcommSpiState spi; }; =20 #endif /* HW_FLEXCOMM_H */ diff --git a/include/hw/ssi/flexcomm_spi.h b/include/hw/ssi/flexcomm_spi.h new file mode 100644 index 0000000000..c39cc33de4 --- /dev/null +++ b/include/hw/ssi/flexcomm_spi.h @@ -0,0 +1,36 @@ +/* + * QEMU model for NXP's FLEXCOMM SPI + * + * 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_FLEXCOMM_SPI_H +#define HW_FLEXCOMM_SPI_H + +#include "hw/misc/flexcomm_function.h" +#include "hw/ssi/ssi.h" + +#define TYPE_FLEXCOMM_SPI "flexcomm-spi" +OBJECT_DECLARE_TYPE(FlexcommSpiState, FlexcommSpiClass, FLEXCOMM_SPI); + +struct FlexcommSpiState { + FlexcommFunction parent_obj; + + SSIBus *bus; + qemu_irq cs[4]; + bool cs_asserted[4]; + uint32_t tx_ctrl; +}; + +struct FlexcommSpiClass { + FlexcommFunctionClass parent_obj; + + FlexcommFunctionSelect select; +}; + +#endif /* HW_FLEXCOMM_SPI_H */ diff --git a/hw/misc/flexcomm.c b/hw/misc/flexcomm.c index b1a2f01acf..fef220eb5b 100644 --- a/hw/misc/flexcomm.c +++ b/hw/misc/flexcomm.c @@ -25,6 +25,7 @@ #include "hw/arm/svd/flexcomm_usart.h" #include "hw/char/flexcomm_usart.h" #include "hw/i2c/flexcomm_i2c.h" +#include "hw/ssi/flexcomm_spi.h" =20 #define REG(s, reg) (s->regs[R_FLEXCOMM_##reg]) #define RF_WR(s, reg, field, val) \ @@ -222,6 +223,7 @@ static void flexcomm_init(Object *obj) sysbus_init_irq(sbd, &s->irq); object_initialize_child(obj, "usart", &s->usart, TYPE_FLEXCOMM_USART); object_initialize_child(obj, "i2c", &s->i2c, TYPE_FLEXCOMM_I2C); + object_initialize_child(obj, "spi", &s->spi, TYPE_FLEXCOMM_SPI); } =20 static void flexcomm_finalize(Object *obj) @@ -253,6 +255,7 @@ static void flexcomm_realize(DeviceState *dev, Error **= errp) memory_region_add_subregion_overlap(&s->container, 0, &s->mmio, -1); flexcomm_func_realize_and_unref(FLEXCOMM_FUNCTION(&s->usart), errp); flexcomm_func_realize_and_unref(FLEXCOMM_FUNCTION(&s->i2c), errp); + flexcomm_func_realize_and_unref(FLEXCOMM_FUNCTION(&s->spi), errp); } =20 static const VMStateDescription vmstate_flexcomm =3D { diff --git a/hw/ssi/flexcomm_spi.c b/hw/ssi/flexcomm_spi.c new file mode 100644 index 0000000000..d8ecd37024 --- /dev/null +++ b/hw/ssi/flexcomm_spi.c @@ -0,0 +1,422 @@ +/* + * QEMU model for NXP's FLEXCOMM SPI + * + * 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 "hw/irq.h" +#include "hw/qdev-properties.h" +#include "qemu/cutils.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "exec/address-spaces.h" +#include "qapi/error.h" +#include "trace.h" +#include "migration/vmstate.h" +#include "hw/misc/flexcomm.h" +#include "hw/arm/svd/flexcomm_spi.h" + +#define REG(s, reg) (s->regs[R_FLEXCOMM_SPI_##reg]) +#define RF_WR(s, reg, field, val) \ + ARRAY_FIELD_DP32(s->regs, FLEXCOMM_SPI_##reg, field, val) +#define RF_RD(s, reg, field) \ + ARRAY_FIELD_EX32(s->regs, FLEXCOMM_SPI_##reg, field) + +#define FLEXCOMM_SSEL_ASSERTED (0) +#define FLEXCOMM_SSEL_DEASSERTED (1) + +#define FLEXCOMM_SPI_FIFOWR_LEN_MIN (3) +#define FLEXCOMM_SPI_FIFOWR_LEN_MAX (15) + +static const FLEXCOMM_SPI_REGISTER_ACCESS_INFO_ARRAY(reg_info); + +static void flexcomm_spi_reset(FlexcommFunction *f) +{ + for (int i =3D 0; i < FLEXCOMM_SPI_REGS_NO; i++) { + hwaddr addr =3D reg_info[i].addr; + + if (addr !=3D -1) { + struct RegisterInfo ri =3D { + .data =3D &f->regs[addr / 4], + .data_size =3D 4, + .access =3D ®_info[i], + }; + + register_reset(&ri); + } + } + + RF_WR(f, FIFOSIZE, FIFOSIZE, 0x8); +} + +static void flexcomm_spi_irq_update(FlexcommFunction *f) +{ + bool irq, per_irqs, fifo_irqs, enabled =3D RF_RD(f, CFG, ENABLE); + + flexcomm_update_fifostat(f); + fifo_irqs =3D REG(f, FIFOINTSTAT) & REG(f, FIFOINTENSET); + + REG(f, INTSTAT) =3D REG(f, STAT) & REG(f, INTENSET); + per_irqs =3D REG(f, INTSTAT) !=3D 0; + + irq =3D enabled && (fifo_irqs || per_irqs); + + trace_flexcomm_spi_irq(DEVICE(f)->id, irq, fifo_irqs, per_irqs, enable= d); + flexcomm_set_irq(f, irq); +} + +static void flexcomm_spi_select(FlexcommFunction *f, bool selected) +{ + FlexcommSpiState *s =3D FLEXCOMM_SPI(f); + FlexcommSpiClass *sc =3D FLEXCOMM_SPI_GET_CLASS(f); + + if (selected) { + bool spol[] =3D { + RF_RD(f, CFG, SPOL0), RF_RD(f, CFG, SPOL1), RF_RD(f, CFG, SPOL= 2), + RF_RD(f, CFG, SPOL3), + }; + + flexcomm_spi_reset(f); + for (int i =3D 0; i < ARRAY_SIZE(s->cs); i++) { + s->cs_asserted[i] =3D false; + qemu_set_irq(s->cs[i], !spol[i]); + } + } + sc->select(f, selected); +} + +static MemTxResult flexcomm_spi_reg_read(void *opaque, hwaddr addr, + uint64_t *data, unsigned size, + MemTxAttrs attrs) +{ + FlexcommFunction *f =3D FLEXCOMM_FUNCTION(opaque); + MemTxResult ret =3D MEMTX_OK; + const struct RegisterAccessInfo *rai =3D ®_info[addr / 4]; + + /* + * Allow 8/16 bits access to the FIFORD LSB half-word. This is support= ed by + * hardware and required for 1/2 byte(s) width DMA transfers. + */ + if (size !=3D 4 && addr !=3D A_FLEXCOMM_SPI_FIFORD) { + ret =3D MEMTX_ERROR; + goto out; + } + + switch (addr) { + case A_FLEXCOMM_SPI_FIFORD: + { + /* If we are running in loopback mode get the data from TX FIFO */ + if (RF_RD(f, CFG, LOOP) && + RF_RD(f, CFG, MASTER)) + { + if (!fifo32_is_empty(f->tx_fifo)) { + *data =3D fifo32_pop(f->tx_fifo); + } + break; + } + + if (!fifo32_is_empty(f->rx_fifo)) { + *data =3D fifo32_pop(f->rx_fifo); + } + break; + } + case A_FLEXCOMM_SPI_FIFORDNOPOP: + { + if (!fifo32_is_empty(f->rx_fifo)) { + *data =3D fifo32_peek(f->rx_fifo); + } + break; + } + default: + *data =3D f->regs[addr / 4]; + break; + } + + flexcomm_spi_irq_update(f); + +out: + trace_flexcomm_spi_reg_read(DEVICE(f)->id, rai->name, addr, *data); + return ret; +} + +static uint32_t fifowr_len_bits(uint32_t val) +{ + int len =3D FIELD_EX32(val, FLEXCOMM_SPI_FIFOWR, LEN); + + if (len < FLEXCOMM_SPI_FIFOWR_LEN_MIN || + len > FLEXCOMM_SPI_FIFOWR_LEN_MAX) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid spi xfer len %d\n", + __func__, val); + return 0; + } + + return len + 1; +} + +static inline uint32_t fifowr_len_bytes(uint32_t val) +{ + return fifowr_len_bits(val) > 8 ? 2 : 1; +} + +static uint32_t flexcomm_spi_xfer_word(FlexcommSpiState *s, uint32_t out_d= ata, + int bytes, bool be) +{ + uint32_t word =3D 0; + int out =3D 0; + + for (int i =3D 0; i < bytes; i++) { + if (be) { + int byte_offset =3D bytes - i - 1; + out =3D (out_data & (0xFF << byte_offset * 8)) >> byte_offset = * 8; + word |=3D ssi_transfer(s->bus, out) << byte_offset * 8; + } else { + out =3D (out_data & (0xFF << i * 8)) >> i * 8; + word |=3D ssi_transfer(s->bus, out) << i * 8; + } + } + + return word; +} + +static uint32_t flexcomm_spi_get_ss_mask(FlexcommSpiState *s, + uint32_t txfifo_val) +{ + FlexcommFunction *f =3D FLEXCOMM_FUNCTION(s); + + uint32_t slave_select_mask =3D 0; + bool ss[] =3D { + FIELD_EX32(txfifo_val, FLEXCOMM_SPI_FIFOWR, TXSSEL0_N), + FIELD_EX32(txfifo_val, FLEXCOMM_SPI_FIFOWR, TXSSEL1_N), + FIELD_EX32(txfifo_val, FLEXCOMM_SPI_FIFOWR, TXSSEL2_N), + FIELD_EX32(txfifo_val, FLEXCOMM_SPI_FIFOWR, TXSSEL3_N), + }; + bool spol[] =3D { + RF_RD(f, CFG, SPOL0), RF_RD(f, CFG, SPOL1), RF_RD(f, CFG, SPOL2), + RF_RD(f, CFG, SPOL3), + }; + + for (int i =3D 0; i < ARRAY_SIZE(s->cs); i++) { + int irq_level =3D ss[i] ? spol[i] : !spol[i]; + + slave_select_mask |=3D (ss[i] << i); + s->cs_asserted[i] =3D ss[i]; + qemu_set_irq(s->cs[i], irq_level); + } + + return slave_select_mask; +} + +static MemTxResult flexcomm_spi_reg_write(void *opaque, hwaddr addr, + uint64_t value, unsigned size, + MemTxAttrs attrs) +{ + FlexcommFunction *f =3D FLEXCOMM_FUNCTION(opaque); + FlexcommSpiState *s =3D FLEXCOMM_SPI(opaque); + const struct RegisterAccessInfo *rai =3D ®_info[addr / 4]; + struct RegisterInfo ri =3D { + .data =3D &f->regs[addr / 4], + .data_size =3D 4, + .access =3D rai, + }; + MemTxResult ret =3D MEMTX_OK; + + trace_flexcomm_spi_reg_write(DEVICE(f)->id, rai->name, addr, value); + + /* + * Allow 8/16 bits access to both the FIFOWR MSB and LSB half-words. T= he + * former is required for updating the control bits while the latter f= or DMA + * transfers of 1/2 byte(s) width. + */ + if (size !=3D 4 && (addr / 4 !=3D R_FLEXCOMM_SPI_FIFOWR)) { + return MEMTX_ERROR; + } + + switch (addr) { + case A_FLEXCOMM_SPI_CFG: + { + register_write(&ri, value, ~0, NULL, false); + break; + } + case A_FLEXCOMM_SPI_INTENCLR: + { + register_write(&ri, value, ~0, NULL, false); + REG(f, INTENSET) &=3D ~REG(f, INTENCLR); + break; + } + case A_FLEXCOMM_SPI_FIFOCFG: + { + register_write(&ri, value, ~0, NULL, false); + flexcomm_reset_fifos(f); + break; + } + case A_FLEXCOMM_SPI_FIFOSTAT: + { + flexcomm_clear_fifostat(f, value); + break; + } + case A_FLEXCOMM_SPI_FIFOINTENSET: + { + REG(f, FIFOINTENSET) |=3D value; + break; + } + case A_FLEXCOMM_SPI_FIFOINTENCLR: + { + register_write(&ri, value, ~0, NULL, false); + REG(f, FIFOINTENSET) &=3D ~REG(f, FIFOINTENCLR); + break; + } + /* update control bits but don't push into the FIFO */ + case A_FLEXCOMM_SPI_FIFOWR + 2: + { + if (value !=3D 0) { + s->tx_ctrl =3D value << 16; + } + break; + } + /* update control bits but don't push into the FIFO */ + case A_FLEXCOMM_SPI_FIFOWR + 3: + { + if (value !=3D 0) { + s->tx_ctrl =3D value << 24; + } + break; + } + case A_FLEXCOMM_SPI_FIFOWR: + { + /* fifo value contains both data and control bits */ + uint32_t txfifo_val; + uint16_t tx_data =3D FIELD_EX32(value, FLEXCOMM_SPI_FIFOWR, TXDATA= ); + uint32_t tx_ctrl =3D value & 0xffff0000; + + if (size > 2 && tx_ctrl !=3D 0) { + /* non-zero writes to control bits updates them */ + s->tx_ctrl =3D tx_ctrl; + } + + /* push the data and control bits into the FIFO */ + txfifo_val =3D tx_data | s->tx_ctrl; + + if (!fifo32_is_full(f->tx_fifo)) { + fifo32_push(f->tx_fifo, txfifo_val); + } + + if (!RF_RD(f, CFG, ENABLE) || !RF_RD(f, FIFOCFG, ENABLETX)) { + break; + } + + /* + * On loopback mode we just insert the values in the TX FIFO. On s= lave + * mode master needs to initiate the SPI transfer. + */ + if (RF_RD(f, CFG, LOOP) || !RF_RD(f, CFG, MASTER)) { + break; + } + + while (!fifo32_is_empty(f->tx_fifo)) { + txfifo_val =3D fifo32_pop(f->tx_fifo); + + uint32_t ss_mask =3D flexcomm_spi_get_ss_mask(s, txfifo_val); + uint32_t data =3D FIELD_EX32(txfifo_val, FLEXCOMM_SPI_FIFOWR, = TXDATA); + uint8_t bytes =3D fifowr_len_bytes(txfifo_val); + bool msb =3D !RF_RD(f, CFG, LSBF); + uint32_t val32; + + val32 =3D flexcomm_spi_xfer_word(s, data, bytes, msb); + + if (!fifo32_is_full(f->rx_fifo)) { + /* Append the mask that informs which client is active */ + val32 |=3D (ss_mask << R_FLEXCOMM_SPI_FIFORD_RXSSEL0_N_SHI= FT); + fifo32_push(f->rx_fifo, val32); + } + + /* If this is the end of the transfer raise the CS line */ + if (FIELD_EX32(txfifo_val, FLEXCOMM_SPI_FIFOWR, EOT)) { + bool spol[ARRAY_SIZE(s->cs)] =3D { + RF_RD(f, CFG, SPOL0), + RF_RD(f, CFG, SPOL1), + RF_RD(f, CFG, SPOL2), + RF_RD(f, CFG, SPOL3), + }; + + for (int i =3D 0; i < ARRAY_SIZE(s->cs); i++) { + if (s->cs_asserted[i]) { + s->cs_asserted[i] =3D false; + qemu_set_irq(s->cs[i], !spol[i]); + } + } + } + } + break; + } + default: + register_write(&ri, value, ~0, NULL, false); + break; + } + + flexcomm_spi_irq_update(f); + + return ret; +} + +static const MemoryRegionOps flexcomm_spi_ops =3D { + .read_with_attrs =3D flexcomm_spi_reg_read, + .write_with_attrs =3D flexcomm_spi_reg_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .valid =3D { + .min_access_size =3D 1, + .max_access_size =3D 4, + .unaligned =3D false, + }, +}; + +static void flexcomm_spi_realize(DeviceState *dev, Error **error) +{ + FlexcommSpiState *s =3D FLEXCOMM_SPI(dev); + + s->bus =3D ssi_create_bus(DEVICE(s), "bus"); + qdev_init_gpio_out_named(DEVICE(s), s->cs, "cs", ARRAY_SIZE(s->cs)); +} + +static const VMStateDescription vmstate_flexcomm_spi =3D { + .name =3D "flexcomm-spi", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_BOOL_ARRAY(cs_asserted, FlexcommSpiState, 4), + VMSTATE_UINT32(tx_ctrl, FlexcommSpiState), + VMSTATE_END_OF_LIST() + } +}; + +static void flexcomm_spi_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + FlexcommFunctionClass *fc =3D FLEXCOMM_FUNCTION_CLASS(klass); + FlexcommSpiClass *sc =3D FLEXCOMM_SPI_CLASS(klass); + + dc->realize =3D flexcomm_spi_realize; + dc->vmsd =3D &vmstate_flexcomm_spi; + sc->select =3D fc->select; + fc->select =3D flexcomm_spi_select; + fc->name =3D "spi"; + fc->has_fifos =3D true; + fc->mmio_ops =3D &flexcomm_spi_ops; +} + +static const TypeInfo flexcomm_spi_types[] =3D { + { + .name =3D TYPE_FLEXCOMM_SPI, + .parent =3D TYPE_FLEXCOMM_FUNCTION, + .instance_size =3D sizeof(FlexcommSpiState), + .class_init =3D flexcomm_spi_class_init, + .class_size =3D sizeof(FlexcommSpiClass), + }, +}; + +DEFINE_TYPES(flexcomm_spi_types); diff --git a/hw/arm/svd/meson.build b/hw/arm/svd/meson.build index 2542b56294..e7d62a7f35 100644 --- a/hw/arm/svd/meson.build +++ b/hw/arm/svd/meson.build @@ -12,4 +12,8 @@ if get_option('mcux-soc-svd') [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/flexcomm_i2c.h', '-p', 'I2C0', '-t', 'FLEXCOMM_I2C', '--fields', 'CFG TIMEOUT:TOMIN MSTCTL MSTDAT STAT:MSTPENDING,MSTSTAT= E INT*:MSTPENDING* SLV*:']) + run_target('svd-flexcomm-spi', command: svd_gen_header + + [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/flexcomm_spi.h', + '-p', 'SPI0', '-t', 'FLEXCOMM_SPI', + '--fields', 'CFG FIFOCFG:ENABLE*,EMPTY* FIFO*:* INT*: STAT']) endif diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig index 9a244fa01d..b373e651e1 100644 --- a/hw/misc/Kconfig +++ b/hw/misc/Kconfig @@ -216,5 +216,6 @@ config XLNX_VERSAL_TRNG config FLEXCOMM bool select I2C + select SSI =20 source macio/Kconfig diff --git a/hw/ssi/meson.build b/hw/ssi/meson.build index 23cd425ab0..58e0d14b37 100644 --- a/hw/ssi/meson.build +++ b/hw/ssi/meson.build @@ -12,3 +12,4 @@ system_ss.add(when: 'CONFIG_IMX', if_true: files('imx_spi= .c')) system_ss.add(when: 'CONFIG_IBEX', if_true: files('ibex_spi_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')) diff --git a/hw/ssi/trace-events b/hw/ssi/trace-events index 089d269994..f849f1f8be 100644 --- a/hw/ssi/trace-events +++ b/hw/ssi/trace-events @@ -53,3 +53,8 @@ pnv_spi_rx_read_N2frame(void) "" pnv_spi_shift_rx(uint8_t byte, uint32_t index) "byte =3D 0x%2.2x into RDR = from payload index %d" pnv_spi_sequencer_stop_requested(const char* reason) "due to %s" pnv_spi_RDR_match(const char* result) "%s" + +# flexcomm_spi.c +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" --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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=1728350497; cv=none; d=zohomail.com; s=zohoarc; b=c6QfUor7VxvWyFIailndQqZcCdxaqHtmmQHF8o7BXFjHedrg+jRcSr7+ffxH6yphZ1iQX5mibJ2dN9M5o3FSXCGzFPp2CgJJYh16s0qDyiGxWBjfB5efsm8Nb223pBjc0BAJLwOnC+k5vw4Q0G93a4qCAhYU0LUmiqAicFr5E60= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350497; 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=h0g2XEqh5TFAysQ/4BwAuoGhpRYdqAqx4UCuVxyPc+Q=; b=N8r06Duimy5i769oNywlxh2ZPlpFOC8rK2LjOCIrsVW7tcYbbEATukyiAku1OInypV9YQ9iNDhUHyTy/iEp7dj1flIeuZqRv0KWYWaOygbEta/lU8eP4VehOd8JO7o7kBvQiET7GBxHMJZ9VsqGMR7XxStzSx+wHEYUf+tiWZXM= 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 1728350497225447.43002035973745; Mon, 7 Oct 2024 18:21:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxytc-0002zq-JK; Mon, 07 Oct 2024 21:20:18 -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 <3kIgEZwUKCvEmTobiZhhZeX.VhfjXfn-WXoXeghgZgn.hkZ@flex--tavip.bounces.google.com>) id 1sxysp-0007zm-OZ for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:29 -0400 Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3kIgEZwUKCvEmTobiZhhZeX.VhfjXfn-WXoXeghgZgn.hkZ@flex--tavip.bounces.google.com>) id 1sxysf-0000A7-Sb for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:24 -0400 Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-71dfa361499so2100343b3a.0 for ; Mon, 07 Oct 2024 18:19:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350353; x=1728955153; 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=h0g2XEqh5TFAysQ/4BwAuoGhpRYdqAqx4UCuVxyPc+Q=; b=BWB2Afny75Rb0luKXPj/Z3aE7bLX6KYxuUTSFvJ7HRHxF9UZaj+zJnI55M88rD+VUe dSNji5xYX+9n6ZrXv8ra0AkVbpKOu9/cSRIeyw+HCBmQ6aQlYSvXQqRJyoBLRLmgb3l+ OdGB8X9E9uKFbXnW7s7Dja7jzj8tMDi34PQAdTOdyzefcebOtQcUVverPPoY/RP2jwAN 8ZQYoyYRXySh/u6jLaJ3E1i+Rr61RZqAsVRlRuahGWg2DsbmaIsbQN8u2jRMsQh6Gsr6 a4FfrYqavMp6rHv/rjawNJii7DCYa9SOh06Fmq3Uc4uIG1EB+E6hinegJDCsVsZ3dzR7 jPTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350353; x=1728955153; 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=h0g2XEqh5TFAysQ/4BwAuoGhpRYdqAqx4UCuVxyPc+Q=; b=CjQQajGiCt2hOKja+sKAjx0lYZALqwr13oueE+EbtrR+88uV5IpMTg5n8121zlmhCQ Pi98GxguByRPyzIvut/8lvaDbwJf0QXc/0eIbNuCQxX8N1buJGA2/9dwEkwrkvBH1CqK 29Bn+C5cE5/vBdTp3m96Q/75WCnqOUdnsBrgUh/B4RDISVdNY/R0qQQfzJtWaIe0w70m y/IuIB/jaaYyev+hCPnN22ixuMl75/qB6Hluyj1jlGuo6eFhyhfFQLGC+4DUIcoQ5vrw cCQ+ZvOCbxNIz0lrWZzri8R+AnNy2RIh35I8yVbaK9K6QTz+4topabosFdtYflcniiqu uC+g== X-Gm-Message-State: AOJu0Yyko5ovDbanV1rLzcN2wtnzIoKT8wqdL0PSdgWutG3TWWMICMyL NqT7KhFwjbUhBez6jBGi0O6B7DZ1OZVM98l0PygLBl8RhVCezDv7nyMvFDNoCtpGUaNJdmbW7xV mLmPxIR8L5po26S8p1DAla0f/X+ulv5uI0xhheQqXxyweuN+3cee6ih45wHodizT/rj+NEPgfl6 4eeqnWlkktE52u36BDkGYu/h5rhQ== X-Google-Smtp-Source: AGHT+IH2ojZoS4xw100tm4xI4XQvhwctpObQyFtqT+tL5TSw0PUe+TwGlkFXiGZ6lPViV1qB2g5VhYD54w== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a05:6a00:7687:b0:71d:fb06:e79b with SMTP id d2e1a72fcca58-71dfb06ea3amr14557b3a.0.1728350352051; Mon, 07 Oct 2024 18:19:12 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:36 -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-11-tavip@google.com> Subject: [PATCH v2 10/25] hw/misc: add support for RT500's clock controller 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::449; envelope-from=3kIgEZwUKCvEmTobiZhhZeX.VhfjXfn-WXoXeghgZgn.hkZ@flex--tavip.bounces.google.com; helo=mail-pf1-x449.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=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 @google.com) X-ZM-MESSAGEID: 1728350498389116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It supports system and audio PLL initialization and SYSTICK and OSTIMER clock source selection. The patch includes automatically generated headers which contains the register layout and helpers. The headers can be regenerated with the svd-rt500-clkctl0 and svd-rt500-clkctl1 targets when the build is configured with --enable-mcux-soc-svd. Signed-off-by: Octavian Purdila --- include/hw/arm/svd/rt500_clkctl0.h | 509 ++++++++++++++++++++++ include/hw/arm/svd/rt500_clkctl1.h | 675 +++++++++++++++++++++++++++++ include/hw/misc/rt500_clk_freqs.h | 18 + include/hw/misc/rt500_clkctl0.h | 35 ++ include/hw/misc/rt500_clkctl1.h | 36 ++ hw/misc/rt500_clkctl0.c | 253 +++++++++++ hw/misc/rt500_clkctl1.c | 238 ++++++++++ hw/arm/Kconfig | 5 + hw/arm/svd/meson.build | 8 + hw/misc/Kconfig | 3 + hw/misc/meson.build | 1 + hw/misc/trace-events | 8 + 12 files changed, 1789 insertions(+) create mode 100644 include/hw/arm/svd/rt500_clkctl0.h create mode 100644 include/hw/arm/svd/rt500_clkctl1.h create mode 100644 include/hw/misc/rt500_clk_freqs.h create mode 100644 include/hw/misc/rt500_clkctl0.h create mode 100644 include/hw/misc/rt500_clkctl1.h create mode 100644 hw/misc/rt500_clkctl0.c create mode 100644 hw/misc/rt500_clkctl1.c diff --git a/include/hw/arm/svd/rt500_clkctl0.h b/include/hw/arm/svd/rt500_= clkctl0.h new file mode 100644 index 0000000000..89be8ff5fb --- /dev/null +++ b/include/hw/arm/svd/rt500_clkctl0.h @@ -0,0 +1,509 @@ +/* + * 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" + +/* Clock Controller 0 */ +#define RT500_CLKCTL0_REGS_NO (490) + +/* Clock Control 0 */ +REG32(RT500_CLKCTL0_PSCCTL0, 0x10); +/* DSP clock control */ +FIELD(RT500_CLKCTL0_PSCCTL0, DSP_CLK, 1, 1); +/* 128KB ROM Controller clock control */ +FIELD(RT500_CLKCTL0_PSCCTL0, ROM_CTRLR_CLK, 2, 1); + +/* Clock Control 1 */ +REG32(RT500_CLKCTL0_PSCCTL1, 0x14); + +/* Clock Control 2 */ +REG32(RT500_CLKCTL0_PSCCTL2, 0x18); + +/* Clock Control 0 Set */ +REG32(RT500_CLKCTL0_PSCCTL0_SET, 0x40); +/* DSP clock set */ +FIELD(RT500_CLKCTL0_PSCCTL0_SET, DSP_CLK, 1, 1); +/* 128KB ROM Controller clock set */ +FIELD(RT500_CLKCTL0_PSCCTL0_SET, ROM_CTRLR_CLK, 2, 1); + +/* Clock Control 1 Set */ +REG32(RT500_CLKCTL0_PSCCTL1_SET, 0x44); + +/* Clock Control 2 Set */ +REG32(RT500_CLKCTL0_PSCCTL2_SET, 0x48); + +/* Clock Control 0 Clear */ +REG32(RT500_CLKCTL0_PSCCTL0_CLR, 0x70); +/* DSP clock clear */ +FIELD(RT500_CLKCTL0_PSCCTL0_CLR, DSP_CLK, 1, 1); +/* 128KB ROM Controller clock clear */ +FIELD(RT500_CLKCTL0_PSCCTL0_CLR, ROM_CTRLR_CLK, 2, 1); + +/* Clock Control 1 Clear */ +REG32(RT500_CLKCTL0_PSCCTL1_CLR, 0x74); + +/* Clock Control 2 Clear */ +REG32(RT500_CLKCTL0_PSCCTL2_CLR, 0x78); + +/* FRO Clock Status */ +REG32(RT500_CLKCTL0_FROCLKSTATUS, 0x10C); + +/* System PLL0 PFD */ +REG32(RT500_CLKCTL0_SYSPLL0PFD, 0x218); +/* PLL Fractional Divider 0 */ +FIELD(RT500_CLKCTL0_SYSPLL0PFD, PFD0, 0, 6); +/* PFD0 Clock Ready Status Flag */ +FIELD(RT500_CLKCTL0_SYSPLL0PFD, PFD0_CLKRDY, 6, 1); +/* PFD0 Clock Gate */ +FIELD(RT500_CLKCTL0_SYSPLL0PFD, PFD0_CLKGATE, 7, 1); +/* PLL Fractional Divider 1 */ +FIELD(RT500_CLKCTL0_SYSPLL0PFD, PFD1, 8, 6); +/* PFD1 Clock Ready Status Flag */ +FIELD(RT500_CLKCTL0_SYSPLL0PFD, PFD1_CLKRDY, 14, 1); +/* PFD1 Clock Gate */ +FIELD(RT500_CLKCTL0_SYSPLL0PFD, PFD1_CLKGATE, 15, 1); +/* PLL Fractional Divider 2 */ +FIELD(RT500_CLKCTL0_SYSPLL0PFD, PFD2, 16, 6); +/* PFD2 Clock Ready Status Flag */ +FIELD(RT500_CLKCTL0_SYSPLL0PFD, PFD2_CLKRDY, 22, 1); +/* PFD2 Clock Gate */ +FIELD(RT500_CLKCTL0_SYSPLL0PFD, PFD2_CLKGATE, 23, 1); +/* PLL Fractional Divider 3 */ +FIELD(RT500_CLKCTL0_SYSPLL0PFD, PFD3, 24, 6); +/* PFD3 Clock Ready Status Flag */ +FIELD(RT500_CLKCTL0_SYSPLL0PFD, PFD3_CLKRDY, 30, 1); +/* PFD3 Clock Gate */ +FIELD(RT500_CLKCTL0_SYSPLL0PFD, PFD3_CLKGATE, 31, 1); + +/* SYSTICK Functional Clock Select */ +REG32(RT500_CLKCTL0_SYSTICKFCLKSEL, 0x760); +/* Select Clock Source */ +FIELD(RT500_CLKCTL0_SYSTICKFCLKSEL, SEL, 0, 3); +/* Systick Divider Output Clock */ +#define RT500_CLKCTL0_SYSTICKFCLKSEL_SEL_SYSTICK_DIV_OUTPUT 0 +/* Low Power Oscillator Clock (LPOSC) */ +#define RT500_CLKCTL0_SYSTICKFCLKSEL_SEL_LPOSC 1 +/* 32 KHz RTC Clock */ +#define RT500_CLKCTL0_SYSTICKFCLKSEL_SEL_A32KHZ_RTC 2 +/* None; this may be selected to reduce power when no output is needed. */ +#define RT500_CLKCTL0_SYSTICKFCLKSEL_SEL_NONE 7 + +/* SYSTICK Functional Clock Divider */ +REG32(RT500_CLKCTL0_SYSTICKFCLKDIV, 0x764); +/* Clock Divider Value Selection */ +FIELD(RT500_CLKCTL0_SYSTICKFCLKDIV, DIV, 0, 8); +/* Reset the Divider Counter */ +FIELD(RT500_CLKCTL0_SYSTICKFCLKDIV, RESET, 29, 1); +/* Halt the Divider Counter */ +FIELD(RT500_CLKCTL0_SYSTICKFCLKDIV, HALT, 30, 1); +/* Divider status flag */ +FIELD(RT500_CLKCTL0_SYSTICKFCLKDIV, REQFLAG, 31, 1); + + +#define RT500_CLKCTL0_REGISTER_ACCESS_INFO_ARRAY(_name) \ + struct RegisterAccessInfo _name[RT500_CLKCTL0_REGS_NO] =3D { \ + [0 ... RT500_CLKCTL0_REGS_NO - 1] =3D { \ + .name =3D "", \ + .addr =3D -1, \ + }, \ + [0x4] =3D { \ + .name =3D "PSCCTL0", \ + .addr =3D 0x10, \ + .ro =3D 0xA208E0E1, \ + .reset =3D 0x5, \ + }, \ + [0x5] =3D { \ + .name =3D "PSCCTL1", \ + .addr =3D 0x14, \ + .ro =3D 0xFEFE7FF3, \ + .reset =3D 0x0, \ + }, \ + [0x6] =3D { \ + .name =3D "PSCCTL2", \ + .addr =3D 0x18, \ + .ro =3D 0xDFFFFFFC, \ + .reset =3D 0x0, \ + }, \ + [0x10] =3D { \ + .name =3D "PSCCTL0_SET", \ + .addr =3D 0x40, \ + .ro =3D 0xA208E0E1, \ + .reset =3D 0x0, \ + }, \ + [0x11] =3D { \ + .name =3D "PSCCTL1_SET", \ + .addr =3D 0x44, \ + .ro =3D 0xFEFE7FF3, \ + .reset =3D 0x0, \ + }, \ + [0x12] =3D { \ + .name =3D "PSCCTL2_SET", \ + .addr =3D 0x48, \ + .ro =3D 0xDFFFFFFC, \ + .reset =3D 0x0, \ + }, \ + [0x1C] =3D { \ + .name =3D "PSCCTL0_CLR", \ + .addr =3D 0x70, \ + .ro =3D 0xA208E0E1, \ + .reset =3D 0x0, \ + }, \ + [0x1D] =3D { \ + .name =3D "PSCCTL1_CLR", \ + .addr =3D 0x74, \ + .ro =3D 0xFEFE7FF3, \ + .reset =3D 0x0, \ + }, \ + [0x1E] =3D { \ + .name =3D "PSCCTL2_CLR", \ + .addr =3D 0x78, \ + .ro =3D 0xDFFFFFFC, \ + .reset =3D 0x0, \ + }, \ + [0x20] =3D { \ + .name =3D "FRO_CONTROL", \ + .addr =3D 0x80, \ + .ro =3D 0x7C000000, \ + .reset =3D 0x0, \ + }, \ + [0x21] =3D { \ + .name =3D "FRO_CAPVAL", \ + .addr =3D 0x84, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x23] =3D { \ + .name =3D "FRO_RDTRIM", \ + .addr =3D 0x8C, \ + .ro =3D 0xFFFFF800, \ + .reset =3D 0x3BF, \ + }, \ + [0x24] =3D { \ + .name =3D "FRO_SCTRIM", \ + .addr =3D 0x90, \ + .ro =3D 0xFFFFFFC0, \ + .reset =3D 0x20, \ + }, \ + [0x42] =3D { \ + .name =3D "FRODIVSEL", \ + .addr =3D 0x108, \ + .ro =3D 0xFFFFFFFC, \ + .reset =3D 0x0, \ + }, \ + [0x43] =3D { \ + .name =3D "FROCLKSTATUS", \ + .addr =3D 0x10C, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x0, \ + }, \ + [0x44] =3D { \ + .name =3D "FRODIVOEN", \ + .addr =3D 0x110, \ + .ro =3D 0xFFFFFFE0, \ + .reset =3D 0x0, \ + }, \ + [0x4C] =3D { \ + .name =3D "LOWFREQCLKDIV", \ + .addr =3D 0x130, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x0, \ + }, \ + [0x58] =3D { \ + .name =3D "SYSOSCCTL0", \ + .addr =3D 0x160, \ + .ro =3D 0xFFFFFFFC, \ + .reset =3D 0x0, \ + }, \ + [0x5A] =3D { \ + .name =3D "SYSOSCBYPASS", \ + .addr =3D 0x168, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x0, \ + }, \ + [0x64] =3D { \ + .name =3D "LPOSCCTL0", \ + .addr =3D 0x190, \ + .ro =3D 0x7FFFFFFF, \ + .reset =3D 0x807BC4D4, \ + }, \ + [0x70] =3D { \ + .name =3D "OSC32KHZCTL0", \ + .addr =3D 0x1C0, \ + .ro =3D 0xFFFFFFFE, \ + .reset =3D 0x0, \ + }, \ + [0x80] =3D { \ + .name =3D "SYSPLL0CLKSEL", \ + .addr =3D 0x200, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x81] =3D { \ + .name =3D "SYSPLL0CTL0", \ + .addr =3D 0x204, \ + .ro =3D 0xFF00DFFC, \ + .reset =3D 0x160002, \ + }, \ + [0x83] =3D { \ + .name =3D "SYSPLL0LOCKTIMEDIV2", \ + .addr =3D 0x20C, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0xCAFE, \ + }, \ + [0x84] =3D { \ + .name =3D "SYSPLL0NUM", \ + .addr =3D 0x210, \ + .ro =3D 0xC0000000, \ + .reset =3D 0x4DD2F15, \ + }, \ + [0x85] =3D { \ + .name =3D "SYSPLL0DENOM", \ + .addr =3D 0x214, \ + .ro =3D 0xC0000000, \ + .reset =3D 0x1FFFFFDB, \ + }, \ + [0x86] =3D { \ + .name =3D "SYSPLL0PFD", \ + .addr =3D 0x218, \ + .ro =3D 0x0, \ + .reset =3D 0x80808080, \ + }, \ + [0x90] =3D { \ + .name =3D "MAINPLLCLKDIV", \ + .addr =3D 0x240, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x0, \ + }, \ + [0x91] =3D { \ + .name =3D "DSPPLLCLKDIV", \ + .addr =3D 0x244, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x0, \ + }, \ + [0x92] =3D { \ + .name =3D "AUX0PLLCLKDIV", \ + .addr =3D 0x248, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x0, \ + }, \ + [0x93] =3D { \ + .name =3D "AUX1PLLCLKDIV", \ + .addr =3D 0x24C, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x0, \ + }, \ + [0x100] =3D { \ + .name =3D "SYSCPUAHBCLKDIV", \ + .addr =3D 0x400, \ + .ro =3D 0x7FFFFF00, \ + .reset =3D 0x0, \ + }, \ + [0x10C] =3D { \ + .name =3D "MAINCLKSELA", \ + .addr =3D 0x430, \ + .ro =3D 0xFFFFFFFC, \ + .reset =3D 0x0, \ + }, \ + [0x10D] =3D { \ + .name =3D "MAINCLKSELB", \ + .addr =3D 0x434, \ + .ro =3D 0xFFFFFFFC, \ + .reset =3D 0x0, \ + }, \ + [0x140] =3D { \ + .name =3D "PFC0DIV", \ + .addr =3D 0x500, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + [0x141] =3D { \ + .name =3D "PFC1DIV", \ + .addr =3D 0x504, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + [0x188] =3D { \ + .name =3D "FLEXSPI0FCLKSEL", \ + .addr =3D 0x620, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x189] =3D { \ + .name =3D "FLEXSPI0FCLKDIV", \ + .addr =3D 0x624, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + [0x18C] =3D { \ + .name =3D "FLEXSPI1FCLKSEL", \ + .addr =3D 0x630, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x18D] =3D { \ + .name =3D "FLEXSPI1FCLKDIV", \ + .addr =3D 0x634, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + [0x190] =3D { \ + .name =3D "SCTFCLKSEL", \ + .addr =3D 0x640, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x191] =3D { \ + .name =3D "SCTIN7CLKDIV", \ + .addr =3D 0x644, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + [0x198] =3D { \ + .name =3D "USBHSFCLKSEL", \ + .addr =3D 0x660, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x199] =3D { \ + .name =3D "USBHSFCLKDIV", \ + .addr =3D 0x664, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + [0x1A0] =3D { \ + .name =3D "SDIO0FCLKSEL", \ + .addr =3D 0x680, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1A1] =3D { \ + .name =3D "SDIO0FCLKDIV", \ + .addr =3D 0x684, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + [0x1A4] =3D { \ + .name =3D "SDIO1FCLKSEL", \ + .addr =3D 0x690, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1A5] =3D { \ + .name =3D "SDIO1FCLKDIV", \ + .addr =3D 0x694, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + [0x1B4] =3D { \ + .name =3D "ADC0FCLKSEL0", \ + .addr =3D 0x6D0, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1B5] =3D { \ + .name =3D "ADC0FCLKSEL1", \ + .addr =3D 0x6D4, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1B6] =3D { \ + .name =3D "ADC0FCLKDIV", \ + .addr =3D 0x6D8, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + [0x1C0] =3D { \ + .name =3D "UTICKFCLKSEL", \ + .addr =3D 0x700, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1C8] =3D { \ + .name =3D "WDT0FCLKSEL", \ + .addr =3D 0x720, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x0, \ + }, \ + [0x1CC] =3D { \ + .name =3D "A32KHZWAKECLKSEL", \ + .addr =3D 0x730, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x1, \ + }, \ + [0x1CD] =3D { \ + .name =3D "A32KHZWAKECLKDIV", \ + .addr =3D 0x734, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x1F, \ + }, \ + [0x1D8] =3D { \ + .name =3D "SYSTICKFCLKSEL", \ + .addr =3D 0x760, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1D9] =3D { \ + .name =3D "SYSTICKFCLKDIV", \ + .addr =3D 0x764, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + [0x1DC] =3D { \ + .name =3D "DPHYCLKSEL", \ + .addr =3D 0x770, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1DD] =3D { \ + .name =3D "DPHYCLKDIV", \ + .addr =3D 0x774, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + [0x1DE] =3D { \ + .name =3D "DPHYESCCLKSEL", \ + .addr =3D 0x778, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1DF] =3D { \ + .name =3D "DPHYESCRXCLKDIV", \ + .addr =3D 0x77C, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000010, \ + }, \ + [0x1E0] =3D { \ + .name =3D "DPHYESCTXCLKDIV", \ + .addr =3D 0x780, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000011, \ + }, \ + [0x1E4] =3D { \ + .name =3D "GPUCLKSEL", \ + .addr =3D 0x790, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1E5] =3D { \ + .name =3D "GPUCLKDIV", \ + .addr =3D 0x794, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + [0x1E8] =3D { \ + .name =3D "DCPIXELCLKSEL", \ + .addr =3D 0x7A0, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1E9] =3D { \ + .name =3D "DCPIXELCLKDIV", \ + .addr =3D 0x7A4, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + } diff --git a/include/hw/arm/svd/rt500_clkctl1.h b/include/hw/arm/svd/rt500_= clkctl1.h new file mode 100644 index 0000000000..baa24eb0fd --- /dev/null +++ b/include/hw/arm/svd/rt500_clkctl1.h @@ -0,0 +1,675 @@ +/* + * 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" + +/* Clock Controller 1 */ +#define RT500_CLKCTL1_REGS_NO (526) + +/* Clock Control 0 */ +REG32(RT500_CLKCTL1_PSCCTL0, 0x10); +/* FlexIO clock control */ +FIELD(RT500_CLKCTL1_PSCCTL0, FlexIO, 29, 1); + +/* Clock Control 1 */ +REG32(RT500_CLKCTL1_PSCCTL1, 0x14); + +/* Clock Control 2 */ +REG32(RT500_CLKCTL1_PSCCTL2, 0x18); + +/* Clock Set 0 */ +REG32(RT500_CLKCTL1_PSCCTL0_SET, 0x40); +/* FlexIO clock control */ +FIELD(RT500_CLKCTL1_PSCCTL0_SET, FlexIO, 29, 1); + +/* Clock Set 1 */ +REG32(RT500_CLKCTL1_PSCCTL1_SET, 0x44); + +/* Clock Set 2 */ +REG32(RT500_CLKCTL1_PSCCTL2_SET, 0x48); + +/* Clock Clear 0 */ +REG32(RT500_CLKCTL1_PSCCTL0_CLR, 0x70); +/* FlexIO clock control clear */ +FIELD(RT500_CLKCTL1_PSCCTL0_CLR, FlexIO, 29, 1); + +/* Clock Clear 1 */ +REG32(RT500_CLKCTL1_PSCCTL1_CLR, 0x74); + +/* Clock Clear 2 */ +REG32(RT500_CLKCTL1_PSCCTL2_CLR, 0x78); + +/* Audio PLL0 PFD */ +REG32(RT500_CLKCTL1_AUDIOPLL0PFD, 0x218); +/* PLL Fractional Divider 0 */ +FIELD(RT500_CLKCTL1_AUDIOPLL0PFD, PFD0, 0, 6); +/* PFD0 Clock Ready Status Flag */ +FIELD(RT500_CLKCTL1_AUDIOPLL0PFD, PFD0_CLKRDY, 6, 1); +/* PFD0 Clock Gate */ +FIELD(RT500_CLKCTL1_AUDIOPLL0PFD, PFD0_CLKGATE, 7, 1); +/* PLL Fractional Divider 1 */ +FIELD(RT500_CLKCTL1_AUDIOPLL0PFD, PFD1, 8, 6); +/* PFD1 Clock Ready Status Flag */ +FIELD(RT500_CLKCTL1_AUDIOPLL0PFD, PFD1_CLKRDY, 14, 1); +/* PFD1 Clock Gate */ +FIELD(RT500_CLKCTL1_AUDIOPLL0PFD, PFD1_CLKGATE, 15, 1); +/* PLL Fractional Divider 2 */ +FIELD(RT500_CLKCTL1_AUDIOPLL0PFD, PFD2, 16, 6); +/* PFD2 Clock Ready Status Flag */ +FIELD(RT500_CLKCTL1_AUDIOPLL0PFD, PFD2_CLKRDY, 22, 1); +/* PFD2 Clock Gate */ +FIELD(RT500_CLKCTL1_AUDIOPLL0PFD, PFD2_CLKGATE, 23, 1); +/* PLL Fractional Divider 3 */ +FIELD(RT500_CLKCTL1_AUDIOPLL0PFD, PFD3, 24, 6); +/* PFD3 Clock Ready Status Flag */ +FIELD(RT500_CLKCTL1_AUDIOPLL0PFD, PFD3_CLKRDY, 30, 1); +/* PFD3 Clock Gate */ +FIELD(RT500_CLKCTL1_AUDIOPLL0PFD, PFD3_CLKGATE, 31, 1); + +/* OS Event Timer Functional Clock Select */ +REG32(RT500_CLKCTL1_OSEVENTTFCLKSEL, 0x480); +/* OS Event Timer Functional Clock Source */ +FIELD(RT500_CLKCTL1_OSEVENTTFCLKSEL, SEL, 0, 3); +/* Low Power Oscillator Clock (LPOSC) */ +#define RT500_CLKCTL1_OSEVENTTFCLKSEL_SEL_LPOSC 0 +/* RTC 32 KHz Clock */ +#define RT500_CLKCTL1_OSEVENTTFCLKSEL_SEL_RTC_32KHZ 1 +/* HCLK Free-Running Clock (Global Time Stamping) */ +#define RT500_CLKCTL1_OSEVENTTFCLKSEL_SEL_TEAL 2 +/* None, output gated to reduce power */ +#define RT500_CLKCTL1_OSEVENTTFCLKSEL_SEL_NONE 7 + + +#define RT500_CLKCTL1_REGISTER_ACCESS_INFO_ARRAY(_name) \ + struct RegisterAccessInfo _name[RT500_CLKCTL1_REGS_NO] =3D { \ + [0 ... RT500_CLKCTL1_REGS_NO - 1] =3D { \ + .name =3D "", \ + .addr =3D -1, \ + }, \ + [0x4] =3D { \ + .name =3D "PSCCTL0", \ + .addr =3D 0x10, \ + .ro =3D 0xD40000FF, \ + .reset =3D 0x0, \ + }, \ + [0x5] =3D { \ + .name =3D "PSCCTL1", \ + .addr =3D 0x14, \ + .ro =3D 0x4E7EFF00, \ + .reset =3D 0x0, \ + }, \ + [0x6] =3D { \ + .name =3D "PSCCTL2", \ + .addr =3D 0x18, \ + .ro =3D 0x3FFCFA60, \ + .reset =3D 0x0, \ + }, \ + [0x10] =3D { \ + .name =3D "PSCCTL0_SET", \ + .addr =3D 0x40, \ + .ro =3D 0xD40000FF, \ + .reset =3D 0x0, \ + }, \ + [0x11] =3D { \ + .name =3D "PSCCTL1_SET", \ + .addr =3D 0x44, \ + .ro =3D 0x4E7EFF00, \ + .reset =3D 0x0, \ + }, \ + [0x12] =3D { \ + .name =3D "PSCCTL2_SET", \ + .addr =3D 0x48, \ + .ro =3D 0x3FFCFA60, \ + .reset =3D 0x0, \ + }, \ + [0x1C] =3D { \ + .name =3D "PSCCTL0_CLR", \ + .addr =3D 0x70, \ + .ro =3D 0xD40000FF, \ + .reset =3D 0x0, \ + }, \ + [0x1D] =3D { \ + .name =3D "PSCCTL1_CLR", \ + .addr =3D 0x74, \ + .ro =3D 0x4E7EFF00, \ + .reset =3D 0x0, \ + }, \ + [0x1E] =3D { \ + .name =3D "PSCCTL2_CLR", \ + .addr =3D 0x78, \ + .ro =3D 0x3FFCFA60, \ + .reset =3D 0x0, \ + }, \ + [0x80] =3D { \ + .name =3D "AUDIOPLL0CLKSEL", \ + .addr =3D 0x200, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x81] =3D { \ + .name =3D "AUDIOPLL0CTL0", \ + .addr =3D 0x204, \ + .ro =3D 0xFF00DFFC, \ + .reset =3D 0x160002, \ + }, \ + [0x83] =3D { \ + .name =3D "AUDIOPLL0LOCKTIMEDIV2", \ + .addr =3D 0x20C, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0xCAFE, \ + }, \ + [0x84] =3D { \ + .name =3D "AUDIOPLL0NUM", \ + .addr =3D 0x210, \ + .ro =3D 0xC0000000, \ + .reset =3D 0x4DD2F15, \ + }, \ + [0x85] =3D { \ + .name =3D "AUDIOPLL0DENOM", \ + .addr =3D 0x214, \ + .ro =3D 0xC0000000, \ + .reset =3D 0x1FFFFFDB, \ + }, \ + [0x86] =3D { \ + .name =3D "AUDIOPLL0PFD", \ + .addr =3D 0x218, \ + .ro =3D 0x0, \ + .reset =3D 0x80808080, \ + }, \ + [0x90] =3D { \ + .name =3D "AUDIOPLLCLKDIV", \ + .addr =3D 0x240, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + [0x100] =3D { \ + .name =3D "DSPCPUCLKDIV", \ + .addr =3D 0x400, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + [0x10C] =3D { \ + .name =3D "DSPCPUCLKSELA", \ + .addr =3D 0x430, \ + .ro =3D 0xFFFFFFFC, \ + .reset =3D 0x0, \ + }, \ + [0x10D] =3D { \ + .name =3D "DSPCPUCLKSELB", \ + .addr =3D 0x434, \ + .ro =3D 0xFFFFFFFC, \ + .reset =3D 0x0, \ + }, \ + [0x120] =3D { \ + .name =3D "OSEVENTTFCLKSEL", \ + .addr =3D 0x480, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x0, \ + }, \ + [0x140] =3D { \ + .name =3D "FRG0CLKSEL", \ + .addr =3D 0x500, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x141] =3D { \ + .name =3D "FRG0CTL", \ + .addr =3D 0x504, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0xFF, \ + }, \ + [0x142] =3D { \ + .name =3D "FC0FCLKSEL", \ + .addr =3D 0x508, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x148] =3D { \ + .name =3D "FRG1CLKSEL", \ + .addr =3D 0x520, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x149] =3D { \ + .name =3D "FRG1CTL", \ + .addr =3D 0x524, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0xFF, \ + }, \ + [0x14A] =3D { \ + .name =3D "FC1FCLKSEL", \ + .addr =3D 0x528, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x150] =3D { \ + .name =3D "FRG2CLKSEL", \ + .addr =3D 0x540, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x151] =3D { \ + .name =3D "FRG2CTL", \ + .addr =3D 0x544, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0xFF, \ + }, \ + [0x152] =3D { \ + .name =3D "FC2FCLKSEL", \ + .addr =3D 0x548, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x158] =3D { \ + .name =3D "FRG3CLKSEL", \ + .addr =3D 0x560, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x159] =3D { \ + .name =3D "FRG3CTL", \ + .addr =3D 0x564, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0xFF, \ + }, \ + [0x15A] =3D { \ + .name =3D "FC3FCLKSEL", \ + .addr =3D 0x568, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x160] =3D { \ + .name =3D "FRG4CLKSEL", \ + .addr =3D 0x580, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x161] =3D { \ + .name =3D "FRG4CTL", \ + .addr =3D 0x584, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0xFF, \ + }, \ + [0x162] =3D { \ + .name =3D "FC4FCLKSEL", \ + .addr =3D 0x588, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x168] =3D { \ + .name =3D "FRG5CLKSEL", \ + .addr =3D 0x5A0, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x169] =3D { \ + .name =3D "FRG5CTL", \ + .addr =3D 0x5A4, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0xFF, \ + }, \ + [0x16A] =3D { \ + .name =3D "FC5FCLKSEL", \ + .addr =3D 0x5A8, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x170] =3D { \ + .name =3D "FRG6CLKSEL", \ + .addr =3D 0x5C0, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x171] =3D { \ + .name =3D "FRG6CTL", \ + .addr =3D 0x5C4, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0xFF, \ + }, \ + [0x172] =3D { \ + .name =3D "FC6FCLKSEL", \ + .addr =3D 0x5C8, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x178] =3D { \ + .name =3D "FRG7CLKSEL", \ + .addr =3D 0x5E0, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x179] =3D { \ + .name =3D "FRG7CTL", \ + .addr =3D 0x5E4, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0xFF, \ + }, \ + [0x17A] =3D { \ + .name =3D "FC7FCLKSEL", \ + .addr =3D 0x5E8, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x180] =3D { \ + .name =3D "FRG8CLKSEL", \ + .addr =3D 0x600, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x181] =3D { \ + .name =3D "FRG8CTL", \ + .addr =3D 0x604, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0xFF, \ + }, \ + [0x182] =3D { \ + .name =3D "FC8FCLKSEL", \ + .addr =3D 0x608, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x188] =3D { \ + .name =3D "FRG9CLKSEL", \ + .addr =3D 0x620, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x189] =3D { \ + .name =3D "FRG9CTL", \ + .addr =3D 0x624, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0xFF, \ + }, \ + [0x18A] =3D { \ + .name =3D "FC9FCLKSEL", \ + .addr =3D 0x628, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x190] =3D { \ + .name =3D "FRG10CLKSEL", \ + .addr =3D 0x640, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x191] =3D { \ + .name =3D "FRG10CTL", \ + .addr =3D 0x644, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0xFF, \ + }, \ + [0x192] =3D { \ + .name =3D "FC10FCLKSEL", \ + .addr =3D 0x648, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x198] =3D { \ + .name =3D "FRG11CLKSEL", \ + .addr =3D 0x660, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x199] =3D { \ + .name =3D "FRG11CTL", \ + .addr =3D 0x664, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0xFF, \ + }, \ + [0x19A] =3D { \ + .name =3D "FC11FCLKSEL", \ + .addr =3D 0x668, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1A0] =3D { \ + .name =3D "FRG12CLKSEL", \ + .addr =3D 0x680, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1A1] =3D { \ + .name =3D "FRG12CTL", \ + .addr =3D 0x684, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0xFF, \ + }, \ + [0x1A2] =3D { \ + .name =3D "FC12FCLKSEL", \ + .addr =3D 0x688, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1A8] =3D { \ + .name =3D "FRG13CLKSEL", \ + .addr =3D 0x6A0, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1A9] =3D { \ + .name =3D "FRG13CTL", \ + .addr =3D 0x6A4, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0xFF, \ + }, \ + [0x1AA] =3D { \ + .name =3D "FC13FCLKSEL", \ + .addr =3D 0x6A8, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1B0] =3D { \ + .name =3D "FRG14CLKSEL", \ + .addr =3D 0x6C0, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1B1] =3D { \ + .name =3D "FRG14CTL", \ + .addr =3D 0x6C4, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0xFF, \ + }, \ + [0x1B2] =3D { \ + .name =3D "FC14FCLKSEL", \ + .addr =3D 0x6C8, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1B8] =3D { \ + .name =3D "FRG15CLKSEL", \ + .addr =3D 0x6E0, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1B9] =3D { \ + .name =3D "FRG15CTL", \ + .addr =3D 0x6E4, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0xFF, \ + }, \ + [0x1BA] =3D { \ + .name =3D "FC15FCLKSEL", \ + .addr =3D 0x6E8, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1C0] =3D { \ + .name =3D "FRG16CLKSEL", \ + .addr =3D 0x700, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1C1] =3D { \ + .name =3D "FRG16CTL", \ + .addr =3D 0x704, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0xFF, \ + }, \ + [0x1C2] =3D { \ + .name =3D "FC16FCLKSEL", \ + .addr =3D 0x708, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1C8] =3D { \ + .name =3D "FRG17CLKSEL", \ + .addr =3D 0x720, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1C9] =3D { \ + .name =3D "FRG17CTL", \ + .addr =3D 0x724, \ + .ro =3D 0xFFFF0000, \ + .reset =3D 0xFF, \ + }, \ + [0x1CA] =3D { \ + .name =3D "FLEXIOCLKSEL", \ + .addr =3D 0x728, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1D0] =3D { \ + .name =3D "FLEXIOCLKDIV", \ + .addr =3D 0x740, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + [0x1D8] =3D { \ + .name =3D "FRGPLLCLKDIV", \ + .addr =3D 0x760, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + [0x1E0] =3D { \ + .name =3D "DMIC0FCLKSEL", \ + .addr =3D 0x780, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1E1] =3D { \ + .name =3D "DMIC0FCLKDIV", \ + .addr =3D 0x784, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + [0x1E8] =3D { \ + .name =3D "CT32BITFCLKSEL0", \ + .addr =3D 0x7A0, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1E9] =3D { \ + .name =3D "CT32BITFCLKSEL1", \ + .addr =3D 0x7A4, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1EA] =3D { \ + .name =3D "CT32BITFCLKSEL2", \ + .addr =3D 0x7A8, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1EB] =3D { \ + .name =3D "CT32BITFCLKSEL3", \ + .addr =3D 0x7AC, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1EC] =3D { \ + .name =3D "CT32BITFCLKSEL4", \ + .addr =3D 0x7B0, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1F0] =3D { \ + .name =3D "AUDIOMCLKSEL", \ + .addr =3D 0x7C0, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1F1] =3D { \ + .name =3D "AUDIOMCLKDIV", \ + .addr =3D 0x7C4, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + [0x1F8] =3D { \ + .name =3D "CLKOUTSEL0", \ + .addr =3D 0x7E0, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1F9] =3D { \ + .name =3D "CLKOUTSEL1", \ + .addr =3D 0x7E4, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x1FA] =3D { \ + .name =3D "CLKOUTFCLKDIV", \ + .addr =3D 0x7E8, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + [0x200] =3D { \ + .name =3D "I3C01FCLKSEL", \ + .addr =3D 0x800, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x201] =3D { \ + .name =3D "I3C01FCLKSTCSEL", \ + .addr =3D 0x804, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x202] =3D { \ + .name =3D "I3C01FCLKSTCDIV", \ + .addr =3D 0x808, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + [0x203] =3D { \ + .name =3D "I3C01FCLKSDIV", \ + .addr =3D 0x80C, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + [0x204] =3D { \ + .name =3D "I3C01FCLKDIV", \ + .addr =3D 0x810, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + [0x205] =3D { \ + .name =3D "I3C01FCLKSTSTCLKSEL", \ + .addr =3D 0x814, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x0, \ + }, \ + [0x208] =3D { \ + .name =3D "WDT1FCLKSEL", \ + .addr =3D 0x820, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x0, \ + }, \ + [0x20C] =3D { \ + .name =3D "ACMP0FCLKSEL", \ + .addr =3D 0x830, \ + .ro =3D 0xFFFFFFF8, \ + .reset =3D 0x7, \ + }, \ + [0x20D] =3D { \ + .name =3D "ACMP0FCLKDIV", \ + .addr =3D 0x834, \ + .ro =3D 0x1FFFFF00, \ + .reset =3D 0x40000000, \ + }, \ + } diff --git a/include/hw/misc/rt500_clk_freqs.h b/include/hw/misc/rt500_clk_= freqs.h new file mode 100644 index 0000000000..1e366d4967 --- /dev/null +++ b/include/hw/misc/rt500_clk_freqs.h @@ -0,0 +1,18 @@ +/* + * QEMU model for RT500 Clock Controller + * + * 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_MISC_RT500_CLK_FREQS_H +#define HW_MISC_RT500_CLK_FREQS_H + +#define RTC32KHZ_CLK_HZ 32000 +#define LPOSC_CLK_HZ 1000000 + +#endif /* HW_MISC_RT500_CLK_FREQS_H */ diff --git a/include/hw/misc/rt500_clkctl0.h b/include/hw/misc/rt500_clkctl= 0.h new file mode 100644 index 0000000000..890743a2ce --- /dev/null +++ b/include/hw/misc/rt500_clkctl0.h @@ -0,0 +1,35 @@ +/* + * QEMU model for RT500 Clock Controller + * + * 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_MISC_RT500_CLKCTL0_H +#define HW_MISC_RT500_CLKCTL0_H + +#include "hw/arm/svd/rt500_clkctl0.h" +#include "hw/sysbus.h" + +#define TYPE_RT500_CLKCTL0 "rt500-clkctl0" +#define RT500_CLKCTL0(o) OBJECT_CHECK(RT500ClkCtl0State, o, TYPE_RT500_CLK= CTL0) + +#define SYSTICKFCLKSEL_DIVOUT 0 +#define SYSTICKFCLKSEL_LPOSC 1 +#define SYSTICKFCLKSEL_32KHZRTC 2 +#define SYSTICKFCLKSEL_NONE 7 + +typedef struct { + SysBusDevice parent_obj; + + MemoryRegion mmio; + uint32_t regs[RT500_CLKCTL0_REGS_NO]; + Clock *systick_clk; + Clock *sysclk; +} RT500ClkCtl0State; + +#endif /* HW_MISC_RT500_CLKCTL0_H */ diff --git a/include/hw/misc/rt500_clkctl1.h b/include/hw/misc/rt500_clkctl= 1.h new file mode 100644 index 0000000000..8b012b1357 --- /dev/null +++ b/include/hw/misc/rt500_clkctl1.h @@ -0,0 +1,36 @@ +/* + * QEMU model for RT500 Clock Controller + * + * 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_MISC_RT500_CLKCTL1_H +#define HW_MISC_RT500_CLKCTL1_H + +#include "hw/arm/svd/rt500_clkctl1.h" +#include "hw/sysbus.h" + +#define TYPE_RT500_CLKCTL1 "rt500-clkctl1" +#define RT500_CLKCTL1(o) OBJECT_CHECK(RT500ClkCtl1State, o, TYPE_RT500_CLK= CTL1) + +#define OSEVENTTFCLKSEL_LPOSC 0 +#define OSEVENTTFCLKSEL_32KHZRTC 1 +#define OSEVENTTFCLKSEL_HCLK 2 +#define OSEVENTTFCLKSEL_NONE 7 + +typedef struct { + SysBusDevice parent_obj; + + MemoryRegion mmio; + uint32_t regs[RT500_CLKCTL1_REGS_NO]; + Clock *sysclk; + Clock *ostimer_clk; +} RT500ClkCtl1State; + +#endif /* HW_MISC_RT500_CLKCTL1_H */ diff --git a/hw/misc/rt500_clkctl0.c b/hw/misc/rt500_clkctl0.c new file mode 100644 index 0000000000..7e7b176719 --- /dev/null +++ b/hw/misc/rt500_clkctl0.c @@ -0,0 +1,253 @@ +/* + * QEMU model for RT500 Clock Controller + * + * 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 "hw/clock.h" +#include "hw/irq.h" +#include "hw/qdev-clock.h" +#include "hw/qdev-properties.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "exec/address-spaces.h" +#include "migration/vmstate.h" +#include "hw/misc/rt500_clkctl0.h" +#include "hw/misc/rt500_clk_freqs.h" + +#include "trace.h" + +#define REG(s, reg) (s->regs[R_RT500_CLKCTL0_##reg]) +#define RF_RD(s, reg, field) \ + ARRAY_FIELD_EX32(s->regs, RT500_CLKCTL0_##reg, field) +#define RF_WR(s, reg, field, val) \ + ARRAY_FIELD_DP32(s->regs, RT500_CLKCTL0_##reg, field, val) + +static const RT500_CLKCTL0_REGISTER_ACCESS_INFO_ARRAY(reg_info); + +static MemTxResult rt500_clkctl0_read(void *opaque, hwaddr addr, + uint64_t *data, unsigned size, + MemTxAttrs attrs) +{ + RT500ClkCtl0State *s =3D opaque; + const struct RegisterAccessInfo *rai =3D ®_info[addr / 4]; + + switch (addr) { + case A_RT500_CLKCTL0_PSCCTL0_SET: + case A_RT500_CLKCTL0_PSCCTL1_SET: + case A_RT500_CLKCTL0_PSCCTL2_SET: + case A_RT500_CLKCTL0_PSCCTL0_CLR: + case A_RT500_CLKCTL0_PSCCTL1_CLR: + case A_RT500_CLKCTL0_PSCCTL2_CLR: + /* write only registers */ + return MEMTX_ERROR; + default: + *data =3D s->regs[addr / 4]; + break; + } + + trace_rt500_clkctl0_reg_read(rai->name, addr, *data); + return MEMTX_OK; +} + +static inline void set_systick_clk_from_div(RT500ClkCtl0State *s) +{ + uint32_t div =3D RF_RD(s, SYSTICKFCLKDIV, DIV) + 1; + uint32_t rate =3D clock_get_hz(s->sysclk); + + clock_set_hz(s->systick_clk, rate / div); +} + +static MemTxResult rt500_clkctl0_write(void *opaque, hwaddr addr, + uint64_t value, unsigned size, + MemTxAttrs attrs) +{ + RT500ClkCtl0State *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_rt500_clkctl0_reg_write(rai->name, addr, value); + + switch (addr) { + case A_RT500_CLKCTL0_PSCCTL0: + case A_RT500_CLKCTL0_PSCCTL1: + case A_RT500_CLKCTL0_PSCCTL2: + { + register_write(&ri, value, ~0, NULL, false); + break; + } + case A_RT500_CLKCTL0_PSCCTL0_SET: + case A_RT500_CLKCTL0_PSCCTL1_SET: + case A_RT500_CLKCTL0_PSCCTL2_SET: + { + uint32_t tmp; + + tmp =3D A_RT500_CLKCTL0_PSCCTL0 + (addr - A_RT500_CLKCTL0_PSCCTL0_= SET); + s->regs[tmp / 4] |=3D value; + break; + } + case A_RT500_CLKCTL0_PSCCTL0_CLR: + case A_RT500_CLKCTL0_PSCCTL1_CLR: + case A_RT500_CLKCTL0_PSCCTL2_CLR: + { + uint32_t tmp; + + tmp =3D A_RT500_CLKCTL0_PSCCTL0 + (addr - A_RT500_CLKCTL0_PSCCTL0_= CLR); + s->regs[tmp / 4] &=3D ~value; + break; + } + default: + register_write(&ri, value, ~0, NULL, false); + } + + switch (addr) { + case A_RT500_CLKCTL0_SYSPLL0PFD: + { + if (!RF_RD(s, SYSPLL0PFD, PFD0_CLKGATE)) { + RF_WR(s, SYSPLL0PFD, PFD0_CLKRDY, 1); + } else { + RF_WR(s, SYSPLL0PFD, PFD0_CLKRDY, 0); + } + if (!RF_RD(s, SYSPLL0PFD, PFD1_CLKGATE)) { + RF_WR(s, SYSPLL0PFD, PFD1_CLKRDY, 1); + } else { + RF_WR(s, SYSPLL0PFD, PFD1_CLKRDY, 0); + } + if (!RF_RD(s, SYSPLL0PFD, PFD2_CLKGATE)) { + RF_WR(s, SYSPLL0PFD, PFD2_CLKRDY, 1); + } else { + RF_WR(s, SYSPLL0PFD, PFD2_CLKRDY, 0); + } + if (!RF_RD(s, SYSPLL0PFD, PFD3_CLKGATE)) { + RF_WR(s, SYSPLL0PFD, PFD3_CLKRDY, 1); + } else { + RF_WR(s, SYSPLL0PFD, PFD3_CLKRDY, 0); + } + break; + } + case A_RT500_CLKCTL0_SYSTICKFCLKSEL: + { + switch (RF_RD(s, SYSTICKFCLKSEL, SEL)) { + case SYSTICKFCLKSEL_DIVOUT: + { + set_systick_clk_from_div(s); + break; + } + case SYSTICKFCLKSEL_LPOSC: + { + clock_set_hz(s->systick_clk, LPOSC_CLK_HZ); + break; + } + case SYSTICKFCLKSEL_32KHZRTC: + { + clock_set_hz(s->systick_clk, RTC32KHZ_CLK_HZ); + break; + } + case SYSTICKFCLKSEL_NONE: + { + clock_set_hz(s->systick_clk, 0); + break; + } + } + clock_propagate(s->systick_clk); + break; + } + case A_RT500_CLKCTL0_SYSTICKFCLKDIV: + { + if (RF_RD(s, SYSTICKFCLKSEL, SEL) =3D=3D SYSTICKFCLKSEL_DIVOUT) { + set_systick_clk_from_div(s); + clock_propagate(s->systick_clk); + } + break; + } + } + + return MEMTX_OK; +} + +static const MemoryRegionOps rt500_clkctl0_ops =3D { + .read_with_attrs =3D rt500_clkctl0_read, + .write_with_attrs =3D rt500_clkctl0_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + .unaligned =3D false, + }, +}; + +static void rt500_clkctl0_reset_enter(Object *obj, ResetType type) +{ + RT500ClkCtl0State *s =3D RT500_CLKCTL0(obj); + + for (int i =3D 0; i < RT500_CLKCTL0_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); + } + } + + /* clock OK immediately after reset */ + REG(s, FROCLKSTATUS) =3D 0x00000001; +} + +static void rt500_clkctl0_init(Object *obj) +{ + RT500ClkCtl0State *s =3D RT500_CLKCTL0(obj); + + memory_region_init_io(&s->mmio, obj, &rt500_clkctl0_ops, s, + TYPE_RT500_CLKCTL0, sizeof(s->regs)); + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); + s->sysclk =3D qdev_init_clock_in(DEVICE(s), "sysclk", NULL, NULL, 0); + s->systick_clk =3D qdev_init_clock_out(DEVICE(s), "systick_clk"); +} + +static const VMStateDescription vmstate_rt500_clkctl0 =3D { + .name =3D "rt500-clkctl0", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT32_ARRAY(regs, RT500ClkCtl0State, RT500_CLKCTL0_REGS_N= O), + VMSTATE_CLOCK(systick_clk, RT500ClkCtl0State), + VMSTATE_END_OF_LIST() + } +}; + +static void rt500_clkctl0_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + + rc->phases.enter =3D rt500_clkctl0_reset_enter; + dc->vmsd =3D &vmstate_rt500_clkctl0; +} + +static const TypeInfo rt500_clkctl0_types[] =3D { + { + .name =3D TYPE_RT500_CLKCTL0, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(RT500ClkCtl0State), + .instance_init =3D rt500_clkctl0_init, + .class_init =3D rt500_clkctl0_class_init, + }, +}; + +DEFINE_TYPES(rt500_clkctl0_types); + diff --git a/hw/misc/rt500_clkctl1.c b/hw/misc/rt500_clkctl1.c new file mode 100644 index 0000000000..ed234ce0f6 --- /dev/null +++ b/hw/misc/rt500_clkctl1.c @@ -0,0 +1,238 @@ +/* + * QEMU model for RT500 Clock Controller + * + * 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 "hw/clock.h" +#include "hw/irq.h" +#include "hw/qdev-clock.h" +#include "hw/qdev-properties.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "exec/address-spaces.h" +#include "migration/vmstate.h" +#include "hw/misc/rt500_clkctl1.h" +#include "hw/misc/rt500_clk_freqs.h" + +#include "trace.h" + +#define REG(s, reg) (s->regs[R_RT500_CLKCTL1_##reg]) +#define RF_RD(s, reg, field) \ + ARRAY_FIELD_EX32(s->regs, RT500_CLKCTL1_##reg, field) +#define RF_WR(s, reg, field, val) \ + ARRAY_FIELD_DP32(s->regs, RT500_CLKCTL1_##reg, field, val) + +static RT500_CLKCTL1_REGISTER_ACCESS_INFO_ARRAY(reg_info); + +static MemTxResult rt500_clkctl1_read(void *opaque, hwaddr addr, + uint64_t *data, unsigned size, + MemTxAttrs attrs) +{ + RT500ClkCtl1State *s =3D opaque; + const struct RegisterAccessInfo *rai =3D ®_info[addr / 4]; + MemTxResult ret =3D MEMTX_OK; + + switch (addr) { + case A_RT500_CLKCTL1_PSCCTL0_SET: + case A_RT500_CLKCTL1_PSCCTL1_SET: + case A_RT500_CLKCTL1_PSCCTL2_SET: + case A_RT500_CLKCTL1_PSCCTL0_CLR: + case A_RT500_CLKCTL1_PSCCTL1_CLR: + case A_RT500_CLKCTL1_PSCCTL2_CLR: + /* write only registers */ + ret =3D MEMTX_ERROR; + break; + default: + *data =3D s->regs[addr / 4]; + break; + } + + trace_rt500_clkctl1_reg_read(rai->name, addr, *data); + return ret; +} + +static MemTxResult rt500_clkctl1_write(void *opaque, hwaddr addr, + uint64_t value, unsigned size, + MemTxAttrs attrs) +{ + RT500ClkCtl1State *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_rt500_clkctl1_reg_write(rai->name, addr, value); + + switch (addr) { + case A_RT500_CLKCTL1_PSCCTL0: + case A_RT500_CLKCTL1_PSCCTL1: + case A_RT500_CLKCTL1_PSCCTL2: + { + s->regs[addr / 4] =3D value | s->regs[addr / 4]; + break; + } + case A_RT500_CLKCTL1_PSCCTL0_SET: + case A_RT500_CLKCTL1_PSCCTL1_SET: + case A_RT500_CLKCTL1_PSCCTL2_SET: + { + uint32_t tmp; + + tmp =3D A_RT500_CLKCTL1_PSCCTL0 + (addr - A_RT500_CLKCTL1_PSCCTL0_= SET); + s->regs[tmp / 4] |=3D value; + break; + } + case A_RT500_CLKCTL1_PSCCTL0_CLR: + case A_RT500_CLKCTL1_PSCCTL1_CLR: + case A_RT500_CLKCTL1_PSCCTL2_CLR: + { + uint32_t tmp; + + tmp =3D A_RT500_CLKCTL1_PSCCTL0 + (addr - A_RT500_CLKCTL1_PSCCTL0_= CLR); + s->regs[tmp / 4] &=3D ~value; + break; + } + default: + register_write(&ri, value, ~0, NULL, false); + } + + switch (addr) { + case A_RT500_CLKCTL1_AUDIOPLL0PFD: + { + if (!RF_RD(s, AUDIOPLL0PFD, PFD0_CLKGATE)) { + RF_WR(s, AUDIOPLL0PFD, PFD0_CLKRDY, 1); + } else { + RF_WR(s, AUDIOPLL0PFD, PFD0_CLKRDY, 0); + } + if (!RF_RD(s, AUDIOPLL0PFD, PFD1_CLKGATE)) { + RF_WR(s, AUDIOPLL0PFD, PFD1_CLKRDY, 1); + } else { + RF_WR(s, AUDIOPLL0PFD, PFD1_CLKRDY, 0); + } + if (!RF_RD(s, AUDIOPLL0PFD, PFD2_CLKGATE)) { + RF_WR(s, AUDIOPLL0PFD, PFD2_CLKRDY, 1); + } else { + RF_WR(s, AUDIOPLL0PFD, PFD2_CLKRDY, 0); + } + if (!RF_RD(s, AUDIOPLL0PFD, PFD3_CLKGATE)) { + RF_WR(s, AUDIOPLL0PFD, PFD3_CLKRDY, 1); + } else { + RF_WR(s, AUDIOPLL0PFD, PFD3_CLKRDY, 0); + } + break; + } + case A_RT500_CLKCTL1_OSEVENTTFCLKSEL: + { + switch (RF_RD(s, OSEVENTTFCLKSEL, SEL)) { + case OSEVENTTFCLKSEL_LPOSC: + { + clock_set_hz(s->ostimer_clk, LPOSC_CLK_HZ); + break; + } + case OSEVENTTFCLKSEL_32KHZRTC: + { + clock_set_hz(s->ostimer_clk, RTC32KHZ_CLK_HZ); + break; + } + case OSEVENTTFCLKSEL_HCLK: + { + clock_set_hz(s->ostimer_clk, clock_get_hz(s->sysclk)); + break; + } + case OSEVENTTFCLKSEL_NONE: + { + clock_set_hz(s->ostimer_clk, 0); + break; + } + } + + clock_propagate(s->ostimer_clk); + break; + } + } + + return MEMTX_OK; +} + + +static const MemoryRegionOps rt500_clkctl1_ops =3D { + .read_with_attrs =3D rt500_clkctl1_read, + .write_with_attrs =3D rt500_clkctl1_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + .unaligned =3D false, + }, +}; + +static void rt500_clkctl1_reset(Object *obj, ResetType type) +{ + RT500ClkCtl1State *s =3D RT500_CLKCTL1(obj); + + for (int i =3D 0; i < RT500_CLKCTL1_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); + } + } +} + +static void rt500_clkctl1_init(Object *obj) +{ + RT500ClkCtl1State *s =3D RT500_CLKCTL1(obj); + + memory_region_init_io(&s->mmio, obj, &rt500_clkctl1_ops, s, + TYPE_RT500_CLKCTL1, sizeof(s->regs)); + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); + s->sysclk =3D qdev_init_clock_in(DEVICE(s), "sysclk", NULL, NULL, 0); + s->ostimer_clk =3D qdev_init_clock_out(DEVICE(s), "ostimer_clk"); +} + +static const VMStateDescription vmstate_rt500_clkctl1 =3D { + .name =3D "rt500-clkctl1", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT32_ARRAY(regs, RT500ClkCtl1State, RT500_CLKCTL1_REGS_N= O), + VMSTATE_CLOCK(ostimer_clk, RT500ClkCtl1State), + VMSTATE_END_OF_LIST() + } +}; + +static void rt500_clkctl1_class_init(ObjectClass *klass, void *data) +{ + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + DeviceClass *dc =3D DEVICE_CLASS(klass); + + rc->phases.enter =3D rt500_clkctl1_reset; + dc->vmsd =3D &vmstate_rt500_clkctl1; + +} + +static const TypeInfo rt500_clkctl1_types[] =3D { + { + .name =3D TYPE_RT500_CLKCTL1, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(RT500ClkCtl1State), + .instance_init =3D rt500_clkctl1_init, + .class_init =3D rt500_clkctl1_class_init, + } +}; + +DEFINE_TYPES(rt500_clkctl1_types); diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index eac5070514..658af0dace 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -629,3 +629,8 @@ config ARMSSE select UNIMP select SSE_COUNTER select SSE_TIMER + +config RT500 + bool + select FLEXCOMM + select RT500_CLKCTL diff --git a/hw/arm/svd/meson.build b/hw/arm/svd/meson.build index e7d62a7f35..9c458b314c 100644 --- a/hw/arm/svd/meson.build +++ b/hw/arm/svd/meson.build @@ -16,4 +16,12 @@ if get_option('mcux-soc-svd') [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/flexcomm_spi.h', '-p', 'SPI0', '-t', 'FLEXCOMM_SPI', '--fields', 'CFG FIFOCFG:ENABLE*,EMPTY* FIFO*:* INT*: STAT']) + run_target('svd-rt500-clkctl0', command: svd_gen_header + + [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/rt500_clkctl0.h= ', + '-p', 'CLKCTL0', '-t', 'RT500_CLKCTL0', + '--fields', 'PSCCTL*:ROM_CTRLR_CLK,DSP_CLK SYSPLL0PFD SYSTICKFCLKSEL= SYSTICKFCLKDIV FROCLKSTATUS:']) + run_target('svd-rt500-clkctl1', command: svd_gen_header + + [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/rt500_clkctl1.h= ', + '-p', 'CLKCTL1', '-t', 'RT500_CLKCTL1', + '--fields', 'PSCCTL*:FlexIO AUDIOPLL0PFD OSEVENTTFCLKSEL']) endif diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig index b373e651e1..02feb93840 100644 --- a/hw/misc/Kconfig +++ b/hw/misc/Kconfig @@ -218,4 +218,7 @@ config FLEXCOMM select I2C select SSI =20 +config RT500_CLKCTL + bool + source macio/Kconfig diff --git a/hw/misc/meson.build b/hw/misc/meson.build index 0d901b9c65..15f9153be4 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -153,3 +153,4 @@ system_ss.add(when: 'CONFIG_SBSA_REF', if_true: files('= sbsa_ec.c')) system_ss.add(when: 'CONFIG_LASI', if_true: files('lasi.c')) =20 system_ss.add(when: 'CONFIG_FLEXCOMM', if_true: files('flexcomm.c')) +system_ss.add(when: 'CONFIG_RT500_CLKCTL', if_true: files('rt500_clkctl0.c= ', 'rt500_clkctl1.c')) diff --git a/hw/misc/trace-events b/hw/misc/trace-events index dc245905dc..b19393dd36 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -368,3 +368,11 @@ flexcomm_irq(const char *id, uint8_t irq) "%s %d" flexcomm_reg_read(const char *devname, const char *regname, uint32_t addr,= uint32_t val) "%s: %s[0x%04x] -> 0x%08x" flexcomm_reg_write(const char *dename, const char *regname, uint32_t addr,= uint32_t val) "%s: %s[0x%04x] <- 0x%08x" flexcomm_fifostat(const char *id, uint32_t fifostat, uint32_t fifoinstat) = "%s: %08x %08x" + +# rt500_clkctl0.c +rt500_clkctl0_reg_read(const char *regname, uint32_t addr, uint32_t val) "= %s[0x%04x] -> 0x%08x" +rt500_clkctl0_reg_write(const char *regname, uint32_t addr, uint32_t val) = "%s[0x%04x] <- 0x%08x" + +# rt500_clkctl1.c +rt500_clkctl1_reg_read(const char *regname, uint32_t addr, uint32_t val) "= %s[0x%04x] -> 0x%08x" +rt500_clkctl1_reg_write(const char *regname, uint32_t addr, uint32_t val) = "%s[0x%04x] <- 0x%08x" --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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 From nobody Sat Nov 23 21:39:54 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=1728350680; cv=none; d=zohomail.com; s=zohoarc; b=T5e8G0TBYkL5j+1F5bebI77E+tT0RfA76vH5F5BjB+OV+4vx5kMHW9VhL6CgNWWXXQ/SNRDtWjyF8G0ZozlmCtEwwZ+xakFUIPfAiPAS4H2gfg7wQVPqhiW8FN1eIPs+N8fNjbDkoqVEVkk0TfHJkf0fiejxbF1yBUBp0cXlOF4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350680; 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=YIWmowqh9ilBPFqbJVFwbgPlrwHIw046vPnX3/duUf8=; b=eeLkvFivO2IMbzxMhHaVBU6+znwAVpCZeMXwfvH968yxwJY2OGgrItTv5qO6E5BDZlnaeIlPnTnyQ3XJrZgkA2iqENPttmzYF3gKp+VYckspSb39VwOBYhudoRHFOkA7wb7TYEo9xVo5onbtU4GLHLejf3qE4cv4mKuumznJuOw= 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 1728350680550645.8421618487168; Mon, 7 Oct 2024 18:24:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxytB-0001Gt-Jz; Mon, 07 Oct 2024 21:19:50 -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 <3k4gEZwUKCvQpWrelckkcha.Ykimaiq-Zarahjkjcjq.knc@flex--tavip.bounces.google.com>) id 1sxysp-0007zo-SQ for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:30 -0400 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3k4gEZwUKCvQpWrelckkcha.Ykimaiq-Zarahjkjcjq.knc@flex--tavip.bounces.google.com>) id 1sxysi-0000Aj-DS for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:24 -0400 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-6e2e5e376fcso36890017b3.2 for ; Mon, 07 Oct 2024 18:19:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350356; x=1728955156; 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=YIWmowqh9ilBPFqbJVFwbgPlrwHIw046vPnX3/duUf8=; b=u7ui+LImFaOOJ5kLN/Jmoe0p2opkvfDsBTOeA0VDRthZMHvRzGRU5al3GHV9mtUeWc gFaEX2ivu3B0QGomD11CP4sbBhZVIzyIeYZDH5AGYUdTXPZp5b3Ni8KIDe9Zle0oMgnL YIv2d82Qcl2gLSaTeljpdRwY5KINJQF6BhO//9aX6d9DDHpluZg+g4eorTdTnOXDfNYe DkrqnfDhL/5P+sGfbnb50VfErshZA0k5jrHG7KJ8F8bg3xjOMzuniH1umvw7eKx9z4FT 5vJhje+nwb3sqFlt4dZeI+YkVPXV+BUdAOajR6jALm+dl0plhhXSlgTbkqK1ZR4ssM4C q/jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350356; x=1728955156; 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=YIWmowqh9ilBPFqbJVFwbgPlrwHIw046vPnX3/duUf8=; b=mSoH8JIS3KSl8/20t1cqmkOB5MeBga5iuw5ckaqFEKILFpLt51yk29y1kTfziVaRRr Ji8BOp1GqXQBhb2LyA3WVAtYkdEHuApLEfaHDkKyzolP8B563TEPcOwrAxK4f1dP3geL R0hhWbouHgvasWznYKOvX/s0DMfSElaiTw67BSO8+3Vb3SQ4fBWVD9KDoagnkHQPIsCj kwcthTnVFzW3v6XhL+n4wlka2DNQdf27IR0TblWklrFktuDvFwYAf63dszi5sMmxUb8G Ty6vC5iTQsjGhqBDG068yLkORGNjrbFFL0+LyrK4VX7h42cxWK/3ZPT41xG5zMvHru1l 25HQ== X-Gm-Message-State: AOJu0Ywevsl+797gUNv/iCkr0J37B1lE5I83l7bkQbpH0UZHZh67vTEX 460yLztxGn9CFh5S6xwJbTm7A3FqrcO5JIhUQuCjADpWTLgVPASe5k0ubkfPY5F9lH4O71H/UOD 9uCeQrR8JmY8yqh7KuJypfuZV6yY87MLytxHkEan5WPflnOaE8TCh/10R3LIXDl1TFlzjq4T52e A4fJQs7dlZtq9BIjvsaVw7bsOZ9g== X-Google-Smtp-Source: AGHT+IESayc9Ykh3LqzVr2AuC96ugMENmY3SXvFs8UUnrZxFn5w0W5/UBHaqraEly00eTLOFk6KJH0+Pgg== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a05:690c:2c87:b0:6e2:b263:1040 with SMTP id 00721157ae682-6e2c6e88722mr1437387b3.0.1728350355919; Mon, 07 Oct 2024 18:19:15 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:38 -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-13-tavip@google.com> Subject: [PATCH v2 12/25] hw/misc: add support for RT500's reset controller 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::1149; envelope-from=3k4gEZwUKCvQpWrelckkcha.Ykimaiq-Zarahjkjcjq.knc@flex--tavip.bounces.google.com; helo=mail-yw1-x1149.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: 1728350682711116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The RT500 reset controller has two instances that have the same register layout but with different fields for some registers. The model only provides set and clear functionality for the various reset lines which is common for both instances. Because of that only one type is implemented for both controllers. The patch includes automatically generated headers which contains the register layout and helpers. The header can be regenerated with the svd-rstctl0 and svd-rstctl1 targets when the build is configured with --enable-mcux-soc-svd. Signed-off-by: Octavian Purdila --- include/hw/arm/svd/rt500_rstctl0.h | 110 ++++++++++++ include/hw/arm/svd/rt500_rstctl1.h | 110 ++++++++++++ include/hw/misc/rt500_rstctl.h | 32 ++++ hw/misc/rt500_rstctl.c | 258 +++++++++++++++++++++++++++++ hw/arm/svd/meson.build | 8 + hw/misc/Kconfig | 3 + hw/misc/meson.build | 1 + hw/misc/trace-events | 4 + 8 files changed, 526 insertions(+) create mode 100644 include/hw/arm/svd/rt500_rstctl0.h create mode 100644 include/hw/arm/svd/rt500_rstctl1.h create mode 100644 include/hw/misc/rt500_rstctl.h create mode 100644 hw/misc/rt500_rstctl.c diff --git a/include/hw/arm/svd/rt500_rstctl0.h b/include/hw/arm/svd/rt500_= rstctl0.h new file mode 100644 index 0000000000..da25f22208 --- /dev/null +++ b/include/hw/arm/svd/rt500_rstctl0.h @@ -0,0 +1,110 @@ +/* + * 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" + +/* Reset Controller 0 */ +#define RT500_RSTCTL0_REGS_NO (31) + +/* System Reset Status Register */ +REG32(RT500_RSTCTL0_SYSRSTSTAT, 0x0); + +/* Peripheral Reset Control Register 0 */ +REG32(RT500_RSTCTL0_PRSTCTL0, 0x10); + +/* Peripheral Reset Control Register 1 */ +REG32(RT500_RSTCTL0_PRSTCTL1, 0x14); + +/* Peripheral Reset Control Register 2 */ +REG32(RT500_RSTCTL0_PRSTCTL2, 0x18); + +/* Peripheral Reset Control Register 0 SET */ +REG32(RT500_RSTCTL0_PRSTCTL0_SET, 0x40); + +/* Peripheral Reset Control Register 1 SET */ +REG32(RT500_RSTCTL0_PRSTCTL1_SET, 0x44); + +/* Peripheral Reset Control Register 2 SET */ +REG32(RT500_RSTCTL0_PRSTCTL2_SET, 0x48); + +/* Peripheral Reset Control Register 0 CLR */ +REG32(RT500_RSTCTL0_PRSTCTL0_CLR, 0x70); + +/* Peripheral Reset Control Register 1 CLR */ +REG32(RT500_RSTCTL0_PRSTCTL1_CLR, 0x74); + +/* Peripheral Reset Control Register 2 CLR */ +REG32(RT500_RSTCTL0_PRSTCTL2_CLR, 0x78); + + +#define RT500_RSTCTL0_REGISTER_ACCESS_INFO_ARRAY(_name) \ + struct RegisterAccessInfo _name[RT500_RSTCTL0_REGS_NO] =3D { \ + [0 ... RT500_RSTCTL0_REGS_NO - 1] =3D { \ + .name =3D "", \ + .addr =3D -1, \ + }, \ + [0x0] =3D { \ + .name =3D "SYSRSTSTAT", \ + .addr =3D 0x0, \ + .ro =3D 0xFFFFFF0E, \ + .reset =3D 0x1, \ + }, \ + [0x4] =3D { \ + .name =3D "PRSTCTL0", \ + .addr =3D 0x10, \ + .ro =3D 0x820AE0F5, \ + .reset =3D 0x7DF51F0A, \ + }, \ + [0x5] =3D { \ + .name =3D "PRSTCTL1", \ + .addr =3D 0x14, \ + .ro =3D 0xFEFE7FF3, \ + .reset =3D 0x101800C, \ + }, \ + [0x6] =3D { \ + .name =3D "PRSTCTL2", \ + .addr =3D 0x18, \ + .ro =3D 0xFFFFFFFC, \ + .reset =3D 0x1C000001, \ + }, \ + [0x10] =3D { \ + .name =3D "PRSTCTL0_SET", \ + .addr =3D 0x40, \ + .ro =3D 0x820AE0F5, \ + .reset =3D 0x0, \ + }, \ + [0x11] =3D { \ + .name =3D "PRSTCTL1_SET", \ + .addr =3D 0x44, \ + .ro =3D 0xFEFE7FF3, \ + .reset =3D 0x0, \ + }, \ + [0x12] =3D { \ + .name =3D "PRSTCTL2_SET", \ + .addr =3D 0x48, \ + .ro =3D 0xFFFFFFFC, \ + .reset =3D 0x0, \ + }, \ + [0x1C] =3D { \ + .name =3D "PRSTCTL0_CLR", \ + .addr =3D 0x70, \ + .ro =3D 0x820AE0F5, \ + .reset =3D 0x0, \ + }, \ + [0x1D] =3D { \ + .name =3D "PRSTCTL1_CLR", \ + .addr =3D 0x74, \ + .ro =3D 0xFEFE7FF3, \ + .reset =3D 0x0, \ + }, \ + [0x1E] =3D { \ + .name =3D "PRSTCTL2_CLR", \ + .addr =3D 0x78, \ + .ro =3D 0xFFFFFFFC, \ + .reset =3D 0x0, \ + }, \ + } diff --git a/include/hw/arm/svd/rt500_rstctl1.h b/include/hw/arm/svd/rt500_= rstctl1.h new file mode 100644 index 0000000000..7b0380798f --- /dev/null +++ b/include/hw/arm/svd/rt500_rstctl1.h @@ -0,0 +1,110 @@ +/* + * 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" + +/* Reset Controller 1 */ +#define RT500_RSTCTL1_REGS_NO (31) + +/* System Reset Status Register */ +REG32(RT500_RSTCTL1_SYSRSTSTAT, 0x0); + +/* Peripheral Reset Control Register 0 */ +REG32(RT500_RSTCTL1_PRSTCTL0, 0x10); + +/* Peripheral Reset Control Register 1 */ +REG32(RT500_RSTCTL1_PRSTCTL1, 0x14); + +/* Peripheral Reset Control Register 2 */ +REG32(RT500_RSTCTL1_PRSTCTL2, 0x18); + +/* Peripheral Reset Control Register 0 SET */ +REG32(RT500_RSTCTL1_PRSTCTL0_SET, 0x40); + +/* Peripheral Reset Control Register 1 SET */ +REG32(RT500_RSTCTL1_PRSTCTL1_SET, 0x44); + +/* Peripheral Reset Control Register 2 SET */ +REG32(RT500_RSTCTL1_PRSTCTL2_SET, 0x48); + +/* Peripheral Reset Control Register 0 CLR */ +REG32(RT500_RSTCTL1_PRSTCTL0_CLR, 0x70); + +/* Peripheral Reset Control Register 1 CLR */ +REG32(RT500_RSTCTL1_PRSTCTL1_CLR, 0x74); + +/* Peripheral Reset Control Register 2 CLR */ +REG32(RT500_RSTCTL1_PRSTCTL2_CLR, 0x78); + + +#define RT500_RSTCTL1_REGISTER_ACCESS_INFO_ARRAY(_name) \ + struct RegisterAccessInfo _name[RT500_RSTCTL1_REGS_NO] =3D { \ + [0 ... RT500_RSTCTL1_REGS_NO - 1] =3D { \ + .name =3D "", \ + .addr =3D -1, \ + }, \ + [0x0] =3D { \ + .name =3D "SYSRSTSTAT", \ + .addr =3D 0x0, \ + .ro =3D 0xFFFFFFFF, \ + .reset =3D 0x1, \ + }, \ + [0x4] =3D { \ + .name =3D "PRSTCTL0", \ + .addr =3D 0x10, \ + .ro =3D 0xD40000FF, \ + .reset =3D 0x1C0FF00, \ + }, \ + [0x5] =3D { \ + .name =3D "PRSTCTL1", \ + .addr =3D 0x14, \ + .ro =3D 0x4E7EFF00, \ + .reset =3D 0xB18100FF, \ + }, \ + [0x6] =3D { \ + .name =3D "PRSTCTL2", \ + .addr =3D 0x18, \ + .ro =3D 0x3FFCFAE0, \ + .reset =3D 0xC001011F, \ + }, \ + [0x10] =3D { \ + .name =3D "PRSTCTL0_SET", \ + .addr =3D 0x40, \ + .ro =3D 0xD40000FF, \ + .reset =3D 0x0, \ + }, \ + [0x11] =3D { \ + .name =3D "PRSTCTL1_SET", \ + .addr =3D 0x44, \ + .ro =3D 0x4E7EFF00, \ + .reset =3D 0x0, \ + }, \ + [0x12] =3D { \ + .name =3D "PRSTCTL2_SET", \ + .addr =3D 0x48, \ + .ro =3D 0x3FFCFAE0, \ + .reset =3D 0x0, \ + }, \ + [0x1C] =3D { \ + .name =3D "PRSTCTL0_CLR", \ + .addr =3D 0x70, \ + .ro =3D 0xD40000FF, \ + .reset =3D 0x0, \ + }, \ + [0x1D] =3D { \ + .name =3D "PRSTCTL1_CLR", \ + .addr =3D 0x74, \ + .ro =3D 0x4E7EFF00, \ + .reset =3D 0x0, \ + }, \ + [0x1E] =3D { \ + .name =3D "PRSTCTL2_CLR", \ + .addr =3D 0x78, \ + .ro =3D 0x3FFCFAE0, \ + .reset =3D 0x0, \ + }, \ + } diff --git a/include/hw/misc/rt500_rstctl.h b/include/hw/misc/rt500_rstctl.h new file mode 100644 index 0000000000..ae7e304b2e --- /dev/null +++ b/include/hw/misc/rt500_rstctl.h @@ -0,0 +1,32 @@ +/* + * QEMU model for RT500 Reset Controller + * + * 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_MISC_RT500_RSTCTL_H +#define HW_MISC_RT500_RSTCTL_H + +#include "hw/arm/svd/rt500_rstctl0.h" +#include "hw/arm/svd/rt500_rstctl1.h" +#include "hw/sysbus.h" + +#define TYPE_RT500_RSTCTL "rt500-rstctl" +#define RT500_RSTCTL(o) OBJECT_CHECK(RT500RstCtlState, o, TYPE_RT500_RSTCT= L) + +#define TYPE_RT500_RSTCTL0 "rt500-rstctl0" +#define TYPE_RT500_RSTCTL1 "rt500-rstctl1" + +typedef struct { + SysBusDevice parent_obj; + + MemoryRegion mmio; + uint32_t regs[RT500_RSTCTL1_REGS_NO]; +} RT500RstCtlState; + +#endif /* HW_MISC_RT500_RSTCTL_H */ diff --git a/hw/misc/rt500_rstctl.c b/hw/misc/rt500_rstctl.c new file mode 100644 index 0000000000..a6e818c0a0 --- /dev/null +++ b/hw/misc/rt500_rstctl.c @@ -0,0 +1,258 @@ +/* + * QEMU model for RT500 Reset Controller + * + * 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 "qapi/error.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "exec/address-spaces.h" +#include "migration/vmstate.h" +#include "hw/misc/rt500_rstctl.h" + +#include "trace.h" + +/* + * There are two intances for RSTCTL with the same register names and layo= ut but + * with different fields. + */ +#define BUILD_BUG_REG_ADDR(reg) \ + QEMU_BUILD_BUG_ON((int)A_RT500_RSTCTL0_##reg !=3D (int)A_RT500_RSTCTL1= _##reg) + +#define REG(s, reg) (s->regs[R_RT500_RSTCTL0_##reg]) +#define RF_WR(s, reg, field, val) \ + ARRAY_FIELD_DP32(s->regs, RT500_RSTCTL0_##reg, field, val) +#define RF_RD(s, reg, field) \ + ARRAY_FIELD_EX32(s->regs, RT500_RSTCTL0_##reg, field) + +#define RSTCTL_SYSRSTSTAT_WMASK (BITS(7, 4) | BIT(0)) +#define RSTCL0_PRSCTL0_WMASK (BITS(30, 26) | BITS(24, 20) | BIT(18) | \ + BIT(16) | BITS(12, 8) | BIT(3) | BIT(1)) +#define RSTCL0_PRSCTL1_WMASK (BIT(24) | BITS(16, 15) | BITS(3, 2)) +#define RSTCL0_PRSCTL2_WMASK (BITS(1, 0)) +#define RSTCL1_PRSCTL0_WMASK (BIT(29) | BIT(27) | BITS(25, 8)) +#define RSTCL1_PRSCTL1_WMASK (BIT(31) | BITS(29, 28) | BITS(24, 23) | \ + BIT(16) | BITS(7, 0)) +#define RSTCL1_PRSCTL2_WMASK (BITS(31, 30) | BITS(17, 16) | BIT(10) | \ + BIT(8) | BITS(4, 0)) + + +/* + * The two RSTCLK modules have different write register masks. + */ +typedef struct { + SysBusDeviceClass parent; + const struct RegisterAccessInfo *reg_info; + int reg_info_num; +} RT500RstCtlClass; + +#define RT500_RSTCTL_CLASS(klass) \ + OBJECT_CLASS_CHECK(RT500RstCtlClass, (klass), TYPE_RT500_RSTCTL) +#define RT500_RSTCTL_GET_CLASS(obj) \ + OBJECT_GET_CLASS(RT500RstCtlClass, (obj), TYPE_RT500_RSTCTL) + +BUILD_BUG_REG_ADDR(SYSRSTSTAT); +BUILD_BUG_REG_ADDR(PRSTCTL0); +BUILD_BUG_REG_ADDR(PRSTCTL1); +BUILD_BUG_REG_ADDR(PRSTCTL2); +BUILD_BUG_REG_ADDR(PRSTCTL0_SET); +BUILD_BUG_REG_ADDR(PRSTCTL1_SET); +BUILD_BUG_REG_ADDR(PRSTCTL2_SET); +BUILD_BUG_REG_ADDR(PRSTCTL0_CLR); +BUILD_BUG_REG_ADDR(PRSTCTL1_CLR); +BUILD_BUG_REG_ADDR(PRSTCTL2_CLR); + +static MemTxResult rt500_rstctl_read(void *opaque, hwaddr addr, + uint64_t *data, unsigned size, + MemTxAttrs attrs) +{ + RT500RstCtlState *s =3D opaque; + RT500RstCtlClass *c =3D RT500_RSTCTL_GET_CLASS(s); + const struct RegisterAccessInfo *rai =3D &c->reg_info[addr / 4]; + MemTxResult ret =3D MEMTX_OK; + + switch (addr) { + case A_RT500_RSTCTL0_SYSRSTSTAT: + case A_RT500_RSTCTL0_PRSTCTL0: + case A_RT500_RSTCTL0_PRSTCTL1: + case A_RT500_RSTCTL0_PRSTCTL2: + *data =3D s->regs[addr / 4]; + break; + default: + ret =3D MEMTX_ERROR; + } + + trace_rt500_rstctl_reg_read(DEVICE(s)->id, rai->name, addr, *data); + return ret; +} + +static MemTxResult rt500_rstctl_write(void *opaque, hwaddr addr, + uint64_t value, unsigned size, + MemTxAttrs attrs) +{ + RT500RstCtlState *s =3D opaque; + RT500RstCtlClass *c =3D RT500_RSTCTL_GET_CLASS(s); + const struct RegisterAccessInfo *rai =3D &c->reg_info[addr / 4]; + struct RegisterInfo ri =3D { + .data =3D &s->regs[addr / 4], + .data_size =3D 4, + .access =3D rai, + }; + + trace_rt500_rstctl_reg_write(DEVICE(s)->id, rai->name, addr, value); + + switch (addr) { + case A_RT500_RSTCTL0_SYSRSTSTAT: + { + /* write 1 to clear bits */ + REG(s, SYSRSTSTAT) &=3D ~value; + break; + } + case A_RT500_RSTCTL0_PRSTCTL0: + case A_RT500_RSTCTL0_PRSTCTL1: + case A_RT500_RSTCTL0_PRSTCTL2: + { + register_write(&ri, value, ~0, NULL, false); + break; + } + case A_RT500_RSTCTL0_PRSTCTL0_SET: + case A_RT500_RSTCTL0_PRSTCTL1_SET: + case A_RT500_RSTCTL0_PRSTCTL2_SET: + { + uint32_t tmp; + + tmp =3D A_RT500_RSTCTL0_PRSTCTL0 + (addr - A_RT500_RSTCTL0_PRSTCTL= 0_SET); + s->regs[tmp / 4] |=3D value; + break; + } + case A_RT500_RSTCTL0_PRSTCTL0_CLR: + case A_RT500_RSTCTL0_PRSTCTL1_CLR: + case A_RT500_RSTCTL0_PRSTCTL2_CLR: + { + uint32_t tmp; + + tmp =3D A_RT500_RSTCTL0_PRSTCTL0 + (addr - A_RT500_RSTCTL0_PRSTCTL= 0_CLR); + s->regs[tmp / 4] &=3D ~value; + break; + } + } + + return MEMTX_OK; +} + +static const MemoryRegionOps rt500_rstctl_ops =3D { + .read_with_attrs =3D rt500_rstctl_read, + .write_with_attrs =3D rt500_rstctl_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .valid =3D { + .min_access_size =3D 1, + .max_access_size =3D 4, + .unaligned =3D false, + }, +}; + +static void rt500_rstctl_reset_enter(Object *obj, ResetType type) +{ + RT500RstCtlState *s =3D RT500_RSTCTL(obj); + RT500RstCtlClass *c =3D RT500_RSTCTL_GET_CLASS(s); + + for (int i =3D 0; i < c->reg_info_num; i++) { + hwaddr addr =3D c->reg_info[i].addr; + + if (addr !=3D -1) { + struct RegisterInfo ri =3D { + .data =3D &s->regs[addr / 4], + .data_size =3D 4, + .access =3D &c->reg_info[i], + }; + + register_reset(&ri); + } + } +} + +static void rt500_rstctl_init(Object *obj) +{ + RT500RstCtlState *s =3D RT500_RSTCTL(obj); + + memory_region_init_io(&s->mmio, obj, &rt500_rstctl_ops, s, + TYPE_RT500_RSTCTL, sizeof(s->regs)); + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); +} + +static const VMStateDescription vmstate_rt500_rstcl0 =3D { + .name =3D "rt500-rstctl0", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT32_ARRAY(regs, RT500RstCtlState, RT500_RSTCTL0_REGS_NO= ), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_rt500_rstcl1 =3D { + .name =3D "rt500-rstctl1", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT32_ARRAY(regs, RT500RstCtlState, RT500_RSTCTL1_REGS_NO= ), + VMSTATE_END_OF_LIST() + } +}; + +static void rt500_rstctl0_class_init(ObjectClass *klass, void *data) +{ + RT500RstCtlClass *rc =3D RT500_RSTCTL_CLASS(klass); + static const RT500_RSTCTL0_REGISTER_ACCESS_INFO_ARRAY(reg_info); + DeviceClass *dc =3D DEVICE_CLASS(klass); + + RESETTABLE_CLASS(klass)->phases.enter =3D rt500_rstctl_reset_enter; + dc->vmsd =3D &vmstate_rt500_rstcl0; + rc->reg_info =3D reg_info; + rc->reg_info_num =3D ARRAY_SIZE(reg_info); +} + +static void rt500_rstctl1_class_init(ObjectClass *klass, void *data) +{ + RT500RstCtlClass *rc =3D RT500_RSTCTL_CLASS(klass); + static const RT500_RSTCTL1_REGISTER_ACCESS_INFO_ARRAY(reg_info); + DeviceClass *dc =3D DEVICE_CLASS(klass); + + RESETTABLE_CLASS(klass)->phases.enter =3D rt500_rstctl_reset_enter; + dc->vmsd =3D &vmstate_rt500_rstcl1; + rc->reg_info =3D reg_info; + rc->reg_info_num =3D ARRAY_SIZE(reg_info); +} + +static const TypeInfo rt500_rstctl_types[] =3D { + { + .name =3D TYPE_RT500_RSTCTL, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(RT500RstCtlState), + .instance_init =3D rt500_rstctl_init, + .abstract =3D true, + }, + { + .name =3D TYPE_RT500_RSTCTL0, + .parent =3D TYPE_RT500_RSTCTL, + .class_init =3D rt500_rstctl0_class_init, + .class_size =3D sizeof(RT500RstCtlClass), + }, + { + .name =3D TYPE_RT500_RSTCTL1, + .parent =3D TYPE_RT500_RSTCTL, + .class_init =3D rt500_rstctl1_class_init, + .class_size =3D sizeof(RT500RstCtlClass), + }, +}; + +DEFINE_TYPES(rt500_rstctl_types); diff --git a/hw/arm/svd/meson.build b/hw/arm/svd/meson.build index adf0f8327a..eb2fab54f5 100644 --- a/hw/arm/svd/meson.build +++ b/hw/arm/svd/meson.build @@ -28,4 +28,12 @@ if get_option('mcux-soc-svd') [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/flexspi.h', '-p', 'FLEXSPI0', '-t', 'FLEXSPI', '--fields', 'STS0:SEQIDLE MCR0:SWRESET INTR:IPCMDDONE']) + run_target('svd-rt500-rstctl0', command: svd_gen_header + + [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/rt500_rstctl0.h= ', + '-p', 'RSTCTL0', '-t', 'RT500_RSTCTL0', + '--fields', 'SYSRSTSTAT: PRSTCTL*:']) + run_target('svd-rt500-rstctl1', command: svd_gen_header + + [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/rt500_rstctl1.h= ', + '-p', 'RSTCTL1', '-t', 'RT500_RSTCTL1', + '--fields', 'SYSRSTSTAT: PRSTCTL*:']) endif diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig index 02feb93840..4b688aead2 100644 --- a/hw/misc/Kconfig +++ b/hw/misc/Kconfig @@ -221,4 +221,7 @@ config FLEXCOMM config RT500_CLKCTL bool =20 +config RT500_RSTCTL + bool + source macio/Kconfig diff --git a/hw/misc/meson.build b/hw/misc/meson.build index 15f9153be4..bf0988fd43 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -154,3 +154,4 @@ system_ss.add(when: 'CONFIG_LASI', if_true: files('lasi= .c')) =20 system_ss.add(when: 'CONFIG_FLEXCOMM', if_true: files('flexcomm.c')) system_ss.add(when: 'CONFIG_RT500_CLKCTL', if_true: files('rt500_clkctl0.c= ', 'rt500_clkctl1.c')) +system_ss.add(when: 'CONFIG_RT500_RSTCTL', if_true: files('rt500_rstctl.c'= )) diff --git a/hw/misc/trace-events b/hw/misc/trace-events index b19393dd36..721ebe4bb7 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -376,3 +376,7 @@ rt500_clkctl0_reg_write(const char *regname, uint32_t a= ddr, uint32_t val) "%s[0x # rt500_clkctl1.c rt500_clkctl1_reg_read(const char *regname, uint32_t addr, uint32_t val) "= %s[0x%04x] -> 0x%08x" rt500_clkctl1_reg_write(const char *regname, uint32_t addr, uint32_t val) = "%s[0x%04x] <- 0x%08x" + +# rt500_rstctl.c +rt500_rstctl_reg_read(const char *id, const char *regname, uint32_t addr, = uint32_t val) "%s: %s[0x%04x] -> 0x%08x" +rt500_rstctl_reg_write(const char *id, const char *regname, uint32_t addr,= uint32_t val) "%s: %s[0x%04x] <- 0x%08x" --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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=1728350654; cv=none; d=zohomail.com; s=zohoarc; b=UQutSlIBQFu/iXxq/wYgJDb0uWf5YbBE8Iz6f0llgN+alNIKnj2MFKQVnUleej8a0oMOd0C8QgGTLxtGMPZFVLSNxDPZu/y3rgDNR3mEnoDH+5yL4ADH0/1EEabfcBo5fomjmP1vUvjQWeI2+fGQBBM1MOT/AW/9LRrxlxvxRvY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350654; 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=MU5YuE7TbN7tgwjXYtOFaVtjIUQzKCZ1o/vW2KAogII=; b=JCBioCAweQveMiQFoeCp6FHvDv0vVU3JCJ8n1ccnDRyYTCSoFiMSEZyRDXcKjBnF8Q/E95QAoL+08dntSrKDxrfl3epoU2A9JKZsMQMUpX1J304FYN5glVEnhhBclwvVYx6rGPhaUq9MZJFDEXwTb+ElYvGI/N5MQBQe487oi7g= 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 1728350654753923.7255858438772; Mon, 7 Oct 2024 18:24:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxytf-000352-FQ; Mon, 07 Oct 2024 21:20:19 -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 <3lYgEZwUKCvYrYtgnemmejc.amkocks-bctcjlmlels.mpe@flex--tavip.bounces.google.com>) id 1sxysq-0007zr-1g for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:30 -0400 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3lYgEZwUKCvYrYtgnemmejc.amkocks-bctcjlmlels.mpe@flex--tavip.bounces.google.com>) id 1sxysi-0000B3-RC for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:24 -0400 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-7db4c1a55f5so3866530a12.3 for ; Mon, 07 Oct 2024 18:19:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350359; x=1728955159; 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=MU5YuE7TbN7tgwjXYtOFaVtjIUQzKCZ1o/vW2KAogII=; b=qORONHHoVHs2rgA0YywavVNLu/wtwfjSQ87uDzc0EdFMohQG26PJm9GECnuOpjxbKK DZ9FoQNOG6uzx69mh8/iOjYaPzQnPfk593hmyMb8MTuOB4exCSxzRs0Pdb+YUX+NjBOU mQeQNUskZgZKaAXnyok8sXX2GAk2ao7jPBsuE3bQFo+PGIXqFmhSCxwW5ChNOuYSoim+ O2drsJ+cw23fVkBimtHawNQDziI6iT1DJjsa6dcNCwyavz+e3xr5F1PeOIWq5GHXR35q kkxYkep857gfAMYTBFqOVuBaIzr1QFjSjpHo0zuhmprzCxRl8y7msazunHhdcYqbNE4v 5WBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350359; x=1728955159; 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=MU5YuE7TbN7tgwjXYtOFaVtjIUQzKCZ1o/vW2KAogII=; b=kX3gTDpiV05mZUhVKmXRE044D8ocx27RZ8QA0PczWgEAReOP3485GVYGZt0MaIFa9u 8BZohdNqfGz35nrUom+Omhj41kj27BSbKiNdrqTK/j9wvdxNij0NBuSqZkVmlohcoy9w elRIjDoZ4o+ddX1Q7lhRG2cXcn5Vg9NX9sbfxrMoEo9dPDPoSUSwqTKnxC/0IObFi80u pJlBlDmtCinoXV8kwvDhLPHH5d/uHvGq3cxqleEDTMCgdIWu+Dgb1p3SHfQmpth09pCk EpooJNpqXfAiedbmC8GI1WZ6dav1RBWykcyriIKkyFxPyES6AIMYGenJfJmj+8nhORKC mDYQ== X-Gm-Message-State: AOJu0YxtYXOExUYUsZMjnXxb/OXz5WgioRFG1D8BiRgnFEWhzyjfsX+t wPf4TaY4Cxdqav0EBTKd5Bc5+0UxxTCcnqkhbDwkqNj8+2xdoKUrg/faDhRGdUfRIOSOoUcOoun huZd7dSbL88FD5x7jOWsNzc0iD71/pgeXw2/96Sv2BDToi3YwAizKlSuBLvKtkBXC30yLt+k6Hv fOkkEkdaTxyVrZSelfsBCEm22LPw== X-Google-Smtp-Source: AGHT+IF9HmhXENweSQdSkW/S0XYyeFBm6fSlA4GmVOmyIujg2iYLS3N7nrXt7nYk0lLC8ZtlqSu12hmCww== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a63:131a:0:b0:6e7:95d3:b35c with SMTP id 41be03b00d2f7-7e9e5a05778mr15039a12.5.1728350357755; Mon, 07 Oct 2024 18:19:17 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:39 -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-14-tavip@google.com> Subject: [PATCH v2 13/25] hw/arm: add basic support for the RT500 SoC 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::549; envelope-from=3lYgEZwUKCvYrYtgnemmejc.amkocks-bctcjlmlels.mpe@flex--tavip.bounces.google.com; helo=mail-pg1-x549.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: 1728350656930116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add basic support for the RT500 SoC. It supports enough peripherals to run the NXP's microXpresso SDK hello world example. The patch includes an automatically generated header which contains peripheral base addreses and interrupt numbers. The header can be regenerated with the svd-rt500 target when the build is configured with --enable-mcux-soc-svd. Signed-off-by: Octavian Purdila --- include/hw/arm/rt500.h | 44 +++++ include/hw/arm/svd/rt500.h | 63 +++++++ hw/arm/rt500.c | 329 +++++++++++++++++++++++++++++++++++++ hw/arm/Kconfig | 2 + hw/arm/meson.build | 1 + hw/arm/svd/meson.build | 4 + 6 files changed, 443 insertions(+) create mode 100644 include/hw/arm/rt500.h create mode 100644 include/hw/arm/svd/rt500.h create mode 100644 hw/arm/rt500.c diff --git a/include/hw/arm/rt500.h b/include/hw/arm/rt500.h new file mode 100644 index 0000000000..26e08c39a6 --- /dev/null +++ b/include/hw/arm/rt500.h @@ -0,0 +1,44 @@ +/* + * i.MX RT500 platforms. + * + * 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_ARM_RT500_H +#define HW_ARM_RT500_H + +#include "hw/arm/armv7m.h" +#include "hw/misc/flexcomm.h" +#include "hw/misc/rt500_clkctl0.h" +#include "hw/misc/rt500_clkctl1.h" +#include "hw/ssi/flexspi.h" +#include "hw/misc/rt500_rstctl.h" + +#define TYPE_RT500 "rt500" +#define RT500(obj) OBJECT_CHECK(RT500State, (obj), TYPE_RT500) + +#define RT500_FLEXCOMM_NUM (17) +#define RT500_FLEXSPI_NUM (2) +#define RT500_RSTCTL_NUM (2) + +typedef struct RT500State { + SysBusDevice parent_obj; + + ARMv7MState armv7m; + MemoryRegion *mem; + FlexcommState flexcomm[RT500_FLEXCOMM_NUM]; + RT500ClkCtl0State clkctl0; + RT500ClkCtl1State clkctl1; + FlexSpiState flexspi[RT500_FLEXSPI_NUM]; + RT500RstCtlState rstctl[RT500_RSTCTL_NUM]; + + Clock *sysclk; + Clock *refclk; +} RT500State; + +#endif /* HW_ARM_RT500_H */ diff --git a/include/hw/arm/svd/rt500.h b/include/hw/arm/svd/rt500.h new file mode 100644 index 0000000000..3594258f2e --- /dev/null +++ b/include/hw/arm/svd/rt500.h @@ -0,0 +1,63 @@ +/* + * Copyright 2016-2023 NXP SPDX-License-Identifier: BSD-3-Clause + * + * Automatically generated by svd-gen-header.py from MIMXRT595S_cm33.xml + */ +#pragma once + +#define RT500_FLEXCOMM0_BASE 0x40106000UL +#define RT500_FLEXCOMM1_BASE 0x40107000UL +#define RT500_FLEXCOMM2_BASE 0x40108000UL +#define RT500_FLEXCOMM3_BASE 0x40109000UL +#define RT500_FLEXCOMM4_BASE 0x40122000UL +#define RT500_FLEXCOMM5_BASE 0x40123000UL +#define RT500_FLEXCOMM6_BASE 0x40124000UL +#define RT500_FLEXCOMM7_BASE 0x40125000UL +#define RT500_FLEXCOMM14_BASE 0x40126000UL +#define RT500_FLEXCOMM15_BASE 0x40127000UL +#define RT500_FLEXCOMM16_BASE 0x40128000UL +#define RT500_FLEXCOMM8_BASE 0x40209000UL +#define RT500_FLEXCOMM9_BASE 0x4020A000UL +#define RT500_FLEXCOMM10_BASE 0x4020B000UL +#define RT500_FLEXCOMM11_BASE 0x4020C000UL +#define RT500_FLEXCOMM12_BASE 0x4020D000UL +#define RT500_FLEXCOMM13_BASE 0x4020E000UL + +#define RT500_FLEXCOMM0_IRQn 0x14UL +#define RT500_FLEXCOMM1_IRQn 0x15UL +#define RT500_FLEXCOMM2_IRQn 0x16UL +#define RT500_FLEXCOMM3_IRQn 0x17UL +#define RT500_FLEXCOMM4_IRQn 0x18UL +#define RT500_FLEXCOMM5_IRQn 0x19UL +#define RT500_FLEXCOMM6_IRQn 0x43UL +#define RT500_FLEXCOMM7_IRQn 0x44UL +#define RT500_FLEXCOMM14_IRQn 0x20UL +#define RT500_FLEXCOMM15_IRQn 0x21UL +#define RT500_FLEXCOMM16_IRQn 0x66UL +#define RT500_FLEXCOMM8_IRQn 0x60UL +#define RT500_FLEXCOMM9_IRQn 0x61UL +#define RT500_FLEXCOMM10_IRQn 0x62UL +#define RT500_FLEXCOMM11_IRQn 0x63UL +#define RT500_FLEXCOMM12_IRQn 0x64UL +#define RT500_FLEXCOMM13_IRQn 0x65UL + +#define RT500_CLKCTL0_BASE 0x40001000UL + + +#define RT500_CLKCTL1_BASE 0x40021000UL + + +#define RT500_FLEXSPI0_BASE 0x40134000UL + +#define RT500_FLEXSPI0_FLEXSPI1_IRQn 0x42UL + +#define RT500_FLEXSPI1_BASE 0x4013C000UL + +#define RT500_FLEXSPI0_FLEXSPI1_IRQn 0x42UL + +#define RT500_RSTCTL0_BASE 0x40000000UL + + +#define RT500_RSTCTL1_BASE 0x40020000UL + + diff --git a/hw/arm/rt500.c b/hw/arm/rt500.c new file mode 100644 index 0000000000..9e4cfb539e --- /dev/null +++ b/hw/arm/rt500.c @@ -0,0 +1,329 @@ +/* + * i.MX RT500 platforms. + * + * 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 "qapi/error.h" +#include "hw/sysbus.h" +#include "hw/arm/boot.h" +#include "hw/boards.h" +#include "hw/irq.h" +#include "qemu/log.h" +#include "qemu/datadir.h" +#include "qemu/units.h" +#include "exec/address-spaces.h" +#include "sysemu/reset.h" +#include "sysemu/runstate.h" +#include "sysemu/sysemu.h" +#include "hw/arm/armv7m.h" +#include "hw/loader.h" +#include "hw/qdev-clock.h" +#include "hw/misc/unimp.h" +#include "hw/arm/rt500.h" +#include "hw/arm/svd/rt500.h" + +#define MMAP_SRAM_CODE_BASE (0x0) +#define MMAP_SRAM_DATA_BASE (0x20000000) +#define MMAP_SRAM_SIZE (5 * MiB) +#define MMAP_BOOT_ROM_BASE (0x03000000) +#define MMAP_BOOT_ROM_SIZE (192 * KiB) +#define MMAP_SDMA_RAM_BASE (0x24100000) +#define MMAP_SDMA_RAM_SIZE (32 * KiB) +#define MMAP_FLEXSPI0_BASE (0x08000000) +#define MMAP_FLEXSPI0_SIZE (128 * MiB) +#define MMAP_FLEXSPI1_BASE (0x28000000) +#define MMAP_FLEXSPI1_SIZE (128 * MiB) + +#define SECURE_OFFSET (0x10000000) + +#define RT500_NUM_IRQ (RT500_FLEXCOMM16_IRQn + 1) + +typedef enum MemInfoType { + MEM_RAM, + MEM_ROM, + MEM_ALIAS +} MemInfoType; + +static void do_sys_reset(void *opaque, int n, int level) +{ + if (level) { + qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); + } +} + +static void rt500_init(Object *obj) +{ + RT500State *s =3D RT500(obj); + + /* Add ARMv7-M device */ + object_initialize_child(obj, "armv7m", &s->armv7m, TYPE_ARMV7M); + + for (int i =3D 0; i < RT500_FLEXCOMM_NUM; i++) { + char *id =3D g_strdup_printf("flexcomm%d", i); + + object_initialize_child(obj, id, &s->flexcomm[i], TYPE_FLEXCOMM); + DEVICE(&s->flexcomm[i])->id =3D id; + } + + object_initialize_child(obj, "clkctl0", &s->clkctl0, TYPE_RT500_CLKCTL= 0); + object_initialize_child(obj, "clkctl1", &s->clkctl1, TYPE_RT500_CLKCTL= 1); + + /* Initialize clocks */ + s->sysclk =3D qdev_init_clock_in(DEVICE(s), "sysclk", NULL, NULL, 0); + s->refclk =3D qdev_init_clock_in(DEVICE(s), "refclk", NULL, NULL, 0); + + for (int i =3D 0; i < RT500_FLEXSPI_NUM; i++) { + char *id =3D g_strdup_printf("flexspi%d", i); + + object_initialize_child(obj, id, &s->flexspi[i], TYPE_FLEXSPI); + DEVICE(&s->flexspi[i])->id =3D id; + } + + for (int i =3D 0; i < RT500_RSTCTL_NUM; i++) { + static const char *types[] =3D { + TYPE_RT500_RSTCTL0, TYPE_RT500_RSTCTL1 + }; + char *id =3D g_strdup_printf("rstctl%d", i); + + object_initialize_child(obj, id, &s->rstctl[i], types[i]); + DEVICE(&s->rstctl[i])->id =3D id; + } +} + +static void rt500_realize_memory(RT500State *s, Error **errp) +{ + static const struct { + const char *name; + hwaddr base; + size_t size; + MemInfoType type; + int alias_for; + } mem_info[] =3D { + { + .name =3D "SRAM (code bus)", + .base =3D MMAP_SRAM_CODE_BASE, + .size =3D MMAP_SRAM_SIZE, + .type =3D MEM_RAM, + }, + { + .name =3D "BOOT-ROM", + .base =3D MMAP_BOOT_ROM_BASE, + .size =3D MMAP_BOOT_ROM_SIZE, + .type =3D MEM_ROM, + }, + { + .name =3D "Smart DMA RAM", + .base =3D MMAP_SDMA_RAM_BASE, + .size =3D MMAP_SDMA_RAM_SIZE, + .type =3D MEM_RAM, + }, + { + .name =3D "SRAM (data bus)", + .base =3D MMAP_SRAM_DATA_BASE, + .size =3D MMAP_SRAM_SIZE, + .type =3D MEM_ALIAS, + .alias_for =3D 0 + }, + }; + + s->mem =3D g_malloc_n(2 * ARRAY_SIZE(mem_info), sizeof(MemoryRegion)); + for (int i =3D 0; i < ARRAY_SIZE(mem_info); i++) { + const char *name =3D mem_info[i].name; + int size =3D mem_info[i].size; + int type =3D mem_info[i].type; + int alias_for =3D mem_info[i].alias_for; + MemoryRegion *mem =3D &s->mem[i]; + uint32_t base =3D mem_info[i].base; + MemoryRegion *sec_mem; + char sec_name[256]; + + switch (type) { + case MEM_RAM: + memory_region_init_ram(mem, OBJECT(s), name, size, errp); + break; + case MEM_ROM: + memory_region_init_rom(mem, OBJECT(s), name, size, errp); + break; + case MEM_ALIAS: + { + MemoryRegion *orig =3D &s->mem[alias_for]; + + memory_region_init_alias(mem, OBJECT(s), name, orig, 0, size); + break; + } + default: + g_assert_not_reached(); + } + + memory_region_add_subregion(get_system_memory(), base, mem); + + /* create secure alias */ + snprintf(sec_name, sizeof(sec_name), "SECURE %s", name); + sec_mem =3D &s->mem[ARRAY_SIZE(mem_info) + i]; + if (type =3D=3D MEM_ALIAS) { + mem =3D &s->mem[alias_for]; + } + memory_region_init_alias(sec_mem, OBJECT(s), sec_name, mem, 0, siz= e); + memory_region_add_subregion(get_system_memory(), base + SECURE_OFF= SET, + sec_mem); + + if (mem_info[i].type =3D=3D MEM_ROM) { + char *fname =3D qemu_find_file(QEMU_FILE_TYPE_BIOS, "rt500.rom= "); + + if (fname) { + int fsize =3D get_image_size(fname); + int ret; + + if (fsize > size) { + error_setg(errp, "rom file too big: %d > %d", fsize, s= ize); + } else { + ret =3D load_image_targphys(fname, base, size); + if (ret < 0) { + error_setg(errp, "could not load rom: %s", fname); + } + } + } + g_free(fname); + } + } +} + +static void rt500_realize(DeviceState *dev, Error **errp) +{ + MachineState *ms =3D MACHINE(qdev_get_machine()); + RT500State *s =3D RT500(dev); + + rt500_realize_memory(s, errp); + + /* Setup ARMv7M CPU */ + qdev_prop_set_uint32(DEVICE(&s->armv7m), "num-irq", RT500_NUM_IRQ); + qdev_prop_set_uint8(DEVICE(&s->armv7m), "num-prio-bits", 3); + qdev_prop_set_string(DEVICE(&s->armv7m), "cpu-type", "cortex-m33-arm-c= pu"); + object_property_set_link(OBJECT(&s->armv7m), "memory", + OBJECT(get_system_memory()), &error_abort); + if (!ms->kernel_filename) { + qdev_prop_set_uint32(DEVICE(&s->armv7m), "init-nsvtor", + MMAP_BOOT_ROM_BASE); + qdev_prop_set_uint32(DEVICE(&s->armv7m), "init-svtor", + MMAP_BOOT_ROM_BASE + SECURE_OFFSET); + } + + qdev_connect_clock_in(DEVICE(&s->armv7m), "cpuclk", s->sysclk); + qdev_connect_clock_in(DEVICE(&s->armv7m), "refclk", + qdev_get_clock_out(DEVICE(&s->clkctl0), "systick_clk"= )); + + sysbus_realize_and_unref(SYS_BUS_DEVICE(&s->armv7m), errp); + qdev_connect_gpio_out_named(DEVICE(&s->armv7m), "SYSRESETREQ", 0, + qemu_allocate_irq(&do_sys_reset, NULL, 0)); + + /* Setup FLEXCOMM */ + for (int i =3D 0; i < RT500_FLEXCOMM_NUM; i++) { + static const uint32_t addr[] =3D { + RT500_FLEXCOMM0_BASE, RT500_FLEXCOMM1_BASE, RT500_FLEXCOMM2_BA= SE, + RT500_FLEXCOMM3_BASE, RT500_FLEXCOMM4_BASE, RT500_FLEXCOMM5_BA= SE, + RT500_FLEXCOMM6_BASE, RT500_FLEXCOMM7_BASE, RT500_FLEXCOMM8_BA= SE, + RT500_FLEXCOMM8_BASE, RT500_FLEXCOMM10_BASE, RT500_FLEXCOMM11_= BASE, + RT500_FLEXCOMM12_BASE, RT500_FLEXCOMM13_BASE, RT500_FLEXCOMM14= _BASE, + RT500_FLEXCOMM15_BASE, RT500_FLEXCOMM16_BASE + }; + static const int irq[] =3D { + RT500_FLEXCOMM0_IRQn, RT500_FLEXCOMM1_IRQn, RT500_FLEXCOMM2_IR= Qn, + RT500_FLEXCOMM3_IRQn, RT500_FLEXCOMM4_IRQn, RT500_FLEXCOMM5_IR= Qn, + RT500_FLEXCOMM6_IRQn, RT500_FLEXCOMM7_IRQn, RT500_FLEXCOMM8_IR= Qn, + RT500_FLEXCOMM9_IRQn, RT500_FLEXCOMM10_IRQn, RT500_FLEXCOMM11_= IRQn, + RT500_FLEXCOMM12_IRQn, RT500_FLEXCOMM13_IRQn, RT500_FLEXCOMM14= _IRQn, + RT500_FLEXCOMM15_IRQn, RT500_FLEXCOMM16_IRQn + }; + static const int functions[] =3D { + FLEXCOMM_FULL, FLEXCOMM_FULL, FLEXCOMM_FULL, + FLEXCOMM_FULL, FLEXCOMM_FULL, FLEXCOMM_FULL, + FLEXCOMM_FULL, FLEXCOMM_FULL, FLEXCOMM_FULL, + FLEXCOMM_FULL, FLEXCOMM_FULL, FLEXCOMM_FULL, + FLEXCOMM_FULL, FLEXCOMM_FULL, FLEXCOMM_HSSPI, + FLEXCOMM_PMICI2C, FLEXCOMM_HSSPI + }; + DeviceState *ds =3D DEVICE(&s->flexcomm[i]); + + qdev_prop_set_uint32(ds, "functions", functions[i]); + sysbus_realize_and_unref(SYS_BUS_DEVICE(ds), errp); + sysbus_mmio_map(SYS_BUS_DEVICE(ds), 0, addr[i]); + sysbus_connect_irq(SYS_BUS_DEVICE(ds), 0, + qdev_get_gpio_in(DEVICE(&s->armv7m), irq[i])); + } + + /* Setup CTLCTL0 */ + qdev_connect_clock_in(DEVICE(&s->clkctl0), "sysclk", s->sysclk); + sysbus_realize_and_unref(SYS_BUS_DEVICE(DEVICE(&s->clkctl0)), errp); + sysbus_mmio_map(SYS_BUS_DEVICE(DEVICE(&s->clkctl0)), 0, RT500_CLKCTL0_= BASE); + + /* Setup CTLCTL1 */ + qdev_connect_clock_in(DEVICE(&s->clkctl1), "sysclk", s->sysclk); + sysbus_realize_and_unref(SYS_BUS_DEVICE(DEVICE(&s->clkctl1)), errp); + sysbus_mmio_map(SYS_BUS_DEVICE(DEVICE(&s->clkctl1)), 0, RT500_CLKCTL1_= BASE); + + /* Setup FlexSPI */ + for (int i =3D 0; i < RT500_FLEXSPI_NUM; i++) { + static const uint32_t addr[] =3D { + RT500_FLEXSPI0_BASE, RT500_FLEXSPI1_BASE + }; + static const uint32_t mmap_base[] =3D { + MMAP_FLEXSPI0_BASE, MMAP_FLEXSPI1_BASE + }; + static const uint32_t mmap_size[] =3D { + MMAP_FLEXSPI0_SIZE, MMAP_FLEXSPI1_SIZE, + }; + DeviceState *ds =3D DEVICE(&s->flexspi[i]); + + qdev_prop_set_uint32(ds, "mmap_size", mmap_size[i]); + sysbus_realize_and_unref(SYS_BUS_DEVICE(ds), errp); + sysbus_mmio_map(SYS_BUS_DEVICE(ds), 0, addr[i]); + sysbus_mmio_map(SYS_BUS_DEVICE(ds), 1, mmap_base[i]); + } + + /* Setup reset controllers */ + for (int i =3D 0; i < RT500_RSTCTL_NUM; i++) { + DeviceState *ds =3D DEVICE(&s->rstctl[i]); + static const uint32_t addr[] =3D { + RT500_RSTCTL0_BASE, RT500_RSTCTL1_BASE + }; + + sysbus_realize_and_unref(SYS_BUS_DEVICE(ds), errp); + sysbus_mmio_map(SYS_BUS_DEVICE(ds), 0, addr[i]); + } +} + +static void rt500_unrealize(DeviceState *ds) +{ + RT500State *s =3D RT500(ds); + + g_free(s->mem); +} + +static void rt500_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + + dc->realize =3D rt500_realize; + dc->unrealize =3D rt500_unrealize; + dc->desc =3D "RT500 (ARM Cortex-M33)"; +} + +static const TypeInfo rt500_types[] =3D { + { + .name =3D TYPE_RT500, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(RT500State), + .instance_init =3D rt500_init, + .class_init =3D rt500_class_init, + }, +}; + +DEFINE_TYPES(rt500_types); + diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 658af0dace..5bc9438945 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -634,3 +634,5 @@ config RT500 bool select FLEXCOMM select RT500_CLKCTL + select FLEXSPI + select RT500_RSTCTL diff --git a/hw/arm/meson.build b/hw/arm/meson.build index 83e4aea10e..a2b20617c9 100644 --- a/hw/arm/meson.build +++ b/hw/arm/meson.build @@ -60,6 +60,7 @@ arm_ss.add(when: 'CONFIG_XEN', if_true: files( 'xen-stubs.c', 'xen-pvh.c', )) +arm_ss.add(when: 'CONFIG_RT500', if_true: files('rt500.c')) =20 system_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmu-common.c')) system_ss.add(when: 'CONFIG_COLLIE', if_true: files('collie.c')) diff --git a/hw/arm/svd/meson.build b/hw/arm/svd/meson.build index eb2fab54f5..07bcc523fd 100644 --- a/hw/arm/svd/meson.build +++ b/hw/arm/svd/meson.build @@ -36,4 +36,8 @@ if get_option('mcux-soc-svd') [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/rt500_rstctl1.h= ', '-p', 'RSTCTL1', '-t', 'RT500_RSTCTL1', '--fields', 'SYSRSTSTAT: PRSTCTL*:']) + run_target('svd-rt500', command: svd_gen_header + + [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/rt500.h', + '-s', 'RT500', '-p', 'FLEXCOMM0', '-p', 'CLKCTL0', '-p', 'CLKCTL1', + '-p', 'FLEXSPI0', '-p', 'FLEXSPI1', '-p', 'RSTCTL0', '-p', 'RSTCTL1'= ]) endif --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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=1728350647; cv=none; d=zohomail.com; s=zohoarc; b=hzIo6HFyRkuVi6peSYRDDWed2kuwBbShdmflHkx2+tmPL6S4cSmfc3eeOkRcgSn94OaYkxDc2xjMy0/52bucV8bQ8jdedOp0bPyQ9ql/2+C0y5bANagrKM04cpwM162znm7pToEFvHOSXq/LJxvKuM+0QcezXJuAjEaVYyd/Hgk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350647; 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=PbhHf80sfK7VkwcTgOuxP6owcvc4suokU3ESxbdaOWI=; b=Zl7/TcYGu6srn4ClVxJgwKMbAqJcI/Ta7ubMJNoPlRbMsxzqXXpu2a1QPKsIjV0KgqdhKdXTP+6Nqg56Ef6Zr4igd3y3rlkBplyEDkunveHPRD6JZF5qZw8Mv9rkcMdE+sfdnt+H6LHGMtxCNpxbxPfLiUiWjl6z7hRhSzHWRTQ= 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 1728350647701287.4895436117214; Mon, 7 Oct 2024 18:24:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxytn-0003cR-4o; Mon, 07 Oct 2024 21:20:29 -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 <3l4gEZwUKCvgyf0nulttlqj.htrvjrz-ij0jqstslsz.twl@flex--tavip.bounces.google.com>) id 1sxysr-00080y-J2 for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:31 -0400 Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3l4gEZwUKCvgyf0nulttlqj.htrvjrz-ij0jqstslsz.twl@flex--tavip.bounces.google.com>) id 1sxysp-0000BZ-Fj for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:28 -0400 Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-71e026caf8bso2116850b3a.2 for ; Mon, 07 Oct 2024 18:19:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350361; x=1728955161; 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=PbhHf80sfK7VkwcTgOuxP6owcvc4suokU3ESxbdaOWI=; b=p3nmD6YyOLnCh8I7N+pee3b7RdHGVDUmDIRf502IYwADTz7FUyYvVoq/UJOrJj2xyU ySGGGpm6HhHDxYSFYuHHRiOvMRKPY7jzt+9DQ922dS34CmzZoomBKZ6YzaBKffw5fTMy AbXWdBGl3qYoQ90brls7UJeFtWvqyQ+IFY9qwa1vWTKOUMmnfDVnDpNF1QQWpaEfXjap /0QAdOJzi5jURBDy6lJqkFtoy+5R4x4X7ccEKBygeJ+QvTAwDJjw7Stm3WCo7/1Ve8es M9FFJccNxxswdxP9oCyzeci7eKPsV8PiPTgT5phcStkjIUeMveLVPB/yv6P1K73i2vWg IH3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350361; x=1728955161; 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=PbhHf80sfK7VkwcTgOuxP6owcvc4suokU3ESxbdaOWI=; b=n/k4SKkAUdCrKwgdhE2wucr2Ra8xTsEnnWTRXBoz545M8Tb7RsGCgOWe+1i5THf+en fhjaZwpQqMYhlIWHbWffkroyALKOzcKAGAJEdYLL8sVDm9bgjcTM17XYy0L2siqrhaIi 6LolKas0F7BBTLLF+qInon1KMGWXcz09fgw2Ml5Xvhqrqe1RlzBg3rIPif56n5+7zB6X niIV2Zg+0WAl8u/8LLfNMKgiAOxrULCRanKvf/BJlcL5iY56PsX9A6VBuEUyYC552UaC 8njdbo33MmCmGH4GJYLmcvF++QrmEeLesxqCa1myoc6xLI0NUcfUSlBrutrIfQwXSF89 bdIA== X-Gm-Message-State: AOJu0Yxj31/ADEgjt5dg9h+21ol/uMdykHkuy2W6IokIcBq7Wv/kOC76 FTX7UVPRxcdiPVhU9nqrbzBJO8htn8+0TFQ+2EGKZcv6oy9cdwJEBmWkwNIHmOSzSpKEvnyS0MJ kU5zkVtTxjRH4ZWhJFldLM8ThZ5X/GYp26+stjy2XSRJ0DCtn2SnHA1wDuIm1qm9ymtiLJG1FxT QUrOSWiaJW/3AponEK4SOeufdnoA== X-Google-Smtp-Source: AGHT+IGgWk8SsfLPaKZ6EeNQEn7lqPAjr3nNGIfVhoWq8dK9fBgwYbuZn6HlAwnrjRMlMn/Um+WXHuNkwA== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a05:6a00:7687:b0:71d:fb06:e79b with SMTP id d2e1a72fcca58-71dfb06ea3amr14561b3a.0.1728350359669; Mon, 07 Oct 2024 18:19:19 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:40 -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-15-tavip@google.com> Subject: [PATCH v2 14/25] hw/arm: add RT595-EVK board 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::449; envelope-from=3l4gEZwUKCvgyf0nulttlqj.htrvjrz-ij0jqstslsz.twl@flex--tavip.bounces.google.com; helo=mail-pf1-x449.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=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 @google.com) X-ZM-MESSAGEID: 1728350648721116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add basic support for the RT595-EVK board, enough to be able to run the NXP's microXpresso SDK hello world example. Signed-off-by: Octavian Purdila --- hw/arm/rt595-evk.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++ hw/arm/Kconfig | 5 ++++ hw/arm/meson.build | 1 + 3 files changed, 70 insertions(+) create mode 100644 hw/arm/rt595-evk.c diff --git a/hw/arm/rt595-evk.c b/hw/arm/rt595-evk.c new file mode 100644 index 0000000000..4f875a0b12 --- /dev/null +++ b/hw/arm/rt595-evk.c @@ -0,0 +1,64 @@ +/* + * i.MX RT595 EVK + * + * 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 "elf.h" +#include "exec/address-spaces.h" +#include "hw/loader.h" +#include "hw/sysbus.h" +#include "hw/boards.h" +#include "qemu/log.h" +#include "hw/arm/armv7m.h" +#include "hw/arm/boot.h" +#include "qapi/error.h" +#include "hw/arm/rt500.h" +#include "hw/qdev-clock.h" +#include "sysemu/reset.h" + +static void rt595_evk_reset(MachineState *ms, ResetType reason) +{ + /* + * CPU reset is not done by default, we need to do it manually when the + * machine is reset. + */ + cpu_reset(first_cpu); + + qemu_devices_reset(reason); +} + +static void rt595_evk_init(MachineState *ms) +{ + RT500State *s; + Clock *sysclk; + + sysclk =3D clock_new(OBJECT(ms), "SYSCLK"); + clock_set_hz(sysclk, 200000000); + + s =3D RT500(object_new(TYPE_RT500)); + qdev_connect_clock_in(DEVICE(s), "sysclk", sysclk); + object_property_add_child(OBJECT(ms), "soc", OBJECT(s)); + sysbus_realize_and_unref(SYS_BUS_DEVICE(s), &error_fatal); + + if (ms->kernel_filename) { + armv7m_load_kernel(ARM_CPU(first_cpu), ms->kernel_filename, 0, 0); + } +} + +static void rt595_evk_machine_init(MachineClass *mc) +{ + mc->desc =3D "RT595 EVK Machine (ARM Cortex-M33)"; + mc->init =3D rt595_evk_init; + mc->reset =3D rt595_evk_reset; + + mc->ignore_memory_transaction_failures =3D true; +} + +DEFINE_MACHINE("rt595-evk", rt595_evk_machine_init); diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 5bc9438945..86d704cf1b 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -636,3 +636,8 @@ config RT500 select RT500_CLKCTL select FLEXSPI select RT500_RSTCTL + +config RT595_EVK + bool + default y + select RT500 diff --git a/hw/arm/meson.build b/hw/arm/meson.build index a2b20617c9..48ae30acef 100644 --- a/hw/arm/meson.build +++ b/hw/arm/meson.build @@ -61,6 +61,7 @@ arm_ss.add(when: 'CONFIG_XEN', if_true: files( 'xen-pvh.c', )) arm_ss.add(when: 'CONFIG_RT500', if_true: files('rt500.c')) +arm_ss.add(when: 'CONFIG_RT595_EVK', if_true: files('rt595-evk.c')) =20 system_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmu-common.c')) system_ss.add(when: 'CONFIG_COLLIE', if_true: files('collie.c')) --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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=1728350588; cv=none; d=zohomail.com; s=zohoarc; b=GFgi43OYNvUBht8tmS/C58jOq2IknQl6vi3Fmg0at8JpY9+Mj5OHGOO81t2fKpItlDipgxUkgnMKFf5too/3Vr13WGTcaCGbNUdetb29CX4HACisXXFmcDYA1DkBhuFT9UkZY1D9e8KiDFkFmSilXaypAEfxUJEn/9F2lJ3ZLVQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350588; 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=ohI0GInatBpkkVc6LlITBXAa2f8u1GNul4wGD6o5kbw=; b=Ca1zgtUPks+AMXQSMHEGo3J6ddf5yWqJY/w4VhmmgDMAoxBZaPBmG51s7q3al7Etekfhfz8H41c8wDYyn6aMgOSIdhFbn+NwVQrukUcPCbL7rsXLkf5jKpQpXQbAc8bkJTK2HHaakSu2XCjvj0X4iWtc9Pd+nh7dSBkfZQ+udSQ= 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 1728350588680991.7913075184427; Mon, 7 Oct 2024 18:23:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxyuB-0004eG-A8; Mon, 07 Oct 2024 21:20:51 -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 <3mYgEZwUKCvovcxkriqqing.eqosgow-fgxgnpqpipw.qti@flex--tavip.bounces.google.com>) id 1sxysx-0008CI-J4 for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:36 -0400 Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3mYgEZwUKCvovcxkriqqing.eqosgow-fgxgnpqpipw.qti@flex--tavip.bounces.google.com>) id 1sxyss-0000CG-Ps for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:33 -0400 Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-71dfeda9ac0so1866077b3a.1 for ; Mon, 07 Oct 2024 18:19:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350363; x=1728955163; 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=ohI0GInatBpkkVc6LlITBXAa2f8u1GNul4wGD6o5kbw=; b=0rSL9sYhIKVm/xcP036gFjJ38oSIMXgXDHlZUNXIz4M2K8wHivHlEp7LRBarCHzD4J OmoVRMD/qJEn8rqnEkwfQa0f3kigbBBVKY4CMbiB++JSdEAVoCBMkbtxiVtXEPgWF0NO tqswvX8g9jeNPnuBNA84sNC0oOepRWggVs8jz2twPcGpmsZZ1vH+BGyu9RF4zjMyCzHr vAj5zWJk87Q6wysAhYRolVZWvt70s59I9csy0VI0oezUw8WndS1WsXvMhkTGIMPkmspp ZL9J8OoGrCKlVJ4dFxmfqghuF54CUlKbLHIMR4ZVOEiNW+exs+LGDhqVTrR0RVGVR0i4 lWEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350363; x=1728955163; 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=ohI0GInatBpkkVc6LlITBXAa2f8u1GNul4wGD6o5kbw=; b=UEKRgPMkBAaTYG/t85t2s1bqIW/u/rJZDxmYjIkDfE/eOs/bc9uRF+dhter8txpQPL ky1ud0w4+60KRpy8J6Z2yhjai1VN5XY2U2hLkCC9dD0dMfW33MmBcSPhM8qs50Ui4BJx zNNMOgDmuC6T/4Uy64LQfJ5Zdr3Jefqmq1CyWqu5u0Om1MdHj0jh11AapXOphKCm2XZ1 I1gNRFcS+5LsIgXMVTUzqFqJ0IlWnQRJXKKYubwVMX4V6QRXBCcJcmcVe6+PP5dcmM61 iIPDYqEpB12OvEeyqPjaNa+L8nU2SbrpYRCWmmAHZsMVPa2NZ2c2XygnBYP7dnfhlOt7 d8Vg== X-Gm-Message-State: AOJu0Yy/LegDmbSxLNCq4XSYXjJmTCO8FkF0MmVYiQIaA8GtlsERmsPZ JMRgq3VAeuN3YO0yAlkF9NT23kS347DAuPgqHlEbODHNwtd43dtpfIYNnkIx2f+oXE1FveefbNI /MF1e42I2D8Vs3jDDkXJl2F/0mq0EQA1by2R1QeXhn4rz8ZTMUjhI5fhCEruuBqIHv32pMiovJA Mw6F/DNTKsAdVfzTJZMHHuDuUSbg== X-Google-Smtp-Source: AGHT+IHfJoafZ1Gh1mSTL3YA6IgQyHpvaYVZtycBjAalruHqjj2i1J3dSMeXAFCXYRQlu7eKJ3STxUEy6Q== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a05:6a00:91db:b0:71e:401:6580 with SMTP id d2e1a72fcca58-71e040166f7mr10095b3a.6.1728350361548; Mon, 07 Oct 2024 18:19:21 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:41 -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-16-tavip@google.com> Subject: [PATCH v2 15/25] tests/qtest: add register access macros and functions 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::449; envelope-from=3mYgEZwUKCvovcxkriqqing.eqosgow-fgxgnpqpipw.qti@flex--tavip.bounces.google.com; helo=mail-pf1-x449.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=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 @google.com) X-ZM-MESSAGEID: 1728350590310116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add utility macros for accessing register or register bit fields in tests, e.g.: REG32_WRITE(FLEXCOMM, PSELID, persel); g_assert(REG32_READ_FIELD(FLEXCOMM, PSELID, PERSEL) =3D=3D persel); Signed-off-by: Octavian Purdila --- tests/qtest/reg-utils.h | 70 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 tests/qtest/reg-utils.h diff --git a/tests/qtest/reg-utils.h b/tests/qtest/reg-utils.h new file mode 100644 index 0000000000..e09aaf3333 --- /dev/null +++ b/tests/qtest/reg-utils.h @@ -0,0 +1,70 @@ +/* + * Register access utilities for device tests. + * + * 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 _REG_UTILS_H +#define _REG_UTILS_H + +#include "libqtest-single.h" +#include "hw/registerfields.h" + +#ifdef DEBUG_REG +#define debug(fmt, args...) fprintf(stderr, fmt, ## args) +#else +#define debug(fmt, args...) +#endif + +#define _REG_OFF(mod, reg) (A_##mod##_##reg) + +#define REG32_READ(mod, reg) \ + ({ \ + uint32_t value; \ + value =3D readl(mod##_BASE + _REG_OFF(mod, reg)); \ + debug("[%s] -> %08x\n", #reg, value); \ + value; \ + }) + +#define REG32_WRITE(mod, reg, value) \ + do { \ + debug("[%s] <- %08x\n", #reg, value); \ + writel(mod##_BASE + _REG_OFF(mod, reg), value); \ + } while (0) + +#define REG_FIELD_VAL(v, mod, reg, field) \ + FIELD_EX32(v, mod##_##reg, field) \ + +#define REG32_READ_FIELD(mod, reg, field) \ + REG_FIELD_VAL(REG32_READ(mod, reg), mod, reg, field) + +#define REG32_WRITE_FIELD(mod, reg, field, val) \ + do { \ + uint32_t _tmp =3D REG32_READ(mod, reg); \ + _tmp =3D FIELD_DP32(_tmp, mod##_##reg, field, val); \ + REG32_WRITE(mod, reg, _tmp); \ + } while (0) + +#define REG32_WRITE_FIELD_NOUPDATE(mod, reg, field, val) \ + do { \ + uint32_t _tmp =3D FIELD_DP32(0, mod##_##reg, field, val); \ + REG32_WRITE(mod, reg, _tmp); \ + } while (0) + +#define WAIT_REG32_FIELD(ns, mod, reg, field, val) \ + do { \ + clock_step(ns); \ + g_assert_cmpuint(REG32_READ_FIELD(mod, reg, field), =3D=3D, val); = \ + } while (0) + +#define REG32_READ_FAIL(mod, reg) \ + readl_fail(mod##_BASE + _REG_OFF(mod, reg)) + +#define REG32_WRITE_FAIL(mod, reg, value) \ + writel_fail(mod##_BASE + _REG_OFF(mod, reg), value) + +#endif /* _REG_UTILS_H */ --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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=1728350733; cv=none; d=zohomail.com; s=zohoarc; b=ABSOAkPawbWpMmTjeu6pcRjAZ/pZKStxC1EnNlG+eNoDHfI8DGpdYegb3imZ7JqanviKLTiSHKlJuK3SivB+bDGwtys+5t6gIvxDRc39A4d2zKCdxSeXIcxi/Xbu7PEkBhVPtjN0r0YDfgFHckdzuLBnsCYin2UYR2drEyEWnf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350733; 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=UWggVGt8pbE9ZLsUZv4jH44X5yOt44e5jHCMlGNjp7Y=; b=Le/28q6cDVBmJ5TvpSHIIJHQyjZaDYedKeXTWDo6XE7QX6bbt6bVQqopjagdzedBj8lHI/tce/xpMBqL5sixPW/insf6y8+2vsKFEmBFcKme1LawAt2em+AcSVhDyJ+DPmlg0icVfWcsmcPbBvSjrVrW39M9hJt+afgeXzdmY3U= 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 172835073355789.49570421511976; Mon, 7 Oct 2024 18:25:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxyuF-0005Jt-N9; Mon, 07 Oct 2024 21:20:55 -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 <3m4gEZwUKCvwxezmtksskpi.gsquiqy-hiziprsrkry.svk@flex--tavip.bounces.google.com>) id 1sxysx-0008CE-JD for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:36 -0400 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3m4gEZwUKCvwxezmtksskpi.gsquiqy-hiziprsrkry.svk@flex--tavip.bounces.google.com>) id 1sxyst-0000CW-74 for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:34 -0400 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-6e2b049b64aso81158297b3.3 for ; Mon, 07 Oct 2024 18:19:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350364; x=1728955164; 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=UWggVGt8pbE9ZLsUZv4jH44X5yOt44e5jHCMlGNjp7Y=; b=a7goeXj4xpd6QVZucbFLqeoo/qPRNmaftLcNPO5RqWa4dtcwb5fvbAOo/gFAuj1eI8 yTqXbWYK5kULLpevzOiSJCy8RTEKyXi1vOw+k/9c9u4ChJTA41b+fuXAaVk8PZCGjCe9 Z6dCam6aESV/eqE8L/a0RvwPlAZrgKpC+SNemGQA7wJAHol0r3R/B/YNyDrAS2/NXMiM 1Q3uY3+F4dRSf+OSSBeyDpJR7ztZb+3gzaXttRYqoYxFv4CQ+3LdPhtStBTOu1md9Oui 1VgEYaekDdL1auVUopeUaVbrUDpGk6s9IoAbnQMUXqH5tsNXyvpsVvHK1PRJ/tIT9ylI Gi6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350364; x=1728955164; 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=UWggVGt8pbE9ZLsUZv4jH44X5yOt44e5jHCMlGNjp7Y=; b=mZ+Yz8s1krXk77laXY97zVaKm9+WD7gIgTDatbze/B2QZnod5q9vCnzekqB0rO5/QF H9GMF2HAeEu7nJvHNyySIqQDjvtsN9OhNU0J0M5dcCTq9MkcaGlw00AjIeOrFgiUtuPX E9+7s6XkayJGYAMfqBPsmjd4vL3xOrkNk3DJGewZ14X43v4LLePCinUbhy9kSHe81YMk xH0VqhmkHuoRJC5FNUMIHsPHHCgWBSHGgH+6KBzknPa8c+ncTc91JyUza8/yJUGvCfmH RqUZ/weEtJSrkS204OkgFqjiwyMl1RNXHqMUkPhV4M71CEsimhHkBhpBrKGMSxdbMoIb huFg== X-Gm-Message-State: AOJu0YzGkHnS7f6a2VuKYVDhnr6wyBBs+CyPJpsCwioV1BubJ2d+dBQ4 FC9epnrthHjVOM5fTOOoaup9BFsWHR/zsX1wefwzKHB97DviRGli8cRh825MLFelAJ9uWyOtW9r +zFkqqsowIn7QcJq1FuBm+tRtvOh0FB8gMkCoNH6TutT+lhRPjQ6/fooKO5+I8tTwfB8urc0esK jz26cEWfZiWZBQfgKXMp2KyyIhpQ== X-Google-Smtp-Source: AGHT+IEnKoproXBmyAwcgsF2f2+HISyD0A+czH81es2a+FVh2KqZfn9xb+61J5CW4nGtkj6QDLnqUisx7g== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a25:26d0:0:b0:e17:8e73:866c with SMTP id 3f1490d57ef6-e2893945130mr35092276.10.1728350363413; Mon, 07 Oct 2024 18:19:23 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:42 -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-17-tavip@google.com> Subject: [PATCH v2 16/25] system/qtest: add APIS to check for memory access failures 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::1149; envelope-from=3m4gEZwUKCvwxezmtksskpi.gsquiqy-hiziprsrkry.svk@flex--tavip.bounces.google.com; helo=mail-yw1-x1149.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=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 @google.com) X-ZM-MESSAGEID: 1728350734856116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add read*/write*_fail qtest APIs to check for memory access failures. Signed-off-by: Octavian Purdila --- tests/qtest/libqtest-single.h | 92 +++++++++++++++++++++++++++++++++++ tests/qtest/libqtest.h | 76 +++++++++++++++++++++++++++++ system/qtest.c | 44 ++++++++++------- tests/qtest/libqtest.c | 73 ++++++++++++++++++++++++++- 4 files changed, 265 insertions(+), 20 deletions(-) diff --git a/tests/qtest/libqtest-single.h b/tests/qtest/libqtest-single.h index 851724cbcb..c22037c8b2 100644 --- a/tests/qtest/libqtest-single.h +++ b/tests/qtest/libqtest-single.h @@ -265,6 +265,98 @@ static inline uint64_t readq(uint64_t addr) return qtest_readq(global_qtest, addr); } =20 +/** + * writeb_fail: + * @addr: Guest address to write to. + * @value: Value being written. + * + * Writes an 8-bit value to memory expecting a failure. + */ +static inline void writeb_fail(uint64_t addr, uint8_t value) +{ + qtest_writeb_fail(global_qtest, addr, value); +} + +/** + * writew_fail: + * @addr: Guest address to write to. + * @value: Value being written. + * + * Writes a 16-bit value to memory expecting a failure. + */ +static inline void writew_fail(uint64_t addr, uint16_t value) +{ + qtest_writew_fail(global_qtest, addr, value); +} + +/** + * writel_fail: + * @addr: Guest address to write to. + * @value: Value being written. + * + * Writes a 32-bit value to memory expecting a failure. + */ +static inline void writel_fail(uint64_t addr, uint32_t value) +{ + qtest_writel_fail(global_qtest, addr, value); +} + +/** + * writeq_fail: + * @addr: Guest address to write to. + * @value: Value being written. + * + * Writes a 64-bit value to memory expecting a failure. + */ +static inline void writeq_fail(uint64_t addr, uint64_t value) +{ + qtest_writeq_fail(global_qtest, addr, value); +} + +/** + * readb_fail: + * @addr: Guest address to read from. + * + * Reads an 8-bit value from memory expecting a failure. + */ +static inline void readb_fail(uint64_t addr) +{ + qtest_readb_fail(global_qtest, addr); +} + +/** + * readw_fail: + * @addr: Guest address to read from. + * + * Reads a 16-bit value from memory expecting a failure. + */ +static inline void readw_fail(uint64_t addr) +{ + qtest_readw_fail(global_qtest, addr); +} + +/** + * readl_fail: + * @addr: Guest address to read from. + * + * Reads a 32-bit value from memory expecting a failure. + */ +static inline void readl_fail(uint64_t addr) +{ + qtest_readl_fail(global_qtest, addr); +} + +/** + * readq_fail: + * @addr: Guest address to read from. + * + * Reads a 64-bit value from memory expecting a failure. + */ +static inline void readq_fail(uint64_t addr) +{ + qtest_readq_fail(global_qtest, addr); +} + /** * memread: * @addr: Guest address to read from. diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h index beb96b18eb..f9bbeb2e60 100644 --- a/tests/qtest/libqtest.h +++ b/tests/qtest/libqtest.h @@ -549,6 +549,82 @@ uint32_t qtest_readl(QTestState *s, uint64_t addr); */ uint64_t qtest_readq(QTestState *s, uint64_t addr); =20 +/** + * qtest_writeb_fail: + * @s: #QTestState instance to operate on. + * @addr: Guest address to write to. + * @value: Value being written. + * + * Writes an 8-bit value to memory expecting a failure. + */ +void qtest_writeb_fail(QTestState *s, uint64_t addr, uint8_t value); + +/** + * qtest_writew_fail: + * @s: #QTestState instance to operate on. + * @addr: Guest address to write to. + * @value: Value being written. + * + * Writes a 16-bit value to memory expecting a failure. + */ +void qtest_writew_fail(QTestState *s, uint64_t addr, uint16_t value); + +/** + * qtest_writel_fail: + * @s: #QTestState instance to operate on. + * @addr: Guest address to write to. + * @value: Value being written. + * + * Writes a 32-bit value to memory expecting a failure. + */ +void qtest_writel_fail(QTestState *s, uint64_t addr, uint32_t value); + +/** + * qtest_writeq_fail: + * @s: #QTestState instance to operate on. + * @addr: Guest address to write to. + * @value: Value being written. + * + * Writes a 64-bit value to memory expecting a failure. + */ +void qtest_writeq_fail(QTestState *s, uint64_t addr, uint64_t value); + +/** + * qtest_readb_fail: + * @s: #QTestState instance to operate on. + * @addr: Guest address to read from. + * + * Reads an 8-bit value from memory expecting a failure. + */ +void qtest_readb_fail(QTestState *s, uint64_t addr); + +/** + * qtest_readw_fail: + * @s: #QTestState instance to operate on. + * @addr: Guest address to read from. + * + * Reads a 16-bit value from memory expecting a failure. + */ +void qtest_readw_fail(QTestState *s, uint64_t addr); + +/** + * qtest_readl_fail: + * @s: #QTestState instance to operate on. + * @addr: Guest address to read from. + * + * Reads a 32-bit value from memory expecting a failure. + */ +void qtest_readl_fail(QTestState *s, uint64_t addr); + +/** + * qtest_readq_fail: + * @s: #QTestState instance to operate on. + * @addr: Guest address to read from. + * + * Reads a 64-bit value from memory expecting a failure. + */ +void qtest_readq_fail(QTestState *s, uint64_t addr); + /** * qtest_memread: * @s: #QTestState instance to operate on. diff --git a/system/qtest.c b/system/qtest.c index 12703a2045..95bb80a2bc 100644 --- a/system/qtest.c +++ b/system/qtest.c @@ -514,26 +514,30 @@ static void qtest_process_command(CharBackend *chr, g= char **words) =20 if (words[0][5] =3D=3D 'b') { uint8_t data =3D value; - address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIE= D, - &data, 1); + ret =3D address_space_write(first_cpu->as, addr, + MEMTXATTRS_UNSPECIFIED, &data, 1); } else if (words[0][5] =3D=3D 'w') { uint16_t data =3D value; tswap16s(&data); - address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIE= D, - &data, 2); + ret =3D address_space_write(first_cpu->as, addr, + MEMTXATTRS_UNSPECIFIED, &data, 2); } else if (words[0][5] =3D=3D 'l') { uint32_t data =3D value; tswap32s(&data); - address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIE= D, - &data, 4); + ret =3D address_space_write(first_cpu->as, addr, + MEMTXATTRS_UNSPECIFIED, &data, 4); } else if (words[0][5] =3D=3D 'q') { uint64_t data =3D value; tswap64s(&data); - address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIE= D, - &data, 8); + ret =3D address_space_write(first_cpu->as, addr, + MEMTXATTRS_UNSPECIFIED, &data, 8); } qtest_send_prefix(chr); - qtest_send(chr, "OK\n"); + if (ret =3D=3D MEMTX_OK) { + qtest_send(chr, "OK\n"); + } else { + qtest_send(chr, "FAIL\n"); + } } else if (strcmp(words[0], "readb") =3D=3D 0 || strcmp(words[0], "readw") =3D=3D 0 || strcmp(words[0], "readl") =3D=3D 0 || @@ -548,26 +552,30 @@ static void qtest_process_command(CharBackend *chr, g= char **words) =20 if (words[0][4] =3D=3D 'b') { uint8_t data; - address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED, - &data, 1); + ret =3D address_space_read(first_cpu->as, addr, + MEMTXATTRS_UNSPECIFIED, &data, 1); value =3D data; } else if (words[0][4] =3D=3D 'w') { uint16_t data; - address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED, - &data, 2); + ret =3D address_space_read(first_cpu->as, addr, + MEMTXATTRS_UNSPECIFIED, &data, 2); value =3D tswap16(data); } else if (words[0][4] =3D=3D 'l') { uint32_t data; - address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED, - &data, 4); + ret =3D address_space_read(first_cpu->as, addr, + MEMTXATTRS_UNSPECIFIED, &data, 4); value =3D tswap32(data); } else if (words[0][4] =3D=3D 'q') { - address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED, - &value, 8); + ret =3D address_space_read(first_cpu->as, addr, + MEMTXATTRS_UNSPECIFIED, &value, 8); tswap64s(&value); } qtest_send_prefix(chr); - qtest_sendf(chr, "OK 0x%016" PRIx64 "\n", value); + if (ret =3D=3D MEMTX_OK) { + qtest_sendf(chr, "OK 0x%016" PRIx64 "\n", value); + } else { + qtest_sendf(chr, "FAIL\n"); + } } else if (strcmp(words[0], "read") =3D=3D 0) { g_autoptr(GString) enc =3D NULL; uint64_t addr, len; diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index 9d07de1fbd..4055d6b953 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -666,7 +666,7 @@ static GString *qtest_client_socket_recv_line(QTestStat= e *s) return line; } =20 -static gchar **qtest_rsp_args(QTestState *s, int expected_args) +static gchar **_qtest_rsp_args(QTestState *s, int expected_args, bool fail) { GString *line; gchar **words; @@ -700,7 +700,11 @@ redo: } =20 g_assert(words[0] !=3D NULL); - g_assert_cmpstr(words[0], =3D=3D, "OK"); + if (fail) { + g_assert_cmpstr(words[0], =3D=3D, "FAIL"); + } else { + g_assert_cmpstr(words[0], =3D=3D, "OK"); + } =20 for (i =3D 0; i < expected_args; i++) { g_assert(words[i] !=3D NULL); @@ -709,6 +713,11 @@ redo: return words; } =20 +static gchar **qtest_rsp_args(QTestState *s, int expected_args) +{ + return _qtest_rsp_args(s, expected_args, false); +} + static void qtest_rsp(QTestState *s) { gchar **words =3D qtest_rsp_args(s, 0); @@ -716,6 +725,13 @@ static void qtest_rsp(QTestState *s) g_strfreev(words); } =20 +static void qtest_rsp_fail(QTestState *s) +{ + gchar **words =3D _qtest_rsp_args(s, 0, true); + + g_strfreev(words); +} + static int qtest_query_target_endianness(QTestState *s) { gchar **args; @@ -1103,6 +1119,13 @@ static void qtest_write(QTestState *s, const char *c= md, uint64_t addr, qtest_rsp(s); } =20 +static void qtest_write_fail(QTestState *s, const char *cmd, uint64_t addr, + uint64_t value) +{ + qtest_sendf(s, "%s 0x%" PRIx64 " 0x%" PRIx64 "\n", cmd, addr, value); + qtest_rsp_fail(s); +} + void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value) { qtest_write(s, "writeb", addr, value); @@ -1123,6 +1146,26 @@ void qtest_writeq(QTestState *s, uint64_t addr, uint= 64_t value) qtest_write(s, "writeq", addr, value); } =20 +void qtest_writeb_fail(QTestState *s, uint64_t addr, uint8_t value) +{ + qtest_write_fail(s, "writeb", addr, value); +} + +void qtest_writew_fail(QTestState *s, uint64_t addr, uint16_t value) +{ + qtest_write_fail(s, "writew", addr, value); +} + +void qtest_writel_fail(QTestState *s, uint64_t addr, uint32_t value) +{ + qtest_write_fail(s, "writel", addr, value); +} + +void qtest_writeq_fail(QTestState *s, uint64_t addr, uint64_t value) +{ + qtest_write_fail(s, "writeq", addr, value); +} + static uint64_t qtest_read(QTestState *s, const char *cmd, uint64_t addr) { gchar **args; @@ -1138,6 +1181,12 @@ static uint64_t qtest_read(QTestState *s, const char= *cmd, uint64_t addr) return value; } =20 +static void qtest_read_fail(QTestState *s, const char *cmd, uint64_t addr) +{ + qtest_sendf(s, "%s 0x%" PRIx64 "\n", cmd, addr); + qtest_rsp_fail(s); +} + uint8_t qtest_readb(QTestState *s, uint64_t addr) { return qtest_read(s, "readb", addr); @@ -1158,6 +1207,26 @@ uint64_t qtest_readq(QTestState *s, uint64_t addr) return qtest_read(s, "readq", addr); } =20 +void qtest_readb_fail(QTestState *s, uint64_t addr) +{ + qtest_read_fail(s, "readb", addr); +} + +void qtest_readw_fail(QTestState *s, uint64_t addr) +{ + qtest_read_fail(s, "readw", addr); +} + +void qtest_readl_fail(QTestState *s, uint64_t addr) +{ + qtest_read_fail(s, "readl", addr); +} + +void qtest_readq_fail(QTestState *s, uint64_t addr) +{ + qtest_read(s, "readq", addr); +} + static int hex2nib(char ch) { if (ch >=3D '0' && ch <=3D '9') { --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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=1728350757; cv=none; d=zohomail.com; s=zohoarc; b=JX31VOVP4xnPQ5oF2CIGwJ43acly52Vye0E7Bvnu3YEvf60vvO5SguoAXW3orCxYjI5agYS63oFGUnYjhWZXUG0bP35sy9CMME+CBjmUSciWyjLSrtKQTY802ZZ0pno1dgcGPRgS5KYFwg549xBB2R8a5P+xWCI8e4ylyh0tI6U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350757; 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=HOp7WmLBwFJSSIU5qqNv1E/gmBAstHCHNzzXu4V4CBY=; b=IDwC5vnYhExTR5IdyTh54I5Z+iiGSp6QL24uxBGPlLpXs6R1Zg/WNvhWOUbjM0wsYuftqtTP05WX66TmujrdUbq8L43AFUnvXPyf68xvHvBD7q6Sz5cpD1MzsNM2BjGRxfplhM2P0hs8Mk2zYaJcGh26Q+glHSQRYwdTKYPrDJ4= 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 1728350757328910.9870133799134; Mon, 7 Oct 2024 18:25:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxyuI-0005bQ-2w; Mon, 07 Oct 2024 21:20:58 -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 <3nIgEZwUKCv0yf0nulttlqj.htrvjrz-ij0jqstslsz.twl@flex--tavip.bounces.google.com>) id 1sxysv-00089N-LA for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:35 -0400 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3nIgEZwUKCv0yf0nulttlqj.htrvjrz-ij0jqstslsz.twl@flex--tavip.bounces.google.com>) id 1sxyss-0000Cg-1v for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:32 -0400 Received: by mail-pj1-x104a.google.com with SMTP id 98e67ed59e1d1-2e08c6fd74fso6742404a91.0 for ; Mon, 07 Oct 2024 18:19:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350365; x=1728955165; 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=HOp7WmLBwFJSSIU5qqNv1E/gmBAstHCHNzzXu4V4CBY=; b=gcV5sD3hgDjDnWMy3BmQm1g9rgsrSLYaaLPiQ13VmiDPVXfnjSQI39+PJS0b2QijWx oamPPd5TuH9unpmiNMyeBNJf0fkl4Sg5Ki0Q5cSrMpWl8IH6oskPZSnhNjSw7JJdJf+3 Phj7ve9b5iydeZb0EgKwGUuQmBYNsI66Wuy5eYGIp2ezkWD/+g9pi6FLMI9zLFkPu0RQ HchOV2UhAKWlDaVLVVPEesJY6vSYQQqMYSt2HVguk8U/PW0htF5NHXv/ddaumKmSIFSv xcUqZ3O5CTsuJCtqYIZGZ7dg538hKy/hBX/AYWRE9EWTvaaKC7uJqzx3BIdOYe2FraIS f7ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350365; x=1728955165; 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=HOp7WmLBwFJSSIU5qqNv1E/gmBAstHCHNzzXu4V4CBY=; b=YDTNy7DKqrPunxYnBB6zpjV/9SFbkPlmCkVmPQJy7tyymIE6DzyKvoAQyqkFpImx4r lbn4Ogtwh+z2r+GjBcSW60jtqGaKPxo92N8cl+OH+soAj8j4Qaf6zufty1OBk71hriRE JK8Xks05+tMew1srHeaWwokhR6ge2kPwWZvTyBee62w0EE57/eawei45yUgykYt0XveZ vYcK1z6g6zP0iEjwSiIs+tXTGV5zglm1uxbxlKSDy3VcqelJLQYvWeLrpFL/DFv5sErx bMKVtkHmcuJoRRY5HLVLXtyIZXr02d4x3/t0fe24hcurJkevlyUSqGJpPHVCGVK+twL6 Ozyg== X-Gm-Message-State: AOJu0YybfRttPAIdB+sXfbbxR6MfLnFB9CMg91uFAqsyQPaMnWJFxDha azj05bwjr7Oye5XtpJV2NYwwekE3VfgM9umgb4xmS/tRgPs9akNCI0tDju43yCrbvlXghK15fJ8 lvDbepuENoYUKf4JoH+g7j+IYiKV3FG8HPgoDu6CMD92kwLQkqKNwH2pQDmKYLMZfRLG6gdQPMj 8Sg56CmC5z7g2u3GK8OGYgAYuEbQ== X-Google-Smtp-Source: AGHT+IFJXWzm9uvmfE9DGIxc/k5/9wTOYabBReC34NNJb04CYptvSM3L/sEK2L2WeiVcgcOnDgOuaxXMJg== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a17:903:234e:b0:206:96ae:dc30 with SMTP id d9443c01a7336-20bff1c282bmr3551625ad.10.1728350364927; Mon, 07 Oct 2024 18:19:24 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:43 -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-18-tavip@google.com> Subject: [PATCH v2 17/25] tests/qtest: add flexcomm tests 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::104a; envelope-from=3nIgEZwUKCv0yf0nulttlqj.htrvjrz-ij0jqstslsz.twl@flex--tavip.bounces.google.com; helo=mail-pj1-x104a.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: 1728350758895116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add flexcomm function selection unit tests. Signed-off-by: Octavian Purdila --- tests/qtest/flexcomm-test.c | 82 +++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 1 + 2 files changed, 83 insertions(+) create mode 100644 tests/qtest/flexcomm-test.c diff --git a/tests/qtest/flexcomm-test.c b/tests/qtest/flexcomm-test.c new file mode 100644 index 0000000000..ffbee8bfb8 --- /dev/null +++ b/tests/qtest/flexcomm-test.c @@ -0,0 +1,82 @@ +/* + * 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/log.h" +#include "qemu/module.h" +#include "qemu/main-loop.h" +#include "exec/memory.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" + +#include "hw/misc/flexcomm.h" +#include "hw/arm/svd/flexcomm.h" +#include "hw/arm/svd/rt500.h" +#include "reg-utils.h" + +#define FLEXCOMM_BASE RT500_FLEXCOMM0_BASE + +static void select_test(gconstpointer data) +{ + static const unsigned persel[] =3D { + FLEXCOMM_PERSEL_USART, + FLEXCOMM_PERSEL_SPI, + FLEXCOMM_PERSEL_I2C, + }; + + g_assert(REG32_READ_FIELD(FLEXCOMM, PSELID, PERSEL) =3D=3D 0); + + /* no register access until a function is selected */ + readl_fail(FLEXCOMM_BASE); + writel_fail(FLEXCOMM_BASE, 0); + + for (int i =3D 0; i < ARRAY_SIZE(persel); i++) { + + REG32_WRITE(FLEXCOMM, PSELID, persel[i]); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM, PSELID, PERSEL), =3D= =3D, + persel[i]); + + /* test that we can access function registers */ + writel(FLEXCOMM_BASE, 0xabcd); + readl(FLEXCOMM_BASE); + } + + /* try to select something invalid */ + REG32_WRITE(FLEXCOMM, PSELID, 7); + /* check for no function selected */ + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM, PSELID, PERSEL), =3D=3D, 0= ); + + /* now select and lock USART */ + REG32_WRITE(FLEXCOMM, PSELID, + FIELD_DP32(FLEXCOMM_PERSEL_USART, FLEXCOMM_PSELID, LOCK, 1= )); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM, PSELID, PERSEL), =3D=3D, + FLEXCOMM_PERSEL_USART); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM, PSELID, LOCK), =3D=3D, 1); + + /* try to change the selection to spi */ + REG32_WRITE(FLEXCOMM, PSELID, FLEXCOMM_PERSEL_SPI); + /* it should still be locked USART */ + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM, PSELID, PERSEL), =3D=3D, + FLEXCOMM_PERSEL_USART); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM, PSELID, LOCK), =3D=3D, 1); +} + +int main(int argc, char **argv) +{ + int ret; + + g_test_init(&argc, &argv, NULL); + + qtest_add_data_func("/flexcomm/select", NULL, select_test); + qtest_start("-M rt595-evk"); + ret =3D g_test_run(); + qtest_end(); + + return ret; +} diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 2b90abf000..f35bb52aa2 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -233,6 +233,7 @@ qtests_arm =3D \ (config_all_devices.has_key('CONFIG_FSI_APB2OPB_ASPEED') ? ['aspeed_fsi-= test'] : []) + \ (config_all_devices.has_key('CONFIG_STM32L4X5_SOC') and config_all_devices.has_key('CONFIG_DM163')? ['dm163-test'] : []) + \ + (config_all_devices.has_key('CONFIG_FLEXCOMM')? ['flexcomm-test'] : []) = + \ ['arm-cpu-features', 'boot-serial-test'] =20 --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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=1728350546; cv=none; d=zohomail.com; s=zohoarc; b=mqa1hbkTpkyTxDCN3aVinFJ8LWz4jWqDaJ3mtkQ15QEaIqj79SFs4uzOy0q4cxXW6/n+VaB/mf7rnwn9TIqkSqU5fAjrEtCaRVlDgzz7DCWLdYUICRXkJwj/NJVvM1k5ysko1ZMD4eRQRIpeKmdiKG6xdQ0JB3az5Jcl5KNzvbo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350546; 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=KH/2xv+ry9E6fErLW4rxS6RZmIvXaaOZIkrg/WhK4hs=; b=WkL/FZGmegInVH6MnCOZOH+El70d7Nfvmy4oJwiS4D/k9fGcVziaGXIx2zpnDrvpTUgw/K6kBl3b+mREE7HeIUtYM49Rbjzsp78oxNg0TsGWJtH6lVEWYcbhJeEOA6yNt7Ka1zebsJ9Kmx0GdTeXCbO92yvSY5J+7UJ2wvBFEtA= 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 1728350546261468.5128148661536; Mon, 7 Oct 2024 18:22:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxyu6-0004AN-Mu; Mon, 07 Oct 2024 21:20:47 -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 <3nogEZwUKCgEubwjqhpphmf.dpnrfnv-efwfmopohov.psh@flex--tavip.bounces.google.com>) id 1sxysx-0008CR-Ja for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:36 -0400 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3nogEZwUKCgEubwjqhpphmf.dpnrfnv-efwfmopohov.psh@flex--tavip.bounces.google.com>) id 1sxyst-0000DM-7E for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:34 -0400 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-6e2baf2ff64so75973027b3.0 for ; Mon, 07 Oct 2024 18:19:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350367; x=1728955167; 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=KH/2xv+ry9E6fErLW4rxS6RZmIvXaaOZIkrg/WhK4hs=; b=E2IPreJg/qpe9C4HZIVYUl2AoLpgWNToFGeYZsH+sMaXZz3c31uhCKtffKNXPBwNZR 3CXoacMfTSpq8TOnLP9S86M/HI3SJ/NwPeP/B52CunBCG1ecXHXugSQPg5hOVPbUz//0 j6Rwm+THEUt/hOKd9dDX+i8goQw5ndtBptBe/bNXwGsCFz+BYN4Pr5vZFsIw8unH8xmR I9/XArOEGjwu7wjaELZlQcxd1oivqpJhmHGuxWZaSJp/ESqHur71Q0xhWeeUFtcXOE8M adWbHJl0xIbX8ogLBSsTllQb14XvWg5Bjxfq4f8UaqV9rHbRvyUPcVxCN2B/wdfGWIE4 9N2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350367; x=1728955167; 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=KH/2xv+ry9E6fErLW4rxS6RZmIvXaaOZIkrg/WhK4hs=; b=uhh8X65gXBBchvyOtfp1kmbC4VlS4xR9H2bpPUGHzFOd+sQISIRdYws6j0+KMJ4dh1 LcRV90bD9IJD7htsy8Gg99rSJOmxlsf1Wzm0eWF7n5BeLhN5WeIZ+PW/KVcUEifqieMw irf6RKePbUbpb2cWi7md33k9sxLgdyfueexnZqi96PlzdWbwloV8zkEHsNwoGtCiWPYX WQ0Qj4wVkP4JqXSXerb2954GE1TRdpzDSG5ZJmCWEutUSajRub6k3du37ZvEgg0j1FTb 3PFQe5+yNDQatPOGyVUiAoG9JJDtHcfJ4pG1kThq/JnAoIdIQDkADfS1AEZ8AhXcENSg DJCw== X-Gm-Message-State: AOJu0YwYBAmhugtdk33HXbNbSmavuKHm2AWsg+jWr4l/TZ9KgZ+/1YDe ZSqKB1Q8rWQHIEKwMG7T5jYpkxr6Tn5kgbHQcyHJFV8cn7PKgw1ePuDdm4NxYXBYwoHVnYNtF/x aLf13jNWMsKtzjCNS61FzGRQ5ECVaq4K7m08lO4oWz0+Y9ohPoHHXNuJ6dGVG86FuQFUoBkubPs frbAkZKUehlnVW+dFaYcHSoS3g8Q== X-Google-Smtp-Source: AGHT+IEPgy4jBCEt/GAlr5KBC579+z7N16RaMIrOgzKSXWJPySuiz34MQJTVEkI0pz4USPrVQ52UP1boKg== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a81:ad0b:0:b0:6e2:121c:4509 with SMTP id 00721157ae682-6e2c72bbd4bmr1572397b3.7.1728350366897; Mon, 07 Oct 2024 18:19:26 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:44 -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-19-tavip@google.com> Subject: [PATCH v2 18/25] tests/qtest: add flexcomm usart tests 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::1149; envelope-from=3nogEZwUKCgEubwjqhpphmf.dpnrfnv-efwfmopohov.psh@flex--tavip.bounces.google.com; helo=mail-yw1-x1149.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=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 @google.com) X-ZM-MESSAGEID: 1728350548533116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add flexcomm usart polling and irq unit tests. Signed-off-by: Octavian Purdila --- tests/qtest/flexcomm-usart-test.c | 316 ++++++++++++++++++++++++++++++ tests/qtest/meson.build | 3 +- 2 files changed, 318 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/flexcomm-usart-test.c diff --git a/tests/qtest/flexcomm-usart-test.c b/tests/qtest/flexcomm-usart= -test.c new file mode 100644 index 0000000000..0ffa49dd6f --- /dev/null +++ b/tests/qtest/flexcomm-usart-test.c @@ -0,0 +1,316 @@ +/* + * 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 + +#include "io/channel-socket.h" +#include "qemu/config-file.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qapi/error.h" +#include "qemu/sockets.h" +#include "sysemu/sysemu.h" +#include "qemu/main-loop.h" +#include "qemu/option.h" +#include "exec/memory.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" + +#include "hw/misc/flexcomm.h" +#include "hw/arm/svd/flexcomm_usart.h" +#include "hw/arm/svd/rt500.h" +#include "reg-utils.h" + +#define FLEXCOMM_BASE RT500_FLEXCOMM0_BASE +#define FLEXCOMM_USART_BASE RT500_FLEXCOMM0_BASE +#define DEVICE_NAME "/machine/soc/flexcomm0" + +struct TestState { + QTestState *qtest; + QIOChannel *ioc; +}; + +static void polling_test(gconstpointer user_data) +{ + struct TestState *t =3D (struct TestState *)user_data; + uint32_t tmp; + char byte; + int fifo_size; + QDict *resp; + + resp =3D qmp("{\"execute\": \"system_reset\"}"); + qdict_unref(resp); + + /* select and lock USART */ + tmp =3D FIELD_DP32(FLEXCOMM_PERSEL_USART, FLEXCOMM_PSELID, LOCK, 1); + REG32_WRITE(FLEXCOMM, PSELID, tmp); + + fifo_size =3D REG32_READ_FIELD(FLEXCOMM_USART, FIFOSIZE, FIFOSIZE); + + /* enable USART */ + REG32_WRITE_FIELD(FLEXCOMM_USART, CFG, ENABLE, 1); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, CFG, ENABLE), =3D=3D= , 1); + + /* enable TX and RX FIFO */ + REG32_WRITE_FIELD(FLEXCOMM_USART, FIFOCFG, ENABLETX, 1); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOCFG, ENABLETX), + =3D=3D, 1); + REG32_WRITE_FIELD(FLEXCOMM_USART, FIFOCFG, ENABLERX, 1); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOCFG, ENABLERX), + =3D=3D, 1); + + /* test writes and fifo counters wrap */ + for (int i =3D 0; i < fifo_size / 2; i++) { + /* check fifostat */ + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOSTAT, RXFULL= ), + =3D=3D, 0); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOSTAT, RXNOTE= MPTY), + =3D=3D, 0); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOSTAT, TXNOTF= ULL), + =3D=3D, 1); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOSTAT, TXEMPT= Y), + =3D=3D, 1); + + REG32_WRITE(FLEXCOMM_USART, FIFOWR, 'a' + i); + qio_channel_read(t->ioc, &byte, 1, &error_abort); + g_assert_cmpuint(byte, =3D=3D, 'a' + i); + } + + /* test reads and fifo level */ + + for (int i =3D 0; i < fifo_size / 2; i++) { + byte =3D 'A' + i; + g_assert_cmpuint(qio_channel_write(t->ioc, &byte, 1, &error_abort), + =3D=3D, 1); + } + + /* wait for the RXLVL to update */ + WAIT_REG32_FIELD(1000, FLEXCOMM_USART, FIFOSTAT, RXLVL, + fifo_size / 2); + + /* check fifo stat */ + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOSTAT, RXFULL), + =3D=3D, 0); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOSTAT, RXNOTEMPTY= ), + =3D=3D, 1); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOSTAT, TXNOTFULL), + =3D=3D, 1); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOSTAT, TXEMPTY), + =3D=3D, 1); + + /* send until FIFO is full */ + for (int i =3D fifo_size / 2; i < fifo_size; i++) { + byte =3D 'A' + i; + g_assert_cmpuint(qio_channel_write(t->ioc, &byte, 1, &error_abort), + =3D=3D, 1); + } + + /* wait for the RXLVL to update */ + WAIT_REG32_FIELD(1000, FLEXCOMM_USART, FIFOSTAT, RXLVL, fifo_size); + + /* check fifo stat */ + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOSTAT, RXFULL), + =3D=3D, 1); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOSTAT, RXNOTEMPTY= ), + =3D=3D, 1); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOSTAT, TXNOTFULL), + =3D=3D, 1); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOSTAT, TXEMPTY), + =3D=3D, 1); + + /* check read no pop */ + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFORDNOPOP, RXDATA), + =3D=3D, 'A'); + + /* now read from the fifo */ + for (int i =3D 0; i < fifo_size; i++) { + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFORD, RXDATA), + =3D=3D, 'A' + i); + } + + /* check fifostat */ + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOSTAT, RXFULL), = =3D=3D, 0); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOSTAT, RXNOTEMPTY= ), + =3D=3D, 0); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOSTAT, TXNOTFULL), + =3D=3D, 1); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOSTAT, TXEMPTY), + =3D=3D, 1); +} + +static void irq_test(gconstpointer user_data) +{ + struct TestState *t =3D (struct TestState *)user_data; + char buf[256] =3D { 0, }; + uint32_t tmp; + QDict *resp; + + resp =3D qmp("{\"execute\": \"system_reset\"}"); + qdict_unref(resp); + + qtest_irq_intercept_out_named(t->qtest, DEVICE_NAME, + SYSBUS_DEVICE_GPIO_IRQ); + + /* select and lock FLEXCOMM_USART */ + tmp =3D FIELD_DP32(FLEXCOMM_PERSEL_USART, FLEXCOMM_PSELID, LOCK, 1); + REG32_WRITE(FLEXCOMM, PSELID, tmp); + + /* + * set RX IRQ/DMA trigger level to 4 bytes - value 3 in FIFOTRIG + * + * 0000 - Trigger when the RX FIFO has received 1 entry (is no longer = empty) + * 0001 - Trigger when the RX FIFO has received 2 entries + * 1111 - Trigger when the RX FIFO has received 16 entries (has become= full) + */ + REG32_WRITE_FIELD(FLEXCOMM_USART, FIFOTRIG, RXLVL, 3); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOTRIG, RXLVL), + =3D=3D, 3); + + /* enable RX trigger for IRQ/DMA */ + REG32_WRITE_FIELD(FLEXCOMM_USART, FIFOTRIG, RXLVLENA, 1); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOTRIG, RXLVLENA), + =3D=3D, 1); + + /* enable RXLVL interrupt */ + REG32_WRITE_FIELD(FLEXCOMM_USART, FIFOINTENSET, RXLVL, 1); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOINTENSET, RXLVL), + =3D=3D, 1); + + /* enable FLEXCOMM_USART */ + REG32_WRITE_FIELD(FLEXCOMM_USART, CFG, ENABLE, 1); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, CFG, ENABLE), + =3D=3D, 1); + + /* enable TX and RX FIFO */ + REG32_WRITE_FIELD(FLEXCOMM_USART, FIFOCFG, ENABLETX, 1); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOCFG, ENABLETX), + =3D=3D, 1); + REG32_WRITE_FIELD(FLEXCOMM_USART, FIFOCFG, ENABLERX, 1); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOCFG, ENABLERX), + =3D=3D, 1); + + /* check interrupt status */ + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOINTSTAT, RXLVL), + =3D=3D, 0); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOINTSTAT, TXLVL), + =3D=3D, 0); + g_assert_false(get_irq(0)); + + /* enable TX trigger for IRQ/DMA */ + REG32_WRITE_FIELD(FLEXCOMM_USART, FIFOTRIG, TXLVLENA, 1); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOTRIG, TXLVLENA), + =3D=3D, 1); + + /* enable irq for TX */ + REG32_WRITE_FIELD(FLEXCOMM_USART, FIFOINTENSET, TXLVL, 1); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOINTENSET, TXLVL), + =3D=3D, 1); + + /* check TX irq */ + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOINTSTAT, TXLVL), + =3D=3D, 1); + g_assert_true(get_irq(0)); + + /* disable irq for TX */ + REG32_WRITE_FIELD(FLEXCOMM_USART, FIFOTRIG, TXLVLENA, 0); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOTRIG, TXLVLENA), + =3D=3D, 0); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOINTSTAT, TXLVL), + =3D=3D, 0); + g_assert_false(get_irq(0)); + + /* send 3 bytes */ + g_assert_cmpuint(qio_channel_write(t->ioc, buf, 3, &error_abort), + =3D=3D, 3); + + /* check that we have 3 bytes in the fifo */ + WAIT_REG32_FIELD(1000, FLEXCOMM_USART, FIFOSTAT, RXLVL, 3); + + /* and no interrupt has been triggered yet */ + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOINTSTAT, RXLVL), + =3D=3D, 0); + g_assert_false(get_irq(0)); + + /* push it over the edge */ + g_assert_cmpuint(qio_channel_write(t->ioc, buf, 1, &error_abort), =3D= =3D, 1); + + /* check that we have 4 bytes in the fifo */ + WAIT_REG32_FIELD(1000, FLEXCOMM_USART, FIFOSTAT, RXLVL, 4); + + /* and the interrupt has been triggered */ + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOINTSTAT, RXLVL), + =3D=3D, 1); + g_assert_true(get_irq(0)); + + /* read one byte from the fifo */ + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFORD, RXDATA), + =3D=3D, 0); + + /* we should have 3 bytes in the FIFO */ + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOSTAT, RXLVL), + =3D=3D, 3); + + /* and no interrupts active */ + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOINTSTAT, RXLVL), + =3D=3D, 0); + g_assert_false(get_irq(0)); +} + +static void close_ioc(void *ioc) +{ + qio_channel_close(ioc, NULL); +} + +int main(int argc, char **argv) +{ + int ret; + struct TestState test; + char *tmp_path =3D g_dir_make_tmp("qemu-flexcomm-usart-test.XXXXXX", N= ULL); + SocketAddress addr =3D { + .type =3D SOCKET_ADDRESS_TYPE_UNIX, + .u.q_unix.path =3D g_build_filename(tmp_path, "sock", NULL), + }; + char *args; + QIOChannelSocket *lioc; + + module_call_init(MODULE_INIT_QOM); + g_test_init(&argc, &argv, NULL); + + lioc =3D qio_channel_socket_new(); + qio_channel_socket_listen_sync(lioc, &addr, 1, &error_abort); + + qtest_add_data_func("/flexcomm-usart/polling", &test, polling_test); + qtest_add_data_func("/flexcomm-usart/irq", &test, irq_test); + + args =3D g_strdup_printf("-M rt595-evk " + "-chardev socket,id=3Dflexcomm0-usart,path=3D%s= ", + addr.u.q_unix.path); + test.qtest =3D qtest_start(args); + + qio_channel_wait(QIO_CHANNEL(lioc), G_IO_IN); + test.ioc =3D QIO_CHANNEL(qio_channel_socket_accept(lioc, &error_abort)= ); + g_assert(test.ioc); + qtest_add_abrt_handler(close_ioc, test.ioc); + + ret =3D g_test_run(); + + qtest_end(); + + qtest_remove_abrt_handler(test.ioc); + g_unlink(addr.u.q_unix.path); + g_free(addr.u.q_unix.path); + g_rmdir(tmp_path); + g_free(tmp_path); + g_free(args); + object_unref(OBJECT(test.ioc)); + object_unref(OBJECT(lioc)); + + return ret; +} diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index f35bb52aa2..c7a5bb61e9 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -233,7 +233,7 @@ qtests_arm =3D \ (config_all_devices.has_key('CONFIG_FSI_APB2OPB_ASPEED') ? ['aspeed_fsi-= test'] : []) + \ (config_all_devices.has_key('CONFIG_STM32L4X5_SOC') and config_all_devices.has_key('CONFIG_DM163')? ['dm163-test'] : []) + \ - (config_all_devices.has_key('CONFIG_FLEXCOMM')? ['flexcomm-test'] : []) = + \ + (config_all_devices.has_key('CONFIG_FLEXCOMM') ? ['flexcomm-test', 'flex= comm-usart-test'] : []) + \ ['arm-cpu-features', 'boot-serial-test'] =20 @@ -350,6 +350,7 @@ qtests =3D { 'virtio-net-failover': files('migration-helpers.c'), 'vmgenid-test': files('boot-sector.c', 'acpi-utils.c'), 'netdev-socket': files('netdev-socket.c', '../unit/socket-helpers.c'), + 'flexcomm-usart-test': [io], } =20 if vnc.found() --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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=1728350601; cv=none; d=zohomail.com; s=zohoarc; b=WOIbNmGYKjXz4dZN2s0FKEZnQWAkuXbAxe9daHtk3so5V4v9VcNbGXVCrCuOum+hmuG1miiEgvBpuZ+HDVsnpddPyDCqB1NmP30xF5qp9asWEHj5IWGeOrj4r8moaqexoTqPuRpj4/JMmVnk2w84j0xqBx/J6DHiWdiWdkfD6TY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350601; 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=nCq9fs8MJ+mFnJecQKMchHHydT4SahSTnFv0Noo9rMg=; b=Td9ffOrxmk9qbAVoiZIz+VZ+iVHvhPOjtUMjWGGBrqGCMI5O/l8PcDETj8N5XQq2Oe8gd+PRUO64BNqcE7MjRica2B1PDJnnxX54nghZmmUCExrJZL2bnvdjrNuORVppy4tHs/Di6jUJ0x1K5fU1kUFW/zX3Yp8QGTZUeM/9nW0= 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 1728350601473166.447393461896; Mon, 7 Oct 2024 18:23:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxyuE-0005Ac-HH; Mon, 07 Oct 2024 21:20:54 -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 <3oIgEZwUKCgMwdylsjrrjoh.frpthpx-ghyhoqrqjqx.ruj@flex--tavip.bounces.google.com>) id 1sxysy-0008Co-3e for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:36 -0400 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3oIgEZwUKCgMwdylsjrrjoh.frpthpx-ghyhoqrqjqx.ruj@flex--tavip.bounces.google.com>) id 1sxysv-0000Da-8r for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:35 -0400 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6e2270a147aso75604587b3.0 for ; Mon, 07 Oct 2024 18:19:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350369; x=1728955169; 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=nCq9fs8MJ+mFnJecQKMchHHydT4SahSTnFv0Noo9rMg=; b=p8iTvODxXhY3EuP2vWuOgIN8T9ZfHG8xPTdYuYj8qiiKd+ua3Lrp4CMOkaZsVYZvCY G/M74SrW5rBZND41lCygiPQVEVEiPv/ERz4QISklBjuDOL7J5Yk5gt5uMR/kj2HXffv4 SLLetMgjy6iXCClodZ9fcdLrRWDuxKsa/NsxKLXPutUOBbFUfXZbyMHswxsf0nGhGIAw wtKk+UrlSQjRVa5+n0o+ajawpxBSNdvh8AWk0h3Cv1AYNGxTx+uoLUL2EmcRn01VS4fo YgAT03tdHW0QhLtfWd8GpGrTqBJBwhWCbDl+PQE8XNt/5JqGDMrKSdwp9WgKQ+QFxHqv wumQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350369; x=1728955169; 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=nCq9fs8MJ+mFnJecQKMchHHydT4SahSTnFv0Noo9rMg=; b=Qy/g/0ztU4ZYCJcvSSCHHbsiiH3TDmO4xHgeztpF39esCkMXH/KNyga29D0Ug24bR8 XPQh9i4svMGJpX6QADvHiMHGOslu3Uut4AinrFI1M+d/CFxD4BcC6DMiU0A1H3cIGqZq pU1VJtG7VIaWXkP4ZeSzKkCdl0A649V5zFbORxOh0K13v5QaTMNNe8FEfryXd6J0p6z9 6jwVwIIzWF06N74VEBrrvBYRHAkCIxAZ1ki7Aimmg0UReUSqUR+GCQI66TKshW6Y+rfW SOLouC6n4yrggLrmd1QqMHTuTKSy1HqxVvbRYLh7yNYj5HRW1pusg2wHLn9yxh+5njnt kfIA== X-Gm-Message-State: AOJu0YzutnqIMEcyJJW3d6PHx/49Iajvcbo6+FCA9b86LrIwgP6O2V3T SKJ81G9pkHXXuuCzg11vaBUGaQ2Cr0LP4iAdQgOY0/kbSScz7ZXw+rT1kl8pRulYJ/3gQ4hapyz vkr4X0fo+YvZHAmX1SyyU5qNvHV01Q53mjW5jtfarXFcqZ/4eL+di8mxxMYUC32noTwHQdS/eoQ 6vV6otTwmC3G+H7LOXuET5fs2TYw== X-Google-Smtp-Source: AGHT+IFUmkLVVZH+vWL0zyz0TcYFmOI86jHuXPIUgCaHGoy2/OH/FDqpkkmIBwci5b1oJCfJzaV6kvhkUQ== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a05:6902:4a8:b0:e28:e4a7:3206 with SMTP id 3f1490d57ef6-e28e4a732e6mr15578276.8.1728350368601; Mon, 07 Oct 2024 18:19:28 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:45 -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-20-tavip@google.com> Subject: [PATCH v2 19/25] hw/misc: add i2c-tester 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::114a; envelope-from=3oIgEZwUKCgMwdylsjrrjoh.frpthpx-ghyhoqrqjqx.ruj@flex--tavip.bounces.google.com; helo=mail-yw1-x114a.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=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 @google.com) X-ZM-MESSAGEID: 1728350602385116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a simple i2c peripheral to be used for testing I2C device models. The peripheral has a fixed number of registers that can be read and written. Signed-off-by: Octavian Purdila --- include/hw/misc/i2c_tester.h | 43 ++++++++++++++ hw/misc/i2c_tester.c | 109 +++++++++++++++++++++++++++++++++++ hw/misc/Kconfig | 5 ++ hw/misc/meson.build | 2 + 4 files changed, 159 insertions(+) create mode 100644 include/hw/misc/i2c_tester.h create mode 100644 hw/misc/i2c_tester.c diff --git a/include/hw/misc/i2c_tester.h b/include/hw/misc/i2c_tester.h new file mode 100644 index 0000000000..f8292fc219 --- /dev/null +++ b/include/hw/misc/i2c_tester.h @@ -0,0 +1,43 @@ +/* + * Simple I2C peripheral for testing I2C device models. + * + * At the moment of introducing this not all of the functionality can be t= ested + * with an existing QEMU peripheral device, notably error paths such as wh= en a + * peripheral device responds with an I2C_NACK during a transaction. + * + * It also provides a place where new future functionality can be added to= help + * with more kinds of tests rather than trying to hack it in a real device= where + * it might not even be possible. + * + * The peripheral allows reading and writing to a fixed number of register= s. + * The first transmitted byte in a transaction sets the index register. No= te + * that the index register is not auto-incremented on neither reads nor wr= ites. + * + * 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_I2C_TESTER_H +#define HW_I2C_TESTER_H + +#include "qemu/osdep.h" +#include "hw/i2c/i2c.h" +#include "hw/irq.h" + +#define I2C_TESTER_NUM_REGS 0x31 + +#define TYPE_I2C_TESTER "i2c-tester" +#define I2C_TESTER(obj) OBJECT_CHECK(I2cTesterState, (obj), TYPE_I2C_TESTE= R) + +typedef struct { + I2CSlave i2c; + bool set_reg_idx; + uint8_t reg_idx; + uint8_t regs[I2C_TESTER_NUM_REGS]; +} I2cTesterState; + +#endif /* HW_I2C_TESTER_H */ diff --git a/hw/misc/i2c_tester.c b/hw/misc/i2c_tester.c new file mode 100644 index 0000000000..77ce8bf91a --- /dev/null +++ b/hw/misc/i2c_tester.c @@ -0,0 +1,109 @@ +/* + * Simple I2C peripheral for testing I2C device models. + * + * 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 "hw/misc/i2c_tester.h" + +#include "qemu/log.h" +#include "qemu/module.h" +#include "migration/vmstate.h" + +static void i2c_tester_reset_enter(Object *o, ResetType type) +{ + I2cTesterState *s =3D I2C_TESTER(o); + + s->set_reg_idx =3D false; + s->reg_idx =3D 0; + memset(s->regs, 0, I2C_TESTER_NUM_REGS); +} + +static int i2c_tester_event(I2CSlave *i2c, enum i2c_event event) +{ + I2cTesterState *s =3D I2C_TESTER(i2c); + + if (event =3D=3D I2C_START_SEND) { + s->set_reg_idx =3D true; + } + + return 0; +} + +static uint8_t i2c_tester_rx(I2CSlave *i2c) +{ + I2cTesterState *s =3D I2C_TESTER(i2c); + + if (s->reg_idx >=3D I2C_TESTER_NUM_REGS) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid reg 0x%02x\n", __func_= _, + s->reg_idx); + return I2C_NACK; + } + + return s->regs[s->reg_idx]; +} + +static int i2c_tester_tx(I2CSlave *i2c, uint8_t data) +{ + I2cTesterState *s =3D I2C_TESTER(i2c); + + if (s->set_reg_idx) { + /* Setting the register in which the operation will be done. */ + s->reg_idx =3D data; + s->set_reg_idx =3D false; + return 0; + } + + if (s->reg_idx >=3D I2C_TESTER_NUM_REGS) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid reg 0x%02x\n", __func_= _, + s->reg_idx); + return I2C_NACK; + } + + /* Write reg data. */ + s->regs[s->reg_idx] =3D data; + + return 0; +} + +static const VMStateDescription vmstate_i2c_tester =3D { + .name =3D "i2c-tester", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_I2C_SLAVE(i2c, I2cTesterState), + VMSTATE_BOOL(set_reg_idx, I2cTesterState), + VMSTATE_UINT8(reg_idx, I2cTesterState), + VMSTATE_UINT8_ARRAY(regs, I2cTesterState, I2C_TESTER_NUM_REGS), + VMSTATE_END_OF_LIST() + } +}; + +static void i2c_tester_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + ResettableClass *rc =3D RESETTABLE_CLASS(oc); + I2CSlaveClass *isc =3D I2C_SLAVE_CLASS(oc); + + rc->phases.enter =3D i2c_tester_reset_enter; + dc->vmsd =3D &vmstate_i2c_tester; + isc->event =3D i2c_tester_event; + isc->recv =3D i2c_tester_rx; + isc->send =3D i2c_tester_tx; +} + +static const TypeInfo i2c_tester_types[] =3D { + { + .name =3D TYPE_I2C_TESTER, + .parent =3D TYPE_I2C_SLAVE, + .instance_size =3D sizeof(I2cTesterState), + .class_init =3D i2c_tester_class_init + }, +}; + +DEFINE_TYPES(i2c_tester_types); diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig index 4b688aead2..3e93c12c8e 100644 --- a/hw/misc/Kconfig +++ b/hw/misc/Kconfig @@ -213,6 +213,11 @@ config IOSB config XLNX_VERSAL_TRNG bool =20 +config I2C_TESTER + bool + default y if TEST_DEVICES + depends on I2C + config FLEXCOMM bool select I2C diff --git a/hw/misc/meson.build b/hw/misc/meson.build index bf0988fd43..cd29db37d7 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -152,6 +152,8 @@ system_ss.add(when: 'CONFIG_SBSA_REF', if_true: files('= sbsa_ec.c')) # HPPA devices system_ss.add(when: 'CONFIG_LASI', if_true: files('lasi.c')) =20 +system_ss.add(when: 'CONFIG_I2C_TESTER', if_true: files('i2c_tester.c')) + system_ss.add(when: 'CONFIG_FLEXCOMM', if_true: files('flexcomm.c')) system_ss.add(when: 'CONFIG_RT500_CLKCTL', if_true: files('rt500_clkctl0.c= ', 'rt500_clkctl1.c')) system_ss.add(when: 'CONFIG_RT500_RSTCTL', if_true: files('rt500_rstctl.c'= )) --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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=1728350739; cv=none; d=zohomail.com; s=zohoarc; b=R/f8hVtHeoyXznJdAfUn/13KbDkdWRaL+H/LccV5XtE4GRuTDJee/LXw7R5Ji5rh+d+CouQtoVKWbFzg0UmdcouRgvaAaRqGS1kRSh4CiBSmHaqQTvSfIYZoWGo5k1CHJUGpjZ/mGyFdU7+s6W6ErIN3X9Oys3Uf0k36TFoNGLk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350739; 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=1slVDOqEB8KWMUfUEIu1Co2wfDTjYSlNZhTPxBm4iBk=; b=A9IfIjgs/5Q5C6ukP1qkguctEVlrG3LS4zGe1hh2O/wQMV5OOMv9kX0fXJvToVqnV+pUaS99TCu366FUsGyEon9gpDmTVXQ7SVZrhBgf6Ib2lCWXa3iUGLoUUD6pvbAN7TxBCAcmgMwGVYYEBY9Yu5DzrCFA2tbOejEzKe1eTNY= 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 1728350739134321.6515033446742; Mon, 7 Oct 2024 18:25:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxyuK-0005iY-Qx; Mon, 07 Oct 2024 21:21:01 -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 <3oogEZwUKCgUyf0nulttlqj.htrvjrz-ij0jqstslsz.twl@flex--tavip.bounces.google.com>) id 1sxysz-0008OB-KP for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:38 -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 <3oogEZwUKCgUyf0nulttlqj.htrvjrz-ij0jqstslsz.twl@flex--tavip.bounces.google.com>) id 1sxysx-0000EB-9V for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:37 -0400 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-e2605ce4276so8766179276.3 for ; Mon, 07 Oct 2024 18:19:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350371; x=1728955171; 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=1slVDOqEB8KWMUfUEIu1Co2wfDTjYSlNZhTPxBm4iBk=; b=P6q/CdY2awtYAOESYIzSPypj0ywt66EHkHcaQ4Ik6RCVsKPZcpdlagLWu2EA9E/qkx kPWPqSogwcG9NFEjbOqhckGS1WXgG4qdQZV3eYnDauQ+RPyljgHmdVxAMjRNLQNJBbUA aszKSpEEukX6Dm5Ymm9yRK38GfC37D7TcY3FKag2cz4S/ofkK52wuluJ0tyoPjcU7nz0 i0AlFclQ5h5Fn5O72lJD3R19/Y3QAJA30KydLPUrajKiOrfvG5GIcPJexaApoW5Cq8nN q4uelEFGtVW9X/of+XOu6LU1/DAY32WDfJlOh1zTeAdX+ZU4qHYSWxvudHq3pSfc9K79 oWyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350371; x=1728955171; 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=1slVDOqEB8KWMUfUEIu1Co2wfDTjYSlNZhTPxBm4iBk=; b=RQMW/EScZxu+RZ37/31blft+ehXqqrR3H5n6Pr9htV9w67Yjj2D+i33Xymjd/HHUfs 7BqbuKKjz3U5rchTTBEonGTPZxieHhUil+AqheW7iQaxbY+Gvb7Dkh4it9cs909ZCP1T 9CZ5+XyiR4AmccVJbap3cCJeL60MvcAz0potETMRoel4WjMVJ5aTmh4QhWxSQ+w6ZEjw HGVIQlGCOUTKr+FH2GGSHSpbEF9xkDtbfYvthymZPPtIvPuYRx801zp7x3255F7L1W42 h2J0CFBsgFWgYIDEJ9cO797WKvPKp1nqhLYcCD9hJJIujUsufTBMEprnmNJ7UFrfEBCs pJ1g== X-Gm-Message-State: AOJu0YxCqNnRn0S9tNB5loauc5rb8Y6wOIfZkgn1lIq7b8vu6IUpty1B yYJYyhVquGkuE277DsnlrWJopyDEbllLsY3Z09XBXMDsiCpcBRbIvnyJ/gb6Fc1F4fkq3OYxM7M HwWp5qQiXjwoWrI0xar+rgdIiLqHEwSJeMYi1ZGJxIEV2IHpk7qxNID3S1hqT4FDgfycH21RKmn /1oaCjOq2I37EnrCaV8GLGV3gAKA== X-Google-Smtp-Source: AGHT+IHxB5sCWH5nkCL2OyLmSweayfDOeEQuNrJr5rUOJUR090O0aNAKrhs0d0x92rZnK79q0Qx+PG1vCw== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a5b:388:0:b0:e20:2502:be14 with SMTP id 3f1490d57ef6-e289391f4abmr10789276.7.1728350370295; Mon, 07 Oct 2024 18:19:30 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:46 -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-21-tavip@google.com> Subject: [PATCH v2 20/25] tests/qtest: add tests for flexcomm i2c 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=3oogEZwUKCgUyf0nulttlqj.htrvjrz-ij0jqstslsz.twl@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=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 @google.com) X-ZM-MESSAGEID: 1728350740923116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add master mode tests for flexcomm i2c. Signed-off-by: Octavian Purdila --- tests/qtest/flexcomm-i2c-test.c | 170 ++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 2 +- 2 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/flexcomm-i2c-test.c diff --git a/tests/qtest/flexcomm-i2c-test.c b/tests/qtest/flexcomm-i2c-tes= t.c new file mode 100644 index 0000000000..45f31da7de --- /dev/null +++ b/tests/qtest/flexcomm-i2c-test.c @@ -0,0 +1,170 @@ +/* + * 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/config-file.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qapi/error.h" +#include "qemu/sockets.h" +#include "sysemu/sysemu.h" +#include "qemu/main-loop.h" +#include "qemu/option.h" +#include "exec/memory.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" +#include "hw/qdev-core.h" + +#include "hw/misc/flexcomm.h" +#include "hw/arm/svd/flexcomm_i2c.h" +#include "hw/arm/svd/rt500.h" +#include "hw/misc/i2c_tester.h" +#include "reg-utils.h" + +#define PERIPH_ADDR (0x50) +#define INVALID_ADDR (0x10) + +#define REG_ADDR 11 +#define REG_VALUE 0xAA + +#define FLEXCOMM_BASE RT500_FLEXCOMM0_BASE +#define FLEXCOMM_I2C_BASE RT500_FLEXCOMM0_BASE +#define DEVICE_NAME "/machine/soc/flexcomm0" + +struct TestState { + QTestState *qtest; +}; + +static void master_test(gconstpointer user_data) +{ + struct TestState *t =3D (struct TestState *)user_data; + uint32_t tmp; + + qtest_irq_intercept_out_named(t->qtest, DEVICE_NAME, + SYSBUS_DEVICE_GPIO_IRQ); + + /* Select and lock I2C */ + tmp =3D FLEXCOMM_PERSEL_I2C; + FIELD_DP32(tmp, FLEXCOMM_PSELID, LOCK, 1); + REG32_WRITE(FLEXCOMM, PSELID, tmp); + + /* Enable master mode */ + REG32_WRITE_FIELD(FLEXCOMM_I2C, CFG, MSTEN, 1); + g_assert(REG32_READ_FIELD(FLEXCOMM_I2C, CFG, MSTEN) =3D=3D 1); + + g_assert(REG32_READ_FIELD(FLEXCOMM_I2C, STAT, MSTPENDING) =3D=3D 1); + g_assert(REG32_READ_FIELD(FLEXCOMM_I2C, STAT, MSTSTATE) =3D=3D + MSTSTATE_IDLE); + + /* Enable interrupts */ + REG32_WRITE_FIELD(FLEXCOMM_I2C, INTENSET, MSTPENDINGEN, 1); + g_assert_true(get_irq(0)); + + /* start for invalid address */ + REG32_WRITE(FLEXCOMM_I2C, MSTDAT, INVALID_ADDR); + REG32_WRITE_FIELD_NOUPDATE(FLEXCOMM_I2C, MSTCTL, MSTSTART, 1); + g_assert(REG32_READ_FIELD(FLEXCOMM_I2C, STAT, MSTSTATE) =3D=3D + MSTSTATE_NAKADR); + g_assert_true(get_irq(0)); + REG32_WRITE_FIELD_NOUPDATE(FLEXCOMM_I2C, MSTCTL, MSTSTOP, 1); + + /* write past the last register */ + REG32_WRITE_FIELD(FLEXCOMM_I2C, MSTDAT, DATA, PERIPH_ADDR); + REG32_WRITE_FIELD_NOUPDATE(FLEXCOMM_I2C, MSTCTL, MSTSTART, 1); + g_assert_true(get_irq(0)); + g_assert(REG32_READ_FIELD(FLEXCOMM_I2C, STAT, MSTSTATE) =3D=3D + MSTSTATE_TXRDY); + REG32_WRITE_FIELD(FLEXCOMM_I2C, MSTDAT, DATA, I2C_TESTER_NUM_REGS + 10= ); + REG32_WRITE_FIELD_NOUPDATE(FLEXCOMM_I2C, MSTCTL, MSTCONTINUE, 1); + g_assert_true(get_irq(0)); + g_assert(REG32_READ_FIELD(FLEXCOMM_I2C, STAT, MSTSTATE) =3D=3D + MSTSTATE_TXRDY); + REG32_WRITE_FIELD_NOUPDATE(FLEXCOMM_I2C, MSTCTL, MSTCONTINUE, 1); + g_assert_true(get_irq(0)); + g_assert(REG32_READ_FIELD(FLEXCOMM_I2C, STAT, MSTSTATE) =3D=3D + MSTSTATE_NAKDAT); + REG32_WRITE_FIELD_NOUPDATE(FLEXCOMM_I2C, MSTCTL, MSTSTOP, 1); + + /* write value to register */ + REG32_WRITE_FIELD(FLEXCOMM_I2C, MSTDAT, DATA, PERIPH_ADDR); + REG32_WRITE_FIELD_NOUPDATE(FLEXCOMM_I2C, MSTCTL, MSTSTART, 1); + g_assert_true(get_irq(0)); + g_assert(REG32_READ_FIELD(FLEXCOMM_I2C, STAT, MSTSTATE) =3D=3D + MSTSTATE_TXRDY); + REG32_WRITE_FIELD(FLEXCOMM_I2C, MSTDAT, DATA, REG_ADDR); + REG32_WRITE_FIELD_NOUPDATE(FLEXCOMM_I2C, MSTCTL, MSTCONTINUE, 1); + g_assert_true(get_irq(0)); + g_assert(REG32_READ_FIELD(FLEXCOMM_I2C, STAT, MSTSTATE) =3D=3D + MSTSTATE_TXRDY); + REG32_WRITE_FIELD(FLEXCOMM_I2C, MSTDAT, DATA, REG_VALUE); + REG32_WRITE_FIELD_NOUPDATE(FLEXCOMM_I2C, MSTCTL, MSTCONTINUE, 1); + g_assert_true(get_irq(0)); + g_assert(REG32_READ_FIELD(FLEXCOMM_I2C, STAT, MSTSTATE) =3D=3D + MSTSTATE_TXRDY); + REG32_WRITE_FIELD_NOUPDATE(FLEXCOMM_I2C, MSTCTL, MSTSTOP, 1); + g_assert_true(get_irq(0)); + g_assert(REG32_READ_FIELD(FLEXCOMM_I2C, STAT, MSTSTATE) =3D=3D + MSTSTATE_IDLE); + + /* read value back from register */ + REG32_WRITE_FIELD(FLEXCOMM_I2C, MSTDAT, DATA, PERIPH_ADDR); + REG32_WRITE_FIELD_NOUPDATE(FLEXCOMM_I2C, MSTCTL, MSTSTART, 1); + g_assert_true(get_irq(0)); + g_assert(REG32_READ_FIELD(FLEXCOMM_I2C, STAT, MSTSTATE) =3D=3D + MSTSTATE_TXRDY); + REG32_WRITE_FIELD(FLEXCOMM_I2C, MSTDAT, DATA, REG_ADDR); + REG32_WRITE_FIELD_NOUPDATE(FLEXCOMM_I2C, MSTCTL, MSTCONTINUE, 1); + g_assert_true(get_irq(0)); + g_assert(REG32_READ_FIELD(FLEXCOMM_I2C, STAT, MSTSTATE) =3D=3D + MSTSTATE_TXRDY); + REG32_WRITE_FIELD(FLEXCOMM_I2C, MSTDAT, DATA, (PERIPH_ADDR + 1)); + REG32_WRITE_FIELD_NOUPDATE(FLEXCOMM_I2C, MSTCTL, MSTSTART, 1); + g_assert_true(get_irq(0)); + g_assert(REG32_READ_FIELD(FLEXCOMM_I2C, STAT, MSTSTATE) =3D=3D + MSTSTATE_RXRDY); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_I2C, MSTDAT, DATA), =3D=3D, + REG_VALUE); + REG32_WRITE_FIELD_NOUPDATE(FLEXCOMM_I2C, MSTCTL, MSTSTOP, 1); + + /* + * Check that the master ended the transaction (i.e. i2c_end_transfer = was + * called). If the master does not properly end the transaction this w= ould + * be seen as a restart and it would not be NACKed. + */ + REG32_WRITE_FIELD(FLEXCOMM_I2C, MSTDAT, DATA, INVALID_ADDR); + REG32_WRITE_FIELD_NOUPDATE(FLEXCOMM_I2C, MSTCTL, MSTSTART, 1); + + g_assert(REG32_READ_FIELD(FLEXCOMM_I2C, STAT, MSTSTATE) =3D=3D + MSTSTATE_NAKADR); + g_assert_true(get_irq(0)); + REG32_WRITE_FIELD_NOUPDATE(FLEXCOMM_I2C, MSTCTL, MSTSTOP, 1); + + /* Disable interrupts */ + REG32_WRITE_FIELD(FLEXCOMM_I2C, INTENCLR, MSTPENDINGCLR, 1); + g_assert_false(get_irq(0)); +} + +int main(int argc, char **argv) +{ + int ret; + struct TestState test; + + module_call_init(MODULE_INIT_QOM); + g_test_init(&argc, &argv, NULL); + + qtest_add_data_func("/flexcomm-i2c/master", &test, master_test); + + test.qtest =3D qtest_start("-M rt595-evk " + "-device i2c-tester,address=3D0x50,bus=3D/flexco= mm0-i2c"); + ret =3D g_test_run(); + qtest_end(); + + return ret; +} diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index c7a5bb61e9..c21b18c304 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -233,7 +233,7 @@ qtests_arm =3D \ (config_all_devices.has_key('CONFIG_FSI_APB2OPB_ASPEED') ? ['aspeed_fsi-= test'] : []) + \ (config_all_devices.has_key('CONFIG_STM32L4X5_SOC') and config_all_devices.has_key('CONFIG_DM163')? ['dm163-test'] : []) + \ - (config_all_devices.has_key('CONFIG_FLEXCOMM') ? ['flexcomm-test', 'flex= comm-usart-test'] : []) + \ + (config_all_devices.has_key('CONFIG_FLEXCOMM') ? ['flexcomm-test', 'flex= comm-usart-test', 'flexcomm-i2c-test'] : []) + \ ['arm-cpu-features', 'boot-serial-test'] =20 --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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=1728350487; cv=none; d=zohomail.com; s=zohoarc; b=RbUszbQrKfT5BshCDSaA/bjO8SJew1tEFGrOE1PVu+YX3wrfjmw4eY8QKAYEBjiXr9YHPpKEoEeOp5wCH3cs/qQHbAh279D1h/WbXb7/iZT0qkWrQsnoaNz0Mmn7iOmo+1LK2cicReFEdV4cRCzV/Xh+IgFTw3oND+Nz0Zs/4gE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350487; 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=1mTGypMKoK88/Cq8OZic1Nsr2IiKXj3+YmHX8y0r+W0=; b=I0l46k8YR+Ig6aCK5jhKBGk+MExxTdhtWFTo9RBup73duyG9HJv93yeA2IbWcx6vjJuP+4oeHLjaxgj87UGKrGUA7tV67TVzxhA49s3O6DKzOm/DnBFS0azVgrcufPLIGnHgmwt5R6sjeBA4WmM6sdwdXflGmFn3mz2UR2ioulc= 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 1728350487415734.9261209816891; Mon, 7 Oct 2024 18:21:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxyug-00073b-1g; Mon, 07 Oct 2024 21:21:22 -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 <3pIgEZwUKCgc0h2pwnvvnsl.jvtxlt1-kl2lsuvunu1.vyn@flex--tavip.bounces.google.com>) id 1sxysy-0008JJ-Py for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:36 -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 <3pIgEZwUKCgc0h2pwnvvnsl.jvtxlt1-kl2lsuvunu1.vyn@flex--tavip.bounces.google.com>) id 1sxysx-0000EV-9b for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:36 -0400 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-e0b8fa94718so7692684276.0 for ; Mon, 07 Oct 2024 18:19:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350372; x=1728955172; 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=1mTGypMKoK88/Cq8OZic1Nsr2IiKXj3+YmHX8y0r+W0=; b=X0SQlrhAI/Nu+zoWl5WzXxCALs4PbN01LsaFsGHJIVaxsj8Ua/zm1l+t5bwOQgS7j1 cRqjdBe/Y4RHO4Lg6/XKR+vzt6A4gNqUP+FqeEwUK//t8QCIQVvV1NcCWza6MmLZ+XJZ BpbIk6IzZkTjerZI7Km5A/A6rWf5YlOnmZ4DsrwptZGspIS2qU1FlwE/Mg++OTyQjfg5 WuCaoyC8w7eC2sxG9A0H6w+ZAH5zYNlzghfXMBKeUZggDI1v0OGP7/Zuma60ORNyrBs1 OS+kO18UhDO/u9orvlqm8LeY7NyRA9TGhNrD8NtaFcryB2vln6XwU2XPoNjLO85UrBVq nrKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350372; x=1728955172; 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=1mTGypMKoK88/Cq8OZic1Nsr2IiKXj3+YmHX8y0r+W0=; b=O2D2/Ajqlge1+Famdvn44oba72mHHuLHMMmXdNP6jNYZhc+wAU9cNF6TCbKlfN7kUW VlIhdVnGIjioJXzFq1HuE6TLOW+fhg1zU7uApTTX/JuX0reX75pcRmsti7m8SE+eamR5 L+jxAOJubBNLfDgf9d3Cn/3xxM6VpVY8sYjsnGBYHFKbQhCJiJImW4LhzvcugPDHGsfM UI2qY/D5meLA9KlzVtYREIplPTVKIfRe8+7zpXJGZqbtk0OuYSVRwvin6z/glKED4fc9 XVPH9wkfQh/PU+8g+QcP8QFSv+bYqhfnPEdRkFH6neTe7j3uJtfRyI3ViRERk4CGC7qT uo8A== X-Gm-Message-State: AOJu0YzC8Q5MzVSVEOIF4zp9ryOUJ0gxhGuCB5te3MGWb4udg/XoFWHU j81/Q7TvK1ETdSqvakS5PtDRkD2v2Ltg0KjpGUYflNfYmea5WgeAjMWnxRHZSg5znIA/eND03tJ E7+YBmZMDkzb8HC8V8IXw1+x3P0W4MGO4/wFuDbhiZKF99PfmSqaEmMI44yiHGjLdu0/cRi1bEv iVsOpTujFs6fZidJ1zgSy6XTdC5Q== X-Google-Smtp-Source: AGHT+IF/ARdhONsx0FgU3D7YbNyHJC6S0I67yHm7MDoA26Xb/wKvXX1888vusp101w+M9RfBvBAteQE5BQ== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a25:dc01:0:b0:e25:fcb:3205 with SMTP id 3f1490d57ef6-e289394d93cmr58923276.8.1728350372143; Mon, 07 Oct 2024 18:19:32 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:47 -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-22-tavip@google.com> Subject: [PATCH v2 21/25] hw/ssi: allow NULL realize callbacks for peripherals 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=3pIgEZwUKCgc0h2pwnvvnsl.jvtxlt1-kl2lsuvunu1.vyn@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: 1728350487980116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Octavian Purdila --- hw/ssi/ssi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/ssi/ssi.c b/hw/ssi/ssi.c index 3f357e8f16..d1f3ce7c22 100644 --- a/hw/ssi/ssi.c +++ b/hw/ssi/ssi.c @@ -105,7 +105,9 @@ static void ssi_peripheral_realize(DeviceState *dev, Er= ror **errp) } s->spc =3D ssc; =20 - ssc->realize(s, errp); + if (ssc->realize) { + ssc->realize(s, errp); + } } =20 static Property ssi_peripheral_properties[] =3D { --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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=1728350637; cv=none; d=zohomail.com; s=zohoarc; b=MDIqDVpyUYSdg0FhQnwgsIbnQJSjluPoASzzl3f1wDGBk1SXBqIjpfr456e6zFmdCvdZmwHBFWfuYGzdnP/pXUBIsNspgOjQS1vGNLP20R4ocHQBx2gbLpI9bnkhnM3i57BmZKT4gu7ggp8vpaTCTpOXOCQ7R0Alxo31hkOHQ+w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350637; 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=YKQ9trFugufZOwGY7NmDfogxKbP5q2hRcs5m3sq43O4=; b=kYMk/CSHOjWA42At5RQ+4hfPGFcugKlh+J8uLKe06R16jiRFAFgmxFJnDONedItfIOOsYv+E+TPW4inNhGaxcCWo8CzjTmFhK3l0K8H/DxF6XVn+Jvd+WPKWqQ7rB238Umewhp23kNGFj8/a6VWgMV62j9yzUA8PZV2T5nKJWgA= 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 17283506371531022.468322522706; Mon, 7 Oct 2024 18:23:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxyuP-0006Mi-3e; Mon, 07 Oct 2024 21:21:05 -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 <3pYgEZwUKCgg1i3qxowwotm.kwuymu2-lm3mtvwvov2.wzo@flex--tavip.bounces.google.com>) id 1sxyt1-0008WK-H9 for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:39 -0400 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3pYgEZwUKCgg1i3qxowwotm.kwuymu2-lm3mtvwvov2.wzo@flex--tavip.bounces.google.com>) id 1sxysz-0000Fg-SG for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:39 -0400 Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-7e9a3e3ec4fso3887702a12.2 for ; Mon, 07 Oct 2024 18:19:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350376; x=1728955176; 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=YKQ9trFugufZOwGY7NmDfogxKbP5q2hRcs5m3sq43O4=; b=F3C+IC6eC4epdm1kGJmbzRUBQVciVWYyA6WR++rji0yQXHhKvTj8/YBSgjztwcIfm1 xIIsNyU50ibZzVecbd4jPj4RXIdVWQXe8A0ouXkbWVvDxoI6dP8kYjF5HaVd2bMiY43I O+y+XApvJMW3iCZ9XmhfHFrlySewGLHT4NQ6z+TXkZrtjZ/beakGCvKYgCBYsjcSm2Fo 3wzesY3r5pavjGusJMRONqs8RevX99bWte05zFSWdB9takPn1q16Ys1fbrC8GxTRzxsM I/ckidQqFPOn5DH7KxCqXwKXx/kHoZ2XDjOvVKZiwLsVZfAEDpGZa1x9wA1iTp/cYhTy FKGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350376; x=1728955176; 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=YKQ9trFugufZOwGY7NmDfogxKbP5q2hRcs5m3sq43O4=; b=Qh0vw1tZROxgVlD5uY5tUqG9NdnvH+ovBoeDACBMo9tzCeVjBfuQC5ITntXa5RKe14 2TqIBwSRlafcx99MhJQR3/P+n3gEIN6VtvA/iFFp3+cprp8MeXZi/UI9MLQilBOrGC35 ONSCdxUX/VrhOtlpP6YExucE77ScgKg72H8LppbaclUvgv8fMMXT6yYbTeytMwAyqXCI s1nOXD+ShbtWaEvjHo6wXm/b7vG2IbqGiKj4K2Zo3ViVikK2rGrLKoF8XppEcmfWFzoT xwGoJIU5DXBTY55wOa2h+xZvDvW5R5vYeJmGA1gpDAQullcVuob0yLISyGX8j0rCqxbC sIgg== X-Gm-Message-State: AOJu0YyDWlC7OtiU1+GXckA9GwQSDNSldUC84IDNMPSPKfndgeYEv8xF SHVAkkDnh2RdT/hh4RVKIHKt/veE0KG6eQ311tcIN0+6moLUBeO44cT5ajWlVUP7PWLroqr/WIT a1MjFjxcB4YvMrQn91EsdvuQDbwWYTdIita/xYoQIZLAJmzTy4rzMjqMmfnNEdikrH4Xf6MD52B +AAHktWwFIQtGmmNVm7igKitlE/A== X-Google-Smtp-Source: AGHT+IHwubTVu63fd9TNbX+TuT3dtVb6xAFFJn5bPr3LB3psw+utH20gvzpptkphd+9FIomlKJBYbnH7kQ== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a17:90a:8a8c:b0:2c9:7616:dec5 with SMTP id 98e67ed59e1d1-2e1e620b95fmr18689a91.2.1728350373992; Mon, 07 Oct 2024 18:19:33 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:48 -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-23-tavip@google.com> Subject: [PATCH v2 22/25] hw/misc: add spi-tester 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::54a; envelope-from=3pYgEZwUKCgg1i3qxowwotm.kwuymu2-lm3mtvwvov2.wzo@flex--tavip.bounces.google.com; helo=mail-pg1-x54a.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=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 @google.com) X-ZM-MESSAGEID: 1728350638527116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a simple SPI peripheral that echoes back received data. Useful for testing SPI controllers. Signed-off-by: Octavian Purdila --- include/hw/misc/spi_tester.h | 32 +++++++++++++++++ hw/misc/spi_tester.c | 67 ++++++++++++++++++++++++++++++++++++ hw/misc/Kconfig | 5 +++ hw/misc/meson.build | 1 + 4 files changed, 105 insertions(+) create mode 100644 include/hw/misc/spi_tester.h create mode 100644 hw/misc/spi_tester.c diff --git a/include/hw/misc/spi_tester.h b/include/hw/misc/spi_tester.h new file mode 100644 index 0000000000..8935f3f1af --- /dev/null +++ b/include/hw/misc/spi_tester.h @@ -0,0 +1,32 @@ +/* + * Simple SPI peripheral device used for SPI controller testing. + * + * 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_SPI_TESTER_H +#define HW_SPI_TESTER_H + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/bswap.h" +#include "hw/irq.h" +#include "hw/ssi/ssi.h" +#include "qemu/timer.h" +#include "hw/qdev-properties.h" + +#define TYPE_SPI_TESTER "spi-tester" +#define SPI_TESTER(obj) OBJECT_CHECK(SpiTesterState, (obj), TYPE_SPI_TESTE= R) + +typedef struct { + SSIPeripheral ssidev; + bool cs; +} SpiTesterState; + +#endif /* HW_SPI_TESTER_H */ diff --git a/hw/misc/spi_tester.c b/hw/misc/spi_tester.c new file mode 100644 index 0000000000..2793ce52dc --- /dev/null +++ b/hw/misc/spi_tester.c @@ -0,0 +1,67 @@ +/* + * Simple SPI peripheral echo device used for SPI controller testing. + * + * 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 "migration/vmstate.h" +#include "hw/misc/spi_tester.h" + +static uint32_t spi_tester_transfer(SSIPeripheral *dev, uint32_t value) +{ + SpiTesterState *s =3D SPI_TESTER(dev); + + if (s->cs) { + return 0; + } + + return value; +} + +static int spi_tester_set_cs(SSIPeripheral *dev, bool select) +{ + SpiTesterState *s =3D SPI_TESTER(dev); + + s->cs =3D select; + + return 0; +} + +static const VMStateDescription vmstate_spi_tester =3D { + .name =3D "spi-tester", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_SSI_PERIPHERAL(ssidev, SpiTesterState), + VMSTATE_BOOL(cs, SpiTesterState), + VMSTATE_END_OF_LIST() + } +}; + +static void spi_tester_class_init(ObjectClass *klass, void *data) +{ + SSIPeripheralClass *k =3D SSI_PERIPHERAL_CLASS(klass); + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->vmsd =3D &vmstate_spi_tester; + k->transfer =3D spi_tester_transfer; + k->set_cs =3D spi_tester_set_cs; + k->cs_polarity =3D SSI_CS_LOW; +} + +static const TypeInfo spi_tester_types[] =3D { + { + .name =3D TYPE_SPI_TESTER, + .parent =3D TYPE_SSI_PERIPHERAL, + .instance_size =3D sizeof(SpiTesterState), + .class_init =3D spi_tester_class_init, + }, +}; + +DEFINE_TYPES(spi_tester_types); diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig index 3e93c12c8e..484ee3149f 100644 --- a/hw/misc/Kconfig +++ b/hw/misc/Kconfig @@ -218,6 +218,11 @@ config I2C_TESTER default y if TEST_DEVICES depends on I2C =20 +config SPI_TESTER + bool + default y if TEST_DEVICES + depends on SSI + config FLEXCOMM bool select I2C diff --git a/hw/misc/meson.build b/hw/misc/meson.build index cd29db37d7..0cece9a964 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -153,6 +153,7 @@ system_ss.add(when: 'CONFIG_SBSA_REF', if_true: files('= sbsa_ec.c')) system_ss.add(when: 'CONFIG_LASI', if_true: files('lasi.c')) =20 system_ss.add(when: 'CONFIG_I2C_TESTER', if_true: files('i2c_tester.c')) +system_ss.add(when: 'CONFIG_SPI_TESTER', if_true: files('spi_tester.c')) =20 system_ss.add(when: 'CONFIG_FLEXCOMM', if_true: files('flexcomm.c')) system_ss.add(when: 'CONFIG_RT500_CLKCTL', if_true: files('rt500_clkctl0.c= ', 'rt500_clkctl1.c')) --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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=1728350768; cv=none; d=zohomail.com; s=zohoarc; b=oK5K74p4DKYp7Uz2BPMFOG71PJNNrJO41wfn0uTHOpR55PVl4lrZudRIsJAIqTA8O/6T1HcyMQauyhDMjXJlznWqcuhRGsqAoNT21Lcngi1HhcNoZo1u5HIl3w4xqrNpmUMFrNMWwQwjJDnl1866nm9l0edcxEw4ml3m55IapIY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350768; 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=6ZAi4gulNhaksWV2hV6e+8oRvcK8JyjNz4xRR0r3KZA=; b=cIyxH7ePP/Smiqu6Nto4kfw8FmwlqKhgYp0pF8dpIQEdW1visl7p7pbG2rsz2WGP3er5D00UlfAFAlAkfbDweNdBY+DIoOexasR/BlZla74Qdwa+twOhDkx6/q/OwjJTVxSjKjy9As4Bh6fCBycjNbyAtLJ4BXVJ33Nn60YPYEY= 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 1728350768767494.1184895674528; Mon, 7 Oct 2024 18:26:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxyur-00085g-DX; Mon, 07 Oct 2024 21:21:34 -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 <3qIgEZwUKCgs4l6t0rzzrwp.nzx1px5-op6pwyzyry5.z2r@flex--tavip.bounces.google.com>) id 1sxyt5-0000Xn-Ff for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:43 -0400 Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3qIgEZwUKCgs4l6t0rzzrwp.nzx1px5-op6pwyzyry5.z2r@flex--tavip.bounces.google.com>) id 1sxyt0-0000GH-KG for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:43 -0400 Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-7174c6cbdbaso5838164b3a.2 for ; Mon, 07 Oct 2024 18:19:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350377; x=1728955177; 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=6ZAi4gulNhaksWV2hV6e+8oRvcK8JyjNz4xRR0r3KZA=; b=mIuqcCO3I+GMI85RVK4eeZvdlM8e2J0QEjuyj570kUH8/ZzIM/fQtJCi47FaP0nwd5 Anid2Poew2RKM2xa0DwtJOymo3y/djxh6ch9RTkBw1Z3j/PwkiglZR3Taa5kmiNo3QvR w0jKirWPnMlXaMuQJQAfFBw9MFwZ76bLmaWude4SfozqTSvW7Lo6EKMQ/fSGj5QxdZC1 WuF7DFWIk/pFJwI6UOdMcDkONKwDzZBcKnqBfCTYKeMqKpdsu46cVDbD1ElHesW+WKsf e3V8B/+uDe4DxRMJAReYhCwDboOQ78zXauBi9faP6UtyiW6Nyj+QMx1bvBqRZJ40RdI9 BYjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350377; x=1728955177; 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=6ZAi4gulNhaksWV2hV6e+8oRvcK8JyjNz4xRR0r3KZA=; b=ouUYmeY3Apj6LmciqKADQZGZvD1v2rOtx7J+JtmVMkMwDSTogcGqDkmUF2Zr7NfzGv hPwsp69O8w3BKnySMoPlZh76oP4nFF25A+XqUOLel01TiMEykY8gKestNgaqyjCPfnKm gK8kj7bfTb9E5gWEn0FM90f7fep0fSaxEUqx4tNEXnQy46JojOT6X+rK9PcELG7dUaw3 8MZ4Be3cZ8yTJ9jgIli5xfyVKvxHunIr0KFvsfo9JperU0+TMoVwUeM6atgAKVbo3/sB QVp97anmWW8hkz1XkyNPMd1qtGcBc9BZgPkkRj1YKe27D81smBMwn2pxffsNs61PbfLz UrqQ== X-Gm-Message-State: AOJu0Yx9kwOnXYJSm1F2LQ+SAb2W29h7BY76wWvsXlhPiOJCHP4efMI6 R0dmRTJ31EkZWGATGX3IVKPItCfCycURl5ZjRUBFxCW9/kRoF+OPLffO+KKLsIiEYNvfBThacj2 Emb5bjXG3LB367OBOGFiDi7w2gqxlwz2n0sYrPCUGDVz7JLqflVED43WgsNAHsg2a+c3cap4yTv 0tJM6WthcaQ+Ejzlhb4//pXzbKRg== X-Google-Smtp-Source: AGHT+IH7/MV6R5ex7R/s8YoXOodTUCEW4seC2LmeSVI6mh5M/35dcwCp5grJHjlS8iaBVFJyIoSE+XHi7g== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a05:6a00:2cf:b0:71d:f324:bd3e with SMTP id d2e1a72fcca58-71df324be2cmr39081b3a.3.1728350376065; Mon, 07 Oct 2024 18:19:36 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:49 -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-24-tavip@google.com> Subject: [PATCH v2 23/25] tests/qtest: add tests for flexcomm spi 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::44a; envelope-from=3qIgEZwUKCgs4l6t0rzzrwp.nzx1px5-op6pwyzyry5.z2r@flex--tavip.bounces.google.com; helo=mail-pf1-x44a.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=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 @google.com) X-ZM-MESSAGEID: 1728350770950116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Sebastian Ene Add master and loopback tests for flexcomm spi. Signed-off-by: Sebastian Ene [tavip: add master mode test, convert to qtest] Signed-off-by: Octavian Purdila --- tests/qtest/flexcomm-spi-test.c | 145 ++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 2 +- 2 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/flexcomm-spi-test.c diff --git a/tests/qtest/flexcomm-spi-test.c b/tests/qtest/flexcomm-spi-tes= t.c new file mode 100644 index 0000000000..4658835b8f --- /dev/null +++ b/tests/qtest/flexcomm-spi-test.c @@ -0,0 +1,145 @@ +/* + * 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/config-file.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qapi/error.h" +#include "qemu/sockets.h" +#include "sysemu/sysemu.h" +#include "qemu/main-loop.h" +#include "qemu/option.h" +#include "exec/memory.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" +#include "hw/qdev-core.h" + +#include "hw/misc/flexcomm.h" +#include "hw/arm/svd/flexcomm_spi.h" +#include "hw/arm/svd/rt500.h" +#include "reg-utils.h" + +/* The number of words sent on the SPI in loopback mode. */ +#define SEQ_LOOPBACK_MODE (8) + +/* This value is used to set the cycle counter for the spi tester */ +#define SPI_TESTER_CONFIG (0x10) + +#define FLEXCOMM_BASE RT500_FLEXCOMM0_BASE +#define FLEXCOMM_SPI_BASE RT500_FLEXCOMM0_BASE +#define DEVICE_NAME "/machine/soc/flexcomm0" + +static void configure_spi(bool master, bool is_loopback_mode) +{ + uint32_t tmp; + + /* Select and lock SPI */ + tmp =3D FLEXCOMM_PERSEL_SPI; + FIELD_DP32(tmp, FLEXCOMM_PSELID, LOCK, 1); + REG32_WRITE(FLEXCOMM, PSELID, tmp); + + /* Disable the FIFO */ + REG32_WRITE_FIELD(FLEXCOMM_SPI, CFG, ENABLE, 0); + REG32_WRITE_FIELD(FLEXCOMM_SPI, FIFOCFG, ENABLETX, 0); + REG32_WRITE_FIELD(FLEXCOMM_SPI, FIFOCFG, ENABLERX, 0); + + if (is_loopback_mode) { + /* Set up SPI interface - loop mode, master mode */ + REG32_WRITE_FIELD(FLEXCOMM_SPI, CFG, LOOP, 1); + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, CFG, LOOP) =3D=3D 1); + } + + if (master) { + REG32_WRITE_FIELD(FLEXCOMM_SPI, CFG, MASTER, 1); + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, CFG, MASTER) =3D=3D 1); + } else { + REG32_WRITE_FIELD(FLEXCOMM_SPI, CFG, MASTER, 0); + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, CFG, MASTER) =3D=3D 0); + } + + /* Enable the FIFO */ + REG32_WRITE_FIELD(FLEXCOMM_SPI, FIFOCFG, ENABLETX, 1); + REG32_WRITE_FIELD(FLEXCOMM_SPI, FIFOCFG, ENABLERX, 1); + + /* Enable the SPI */ + REG32_WRITE_FIELD(FLEXCOMM_SPI, CFG, ENABLE, 1); + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, CFG, ENABLE) =3D=3D 1); +} + +/* The SPI controller running in master mode can run in loopback mode for = */ +/* internal testing. Transmit and receive lines are connected together. */ +static void loopback_test(gconstpointer user_data) +{ + configure_spi(true, true); + + /* Write a sequence */ + for (int i =3D 0; i < SEQ_LOOPBACK_MODE; i++) { + REG32_WRITE(FLEXCOMM_SPI, FIFOWR, i); + } + + /* Read the sequence back */ + for (int i =3D 0; i < SEQ_LOOPBACK_MODE; i++) { + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, FIFORD, RXDATA) =3D=3D i); + } +} + +static void master_test(gconstpointer user_data) +{ + uint32_t tmp; + + configure_spi(true, false); + + REG32_WRITE_FIELD(FLEXCOMM_SPI, CFG, LSBF, 1); + + /* single 16bit word transfer */ + + tmp =3D FIELD_DP32(0x1122, FLEXCOMM_SPI_FIFOWR, EOT, 1); + tmp =3D FIELD_DP32(tmp, FLEXCOMM_SPI_FIFOWR, TXSSEL0_N, 1); + tmp =3D FIELD_DP32(tmp, FLEXCOMM_SPI_FIFOWR, LEN, 0xF); + REG32_WRITE(FLEXCOMM_SPI, FIFOWR, tmp); + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, FIFOSTAT, RXNOTEMPTY) =3D=3D 1= ); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_SPI, FIFORD, RXDATA), + =3D=3D, 0x1122); + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, FIFOSTAT, RXNOTEMPTY) =3D=3D 0= ); + + /* multi word 8 bits transfer */ + + tmp =3D FIELD_DP32(0x11, FLEXCOMM_SPI_FIFOWR, TXSSEL0_N, 1); + tmp =3D FIELD_DP32(tmp, FLEXCOMM_SPI_FIFOWR, LEN, 0x7); + REG32_WRITE(FLEXCOMM_SPI, FIFOWR, tmp); + tmp =3D 0x22; + FIELD_DP32(tmp, FLEXCOMM_SPI_FIFOWR, EOT, 1); + FIELD_DP32(tmp, FLEXCOMM_SPI_FIFOWR, TXSSEL0_N, 1); + FIELD_DP32(tmp, FLEXCOMM_SPI_FIFOWR, LEN, 0x7); + REG32_WRITE(FLEXCOMM_SPI, FIFOWR, tmp); + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, FIFOSTAT, RXNOTEMPTY) =3D=3D 1= ); + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, FIFORD, RXDATA) =3D=3D 0x11); + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, FIFOSTAT, RXNOTEMPTY) =3D=3D 1= ); + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, FIFORD, RXDATA) =3D=3D 0x22); + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, FIFOSTAT, RXNOTEMPTY) =3D=3D 0= ); +} + +int main(int argc, char **argv) +{ + int ret; + + module_call_init(MODULE_INIT_QOM); + g_test_init(&argc, &argv, NULL); + + qtest_add_data_func("/flexcomm-spi/loopack", NULL, loopback_test); + qtest_add_data_func("/flexcomm-spi/master", NULL, master_test); + + qtest_start("-M rt595-evk -device spi-tester,bus=3D/flexcomm0-spi"); + ret =3D g_test_run(); + qtest_end(); + + return ret; +} diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index c21b18c304..d3bf33b855 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -233,7 +233,7 @@ qtests_arm =3D \ (config_all_devices.has_key('CONFIG_FSI_APB2OPB_ASPEED') ? ['aspeed_fsi-= test'] : []) + \ (config_all_devices.has_key('CONFIG_STM32L4X5_SOC') and config_all_devices.has_key('CONFIG_DM163')? ['dm163-test'] : []) + \ - (config_all_devices.has_key('CONFIG_FLEXCOMM') ? ['flexcomm-test', 'flex= comm-usart-test', 'flexcomm-i2c-test'] : []) + \ + (config_all_devices.has_key('CONFIG_FLEXCOMM') ? ['flexcomm-test', 'flex= comm-usart-test', 'flexcomm-i2c-test', 'flexcomm-spi-test'] : []) + \ ['arm-cpu-features', 'boot-serial-test'] =20 --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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=1728350572; cv=none; d=zohomail.com; s=zohoarc; b=Yj1Ix3xPWSP9isxqGqW/7BiGz2KI2jPc0hQl372ICgPtOgG4lvxaNn6pcRXnmS3/2ehr0FK66fA87gWvnkF2UJVGWyS18OdehoFwhVqAWS92PhBeBQL2xS9TCtglLJ48Cfmlshodv0tohNzaSIWlXEuKdScnFsUOm3ONPT+Gh/I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350572; 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=4/p/dqyX4FDV19scC8uVsqmc4fVxq0udNnyaIq4QvGw=; b=BW70hbrddBlXZ0e/6UgP5mt42IhfXBp3vfWsIw6tZeIp0AygL25IVT65O3rsBOA1/iBKkg+a4WeulB43JvznJCw5OLicMwENL5ud2s7JUhT+ZMDUPoejf1tUjf8U5FTGfWphRDrqX+AaVLY4NUp9GpAkGkebPqMC/E2Y6NeQq6g= 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 1728350572466134.94269626847495; Mon, 7 Oct 2024 18:22:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxyuh-000782-9r; Mon, 07 Oct 2024 21:21:24 -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 <3qYgEZwUKCgw5m7u1s00sxq.o0y2qy6-pq7qxz0zsz6.03s@flex--tavip.bounces.google.com>) id 1sxyt5-0000Vc-49 for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:43 -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 <3qYgEZwUKCgw5m7u1s00sxq.o0y2qy6-pq7qxz0zsz6.03s@flex--tavip.bounces.google.com>) id 1sxyt3-0000Gf-8X for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:42 -0400 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-e2605a8c7e0so7835850276.0 for ; Mon, 07 Oct 2024 18:19:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350378; x=1728955178; 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=4/p/dqyX4FDV19scC8uVsqmc4fVxq0udNnyaIq4QvGw=; b=dRNmDKoqGYJKz8PvcVLvateHdv0/LjTyXs3i9pC5R6VozwdL1isHYoN9bWZCTM0oaa mjsa4doJKgz+6W+zOH8rorErIEKmGYqPtejTxLrYDnDeRnhGYPp1mTxRhg48Vu7bFtak IzkillXatDI/zLTvT2Elgw+4noX0qZ5f9aTEkA3YtktRog7xAvwM4ZuJ341ekUECA2x0 Psi9LtUmhIHJpv3X77x6bCmYgl9Ccd/rS15yLwSifOfXJPusQDndwdUDabaSDCHGHhko 86O54MQ6Uwf/Sj6z0wdK9aMmBp8jE7EFio5q6Q6u6DlaowCJ8z/7Y8L3ZG5BwI/O6ya1 HyWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350378; x=1728955178; 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=4/p/dqyX4FDV19scC8uVsqmc4fVxq0udNnyaIq4QvGw=; b=HFC6RTlZ9dqTCke8cXZuzeLfOKzjt95i/hwRmcfM0fUWjUFBDOJUUE9EFndMd5f36z 5k8TTMgt6Gk5ONFMjBhoiyoSdv/sMjtQe2KTUo13hSi9NpI2fdrwCyi7XjzdWX9r+tRN sg7TMDchCoyYFfPa8jziG2IHQQ3z0m29aQIfbJ8eRq8c39p1RUrpL8g3dl74RFX6Ued/ ct9lgLHagIjeUmRSj55hxKL3XjeyKzVrB6TmL9ndireL7Eewc5+rKjlRAWNedV+LvCcN Em7rolP7rtu6L0sJ+xyp0WZ3kIrE11tAerNBEUa3BhTHFbFXvEDNZzL2hgVfXj4ngDOZ adYA== X-Gm-Message-State: AOJu0YwnLfnSot5pFwUIsZPxiJCjnxtzaU7FWwvoTXE6yN9pOBRFa+bm k5Ep7SFwrsJQyjWfh38uMpbmWlZHN7OB5TzLMdkfzShcIO1PyUe7ngNVVfR5mOy0GsCuaQ7wBSp EqMW0V78ZgVsr/+epEIHYJyHk+zrZ9fCuLjAcLYqNSFCWLxL8s+4I64Zz7ad8TBfs2TzH+wnz7r 2XaaTfy+wP+np3CQVU4cGPy+IeMA== X-Google-Smtp-Source: AGHT+IEoeuT9lk85qy1pXmXRYWYcENTbtYkdXXuFKfukech2eGzywLrqJOXChcePRGtAMnAtL77NjiAJIQ== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a05:6902:1786:b0:e25:d202:d376 with SMTP id 3f1490d57ef6-e28be89b1a9mr5368276.6.1728350377903; Mon, 07 Oct 2024 18:19:37 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:50 -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-25-tavip@google.com> Subject: [PATCH v2 24/25] systems/qtest: add device clock APIs 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=3qYgEZwUKCgw5m7u1s00sxq.o0y2qy6-pq7qxz0zsz6.03s@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, WEIRD_QUOTING=0.001 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 @google.com) X-ZM-MESSAGEID: 1728350574353116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add qtest APIs to check the device clock frequency. Signed-off-by: Octavian Purdila --- include/hw/qdev-clock.h | 10 +++++++ tests/qtest/libqtest-single.h | 24 +++++++++++++++++ tests/qtest/libqtest.h | 22 +++++++++++++++ hw/core/qdev-clock.c | 2 +- system/qtest.c | 51 +++++++++++++++++++++++++++++++++++ tests/qtest/libqtest.c | 29 ++++++++++++++++++++ 6 files changed, 137 insertions(+), 1 deletion(-) diff --git a/include/hw/qdev-clock.h b/include/hw/qdev-clock.h index ffa0f7ba09..19ed34ae88 100644 --- a/include/hw/qdev-clock.h +++ b/include/hw/qdev-clock.h @@ -15,6 +15,7 @@ #define QDEV_CLOCK_H =20 #include "hw/clock.h" +#include "hw/qdev-core.h" =20 /** * qdev_init_clock_in: @@ -161,4 +162,13 @@ typedef struct ClockPortInitElem ClockPortInitArray[]; */ void qdev_init_clocks(DeviceState *dev, const ClockPortInitArray clocks); =20 +/** + * qdev_get_clocklist: + * @dev: the device to find clock for + * @name: clock name + * + * Returns: a named clock list entry or NULL if the clock was not found + */ +NamedClockList *qdev_get_clocklist(DeviceState *dev, const char *name); + #endif /* QDEV_CLOCK_H */ diff --git a/tests/qtest/libqtest-single.h b/tests/qtest/libqtest-single.h index c22037c8b2..51eb69ff74 100644 --- a/tests/qtest/libqtest-single.h +++ b/tests/qtest/libqtest-single.h @@ -408,4 +408,28 @@ static inline int64_t clock_step(int64_t step) return qtest_clock_step(global_qtest, step); } =20 +/** + * qtest_qdev_clock_in_get_hz: + * @path: QOM path of a device. + * @name: Clock name. + * + * Returns: device clock frequency in HZ + */ +static inline uint64_t dev_clock_in_get_hz(const char *path, const char *n= ame) +{ + return qtest_dev_clock_in_get_hz(global_qtest, path, name); +} + +/** + * qtest_qdev_clock_out_get_hz: + * @path: QOM path of a device. + * @name: Clock name. + * + * Returns: device clock frequency in HZ + */ +static inline uint64_t dev_clock_out_get_hz(const char *path, const char *= name) +{ + return qtest_dev_clock_out_get_hz(global_qtest, path, name); +} + #endif diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h index f9bbeb2e60..cfb7098985 100644 --- a/tests/qtest/libqtest.h +++ b/tests/qtest/libqtest.h @@ -1169,4 +1169,26 @@ bool have_qemu_img(void); */ bool mkimg(const char *file, const char *fmt, unsigned size_mb); =20 +/** + * qtest_qdev_clock_in_get_hz: + * @s: #QTestState instance to operate on. + * @path: QOM path of a device. + * @name: Clock name. + * + * Returns: device clock frequency in HZ + */ +uint64_t qtest_dev_clock_in_get_hz(QTestState *s, const char *path, + const char *name); + +/** + * qtest_qdev_clock_out_get_hz: + * @s: #QTestState instance to operate on. + * @path: QOM path of a device. + * @name: Clock name. + * + * Returns: device clock frequency in HZ + */ +uint64_t qtest_dev_clock_out_get_hz(QTestState *s, const char *path, + const char *name); + #endif diff --git a/hw/core/qdev-clock.c b/hw/core/qdev-clock.c index 82799577f3..3c9e2d5d73 100644 --- a/hw/core/qdev-clock.c +++ b/hw/core/qdev-clock.c @@ -144,7 +144,7 @@ void qdev_init_clocks(DeviceState *dev, const ClockPort= InitArray clocks) } } =20 -static NamedClockList *qdev_get_clocklist(DeviceState *dev, const char *na= me) +NamedClockList *qdev_get_clocklist(DeviceState *dev, const char *name) { NamedClockList *ncl; =20 diff --git a/system/qtest.c b/system/qtest.c index 95bb80a2bc..465666a416 100644 --- a/system/qtest.c +++ b/system/qtest.c @@ -19,6 +19,7 @@ #include "exec/ioport.h" #include "exec/memory.h" #include "exec/tswap.h" +#include "hw/qdev-clock.h" #include "hw/qdev-core.h" #include "hw/irq.h" #include "hw/core/cpu.h" @@ -245,6 +246,20 @@ static void *qtest_server_send_opaque; * * Forcibly set the given interrupt pin to the given level. * + * Device clock frequency + * """""""""""""""""""""" + * + * .. code-block:: none + * + * > qdev_clock_out_get_hz QOM-PATH CLOCK-NAME + * < OK HZ + * + * .. code-block:: none + * + * > qdev_clock_in_get_hz QOM-PATH CLOCK-NAME + * < OK HZ + * + * where HZ is the clock frequency in hertz. */ =20 static int hex2nib(char ch) @@ -758,6 +773,42 @@ static void qtest_process_command(CharBackend *chr, gc= har **words) qtest_send_prefix(chr); qtest_sendf(chr, "OK %"PRIi64"\n", (int64_t)qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); + } else if (strcmp(words[0], "qdev_clock_in_get_hz") =3D=3D 0 || + strcmp(words[0], "qdev_clock_out_get_hz") =3D=3D 0) { + bool is_outbound =3D words[0][11] =3D=3D 'o'; + DeviceState *dev; + NamedClockList *ncl; + + g_assert(words[1]); + g_assert(words[2]); + + dev =3D DEVICE(object_resolve_path(words[1], NULL)); + if (!dev) { + qtest_send_prefix(chr); + qtest_send(chr, "FAIL Unknown device\n"); + return; + } + + ncl =3D qdev_get_clocklist(dev, words[2]); + if (!ncl) { + qtest_send_prefix(chr); + qtest_send(chr, "FAIL Unknown clock\n"); + return; + } + + if (is_outbound && !ncl->output) { + qtest_send_prefix(chr); + qtest_send(chr, "FAIL Not an output clock\n"); + return; + } + + if (!is_outbound && ncl->output) { + qtest_send_prefix(chr); + qtest_send(chr, "FAIL Not an input clock\n"); + return; + } + + qtest_sendf(chr, "OK %u\n", clock_get_hz(ncl->clock)); } else if (process_command_cb && process_command_cb(chr, words)) { /* Command got consumed by the callback handler */ } else { diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index 4055d6b953..cc11b5f42e 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -2065,3 +2065,32 @@ bool mkimg(const char *file, const char *fmt, unsign= ed size_mb) =20 return ret && !err; } + +static uint64_t qtest_dev_clock_get_hz(QTestState *s, const char *path, + const char *name, bool out) +{ + gchar **args; + int ret; + uint64_t value; + + qtest_sendf(s, "qdev_clock_%s_get_hz %s %s\n", out ? "out" : "in", + path, name); + args =3D qtest_rsp_args(s, 2); + ret =3D qemu_strtou64(args[1], NULL, 0, &value); + g_assert(!ret); + g_strfreev(args); + + return value; +} + +uint64_t qtest_dev_clock_out_get_hz(QTestState *s, const char *path, + const char *name) +{ + return qtest_dev_clock_get_hz(s, path, name, true); +} + +uint64_t qtest_dev_clock_in_get_hz(QTestState *s, const char *path, + const char *name) +{ + return qtest_dev_clock_get_hz(s, path, name, false); +} --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Sat Nov 23 21:39:54 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=1728350684; cv=none; d=zohomail.com; s=zohoarc; b=Ud4+vb0XDZg72cfb0lFONG96xcJdK6IakR6ayivTUdyc90bS0t/HIY49Tx9LYimZS/wN8ETshi74cvoRlGcHczWqd1QhzHELFKQ7MzxgOs6wNmA3Air8fADltY4Sz2KRaXv+XYxIY9/6VLPlwGkTWW4isZ/T13Oz6qygeZQyyrk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728350684; 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=49FquaWPsQCXDvZ+9iOGQgsSq0aM4lH+3lh+RTdFI2o=; b=McrpzlvQSlUyBDdtvCHvqzv/qntvtnpediXPaAD05yjtuKM17KAOPQAGDRvlNz/cdtDI7vNwawaC4XTJyq2CIjL2eLdPSKlb/GuRE42VESMm/b7V6BRFXJFG4fiquxZF7x+Yva1D8Jcr/DsRPQBXo2yetUOMiNOdxSX5ZFCiJn0= 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 1728350684265591.2681116168277; Mon, 7 Oct 2024 18:24:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxyuo-0007qZ-D3; Mon, 07 Oct 2024 21:21:30 -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 <3q4gEZwUKCg47o9w3u22uzs.q204s08-rs9sz121u18.25u@flex--tavip.bounces.google.com>) id 1sxyt6-0000c9-Ax for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:44 -0400 Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3q4gEZwUKCg47o9w3u22uzs.q204s08-rs9sz121u18.25u@flex--tavip.bounces.google.com>) id 1sxyt3-0000HA-R1 for qemu-devel@nongnu.org; Mon, 07 Oct 2024 21:19:44 -0400 Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-71e11abb22aso518153b3a.1 for ; Mon, 07 Oct 2024 18:19:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728350380; x=1728955180; 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=49FquaWPsQCXDvZ+9iOGQgsSq0aM4lH+3lh+RTdFI2o=; b=ZbGg8t+qbV8sonNVz0B5vAy1Q0OrO5tMy1xHL4d5DTHJstdZK0I3leAavZ7yUwJ5/K HzzcIG0Emk/za25DfQrPu4xxJWzP9b5d8Apai9CO3wWRVSCIG8/rv2QWPVH0csLuYVcm GMh2PhjyZ1COo381ynQF4BUECvcjCRnXXiQCR33b4NvfKLEPB8h2qZ10uDfkUG0o1IKH hUFSpHWyeuCGAEyfwZA8w5r8JBMFwesiVKsC9vGt0ByRTH1sx88VE+OIZA9uC3061nx/ jBeEqqvcyqYy1S9CQEi/lp0TNLawL8sa0N6AJsf7O0qu9ccT1m5CUfliHJ7j6/Qshbqd nHlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728350380; x=1728955180; 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=49FquaWPsQCXDvZ+9iOGQgsSq0aM4lH+3lh+RTdFI2o=; b=kN7aUTSKEOpU4Gf12JSfxUUo4KvXdTkpD1YnXJrcZIgtKaFYrnqRnCLTz3m/EMPatc M87MVvbvq4GyxhvvM56bNu/8/BiK5PFeSjUT7IORxyPRVT7y2F/P6A/mHKzpn+tRc4cS Okj8kIzsbHhjGCKA9gWHR4oDz3CALEq2ZX8NCW94UjzqgagO1c4IXbQHav0+VLmuytBl ix4c2NON2PyFSJkSD56hMW6ngpk7X101z00MZm9qxh/8Wt9SmG7yB+QtBXNcHY9fohCs /9/J5XAjyVEna5cc5I/7OzVpQycaQyJnTRYKF3kejTFjezvBUP++EeJ+YTiZ9mt9ILUF pTKQ== X-Gm-Message-State: AOJu0Yz7/DheuOcfHVxyQ9dpJkLQMcS+MIAIWKnEK9rRn2Z/gDcoLE6C 9kcr/Kve4s3A7jtzeULvdr1gRMjnLIjvKX62h8SsN7wa72QzlULbTHKjS1zqY6YS0j3v7Z/4VcH 69kYiezcxHmtTzUuPS78mJSysypWfB+tbeCY+TVHGgy4CXfohyVvlj7VGGGbRWEAbnIxDRdoCjm 1KEOQb3tCgXPa1sWYNyxmyYTfyNQ== X-Google-Smtp-Source: AGHT+IHJH7MDeTk7Nh7rloj7vbrxdaiHNNx6zsfSUnM9QveGoJqzgfjpJEuaUwn1zp3dxVmynOyZGpE3ag== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a05:6a00:324b:b0:71d:eb98:7341 with SMTP id d2e1a72fcca58-71deb987431mr22279b3a.2.1728350379687; Mon, 07 Oct 2024 18:19:39 -0700 (PDT) Date: Mon, 7 Oct 2024 18:18:51 -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-26-tavip@google.com> Subject: [PATCH v2 25/25] tests/qtest: add tests for RT500's clock controller 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::44a; envelope-from=3q4gEZwUKCg47o9w3u22uzs.q204s08-rs9sz121u18.25u@flex--tavip.bounces.google.com; helo=mail-pf1-x44a.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=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 @google.com) X-ZM-MESSAGEID: 1728350684728116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add test to exercise clocks set and clear, system PLL initialization, audio PLL initialization, systick and ostimer clock source selection. Signed-off-by: Octavian Purdila --- tests/qtest/rt500-clkctl-test.c | 195 ++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 1 + 2 files changed, 196 insertions(+) create mode 100644 tests/qtest/rt500-clkctl-test.c diff --git a/tests/qtest/rt500-clkctl-test.c b/tests/qtest/rt500-clkctl-tes= t.c new file mode 100644 index 0000000000..d5b83d81da --- /dev/null +++ b/tests/qtest/rt500-clkctl-test.c @@ -0,0 +1,195 @@ +/* + * 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/log.h" +#include "qemu/module.h" +#include "qemu/main-loop.h" +#include "exec/memory.h" +#include "hw/clock.h" +#include "hw/irq.h" +#include "hw/qdev-clock.h" +#include "hw/qdev-properties.h" + +#include "hw/misc/rt500_clkctl0.h" +#include "hw/misc/rt500_clkctl1.h" +#include "hw/misc/rt500_clk_freqs.h" +#include "hw/arm/svd/rt500.h" +#include "reg-utils.h" + +#define SYSCLK_HZ 200000000 +#define CLKCTL0_NAME "/machine/soc/clkctl0" +#define CLKCTL1_NAME "/machine/soc/clkctl1" + +static void pscctl_test(gconstpointer user_data) +{ + /* rom controller clock should be enabled at reset */ + g_assert(REG32_READ_FIELD(RT500_CLKCTL0, PSCCTL0, ROM_CTRLR_CLK) =3D= =3D 1); + + /* DSP clk is disabled at reset */ + g_assert(REG32_READ_FIELD(RT500_CLKCTL0, PSCCTL0, DSP_CLK) =3D=3D 0); + + /* check PSCTL_SET functionality */ + REG32_WRITE_FIELD_NOUPDATE(RT500_CLKCTL0, PSCCTL0_SET, DSP_CLK, 1); + g_assert(REG32_READ_FIELD(RT500_CLKCTL0, PSCCTL0, DSP_CLK) =3D=3D 1); + + /* check PSCTL_CLR functionality */ + REG32_WRITE_FIELD_NOUPDATE(RT500_CLKCTL0, PSCCTL0_CLR, DSP_CLK, 1); + g_assert(REG32_READ_FIELD(RT500_CLKCTL0, PSCCTL0, DSP_CLK) =3D=3D 0); + + /* FLEXIO clk is disabled at reset */ + g_assert(REG32_READ_FIELD(RT500_CLKCTL1, PSCCTL0, FlexIO) =3D=3D 0); + + /* check PSCTL_SET functionality */ + REG32_WRITE_FIELD_NOUPDATE(RT500_CLKCTL1, PSCCTL0_SET, FlexIO, 1); + g_assert(REG32_READ_FIELD(RT500_CLKCTL1, PSCCTL0, FlexIO) =3D=3D 1); + + /* check PSCTL_CLR functionality */ + REG32_WRITE_FIELD_NOUPDATE(RT500_CLKCTL1, PSCCTL0_CLR, FlexIO, 1); + g_assert(REG32_READ_FIELD(RT500_CLKCTL1, PSCCTL0, FlexIO) =3D=3D 0); +} + +static void audiopll0pfd_test(gconstpointer user_data) +{ + /* audio plls are gated at boot */ + g_assert(REG32_READ_FIELD(RT500_CLKCTL1, AUDIOPLL0PFD, PFD3_CLKGATE) = =3D=3D 1); + g_assert(REG32_READ_FIELD(RT500_CLKCTL1, AUDIOPLL0PFD, PFD2_CLKGATE) = =3D=3D 1); + g_assert(REG32_READ_FIELD(RT500_CLKCTL1, AUDIOPLL0PFD, PFD1_CLKGATE) = =3D=3D 1); + g_assert(REG32_READ_FIELD(RT500_CLKCTL1, AUDIOPLL0PFD, PFD0_CLKGATE) = =3D=3D 1); + + /* ,,, and clocks are not ready */ + g_assert(REG32_READ_FIELD(RT500_CLKCTL1, AUDIOPLL0PFD, PFD3_CLKRDY) = =3D=3D 0); + g_assert(REG32_READ_FIELD(RT500_CLKCTL1, AUDIOPLL0PFD, PFD2_CLKRDY) = =3D=3D 0); + g_assert(REG32_READ_FIELD(RT500_CLKCTL1, AUDIOPLL0PFD, PFD1_CLKRDY) = =3D=3D 0); + g_assert(REG32_READ_FIELD(RT500_CLKCTL1, AUDIOPLL0PFD, PFD0_CLKRDY) = =3D=3D 0); + + /* ungate all plls and check that clocks are ready */ + REG32_WRITE_FIELD(RT500_CLKCTL1, AUDIOPLL0PFD, PFD3_CLKGATE, 0); + REG32_WRITE_FIELD(RT500_CLKCTL1, AUDIOPLL0PFD, PFD2_CLKGATE, 0); + REG32_WRITE_FIELD(RT500_CLKCTL1, AUDIOPLL0PFD, PFD1_CLKGATE, 0); + REG32_WRITE_FIELD(RT500_CLKCTL1, AUDIOPLL0PFD, PFD0_CLKGATE, 0); + + g_assert(REG32_READ_FIELD(RT500_CLKCTL1, AUDIOPLL0PFD, PFD3_CLKRDY) = =3D=3D 1); + g_assert(REG32_READ_FIELD(RT500_CLKCTL1, AUDIOPLL0PFD, PFD2_CLKRDY) = =3D=3D 1); + g_assert(REG32_READ_FIELD(RT500_CLKCTL1, AUDIOPLL0PFD, PFD1_CLKRDY) = =3D=3D 1); + g_assert(REG32_READ_FIELD(RT500_CLKCTL1, AUDIOPLL0PFD, PFD0_CLKRDY) = =3D=3D 1); +} + +static void syspll0pfd_test(gconstpointer user_data) +{ + /* system plls are gated at boot */ + g_assert(REG32_READ_FIELD(RT500_CLKCTL0, SYSPLL0PFD, PFD3_CLKGATE) =3D= =3D 1); + g_assert(REG32_READ_FIELD(RT500_CLKCTL0, SYSPLL0PFD, PFD2_CLKGATE) =3D= =3D 1); + g_assert(REG32_READ_FIELD(RT500_CLKCTL0, SYSPLL0PFD, PFD1_CLKGATE) =3D= =3D 1); + g_assert(REG32_READ_FIELD(RT500_CLKCTL0, SYSPLL0PFD, PFD0_CLKGATE) =3D= =3D 1); + + /* ,,, and clocks are not ready */ + g_assert(REG32_READ_FIELD(RT500_CLKCTL0, SYSPLL0PFD, PFD3_CLKRDY) =3D= =3D 0); + g_assert(REG32_READ_FIELD(RT500_CLKCTL0, SYSPLL0PFD, PFD2_CLKRDY) =3D= =3D 0); + g_assert(REG32_READ_FIELD(RT500_CLKCTL0, SYSPLL0PFD, PFD1_CLKRDY) =3D= =3D 0); + g_assert(REG32_READ_FIELD(RT500_CLKCTL0, SYSPLL0PFD, PFD0_CLKRDY) =3D= =3D 0); + + /* ungate all plls and check that clocks are ready */ + REG32_WRITE_FIELD(RT500_CLKCTL0, SYSPLL0PFD, PFD3_CLKGATE, 0); + REG32_WRITE_FIELD(RT500_CLKCTL0, SYSPLL0PFD, PFD2_CLKGATE, 0); + REG32_WRITE_FIELD(RT500_CLKCTL0, SYSPLL0PFD, PFD1_CLKGATE, 0); + REG32_WRITE_FIELD(RT500_CLKCTL0, SYSPLL0PFD, PFD0_CLKGATE, 0); + + g_assert(REG32_READ_FIELD(RT500_CLKCTL0, SYSPLL0PFD, PFD3_CLKRDY) =3D= =3D 1); + g_assert(REG32_READ_FIELD(RT500_CLKCTL0, SYSPLL0PFD, PFD2_CLKRDY) =3D= =3D 1); + g_assert(REG32_READ_FIELD(RT500_CLKCTL0, SYSPLL0PFD, PFD1_CLKRDY) =3D= =3D 1); + g_assert(REG32_READ_FIELD(RT500_CLKCTL0, SYSPLL0PFD, PFD0_CLKRDY) =3D= =3D 1); +} + +static void systick_clk_test(gconstpointer user_data) +{ + /* systick is not running at reset */ + g_assert_cmpuint(dev_clock_out_get_hz(CLKCTL0_NAME, "systick_clk"), = =3D=3D, 0); + + /* select divout no divisor */ + REG32_WRITE_FIELD(RT500_CLKCTL0, SYSTICKFCLKSEL, SEL, + SYSTICKFCLKSEL_DIVOUT); + g_assert_cmpuint(dev_clock_out_get_hz(CLKCTL0_NAME, "systick_clk"), + =3D=3D, SYSCLK_HZ); + + /* change divisor to 2 */ + REG32_WRITE_FIELD(RT500_CLKCTL0, SYSTICKFCLKDIV, DIV, 1); + g_assert_cmpuint(dev_clock_out_get_hz(CLKCTL0_NAME, "systick_clk"), + =3D=3D, SYSCLK_HZ / 2); + + /* select lpsoc */ + REG32_WRITE_FIELD(RT500_CLKCTL0, SYSTICKFCLKSEL, SEL, + SYSTICKFCLKSEL_LPOSC); + g_assert_cmpuint(dev_clock_out_get_hz(CLKCTL0_NAME, "systick_clk"), + =3D=3D, LPOSC_CLK_HZ); + + /* select lpsoc */ + REG32_WRITE_FIELD(RT500_CLKCTL0, SYSTICKFCLKSEL, SEL, + SYSTICKFCLKSEL_32KHZRTC); + g_assert_cmpuint(dev_clock_out_get_hz(CLKCTL0_NAME, "systick_clk"), + =3D=3D, RTC32KHZ_CLK_HZ); + + /* disable clock */ + REG32_WRITE_FIELD(RT500_CLKCTL0, SYSTICKFCLKSEL, SEL, + SYSTICKFCLKSEL_NONE); + g_assert_cmpuint(dev_clock_out_get_hz(CLKCTL0_NAME, "systick_clk"), + =3D=3D, 0); +} + +static void ostimer_clk_test(gconstpointer user_data) +{ + /* systick is not running at reset */ + g_assert_cmpuint(dev_clock_out_get_hz(CLKCTL1_NAME, "ostimer_clk"), = =3D=3D, 0); + + /* select lpsoc */ + REG32_WRITE_FIELD(RT500_CLKCTL1, OSEVENTTFCLKSEL, SEL, + OSEVENTTFCLKSEL_LPOSC); + g_assert_cmpuint(dev_clock_out_get_hz(CLKCTL1_NAME, "ostimer_clk"), = =3D=3D, + LPOSC_CLK_HZ); + + /* select 32khz RTC */ + REG32_WRITE_FIELD(RT500_CLKCTL1, OSEVENTTFCLKSEL, SEL, + OSEVENTTFCLKSEL_32KHZRTC); + g_assert_cmpuint(dev_clock_out_get_hz(CLKCTL1_NAME, "ostimer_clk"), = =3D=3D, + RTC32KHZ_CLK_HZ); + + /* select hclk */ + REG32_WRITE_FIELD(RT500_CLKCTL1, OSEVENTTFCLKSEL, SEL, + OSEVENTTFCLKSEL_HCLK); + g_assert_cmpuint(dev_clock_out_get_hz(CLKCTL1_NAME, "ostimer_clk"), = =3D=3D, + SYSCLK_HZ); + + /* disable clock */ + REG32_WRITE_FIELD(RT500_CLKCTL1, OSEVENTTFCLKSEL, SEL, + OSEVENTTFCLKSEL_NONE); + g_assert_cmpuint(dev_clock_out_get_hz(CLKCTL1_NAME, "ostimer_clk"), = =3D=3D, 0); +} + +int main(int argc, char **argv) +{ + int ret; + + g_test_init(&argc, &argv, NULL); + + qtest_add_data_func("/rt500-clkctl/pscctl-test", NULL, pscctl_test); + qtest_add_data_func("/rt500-clkctl/syspll0pfd-test", NULL, + syspll0pfd_test); + qtest_add_data_func("/rt500-clkctl/audiopll0pfd-test", NULL, + audiopll0pfd_test); + g_test_add_data_func("/rt500-clkctl/systick-test", NULL, + systick_clk_test); + g_test_add_data_func("/rt500-clkctl/ostimer-clk-test", NULL, + ostimer_clk_test); + + qtest_start("-M rt595-evk"); + ret =3D g_test_run(); + qtest_end(); + + return ret; +} diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index d3bf33b855..1a2d2ca3e1 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -234,6 +234,7 @@ qtests_arm =3D \ (config_all_devices.has_key('CONFIG_STM32L4X5_SOC') and config_all_devices.has_key('CONFIG_DM163')? ['dm163-test'] : []) + \ (config_all_devices.has_key('CONFIG_FLEXCOMM') ? ['flexcomm-test', 'flex= comm-usart-test', 'flexcomm-i2c-test', 'flexcomm-spi-test'] : []) + \ + (config_all_devices.has_key('CONFIG_RT500_CLKCTL') ? ['rt500-clkctl-test= '] : []) + \ ['arm-cpu-features', 'boot-serial-test'] =20 --=20 2.47.0.rc0.187.ge670bccf7e-goog