From patchwork Wed Feb 28 22:30:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 10250045 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B639760212 for ; Wed, 28 Feb 2018 22:36:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C46828BA9 for ; Wed, 28 Feb 2018 22:36:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 907EB28E7A; Wed, 28 Feb 2018 22:36:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 44BE828BA9 for ; Wed, 28 Feb 2018 22:36:31 +0000 (UTC) Received: from localhost ([::1]:47422 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erAKs-0000bs-4C for patchwork-qemu-devel@patchwork.kernel.org; Wed, 28 Feb 2018 17:36:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34079) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erAK4-0000FG-5N for qemu-devel@nongnu.org; Wed, 28 Feb 2018 17:35:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erAJz-0006Fe-6Z for qemu-devel@nongnu.org; Wed, 28 Feb 2018 17:35:40 -0500 Received: from mail-by2nam03on0046.outbound.protection.outlook.com ([104.47.42.46]:13344 helo=NAM03-BY2-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 1erAJy-0006BC-7L for qemu-devel@nongnu.org; Wed, 28 Feb 2018 17:35:34 -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=Id5V0o+aFqDxiS9KL2zRenDEW0asLzQiSNmCN474lzk=; b=kVfPVsv8eIDfYQmytHl2A/1S/ZQvCqvRm61wtlMOes31oqHa/4Z5ktXUNb8uTZqUJgA2eDu8FgTOKK0C7FzbZ0+YyBhDqxanKBqp8ngyWDD795ch6V/w0i5IOH1t27JwYeg1AKU+W33hXHMCvab+Wnwxz0XsVYB0q/k/NFsciGU= Received: from MWHPR0201CA0017.namprd02.prod.outlook.com (10.167.160.158) by BN6PR02MB2258.namprd02.prod.outlook.com (10.168.253.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.548.13; Wed, 28 Feb 2018 22:35:31 +0000 Received: from BL2NAM02FT060.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e46::201) by MWHPR0201CA0017.outlook.office365.com (2603:10b6:301:74::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.548.13 via Frontend Transport; Wed, 28 Feb 2018 22:35:30 +0000 Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.60.100 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.60.100; helo=xsj-pvapsmtpgw02; Received: from xsj-pvapsmtpgw02 (149.199.60.100) by BL2NAM02FT060.mail.protection.outlook.com (10.152.76.124) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.527.18 via Frontend Transport; Wed, 28 Feb 2018 22:35:29 +0000 Received: from unknown-38-66.xilinx.com ([149.199.38.66]:55179 helo=xsj-pvapsmtp01) by xsj-pvapsmtpgw02 with esmtp (Exim 4.63) (envelope-from ) id 1erAJt-0003Ng-35; Wed, 28 Feb 2018 14:35:29 -0800 Received: from [127.0.0.1] (helo=localhost) by xsj-pvapsmtp01 with smtp (Exim 4.63) (envelope-from ) id 1erAJs-0005eJ-Vs; Wed, 28 Feb 2018 14:35:29 -0800 Received: from xsj-pvapsmtp01 (xsj-smtp.xilinx.com [149.199.38.66]) by xsj-smtp-dlp2.xlnx.xilinx.com (8.13.8/8.13.1) with ESMTP id w1SMZNVk013266; Wed, 28 Feb 2018 14:35:23 -0800 Received: from [172.19.2.220] (helo=xsjalistai50.xilinx.com) by xsj-pvapsmtp01 with esmtp (Exim 4.63) (envelope-from ) id 1erAJn-0005dW-KG; Wed, 28 Feb 2018 14:35:23 -0800 From: Alistair Francis To: , , Date: Wed, 28 Feb 2018 14:30:44 -0800 Message-ID: <000b7176df121bd34c3329c45b93dc79d5f4f3ff.1519856998.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.100; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(396003)(376002)(39860400002)(39380400002)(346002)(2980300002)(438002)(189003)(199004)(5660300001)(106002)(51416003)(2201001)(36756003)(9786002)(4326008)(316002)(59450400001)(54906003)(110136005)(16586007)(7696005)(50226002)(478600001)(39060400002)(2906002)(81156014)(6666003)(47776003)(6346003)(36386004)(8936002)(2950100002)(106466001)(77096007)(118296001)(26005)(50466002)(186003)(81166006)(76176011)(8676002)(356003)(336011)(305945005)(48376002)(63266004)(107986001)(2101003)(5001870100001); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR02MB2258; H:xsj-pvapsmtpgw02; FPR:; SPF:Pass; PTR:xapps1.xilinx.com,unknown-60-100.xilinx.com; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2NAM02FT060; 1:DksCKVaco47GOm9QNlHBaMVdIy0QmK2dJIFFiDjYIVoeQ3CYYHZuozpyKUFigGyj/EDtO9JMKpqaOcYWUfd4F3fnLuV0Xn3hSWfslacBgS9IHdGHqxqW1jdtG+UZvbcS MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 57eefd83-95c0-41c7-87a0-08d57efb925f X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(4608076)(2017052603307)(7153060); SRVR:BN6PR02MB2258; X-Microsoft-Exchange-Diagnostics: 1; BN6PR02MB2258; 3:5sWlTka9fPZi5w4F6wYF1v2mu1h+bLNroiScFB0zP1inLdsAvKC1yzq7T7UT66TKM2AkwFrGi8hN2Z7kl6lx7i82QztDGhvQ9kQXpQEu/AqZCljO41dHd9IZmX+h0K1skDj2xKv2fMf75DOqBwbu3FOAT/DjrjOty7K7LBlY/3KQpGkKMe8uOciO3kArOmfJI78GybM/PLqxhtFxgn0om153eRriLDEpmAwNgKY0M9XPtqSkijxrWecZhc8c6DAoFHgfFfFrxbdPDdeG4PAFDnECKCrkFFZI8Qc9MWAlWzma2nr3O92ekMCBGlESDgMItLSTYsAeqbQpAkrJh8xIsH1s8nbBt/Iyk1Yzlv33sc0=; 25:9kbeDZ7Ru1GWhvD5DdJKPUH7DiWDCGY6iyWokK33eZyQZtL+wRDcol+Ul85TL06E7mRapAnfgXOEWDZZJUEDEtgVHAt8hYx4qShp3fCg2uhWBI6+GZJRavVPMzvOD84Ln8MyJacqaunfHSdJZNvdR+HSTS/Iy+B2uo39vzBSSl+h4x3DbSyGoS8rQJ8PtwIkSQEbTZgDn1NjTMhGnE/drk6wsmRWcHx7YwIkA513O7UufV2s1w0byLNvGKX7AnNkJNl78KK8+ySHxqc0DyTRQbvzAfHti8A3o5qQ/iy0/71QyZRaO6l91IJwzbM7UzwFboyYriQLQFZ4jB3pe2b81g== X-MS-TrafficTypeDiagnostic: BN6PR02MB2258: X-Microsoft-Exchange-Diagnostics: 1; BN6PR02MB2258; 31:DgxZcLe2s5FnbEb6aP4CYF9qsKJuVvq+dpoxc2s7P5fTY5wsmeqgAU881E2jG86Yk9GHrVoA2dVFV55VkJqF63KOcPJUq55gnnFpc9k5/kVCUrcFFO44yKhL7FPWKLGfpAc0vrUC7Z2PoNIpIJBZQJqd7VvmEbzRlGahrouuSNW4kREqksmupIumUtq2/tkxmusWjgGWylwJOCVLVYrnXbk6bO+QgtrZxxYVk3LsxK0=; 20:sQJlfiR1pg5mAKD3wQl0JKWZ6qm5OEg9nD7B2zfpxptSeTKpJyXj9VU8uUwq3gYyXtIIwpENaccuidSEChINjETG8nBf1wahjjSxkq1i7kgjkCNbfedTfgTz9bmROIi1BG9MASgVlrs1FSEIxijpnHwZwxOhGetftH4nIzk0o18L08DeXXROKabjOZHp58cWjbqycHZdC00U4zCADzwIGa1/fp5RtTAeQwisV+E4GXRdRnf0h6TXGZTmFcOpN9eEgKo3JEpWEcF3+ZWh3DtGasmtlS8hVBgCgKckO58XT0+YjDiUBprflRrFF4zgmIDRaW//PgrftfKkE21jV6qdg3frvmYqjes+7JkGuhXMzx80Cssu87x+G9Qk7Jgn/kWM1jRz9Kv1LUAvKLbqO590aZJ9oWJ2Ur0SfGqXdS3ynswokWC/LnWaEkb4T2z4dNj/RyjsvkQja/Ipb+CoyAoWwHki8Q6AkqjNwOsWNS/vv546xAO3xhSUwcrl9LIA4VcD 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:(8211001083)(6040501)(2401047)(5005006)(8121501046)(3231220)(944501220)(10201501046)(3002001)(93006095)(93004095)(6055026)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(20161123562045)(20161123560045)(6072148)(201708071742011); SRVR:BN6PR02MB2258; BCL:0; PCL:0; RULEID:; SRVR:BN6PR02MB2258; X-Microsoft-Exchange-Diagnostics: 1; BN6PR02MB2258; 4:J7p053ozb2XeBYCpasFCpzJ7McBnhhmWAYjTc2KRHMqssyi7S+X08iNx7T1GoTsSKnBlg1CmKXHXGqM7HLTmb2lCE/2bAWNin+USLb3dUT5K8x/Hbl4vHvI4JCP7CFSrJMzAXX8a/rMdzN+c8jony5x4P8Va05gTUoAs+xf+se9K2BenMwRPfboZXO/tItkiDRa/eFduo8ztGyKvL5eGG2ubNzdaVJuJ+QmmuledhYTN0t8xU9KL54BOlW1yejvfmJdOJxw8/TOvujrw1XJUMTtJuc5ODgOX8p6K+MOb0tqKlkDT4fQoAxdmLGBiWBSI X-Forefront-PRVS: 0597911EE1 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN6PR02MB2258; 23:sic2aWtDRPWS4f0JzQ/ZQyACddgH2lIUonHwQavfy?= =?us-ascii?Q?OTo/B5AdZsNTr8+cdlTNG4lzaqT2ddr2uy1POnIMGnoWQJMASyV9wNKiUglP?= =?us-ascii?Q?2tXCldDhtGPghyS1Do2yBcZQoDmRj6w6x13IXXktJRogEBX8L/NpV4A7D2Zo?= =?us-ascii?Q?rm3FjoTNDJ6wDkJwBQnM2/Qq72V5v3Wf9z5exbcy22dpdAOzlmMZXF/pT83A?= =?us-ascii?Q?nyo03AsMiwZiNoCpnA3kERB8lGRyz4k5+PwXkZxVnhGRpyMncG4BFBoLvGU+?= =?us-ascii?Q?5+NMBByahmIZrb6iwZMwKl5/jMTlmgejRMt0Gy+MzEmBgW6riuf0G6LxwJKK?= =?us-ascii?Q?kRfCx7gDYhJRlR6xHW/WiWuwF9hup0Keje3H8+2mFSpIFWpx7X6EHzUvlcQi?= =?us-ascii?Q?Au7XP8gmyVTa75mwr0vZ2v7bVayStBkldYUmVs1Q2pl46OUA7qHZ7EYj5oeu?= =?us-ascii?Q?h/CI+g90f/kV/eHMdscg2HujlvnB8Kvf9mgeokdE75uqrrgvt4eqyIn6xwYn?= =?us-ascii?Q?5CXoCuUs2KsDFQpoif28NxNzH3rEGD5YgPLnTsCMdkVjJkBaGJe/eAfRMOWk?= =?us-ascii?Q?NvCjkvoR7ae9ah2MsLcONNjqpquYb9oAz3UCxiwLDhlRAnwm0BgV2Z3ciGEO?= =?us-ascii?Q?sXuAmUYXrkqE3zWtsGh4TQVm2/0sf5r8cKetoLKyPqQeMxNo7hio7WeiDl1n?= =?us-ascii?Q?ZvXE1Jiwac2uV8L1+cXX/er7fat7gNvJBajVNZtdmerMzO7TdM0LBsHKmD6u?= =?us-ascii?Q?r6XkloGMRy5rJBcphkdILOLwiEmtbJR+VA2+eOfGtxUrLGrONqSbRrKdsRik?= =?us-ascii?Q?vb5rwfCt0UunKDDt2KMU5Nqa6ShGmwCAEApcofuOwXmK10wvX4pgQIGmabuz?= =?us-ascii?Q?5K/k8hGFTjb+w1kKQ9RF2e+m3+cS02hsiEj+YzHhIe468dvgXL3DB0nJG+vS?= =?us-ascii?Q?jKmappYbwIf0EuI0o2Lf0eeLHzzCcX2VCceFTSM2MSttyQPG6j/2UMUb2yDf?= =?us-ascii?Q?HK+biaUAmX7cxt8jgZIoXCSkR5gSSEKjzmVHink9mI/iplUpP1U4U9okcV6S?= =?us-ascii?Q?MVsje4d9RjTNiO578VUjgupn5qgzI5N82y21PGU/yl1JcVFkwibLTrkcuCHR?= =?us-ascii?Q?JyCfOG8ZyYDkte0DaQJDa0CF+CK7Wg0z2sYJR01DY7uoXyfJsCB3g=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; BN6PR02MB2258; 6:2NoXqIz1k1I19t0R6iTLovOA5ksmgeKm78+yWB/9HKsQ+HJEqK2c7esPDizFsopaDUIyCm4nVYzakhWzpRSwAPcFo2A6iUvlbGgOSHSErg6Fk8j2Qp+L+u7xsfN+aVF4c29a+bWPCorT6MZwjy7Xp20HN7KjBvPv0YAWafeuzcduWkOcl4tSY8Dp4Ep0DpeDYe3GTaAfCWVAQMlH5W78Bl26m2Nm+cYG8vYYGa9nO7CmwVih+sDSMHH7itJPb3HNaT1yzkohgmDpsPcAwjLERi2WRkxVSvNrQEImDW6UwDbCb5osZDmA/8XcX+sitZ7HnFs80d9AwF5B1Hm2KrNTGluCn5AgygRZ/cjnfWNao6Q=; 5:gZS22EXUDDpZ7NbpXcGpeiHLi9gqHjBeVBQzxgDsLcwdtySYp6+q5us3MXGaAaUpKZEFKhe5/zH7ZiY5cWeliS6nrkwTveP/j+rBEKE1OS7S6dmea0cSSgaVCb6WsMZXk4qDl+prZlxE5lsnNsLPVTqTozuEcNiHX+JChbDZX1U=; 24:/0MD4lSeJftj6527aFqyxZN2n4VSUSdJUePFCy6UM0gSCucFdt15qYeDJ//RT856nR3KzeAjsYAd1chd4ye6iexKyOGyDOnDNbd8fmIlkzY=; 7:r0lyInnzMS5jx8ruuD2cwDCUcKNVaPcbNEJTI5sCDap6DPowLOeZ/bVTiSDYm7MIWzz4ALguv8DJTPQQA5GZVEbi/317cTMahYNw9XbU8FECwOLrv/7ZZ33h9C2cu9ZHQH9zg9V5EylblJHOiNMek1XbZgeEEZKMw4r4CZQiMOkvtnLBPhumFWWgYjSxmegJ/z7tDaXIYd+QU10Vd9oBxHVXN/KrfeJMAfP+yK6I/Sc0NibPSULXnbBv+ssD9A13 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2018 22:35:29.7137 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 57eefd83-95c0-41c7-87a0-08d57efb925f 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.100]; Helo=[xsj-pvapsmtpgw02] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR02MB2258 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.42.46 Subject: [Qemu-devel] [PATCH v2 1/5] 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daudé --- V2: - Use UINT32_MAX and uint64_t in xlnx_iomod_pit_ctr_pr() - Name frequency varaible frequency_hz - Shorten R_MAX #define 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..75cac6bedd --- /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_pit" + +#define XLNX_ZYNQMP_IOMODULE_PIT(obj) \ + OBJECT_CHECK(XlnxPMUPIT, (obj), TYPE_XLNX_ZYNQMP_IOMODULE_PIT) + +#define XLNX_ZYNQMP_IOMOD_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_hz; + + uint32_t regs[XLNX_ZYNQMP_IOMOD_PIT_R_MAX]; + RegisterInfo regs_info[XLNX_ZYNQMP_IOMOD_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..a6bdc5211d --- /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); + uint64_t ret; + + if (s->ps_enable) { + ret = s->ps_counter; + } else { + ret = ptimer_get_count(s->ptimer); + } + + return ret & UINT32_MAX; +} + +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_hz); + + /* 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_IOMOD_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_IOMOD_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_hz, 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