From patchwork Tue Feb 6 22:23:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 870140 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=xilinx.onmicrosoft.com header.i=@xilinx.onmicrosoft.com header.b="eF/zgXRY"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zbfLL4j1Mz9s4q for ; Wed, 7 Feb 2018 09:30:50 +1100 (AEDT) Received: from localhost ([::1]:44050 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejBlI-0000Kt-O5 for incoming@patchwork.ozlabs.org; Tue, 06 Feb 2018 17:30:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57836) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejBiG-0006ME-Uj for qemu-devel@nongnu.org; Tue, 06 Feb 2018 17:27:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ejBiD-000397-N3 for qemu-devel@nongnu.org; Tue, 06 Feb 2018 17:27:40 -0500 Received: from mail-sn1nam02on0074.outbound.protection.outlook.com ([104.47.36.74]:43552 helo=NAM02-SN1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ejBiD-000374-CE for qemu-devel@nongnu.org; Tue, 06 Feb 2018 17:27:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector1-xilinx-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=btu/eoD2bj48vLHXAtzYodSD5jWQS6AAfEmAZKwjwUU=; b=eF/zgXRYUsq1FAL4TNCq4E7H3nC+zXRXiQnOYVJCO9hPdMbVoS1HhKnM01nedRb0W+ANP+JIa5eBd9LbGnUyoOOxW0IWJhdoN5nVXWkn8BBhklUgKONWorJ5XXDxoHSdkFIAfxu2LU5rYMqlhQWuCr+yNAkVQjV4nrcBoyWYM8A= Received: from SN4PR0201CA0061.namprd02.prod.outlook.com (10.171.31.151) by DM5PR02MB3387.namprd02.prod.outlook.com (10.164.153.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.464.11; Tue, 6 Feb 2018 22:27:34 +0000 Received: from SN1NAM02FT015.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e44::204) by SN4PR0201CA0061.outlook.office365.com (2603:10b6:803:20::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.464.11 via Frontend Transport; Tue, 6 Feb 2018 22:27:34 +0000 Authentication-Results: spf=pass (sender IP is 149.199.60.83) smtp.mailfrom=xilinx.com; gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=bestguesspass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.60.83 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.60.83; helo=xsj-pvapsmtpgw01; Received: from xsj-pvapsmtpgw01 (149.199.60.83) by SN1NAM02FT015.mail.protection.outlook.com (10.152.72.109) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.444.20 via Frontend Transport; Tue, 6 Feb 2018 22:27:34 +0000 Received: from unknown-38-66.xilinx.com ([149.199.38.66] helo=xsj-pvapsmtp01) by xsj-pvapsmtpgw01 with esmtp (Exim 4.63) (envelope-from ) id 1ejBi9-0008AI-Lf; Tue, 06 Feb 2018 14:27:33 -0800 Received: from [127.0.0.1] (helo=localhost) by xsj-pvapsmtp01 with smtp (Exim 4.63) (envelope-from ) id 1ejBi9-0000s1-Ir; Tue, 06 Feb 2018 14:27:33 -0800 Received: from xsj-pvapsmtp01 (xsj-pvapsmtp01.xilinx.com [149.199.38.66]) by xsj-smtp-dlp1.xlnx.xilinx.com (8.13.8/8.13.1) with ESMTP id w16MRWTD012168; Tue, 6 Feb 2018 14:27:32 -0800 Received: from [172.19.2.220] (helo=xsjalistai50.xilinx.com) by xsj-pvapsmtp01 with esmtp (Exim 4.63) (envelope-from ) id 1ejBi8-0000rn-0A; Tue, 06 Feb 2018 14:27:32 -0800 From: Alistair Francis To: , , Date: Tue, 6 Feb 2018 14:23:02 -0800 Message-ID: <378759b13cf65246de7ce565045f877e4a224aa0.1517955702.git.alistair.francis@xilinx.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: X-RCIS-Action: ALLOW X-TM-AS-Product-Ver: IMSS-7.1.0.1224-8.2.0.1013-23620.005 X-TM-AS-User-Approved-Sender: Yes;Yes X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:149.199.60.83; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(39840400004)(39380400002)(346002)(376002)(396003)(2980300002)(438002)(199004)(189003)(47776003)(36756003)(81156014)(8676002)(81166006)(51416003)(2906002)(186003)(356003)(50226002)(305945005)(2201001)(16586007)(316002)(575784001)(9786002)(63266004)(110136005)(54906003)(106002)(26005)(76176011)(5660300001)(106466001)(36386004)(8936002)(50466002)(4326008)(39060400002)(48376002)(6666003)(59450400001)(7696005)(336011)(118296001)(77096007)(2950100002)(478600001)(107986001)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR02MB3387; H:xsj-pvapsmtpgw01; FPR:; SPF:Pass; PTR:unknown-60-83.xilinx.com; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; SN1NAM02FT015; 1:W4HTij+BA8xi8301Kkrm8EWj740bEzDwYfiWZeT2l2Phs18yJsM6yQUjurXSv24SD9PMR81jV11wv8K2MdeGWot2LiVTwHSCFvO23qHP4x9qHbg+mAXhgDpDolTvVemI MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cfd039a2-a050-415f-fd80-08d56db0d1d6 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(4608076)(2017052603307)(7153060); SRVR:DM5PR02MB3387; X-Microsoft-Exchange-Diagnostics: 1; DM5PR02MB3387; 3:HeCjcRH/fASiKs2qrTyovOa4pnZzRtvX4iYx8JVLfpyBKnknX0XzbQhjOpvyoOvj2YHhpD0yDF7LfPwJL9ecZmpftYDEr/y9/vScYAWxrmot9cqin2MeAacGXa89xGQZ4boF0P2TbM7Lfv/HazLkto3l0kDAjTyulhKbI58w7QRW7Y/25TNfFyNPLcKd0X62I+1gdFPA9Uxo4hW9PLDVIobuLGFNIjugExCQ/KO0WRM7VHXri/1RNguGcJLQUrBVJZz5zF3AKbRXvo83BLBMJeRODdinbKgDVWsXV6WUCbigVzo+V1bXVx2an6hfU/RcPPyrp6wvLCX044lsRgUNfsYmeK8vi4vmfg7Olt7NzM0=; 25:yQRwULX78CX1RVdJr+MZ6IYiPLn3h60bCjmZx3Y6lacoDEZyBcnXOnqAFaUBoDjhKDpZfWsFM8kWjka3X//XrKC5n5wlH1TURM+cPJCJpMwaPA3BqM30ARU6wlB5EgJvleA9oEtXHFRBdcm1imoTnjeGArJw7rraGRLiCfHOI0rBZTBxpCmPj/jKBg4dz7mfTkhSnCxCHxGWHilrcb9YDFXWbu0IJCC7zMmlAds1A6ihlk2xG7kW2MSxvA5MonsrE5y9Nb6N4tdg3x1ybdtf7D0hQVqs9sOZDJrJ58yq6idhFfaGrg7QySSb1rVXA5aCe2Zqm5ZRVyHPkAaUrSIIxw== X-MS-TrafficTypeDiagnostic: DM5PR02MB3387: X-Microsoft-Exchange-Diagnostics: 1; DM5PR02MB3387; 31:kML8o6uQJ0sKlAiOBLRx2JunVdTMgv7U/ETZ6xRjOZJJDnur66AoO9sr6xEbnmqe8yyyBjCXteK7bUDRrebrv7V+UFDqQE5TSwD4VnbIFTnK3raS06ojOeERWCq0Uwr8kcWy+ZFHDCdFU3qlZ/BHkxtTEuWVXFV8piO1pa2nKBXSKsEhkWrvA38p6XxQo+MbQs6m3xzvkZn9pFJRKFjDwOm2JVWODrcOo+2jMC1VYjQ=; 20:S7ibtQEoK6554YItrQsJDW6RhirdQPESqxEgtsh4NmWJoBVV3iGXenOZP8A1WYClViKkAAmTVm1w1wTsrfVvwykg7T7xm4ccdUkZNiu8xi6oh7Foly1tWJ8Qd021igLVqt3hv47USYUeDYTpKqHLPtvVKlmlKQD4RGiVtIpxxV4L1uWK2tYhBuWbMByuNejiZH+DnQFDbOlTG2OW2Jl/FPDLxCXGvycDNkI5r0/wh9LuBYdW87Ckgwrahxtt7WdlMpPf+lu598fZK+DC8JAZdRX0sMa/Ps7UC+lY23lqdEpgQescJciE+NUp52P3g78XC0PoCsevzUxGTcya+9hml0JtFfYZfuOPmxM4hszQc5zTEol1fzq1tMGq0i8vY9UX3cTqRh+jK8Giutx1dWXtyXtUXMeJZ9HxNuZTKaXjEKQ5ZUcpJCBKJJJ+EHmdJyX0B4PpwfOmUQKgHWrLqAPQA+1/yWz+jlmBvotZaTzrIRns9n7kmIr/e5TlgByd2gXG X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(192813158149592); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(8121501046)(5005006)(10201501046)(3002001)(3231101)(2400082)(944501161)(93006095)(93004095)(6055026)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(20161123558120)(6072148)(201708071742011); SRVR:DM5PR02MB3387; BCL:0; PCL:0; RULEID:; SRVR:DM5PR02MB3387; X-Microsoft-Exchange-Diagnostics: 1; DM5PR02MB3387; 4:9m5duNJlioOX/D9XShT0oIU7r3f7+HEzDB6FeL4tLde0u1PV9ycw6QGrRDIZqy/xJMhi+SHHqA7kqTvz/0ocvHQZZFpUMEHy5BCOe+ZSZdykthkI4Fe3CGFZdy3+N7RqeLtqwZe2H/aCaXg8xZV6FBK2zfHkOKlL2zP97IrUUj2H3qx7S43yBOtamNiAB3P7QVsrfCVi52G5pHrqTvgXAXZkuXxkxixPgF4jGlNZkyBKkgRVI39BNUoF11+vL1FCpClcA7qS44FtOheJQpxtzrtLKLE68YfrnVP/XRqcdoT91APF/vHklTdLgUWgdxQa X-Forefront-PRVS: 0575F81B58 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR02MB3387; 23:tzbhMSrWl9Jshx01LGd4srlRiKsQ9qLz+T9JHBGzO?= t8nkQTKACyOaxKFj5Fe+mnnG0wJxqmQWq7khfhtZvw446/0blt82M/uU/yhxJoiu3ls40BWwEWP8/xM2eRXLthF5mnHFpcTTyVEAlADA7SoGSRMt5BqhNFrZYrRW6STKBThwKlOOvVOJbHwHYpP8wpqmB7ZO9khUtg+/6m7rrrTMnS2hCTEk7JQqZ//EXuxmPhByWTJVGGhIb4mo4+h7YWYRCiQFNVGUBwLZIa2lqbsPJr0Ia7QHSMd3ImCPXDmbooWx+Kg+r/THDv2wNcEnxefwm3qz2NVroWXuAsio4d64Z7VA2rpU8fTkbWJgS3R7Pj1+BiDqSaNe7z6OYYEfRnm0fwQWf8cWgUu/ouwoTpz4nn3+aR/Vqe9Pjlgk8Z+V+gjVoptyE+ksuzr4F5YUSfeL1x0JHpJyTx3VBqsOZOP2v+LD6Fwa6gXjYICsKNBaz1cY8iI0b1C5j0WXkQJKxNaWellRTCI1aI0iwQmV1kxYfG07uHQYxpOBdQ3Qr/OzzWka5gEgv1rHvVSRxi4Isu8XVTxZpRp/Pc017HIV8i1DgRvQSnOe3gUoFx2R98zWQXNzTgr8pNVr3+5+uVoxziL7jFVcZ/AMYBXXXsCE8qG1NXvhzt/KyC9WqRvfAOH0LHGG3dKOi4ZiKXZbsGMZsIP2hjv18njdngp3+JbZmHfjBOn4A2wEkmh3Fh1iGzOrPNSzyZdlUwbCj7tQ/d06aZyCISUxno/p3eUwVsG5CKivVjWug0Zd2V1pxLb6LdDbCEA6hDAdt6mGxqq/3hPBUskj98uytiqnF0WaTfYDr64zwJGW4KX38unViHSJuNbX0m/x8Ka7cAIf2AjnBs5weIfmAg/l6hjxriS7UozC4YXqpc66i3AAT1LFEQjuunWVGXpLvKx4r7NlwgpBkX73BMDK9Ba/2I+68zSgQllsGVDvFtV7Rz/Ypf4pHnNZ7lh5o//SDJXFLf9wu/QrbPjqKCy9YHhEo0jvEsAj622mKesVgzFnX4HKmMsXsy8mtYUfxz9Il8U06kQHNooJ182DtByLoMfWybK+qo8gCJ5UXN+o03qV+3a55A6cOtgvVFjwmklPxTR+37elbobahiiM4Nb X-Microsoft-Exchange-Diagnostics: 1; DM5PR02MB3387; 6:rUlk6KUkAU7C2vl6vH0fTJcon6lDplW10cSDJhHU3NzNeIFAGrIyEW4m1DK6e2USMyhk+RiDHuxpjyZkyZRmhrDiqKoOrr7q7PC9y0sMyZbYuvC0bXTcBOkwMI1IKN1XTCsxU3lQT3dxZeh/S3PyALplbcUtvR7hIE+2+fBfokuJgu5wfSzaLCmogy23y1RyLlGZHjcnqMzplFJWuWTwtr4RLCWoeKt+dEzP0nMMdtSIIbr2q4PSenS/z3xvGhDk4+S2wjB6JdmOgkmkhLN1XnCYWGW9cB+pHNZMEe4q5tNE/i+Wyh6LKkw52N8UTuNxnRU6Wr1/aJPg6jHXbdwjkMbHipUznkz/iixua6/sLz0=; 5:3hN7t1wH2MM2LSbe42KVNo0SDlG2jrDkLt5OTuDIdj62VLQW+ie/YKXAQv9W628zC2YdoLmFDz4utxh3CI/QVR0OjPtAYIfRvcLx7z5FsgtIbFpQXTdVV7zgzEsJlbcpCOPZkLQ2dXqnzkoB9SbcpOnHp4jDBBF/xCWM51jsYbk=; 24:hbiTiSQyHw2XkAbELZLLVMeQ9IFFGtc7flJr+haHjFc/tvdjEFd2nlUpLIld9NNxXtqt6pvdngV/XiFV0D5+pQ6eEUhYQ+GEYeXJmKC4T7Y=; 7:rfLo+7xC+RNtp4BdMJlSW9rdSvHaR02xfUNWJBfEwCt3V+FAAuCSdZTM2KRllWXIOBdMc0AxB6zFA6LBNdVCFwT5XwfhSuvBCRw3L5vS4GuUnzvhE28k4hlL4vDKGPXHVRl2gR1jc/WFcXgNQccZYB3tbIPANpu0w7FIPqXJUwDujIgW1dgXVfcMl4ei9sak5FjVy3TS7EPd+hl2ngd3JZRgFR23qz4YvoygZx03waWVOF/W/cCzl2pzmBaFS3VD SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2018 22:27:34.2492 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cfd039a2-a050-415f-fd80-08d56db0d1d6 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.60.83]; Helo=[xsj-pvapsmtpgw01] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR02MB3387 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.36.74 Subject: [Qemu-devel] [PATCH v1 1/2] timer: Initial commit of xlnx-pmu-iomod-pit device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair23@gmail.com, alistair.francis@xilinx.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Alistair Francis --- include/hw/timer/xlnx-pmu-iomod-pit.h | 58 ++++++++ hw/timer/xlnx-pmu-iomod-pit.c | 241 ++++++++++++++++++++++++++++++++++ hw/timer/Makefile.objs | 2 + 3 files changed, 301 insertions(+) create mode 100644 include/hw/timer/xlnx-pmu-iomod-pit.h create mode 100644 hw/timer/xlnx-pmu-iomod-pit.c diff --git a/include/hw/timer/xlnx-pmu-iomod-pit.h b/include/hw/timer/xlnx-pmu-iomod-pit.h new file mode 100644 index 0000000000..15f9f0dee5 --- /dev/null +++ b/include/hw/timer/xlnx-pmu-iomod-pit.h @@ -0,0 +1,58 @@ +/* + * QEMU model of Xilinx I/O Module PIT + * + * Copyright (c) 2013 Xilinx Inc + * Written by Edgar E. Iglesias + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "hw/ptimer.h" + +#define TYPE_XLNX_ZYNQMP_IOMODULE_PIT "xlnx.pmu_iomodule" + +#define XLNX_ZYNQMP_IOMODULE_PIT(obj) \ + OBJECT_CHECK(XlnxPMUPIT, (obj), TYPE_XLNX_ZYNQMP_IOMODULE_PIT) + +#define XLNX_ZYNQMP_IOMODULE_PIT_R_MAX (0x08 + 1) + +typedef struct XlnxPMUPIT { + SysBusDevice parent_obj; + MemoryRegion iomem; + + QEMUBH *bh; + ptimer_state *ptimer; + + qemu_irq irq; + /* IRQ to pulse out when present timer hits zero */ + qemu_irq hit_out; + + /* Counter in Pre-Scalar(ps) Mode */ + uint32_t ps_counter; + /* ps_mode irq-in to enable/disable pre-scalar */ + bool ps_enable; + /* State var to remember hit_in level */ + bool ps_level; + + uint32_t frequency; + + uint32_t regs[XLNX_ZYNQMP_IOMODULE_PIT_R_MAX]; + RegisterInfo regs_info[XLNX_ZYNQMP_IOMODULE_PIT_R_MAX]; +} XlnxPMUPIT; diff --git a/hw/timer/xlnx-pmu-iomod-pit.c b/hw/timer/xlnx-pmu-iomod-pit.c new file mode 100644 index 0000000000..cdfef1a440 --- /dev/null +++ b/hw/timer/xlnx-pmu-iomod-pit.c @@ -0,0 +1,241 @@ +/* + * QEMU model of Xilinx I/O Module PIT + * + * Copyright (c) 2013 Xilinx Inc + * Written by Edgar E. Iglesias + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "hw/sysbus.h" +#include "hw/ptimer.h" +#include "hw/register.h" +#include "qemu/main-loop.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "hw/timer/xlnx-pmu-iomod-pit.h" + +#ifndef XLNX_ZYNQMP_IOMODULE_PIT_ERR_DEBUG +#define XLNX_ZYNQMP_IOMODULE_PIT_ERR_DEBUG 0 +#endif + +REG32(PIT_PRELOAD, 0x00) +REG32(PIT_COUNTER, 0x04) +REG32(PIT_CONTROL, 0x08) + FIELD(PIT_CONTROL, PRELOAD, 1, 1) + FIELD(PIT_CONTROL, EN, 0, 1) + +static uint64_t xlnx_iomod_pit_ctr_pr(RegisterInfo *reg, uint64_t val) +{ + XlnxPMUPIT *s = XLNX_ZYNQMP_IOMODULE_PIT(reg->opaque); + uint32_t ret; + + if (s->ps_enable) { + ret = s->ps_counter; + } else { + ret = ptimer_get_count(s->ptimer); + } + + return ret; +} + +static void xlnx_iomod_pit_control_pw(RegisterInfo *reg, uint64_t val) +{ + XlnxPMUPIT *s = XLNX_ZYNQMP_IOMODULE_PIT(reg->opaque); + + ptimer_stop(s->ptimer); + + if (val & R_PIT_CONTROL_EN_MASK) { + if (s->ps_enable) { + /* pre-scalar mode do-Nothing here */ + s->ps_counter = s->regs[R_PIT_PRELOAD]; + } else { + ptimer_set_limit(s->ptimer, s->regs[R_PIT_PRELOAD], 1); + ptimer_run(s->ptimer, !(val & R_PIT_CONTROL_PRELOAD_MASK)); + + } + } +} + +static const RegisterAccessInfo xlnx_iomod_pit_regs_info[] = { + { .name = "PIT_PRELOAD", .addr = A_PIT_PRELOAD, + .ro = 0xffffffff, + },{ .name = "PIT_COUNTER", .addr = A_PIT_COUNTER, + .ro = 0xffffffff, + .post_read = xlnx_iomod_pit_ctr_pr, + },{ .name = "PIT_CONTROL", .addr = A_PIT_CONTROL, + .rsvd = 0xfffffffc, + .post_write = xlnx_iomod_pit_control_pw, + } +}; + +static void xlnx_iomod_pit_timer_hit(void *opaque) +{ + XlnxPMUPIT *s = XLNX_ZYNQMP_IOMODULE_PIT(opaque); + + qemu_irq_pulse(s->irq); + + /* hit_out to make another pit move it's counter in pre-scalar mode. */ + qemu_irq_pulse(s->hit_out); +} + +static void xlnx_iomod_pit_ps_config(void *opaque, int n, int level) +{ + XlnxPMUPIT *s = XLNX_ZYNQMP_IOMODULE_PIT(opaque); + + s->ps_enable = level; +} + +static void xlnx_iomod_pit_ps_hit_in(void *opaque, int n, int level) +{ + XlnxPMUPIT *s = XLNX_ZYNQMP_IOMODULE_PIT(opaque); + + if (!ARRAY_FIELD_EX32(s->regs, PIT_CONTROL, EN)) { + /* PIT disabled */ + return; + } + + /* Count only on positive edge */ + if (!s->ps_level && level) { + if (s->ps_counter) { + s->ps_counter--; + } + s->ps_level = level; + } else { + /* Not on positive edge */ + s->ps_level = level; + return; + } + + /* If timer expires, try to preload or stop */ + if (s->ps_counter == 0) { + xlnx_iomod_pit_timer_hit(opaque); + + /* Check for pit preload/one-shot mode */ + if (ARRAY_FIELD_EX32(s->regs, PIT_CONTROL, PRELOAD)) { + /* Preload Mode, Reload the ps_counter */ + s->ps_counter = s->regs[R_PIT_PRELOAD]; + } else { + /* One-Shot mode, turn off the timer */ + s->regs[R_PIT_CONTROL] &= ~R_PIT_CONTROL_PRELOAD_MASK; + } + } +} + +static void xlnx_iomod_pit_reset(DeviceState *dev) +{ + XlnxPMUPIT *s = XLNX_ZYNQMP_IOMODULE_PIT(dev); + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(s->regs_info); ++i) { + register_reset(&s->regs_info[i]); + } + + s->ps_level = false; +} + +static const MemoryRegionOps xlnx_iomod_pit_ops = { + .read = register_read_memory, + .write = register_write_memory, + .endianness = DEVICE_LITTLE_ENDIAN, + .valid = { + .min_access_size = 4, + .max_access_size = 4, + }, +}; + +static void xlnx_iomod_pit_realize(DeviceState *dev, Error **errp) +{ + XlnxPMUPIT *s = XLNX_ZYNQMP_IOMODULE_PIT(dev); + + s->bh = qemu_bh_new(xlnx_iomod_pit_timer_hit, s); + s->ptimer = ptimer_init(s->bh, PTIMER_POLICY_DEFAULT); + ptimer_set_freq(s->ptimer, s->frequency); + + /* IRQ out to pulse when present timer expires/reloads */ + qdev_init_gpio_out_named(dev, &s->hit_out, "ps_hit_out", 1); + + /* IRQ in to enable pre-scalar mode. Routed from gpo1 */ + qdev_init_gpio_in_named(dev, xlnx_iomod_pit_ps_config, "ps_config", 1); + + /* hit_out of neighbouring PIT is received as hit_in */ + qdev_init_gpio_in_named(dev, xlnx_iomod_pit_ps_hit_in, "ps_hit_in", 1); +} + +static void xlnx_iomod_pit_init(Object *obj) +{ + XlnxPMUPIT *s = XLNX_ZYNQMP_IOMODULE_PIT(obj); + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); + RegisterInfoArray *reg_array; + + memory_region_init(&s->iomem, obj, TYPE_XLNX_ZYNQMP_IOMODULE_PIT, + XLNX_ZYNQMP_IOMODULE_PIT_R_MAX * 4); + reg_array = + register_init_block32(DEVICE(obj), xlnx_iomod_pit_regs_info, + ARRAY_SIZE(xlnx_iomod_pit_regs_info), + s->regs_info, s->regs, + &xlnx_iomod_pit_ops, + XLNX_ZYNQMP_IOMODULE_PIT_ERR_DEBUG, + XLNX_ZYNQMP_IOMODULE_PIT_R_MAX * 4); + memory_region_add_subregion(&s->iomem, + 0x0, + ®_array->mem); + sysbus_init_mmio(sbd, &s->iomem); + sysbus_init_irq(sbd, &s->irq); +} + +static const VMStateDescription vmstate_xlnx_iomod_pit = { + .name = TYPE_XLNX_ZYNQMP_IOMODULE_PIT, + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_END_OF_LIST(), + } +}; + +static Property xlnx_iomod_pit_properties[] = { + DEFINE_PROP_UINT32("frequency", XlnxPMUPIT, frequency, 66000000), + DEFINE_PROP_END_OF_LIST(), +}; + +static void xlnx_iomod_pit_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + dc->reset = xlnx_iomod_pit_reset; + dc->realize = xlnx_iomod_pit_realize; + dc->props = xlnx_iomod_pit_properties; + dc->vmsd = &vmstate_xlnx_iomod_pit; +} + +static const TypeInfo xlnx_iomod_pit_info = { + .name = TYPE_XLNX_ZYNQMP_IOMODULE_PIT, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(XlnxPMUPIT), + .class_init = xlnx_iomod_pit_class_init, + .instance_init = xlnx_iomod_pit_init, +}; + +static void xlnx_iomod_pit_register_types(void) +{ + type_register_static(&xlnx_iomod_pit_info); +} + +type_init(xlnx_iomod_pit_register_types) diff --git a/hw/timer/Makefile.objs b/hw/timer/Makefile.objs index 8c19eac3b6..805c480cad 100644 --- a/hw/timer/Makefile.objs +++ b/hw/timer/Makefile.objs @@ -43,3 +43,5 @@ common-obj-$(CONFIG_ASPEED_SOC) += aspeed_timer.o common-obj-$(CONFIG_SUN4V_RTC) += sun4v-rtc.o common-obj-$(CONFIG_CMSDK_APB_TIMER) += cmsdk-apb-timer.o common-obj-$(CONFIG_MSF2) += mss-timer.o + +common-obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-pmu-iomod-pit.o