From patchwork Wed Jan 22 01:58:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bobby Eshleman X-Patchwork-Id: 11344997 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BD92D1398 for ; Wed, 22 Jan 2020 05:15:07 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9A54D24656 for ; Wed, 22 Jan 2020 05:15:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BdWVII49" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9A54D24656 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iu8L9-00058F-Dz; Wed, 22 Jan 2020 05:14:07 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iu5Ki-00068t-54 for xen-devel@lists.xenproject.org; Wed, 22 Jan 2020 02:01:28 +0000 X-Inumbo-ID: 02b0ef06-3cbb-11ea-9fd7-bc764e2007e4 Received: from mail-yb1-xb42.google.com (unknown [2607:f8b0:4864:20::b42]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 02b0ef06-3cbb-11ea-9fd7-bc764e2007e4; Wed, 22 Jan 2020 02:00:49 +0000 (UTC) Received: by mail-yb1-xb42.google.com with SMTP id c13so2410940ybq.5 for ; Tue, 21 Jan 2020 18:00:49 -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 :mime-version:content-transfer-encoding; bh=cXIZq7tT5AofAb/PhGxVJPY146dZrQoSr7TqNUyNaBo=; b=BdWVII49282PFkD0jBmbhY79KHtyX1vqgAoM+U11AMiP413n3wLCWabalAUhrilozu pb/OwR0Vpyq7A2Ty/u1xp3U0Yn8068j3CuZFou3BGKpCsoZ6lhy+2rM34stKazIgYcT4 3osuhHDNqNDXenzB9yTP5kSDrJ+eb0hW+j4ZfKIybj5h03otxrPT8kGtUGvt9Z+gVItx ulo5oS00GJRF+qF94CfSD07JsMNXeWUqzlfNF5HQ3u+OOfDfsgpYZMRIp6EvciR5kVn6 jl9L4V64UKjzAFMuCw0N+O4Oo41Pwxwc0W0upD6+k/nSBq9ALTRaohJ15FmDPj9drC69 mhaQ== 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:mime-version:content-transfer-encoding; bh=cXIZq7tT5AofAb/PhGxVJPY146dZrQoSr7TqNUyNaBo=; b=qUBpMbfcmaERmgwoAYCnC1sRPTsJ/5gnz6Tfu0goWvC8asyCJ+ZmOqBKfDt3mwHK8f N00mEUymDgW70+d9eX+3D+D4/mu8E2XPZckrEm8meuEEgYV99LwruM3hcPuzXT84Krol /DtCIm7EUukb7ffwWncEm17tYImF0H9jSDuEI0voaf29psSvJU9nr0ftpyrJ/0zvRe/L ydY9fjOru/bCkC0jOeUMOI4iRd3P+r1+2mLcX+9vwnPHGJ+agdqam+1q3VpmI238fuCk 8zZzWNv6eq6FrfegLYuVVCgjaAaI5mPbN+CjZdOCZgx7/4emIH7prMZ2+UdDNeJYCN3Y cCPQ== X-Gm-Message-State: APjAAAUbUOMns9jJ03SpFiMtAkBAw4jvcTH8JvKX9P2TFMeGusLauNuX kFgq3eAHCcJy77vsP3FFfVIWXufky9JIYQ== X-Google-Smtp-Source: APXvYqxrYfyfh6RW34AeVTgBZxCXIBF+OEAIJsKBiD6cmISl/EIvfVWicHERwWI+QU4LoqsIlfkwSA== X-Received: by 2002:a81:4303:: with SMTP id q3mr5540359ywa.242.1579658448042; Tue, 21 Jan 2020 18:00:48 -0800 (PST) Received: from bobbye-pc.knology.net ([216.186.244.35]) by smtp.gmail.com with ESMTPSA id q185sm17504248ywh.61.2020.01.21.18.00.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jan 2020 18:00:47 -0800 (PST) From: Bobby Eshleman To: xen-devel@lists.xenproject.org Date: Tue, 21 Jan 2020 19:58:51 -0600 Message-Id: X-Mailer: git-send-email 2.25.0 In-Reply-To: References: MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 22 Jan 2020 05:14:01 +0000 Subject: [Xen-devel] [RFC XEN PATCH 12/23] riscv: Add time.c X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Bobby Eshleman , Stefano Stabellini , Julien Grall , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Bobby Eshleman , Dan Robertson , Alistair Francis Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Alistair Francis Signed-off-by: Alistair Francis --- xen/arch/riscv/time.c | 74 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 xen/arch/riscv/time.c diff --git a/xen/arch/riscv/time.c b/xen/arch/riscv/time.c new file mode 100644 index 0000000000..5358a22bd7 --- /dev/null +++ b/xen/arch/riscv/time.c @@ -0,0 +1,74 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +unsigned long __read_mostly cpu_khz; /* CPU clock frequency in kHz. */ + +uint64_t __read_mostly boot_count; + +s_time_t ticks_to_ns(uint64_t ticks) +{ + return muldiv64(ticks, SECONDS(1), 1000 * cpu_khz); +} + +void __init preinit_xen_time(void) +{ + if ( !cpu_khz ) + cpu_khz = 1000; + + boot_count = get_cycles(); +} + +s_time_t get_s_time(void) +{ + uint64_t ticks = get_cycles() - boot_count; + return ticks_to_ns(ticks); +} + + +/* VCPU PV timers. */ +void send_timer_event(struct vcpu *v) +{ + send_guest_vcpu_virq(v, VIRQ_TIMER); +} + +/* VCPU PV clock. */ +void update_vcpu_system_time(struct vcpu *v) +{ + /* XXX update shared_info->wc_* */ +} + +void domain_set_time_offset(struct domain *d, int64_t time_offset_seconds) +{ + d->time_offset_seconds = time_offset_seconds; +} + +int reprogram_timer(s_time_t timeout) +{ + /* TODO */ + + return 0; +}