From patchwork Wed Jan 11 20:19:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artyom Tarasenko X-Patchwork-Id: 9511479 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 98F346075C for ; Wed, 11 Jan 2017 21:29:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A6C22869E for ; Wed, 11 Jan 2017 21:29:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DDD9286A2; Wed, 11 Jan 2017 21:29:09 +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=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 F10EB2869E for ; Wed, 11 Jan 2017 21:29:08 +0000 (UTC) Received: from localhost ([::1]:57264 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cRQSC-0001Kr-3y for patchwork-qemu-devel@patchwork.kernel.org; Wed, 11 Jan 2017 16:29:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55261) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cRPOj-0007AL-BN for qemu-devel@nongnu.org; Wed, 11 Jan 2017 15:21:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cRPOi-0001WK-6r for qemu-devel@nongnu.org; Wed, 11 Jan 2017 15:21:29 -0500 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:36722) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cRPOi-0001W0-0U for qemu-devel@nongnu.org; Wed, 11 Jan 2017 15:21:28 -0500 Received: by mail-wm0-x244.google.com with SMTP id r126so557502wmr.3 for ; Wed, 11 Jan 2017 12:21:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=R2r7Rwjyhe8lV4baehHTJgCtF7C7wxEPqGHq0p+dxEE=; b=vdMTK9TbKoVW2ZJQkzqaxiUjDWgdzmT6Bxi8J8Q27S0tWboxze4SPGLBebklamcF6G tgt3w9A55DD+/OFiYKNRdtbNEwfZUFd0UWiNXCGzqOzDbnBKZ7lajeOg+kW6yBFby4+R jTSwKM7PQ7+niCxd/975D3byyUUK9uRLrntrVkqzMEKDXuuBIjqmHl0OnawuFuhWO9AA 71Wx/9zSJ3stj6J+qgu0SCdUHrf5bbIKdTeXdrZNT3PAqAQN59FEyr2r5vHaDAxAs9Gv c4TYJkB66ERFpmnRw1PKpcxfGXJeDV9qSpkGsp0vcObgxijgFEBEpq7DJPsTsdBgZrNj 3G3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=R2r7Rwjyhe8lV4baehHTJgCtF7C7wxEPqGHq0p+dxEE=; b=E62m9+BRUNB4xAZuwHtUlm2Dp26LrTbeTo3aM00sCVa5KcwdXumrAIOu00Yi1o6NWk Va8k/F4LEilEJlbPjlLRD/bssfNuTpy4VBYfcWPi+s3liZkciKj0WowPz5cw1VIGC5UK Fk9BPa81zeBq7uV8yVLreKicAaWrNDW8CCbElU+oqPlpAN4fxA09JlOKpxAgveEyrqY6 9iS0Wapz5N0R/1oKy8ujsji+Shj2a1kaFWYlCrA81f7xjSGmwdE3vfQN3xTsFYBFuRzJ f8xde9PbD11Px/OVjGEqr4VUKtDKuOkN/HSXCpO3XV2yoLl4C6FEUzf4xoMhgMsdu9o1 6R7g== X-Gm-Message-State: AIkVDXL14mJzoF06vZUjgLG0+b+k1uDSm+HB85dpTI/sErNB6g53QkS3sQZiRcb+SqmyRw== X-Received: by 10.223.131.34 with SMTP id 31mr4879345wrd.119.1484166087039; Wed, 11 Jan 2017 12:21:27 -0800 (PST) Received: from localhost (x55b4b54a.dyn.telefonica.de. [85.180.181.74]) by smtp.gmail.com with ESMTPSA id cs4sm10050826wjd.42.2017.01.11.12.21.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jan 2017 12:21:25 -0800 (PST) From: Artyom Tarasenko To: qemu-devel@nongnu.org Date: Wed, 11 Jan 2017 21:19:59 +0100 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [PATCH v2 28/30] target-sparc: implement sun4v RTC 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: Mark Cave-Ayland , Artyom Tarasenko , Richard Henderson 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: Artyom Tarasenko --- MAINTAINERS | 6 +++ hw/timer/Makefile.objs | 2 + hw/timer/sun4v-rtc.c | 102 +++++++++++++++++++++++++++++++++++++++++++ include/hw/timer/sun4v-rtc.h | 1 + 4 files changed, 111 insertions(+) create mode 100644 hw/timer/sun4v-rtc.c create mode 100644 include/hw/timer/sun4v-rtc.h diff --git a/MAINTAINERS b/MAINTAINERS index 1444b26..54588e5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1098,6 +1098,12 @@ F: hw/nvram/chrp_nvram.c F: include/hw/nvram/chrp_nvram.h F: tests/prom-env-test.c +sun4v RTC +M: Artyom Tarasenko +S: Maintained +F: hw/timer/sun4v-rtc.c +F: include/hw/timer/sun4v-rtc.h + Subsystems ---------- Audio diff --git a/hw/timer/Makefile.objs b/hw/timer/Makefile.objs index 7ba8c23..c1e93a3 100644 --- a/hw/timer/Makefile.objs +++ b/hw/timer/Makefile.objs @@ -34,3 +34,5 @@ obj-$(CONFIG_ALLWINNER_A10_PIT) += allwinner-a10-pit.o common-obj-$(CONFIG_STM32F2XX_TIMER) += stm32f2xx_timer.o common-obj-$(CONFIG_ASPEED_SOC) += aspeed_timer.o + +common-obj-$(CONFIG_SUN4V_RTC) += sun4v-rtc.o diff --git a/hw/timer/sun4v-rtc.c b/hw/timer/sun4v-rtc.c new file mode 100644 index 0000000..82e9e14 --- /dev/null +++ b/hw/timer/sun4v-rtc.c @@ -0,0 +1,102 @@ +/* + * QEMU sun4v Real Time Clock device + * + * The sun4v_rtc device (sun4v tod clock) + * + * Copyright (c) 2016 Artyom Tarasenko + * + * This code is licensed under the GNU GPL v3 or (at your option) any later + * version. + */ + +#include "qemu/osdep.h" +#include "hw/hw.h" +#include "hw/sysbus.h" +#include "qemu/timer.h" +#include "hw/timer/sun4v-rtc.h" + +//#define DEBUG_SUN4V_RTC + +#ifdef DEBUG_SUN4V_RTC +#define DPRINTF(fmt, ...) \ + do { printf("sun4v_rtc: " fmt , ## __VA_ARGS__); } while (0) +#else +#define DPRINTF(fmt, ...) do {} while (0) +#endif + +#define TYPE_SUN4V_RTC "sun4v_rtc" +#define SUN4V_RTC(obj) OBJECT_CHECK(Sun4vRtc, (obj), TYPE_SUN4V_RTC) + +typedef struct Sun4vRtc { + SysBusDevice parent_obj; + + MemoryRegion iomem; +} Sun4vRtc; + +static uint64_t sun4v_rtc_read(void *opaque, hwaddr addr, + unsigned size) +{ + uint64_t val = qemu_clock_get_ms(QEMU_CLOCK_REALTIME) / 1000; + if (!(addr & 4ULL)) { + /* accessing the high 32 bits */ + val >>= 32; + } + DPRINTF("read from " TARGET_FMT_plx " val %lx\n", addr, val); + return val; +} + +static void sun4v_rtc_write(void *opaque, hwaddr addr, + uint64_t val, unsigned size) +{ + DPRINTF("write 0x%x to " TARGET_FMT_plx "\n", (unsigned)val, addr); +} + +static const MemoryRegionOps sun4v_rtc_ops = { + .read = sun4v_rtc_read, + .write = sun4v_rtc_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +void sun4v_rtc_init(hwaddr addr) +{ + DeviceState *dev; + SysBusDevice *s; + + dev = qdev_create(NULL, TYPE_SUN4V_RTC); + s = SYS_BUS_DEVICE(dev); + + qdev_init_nofail(dev); + + sysbus_mmio_map(s, 0, addr); +} + +static int sun4v_rtc_init1(SysBusDevice *dev) +{ + Sun4vRtc *s = SUN4V_RTC(dev); + + memory_region_init_io(&s->iomem, OBJECT(s), &sun4v_rtc_ops, s, + "sun4v-rtc", 0x08ULL); + sysbus_init_mmio(dev, &s->iomem); + return 0; +} + +static void sun4v_rtc_class_init(ObjectClass *klass, void *data) +{ + SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); + + k->init = sun4v_rtc_init1; +} + +static const TypeInfo sun4v_rtc_info = { + .name = TYPE_SUN4V_RTC, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(Sun4vRtc), + .class_init = sun4v_rtc_class_init, +}; + +static void sun4v_rtc_register_types(void) +{ + type_register_static(&sun4v_rtc_info); +} + +type_init(sun4v_rtc_register_types) diff --git a/include/hw/timer/sun4v-rtc.h b/include/hw/timer/sun4v-rtc.h new file mode 100644 index 0000000..407278f --- /dev/null +++ b/include/hw/timer/sun4v-rtc.h @@ -0,0 +1 @@ +void sun4v_rtc_init(hwaddr addr);