From nobody Mon Mar 2 08:45:01 2026 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1772303031; cv=none; d=zohomail.com; s=zohoarc; b=POCi/zonQeqahsRCXZ/MdbpUKTgz2d1TPMv1jZf1ZcVfebQPRUjCRrdswUD1I1DEk9junE/BXd9ol8M40tHqa5MdGzvZCTehV6jg88h8hjLJggd+Cgwn2O9IIQGrjyH2Ne6UIySY3njUNdOQGPWa4I+S40/HTYNcfEHpnltY2lE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772303031; h=Content-Transfer-Encoding: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=df8v64vKr9GL2MFEEjx8VlY0YbTzSnpQefqjrHPWyJw=; b=OqtNgxtEeTL1o64MdY4tPzvwRhkA427jUDgLbmLvhbpVjnVMwaMvG+jtmXa614JTDe4iznEDCQWbC6ew7Ohz2X1G2EvlFK2ES3EWsrDZ6xDiCCLFsLsmUw6ESnKgBeh5tpCIWc+a/9NrzwkWafmdivo4ssbJb1T2nwqrYo+fWuY= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772303031599227.38631057664463; Sat, 28 Feb 2026 10:23:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vwOy6-0005E6-OT; Sat, 28 Feb 2026 13:23:10 -0500 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 ) id 1vwOy1-0005DI-BD for qemu-devel@nongnu.org; Sat, 28 Feb 2026 13:23:05 -0500 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vwOxz-0002pT-E6 for qemu-devel@nongnu.org; Sat, 28 Feb 2026 13:23:05 -0500 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-824a829f9bbso1460642b3a.0 for ; Sat, 28 Feb 2026 10:23:03 -0800 (PST) Received: from visitorckw-work01.c.googlers.com.com (7.162.199.104.bc.googleusercontent.com. [104.199.162.7]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8273a05e831sm8731008b3a.58.2026.02.28.10.23.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Feb 2026 10:23:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772302982; x=1772907782; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=df8v64vKr9GL2MFEEjx8VlY0YbTzSnpQefqjrHPWyJw=; b=ZAH4YpG+viR20jNcfmPPcbcRX5q9br2enddmGOyYPk5XQn65RshahBWZAYiWhD1TR7 awC7+PMkpRwEOU6KKuIvMBTgfHvkr+QFaSfFbCcWo0l/51gytYK0vdJCPhnnBSlKJaCU /9funWpv3+RIUhPPxDQFLSawpnkJARh/HJ+UflaqGWwc7PD4jCYMfsXdvldUb/dhAENV uU8CdY2s3rWSwnCEgmcsP2uHHlpABLerC1FfOSJUo81yZ9U/vlluU3Te3+CldrDaQh5k 10T3+NPYimykFNYn2O2g+hYMhtZEKXxESMimf2CcIHNxQpiLNyHUXvYdCiGsLulOL83n tAxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772302982; x=1772907782; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=df8v64vKr9GL2MFEEjx8VlY0YbTzSnpQefqjrHPWyJw=; b=nvh/ZN+AjXG8WWE/lfhcG45SOHebPLO4xTfRJGX6YVPmPuo6eIBLDMuG4fSoFlHeoo BlMiryPniXXcgvEpQR8EKdJNh2lLjGhyHkpruYJ+lPC+draLCHcTlqcfptZ6QNB0uNue AqSWTVd+ETZ4yvbt8SR8AWsd3xZ8PNqbwxghNcRVEfm06delHr/gKsmJdY2pWh6bSkZS tyIUnplu/vWxa6K4/zMWokI8HpN3zkVlUONpPNnVC6hp6Bp0H+sO8dKFVqN4IaUKrrcu y9p+t6gMKhyHX3P2DeAHRw7+GzD6NDPoqPzpEeGmWN1tQeTcx1bO2GpmqQ4Qrg6m+df+ E8zQ== X-Forwarded-Encrypted: i=1; AJvYcCUfAqFeQ4djzy9NBJc9SLBE9N2wzjDPv6NFerp/9f/iea5JfykpUxIdS8kzH890wY/VBnVmn1keqSpV@nongnu.org X-Gm-Message-State: AOJu0YwH/ZMsTS+R8rGH2+72ZZSATPcRllyB2riQYCOsG3OA6+CyFYXh eSZWSghyhv3qzDSeo8oWESOlKp2wvZtR1dCr8x9uIWx7092z5GoO15IF X-Gm-Gg: ATEYQzwSgOqz3GzxFXmsAWVmscDGa5LfuqjKeT6lWyh9no0ZZgCpYzA4+9cuU6EOH8m 76VvdTTU2S0xuuiO1cVsy8jwCAQ+/ePYyKlf0fUslgWXEYJPtsphx7AyxRtxld+wi2q1SL3n1Dk ROZqSJvi+4/ebHM4KHOgwg7SpoZOrg1r4FK2d1PNu/oAysMaIDg/p8sU5ywLeNkbLwTmYztOjau b3vazWONlp149kcnRoxFjfqXQM7DhE/wlyFXYymEVGthoJBEcn6eoP2jI9F1FIDo8VYYwwKF1+3 LFEt0+WVOU+W/XADh2+VW/S3rRo/q8vw+K+vbPV6c+jfB/nwWCSfPL4xbfz0cDC/VKk3JtR276P pKbHiHGrVrZjc9x+SNw8IDVEsArLXH/LNK/KpVFzoXvz09N4M02zj3vtNoqqeXRAxTs9kynkqfC xbqTZGbGMUNSfUhkh47u3BYeEnRiLUeuUiyWKdbDWBkLagIIMa4pDWQT9cNrS5oQiyoe7Z8B/km 2l+MZhSMwPnwTBbZshuPQInAg7NyWxlVBJ5 X-Received: by 2002:a05:6a00:4c99:b0:827:37ef:7321 with SMTP id d2e1a72fcca58-8274d92e069mr5862902b3a.8.1772302981939; Sat, 28 Feb 2026 10:23:01 -0800 (PST) From: Kuan-Wei Chiu To: pbonzini@redhat.com, mst@redhat.com, cohuck@redhat.com Cc: eleanor15x@gmail.com, jserv@ccns.ncku.edu.tw, qemu-devel@nongnu.org, Kuan-Wei Chiu Subject: [PATCH 1/2] standard-headers: Add virtio_rtc.h from Linux 7.0-rc1 Date: Sat, 28 Feb 2026 18:22:45 +0000 Message-ID: <20260228182246.700714-2-visitorckw@gmail.com> X-Mailer: git-send-email 2.53.0.473.g4a7958ca14-goog In-Reply-To: <20260228182246.700714-1-visitorckw@gmail.com> References: <20260228182246.700714-1-visitorckw@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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::42d; envelope-from=visitorckw@gmail.com; helo=mail-pf1-x42d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: qemu development 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 @gmail.com) X-ZM-MESSAGEID: 1772303034218158500 Content-Type: text/plain; charset="utf-8" Add virtio_rtc.h from the upstream Linux kernel using scripts/update-linux-headers.sh. Source: - Linux commit 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f (v7.0-rc1) - Author: Linus Torvalds - Date: Sun Feb 22 13:18:59 2026 -0800 Signed-off-by: Kuan-Wei Chiu --- include/standard-headers/linux/virtio_rtc.h | 237 ++++++++++++++++++++ 1 file changed, 237 insertions(+) create mode 100644 include/standard-headers/linux/virtio_rtc.h diff --git a/include/standard-headers/linux/virtio_rtc.h b/include/standard= -headers/linux/virtio_rtc.h new file mode 100644 index 0000000000..7e2c21ebff --- /dev/null +++ b/include/standard-headers/linux/virtio_rtc.h @@ -0,0 +1,237 @@ +/* SPDX-License-Identifier: ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-C= lause) */ +/* + * Copyright (C) 2022-2024 OpenSynergy GmbH + * Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef _LINUX_VIRTIO_RTC_H +#define _LINUX_VIRTIO_RTC_H + +#include "standard-headers/linux/types.h" + +/* alarm feature */ +#define VIRTIO_RTC_F_ALARM 0 + +/* read request message types */ + +#define VIRTIO_RTC_REQ_READ 0x0001 +#define VIRTIO_RTC_REQ_READ_CROSS 0x0002 + +/* control request message types */ + +#define VIRTIO_RTC_REQ_CFG 0x1000 +#define VIRTIO_RTC_REQ_CLOCK_CAP 0x1001 +#define VIRTIO_RTC_REQ_CROSS_CAP 0x1002 +#define VIRTIO_RTC_REQ_READ_ALARM 0x1003 +#define VIRTIO_RTC_REQ_SET_ALARM 0x1004 +#define VIRTIO_RTC_REQ_SET_ALARM_ENABLED 0x1005 + +/* alarmq message types */ + +#define VIRTIO_RTC_NOTIF_ALARM 0x2000 + +/* Message headers */ + +/** common request header */ +struct virtio_rtc_req_head { + uint16_t msg_type; + uint8_t reserved[6]; +}; + +/** common response header */ +struct virtio_rtc_resp_head { +#define VIRTIO_RTC_S_OK 0 +#define VIRTIO_RTC_S_EOPNOTSUPP 2 +#define VIRTIO_RTC_S_ENODEV 3 +#define VIRTIO_RTC_S_EINVAL 4 +#define VIRTIO_RTC_S_EIO 5 + uint8_t status; + uint8_t reserved[7]; +}; + +/** common notification header */ +struct virtio_rtc_notif_head { + uint16_t msg_type; + uint8_t reserved[6]; +}; + +/* read requests */ + +/* VIRTIO_RTC_REQ_READ message */ + +struct virtio_rtc_req_read { + struct virtio_rtc_req_head head; + uint16_t clock_id; + uint8_t reserved[6]; +}; + +struct virtio_rtc_resp_read { + struct virtio_rtc_resp_head head; + uint64_t clock_reading; +}; + +/* VIRTIO_RTC_REQ_READ_CROSS message */ + +struct virtio_rtc_req_read_cross { + struct virtio_rtc_req_head head; + uint16_t clock_id; +/* Arm Generic Timer Counter-timer Virtual Count Register (CNTVCT_EL0) */ +#define VIRTIO_RTC_COUNTER_ARM_VCT 0 +/* x86 Time-Stamp Counter */ +#define VIRTIO_RTC_COUNTER_X86_TSC 1 +/* Invalid */ +#define VIRTIO_RTC_COUNTER_INVALID 0xFF + uint8_t hw_counter; + uint8_t reserved[5]; +}; + +struct virtio_rtc_resp_read_cross { + struct virtio_rtc_resp_head head; + uint64_t clock_reading; + uint64_t counter_cycles; +}; + +/* control requests */ + +/* VIRTIO_RTC_REQ_CFG message */ + +struct virtio_rtc_req_cfg { + struct virtio_rtc_req_head head; + /* no request params */ +}; + +struct virtio_rtc_resp_cfg { + struct virtio_rtc_resp_head head; + /** # of clocks -> clock ids < num_clocks are valid */ + uint16_t num_clocks; + uint8_t reserved[6]; +}; + +/* VIRTIO_RTC_REQ_CLOCK_CAP message */ + +struct virtio_rtc_req_clock_cap { + struct virtio_rtc_req_head head; + uint16_t clock_id; + uint8_t reserved[6]; +}; + +struct virtio_rtc_resp_clock_cap { + struct virtio_rtc_resp_head head; +#define VIRTIO_RTC_CLOCK_UTC 0 +#define VIRTIO_RTC_CLOCK_TAI 1 +#define VIRTIO_RTC_CLOCK_MONOTONIC 2 +#define VIRTIO_RTC_CLOCK_UTC_SMEARED 3 +#define VIRTIO_RTC_CLOCK_UTC_MAYBE_SMEARED 4 + uint8_t type; +#define VIRTIO_RTC_SMEAR_UNSPECIFIED 0 +#define VIRTIO_RTC_SMEAR_NOON_LINEAR 1 +#define VIRTIO_RTC_SMEAR_UTC_SLS 2 + uint8_t leap_second_smearing; +#define VIRTIO_RTC_FLAG_ALARM_CAP (1 << 0) + uint8_t flags; + uint8_t reserved[5]; +}; + +/* VIRTIO_RTC_REQ_CROSS_CAP message */ + +struct virtio_rtc_req_cross_cap { + struct virtio_rtc_req_head head; + uint16_t clock_id; + uint8_t hw_counter; + uint8_t reserved[5]; +}; + +struct virtio_rtc_resp_cross_cap { + struct virtio_rtc_resp_head head; +#define VIRTIO_RTC_FLAG_CROSS_CAP (1 << 0) + uint8_t flags; + uint8_t reserved[7]; +}; + +/* VIRTIO_RTC_REQ_READ_ALARM message */ + +struct virtio_rtc_req_read_alarm { + struct virtio_rtc_req_head head; + uint16_t clock_id; + uint8_t reserved[6]; +}; + +struct virtio_rtc_resp_read_alarm { + struct virtio_rtc_resp_head head; + uint64_t alarm_time; +#define VIRTIO_RTC_FLAG_ALARM_ENABLED (1 << 0) + uint8_t flags; + uint8_t reserved[7]; +}; + +/* VIRTIO_RTC_REQ_SET_ALARM message */ + +struct virtio_rtc_req_set_alarm { + struct virtio_rtc_req_head head; + uint64_t alarm_time; + uint16_t clock_id; + /* flag VIRTIO_RTC_FLAG_ALARM_ENABLED */ + uint8_t flags; + uint8_t reserved[5]; +}; + +struct virtio_rtc_resp_set_alarm { + struct virtio_rtc_resp_head head; + /* no response params */ +}; + +/* VIRTIO_RTC_REQ_SET_ALARM_ENABLED message */ + +struct virtio_rtc_req_set_alarm_enabled { + struct virtio_rtc_req_head head; + uint16_t clock_id; + /* flag VIRTIO_RTC_ALARM_ENABLED */ + uint8_t flags; + uint8_t reserved[5]; +}; + +struct virtio_rtc_resp_set_alarm_enabled { + struct virtio_rtc_resp_head head; + /* no response params */ +}; + +/** Union of request types for requestq */ +union virtio_rtc_req_requestq { + struct virtio_rtc_req_read read; + struct virtio_rtc_req_read_cross read_cross; + struct virtio_rtc_req_cfg cfg; + struct virtio_rtc_req_clock_cap clock_cap; + struct virtio_rtc_req_cross_cap cross_cap; + struct virtio_rtc_req_read_alarm read_alarm; + struct virtio_rtc_req_set_alarm set_alarm; + struct virtio_rtc_req_set_alarm_enabled set_alarm_enabled; +}; + +/** Union of response types for requestq */ +union virtio_rtc_resp_requestq { + struct virtio_rtc_resp_read read; + struct virtio_rtc_resp_read_cross read_cross; + struct virtio_rtc_resp_cfg cfg; + struct virtio_rtc_resp_clock_cap clock_cap; + struct virtio_rtc_resp_cross_cap cross_cap; + struct virtio_rtc_resp_read_alarm read_alarm; + struct virtio_rtc_resp_set_alarm set_alarm; + struct virtio_rtc_resp_set_alarm_enabled set_alarm_enabled; +}; + +/* alarmq notifications */ + +/* VIRTIO_RTC_NOTIF_ALARM notification */ + +struct virtio_rtc_notif_alarm { + struct virtio_rtc_notif_head head; + uint16_t clock_id; + uint8_t reserved[6]; +}; + +/** Union of notification types for alarmq */ +union virtio_rtc_notif_alarmq { + struct virtio_rtc_notif_alarm alarm; +}; + +#endif /* _LINUX_VIRTIO_RTC_H */ --=20 2.53.0.473.g4a7958ca14-goog From nobody Mon Mar 2 08:45:01 2026 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1772303039; cv=none; d=zohomail.com; s=zohoarc; b=KXlFc0DCKR4sG+Qq/Rfmrd9RTAby/DYMOC7kEVC1RT7tQGdCQOEpqOCUi/uprw/LrmZPJtoCjPjIltb/cElHhmmU6apc1iOGZiRSSCTW+Be6XJFjtcT2N1jY7nwrb7V+zueosvWpndL5IoHjqMVG8fPxATAVgn6QVkv0tqvyI6o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772303039; h=Content-Transfer-Encoding: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=dIy/qwW8DhmsA/gz1aMOdjK4wzunev82qsw+l2OLW9E=; b=HRUICeRAj9Zzia737JicusGL0B3wwIgS2s/BdftN1mwM2Qyg2gKbOcmaqGXHEMd4UZmscyc2yLwlTYS8vOxtN1c9P2VhU/0G6HmK8hWb/EIkm67Ko7cgwnAgN0kJDk6WnKJTeiRcwZ80kP8avJFF31AH6/lyWYrbtefeB6zSN8g= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772303039013229.9476326265601; Sat, 28 Feb 2026 10:23:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vwOy9-0005El-L5; Sat, 28 Feb 2026 13:23:13 -0500 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 ) id 1vwOy7-0005EO-It for qemu-devel@nongnu.org; Sat, 28 Feb 2026 13:23:12 -0500 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vwOy5-0002pw-A9 for qemu-devel@nongnu.org; Sat, 28 Feb 2026 13:23:11 -0500 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-824b5f015bcso3667565b3a.1 for ; Sat, 28 Feb 2026 10:23:08 -0800 (PST) Received: from visitorckw-work01.c.googlers.com.com (7.162.199.104.bc.googleusercontent.com. [104.199.162.7]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8273a05e831sm8731008b3a.58.2026.02.28.10.23.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Feb 2026 10:23:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772302988; x=1772907788; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dIy/qwW8DhmsA/gz1aMOdjK4wzunev82qsw+l2OLW9E=; b=bCJ3PI5Da/bTGribRvVgfFfP5ZL/PnAKIZvsULLsSSJod64JMQmXirW1+cFNtAdocP Vg0H1S8OG67LtF+BGlj4hBNJ6fQPKu3qpyocxaxTixDpyXeN+cPKFvxOxoovWOrQCXor vrFlQ9UpBPRq29Nd2ZsUpf8/awvz8EdoI2PLzJxFYrF+m5MxO2SntWBRIPQVK4FjFLk0 83//EksoWMtO8UfiGEhLJuvGCB0Mc3IN2Y487LfUaLrlMUZkddMsH6dTY/dzspOYfGaY Wr3/E1eKJwMPRYH9vHeon1yhKvrefog9XcRnu9MrpsfjdpAGFt9nVlC3+6YEtYB4vAZI KGtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772302988; x=1772907788; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=dIy/qwW8DhmsA/gz1aMOdjK4wzunev82qsw+l2OLW9E=; b=PSpv//B5bgFcJmVq14RZyU28rYi96yTdfsvrndBO91+HHG/XZ5HXeXt0IFi4a1Jzwb 1BYb73AzgkrNF5J7e1y3+kYM2UZACn7FUaNkap/1k6hiiwo/ZrzlU/DO0dzsGBE17zrP W/0lZyj40fQ+9vnih4NTWUN9BfvqpJaqPEuC+46l0Cpi3Bc+M+rIGjvyDKmB8SRQ96+g 0sC05NSjLsnhL412WyCiFZPeSsU4FKHAdOF2Cj1XtcvK07ViAQo39EpN6OTenmUqcboc lfgTp1tkw9ebIsWsqZ63uMNyZgIdNGwqg+gg2mWuclvQw8W6vSEAAxdvo3BdLm4CFa2W fcTg== X-Forwarded-Encrypted: i=1; AJvYcCWemc9Hi+nEnbTOcLNvAI4cLkaE4UCtM24/Duj7Dvuq32C33IpnKh2fzP/ugov+0PMEgsUgiD6nJi1i@nongnu.org X-Gm-Message-State: AOJu0YyayfFv39HWDcvrLopsP99russE5WeE1nGef30vCkpa3hyf4+ug zgxFL74NnPWp4kl7TpcNBOjIuLtA1dfVcDaPeHPH9BS4klW+hM6PVGnl X-Gm-Gg: ATEYQzxmrw3GgiEJxhuUuClUcloXo7GfU6BsfdNBbaU2gRwuqw2eNesbo6jplKRlcff w2TPRs1S19faqtaDsGpFOH239q0LyFmq22GgQ1LNq528dUpEHWzwWCPrLJrp9ZfPYQY66ZIcslV KAXC5NttAjmzodocx4VAPAgPXsjCAnZVeVuyS7t7e8JdI9N6g5E1AmkOjtYmrOVU94XbkeVlIUd VG5zyNuN8GjObDzY22cg5CZvHj0wsJqKmKx+b7X4QILlum3OFAkN1OklKyobsiCddezA5ARZTyn LNxWme9tbYXTAa46eFFk2MWr2SaviegaY4ml2qlz81YGEdO0YYlCfM9jYhBqv6A76plwTSralfT zny1Yb6+Ur4i76+Rfm5XP/TTqZvMJrpQhOMP5UE4olgks/HSpAahCjF4qi24lyqFWL9A+zoYq8D VUWKCMO/ZvOq0vzJ50c21E1vqBy5TNo6cUNsTRfmG0vGfm9ywZ9Aw2lSk8DAq36MpalgC7a2Uo3 L6C9amd38rdsVHt7ap1ej/dkBEhN7AjjefE X-Received: by 2002:a05:6a00:2d09:b0:821:8492:7f73 with SMTP id d2e1a72fcca58-8274da7a78fmr7182863b3a.63.1772302987769; Sat, 28 Feb 2026 10:23:07 -0800 (PST) From: Kuan-Wei Chiu To: pbonzini@redhat.com, mst@redhat.com, cohuck@redhat.com Cc: eleanor15x@gmail.com, jserv@ccns.ncku.edu.tw, qemu-devel@nongnu.org, Kuan-Wei Chiu Subject: [PATCH 2/2] virtio-rtc: Add basic virtio-rtc support Date: Sat, 28 Feb 2026 18:22:46 +0000 Message-ID: <20260228182246.700714-3-visitorckw@gmail.com> X-Mailer: git-send-email 2.53.0.473.g4a7958ca14-goog In-Reply-To: <20260228182246.700714-1-visitorckw@gmail.com> References: <20260228182246.700714-1-visitorckw@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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::430; envelope-from=visitorckw@gmail.com; helo=mail-pf1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: qemu development 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 @gmail.com) X-ZM-MESSAGEID: 1772303041738158500 Content-Type: text/plain; charset="utf-8" Introduce the core device and PCI bindings for the virtio-rtc device (VIRTIO_ID_CLOCK). This implementation provides a read-only clock that returns the host's time (QEMU_CLOCK_HOST) to the guest. It handles fundamental control requests, reporting a single supported clock of type VIRTIO_RTC_CLOCK_UTC, and responds to standard read requests. - Virtio RTC Spec: https://github.com/oasis-tcs/virtio-spec/tree/master/device-types/rtc - Linux Virtio RTC driver: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/dri= vers/virtio/virtio_rtc_driver.c?h=3Dv7.0-rc1 Signed-off-by: Kuan-Wei Chiu --- MAINTAINERS | 7 ++ hw/virtio/Kconfig | 5 + hw/virtio/meson.build | 2 + hw/virtio/virtio-rtc-pci.c | 65 +++++++++++ hw/virtio/virtio-rtc.c | 190 +++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-rtc.h | 22 ++++ 6 files changed, 291 insertions(+) create mode 100644 hw/virtio/virtio-rtc-pci.c create mode 100644 hw/virtio/virtio-rtc.c create mode 100644 include/hw/virtio/virtio-rtc.h diff --git a/MAINTAINERS b/MAINTAINERS index 606b16762c..69dfd07a36 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2522,6 +2522,13 @@ F: include/system/rng*.h F: backends/rng*.c F: tests/qtest/virtio-rng-test.c =20 +virtio-rtc +M: Kuan-Wei Chiu +S: Maintained +F: hw/virtio/virtio-rtc.c +F: hw/virtio/virtio-rtc-pci.c +F: include/hw/virtio/virtio-rtc.h + virtio-nsm M: Alexander Graf M: Dorjoy Chowdhury diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig index 8895682c61..fb8b53f287 100644 --- a/hw/virtio/Kconfig +++ b/hw/virtio/Kconfig @@ -76,6 +76,11 @@ config VIRTIO_MEM depends on VIRTIO_MEM_SUPPORTED select VIRTIO_MD =20 +config VIRTIO_RTC + bool + default y + depends on VIRTIO + config VHOST_VSOCK_COMMON bool depends on VIRTIO diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index 6675b63ce6..68c89495a1 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -55,6 +55,7 @@ else endif system_virtio_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', if_true: files('vhos= t-user-vsock.c')) system_virtio_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('virtio-rng= .c')) +system_virtio_ss.add(when: 'CONFIG_VIRTIO_RTC', if_true: files('virtio-rtc= .c')) =20 specific_virtio_ss.add(when: 'CONFIG_VIRTIO_BALLOON', if_true: files('virt= io-balloon.c')) specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true: files('vhost= -user-fs.c')) @@ -78,6 +79,7 @@ virtio_pci_ss.add(when: 'CONFIG_VIRTIO_CRYPTO', if_true: = files('virtio-crypto-pc virtio_pci_ss.add(when: 'CONFIG_VIRTIO_INPUT_HOST', if_true: files('virtio= -input-host-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VIRTIO_INPUT', if_true: files('virtio-inpu= t-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('virtio-rng-pc= i.c')) +virtio_pci_ss.add(when: 'CONFIG_VIRTIO_RTC', if_true: files('virtio-rtc-pc= i.c')) virtio_pci_ss.add(when: 'CONFIG_VIRTIO_NSM', if_true: [files('virtio-nsm-p= ci.c', 'cbor-helpers.c'), libcbor]) virtio_pci_ss.add(when: 'CONFIG_VIRTIO_BALLOON', if_true: files('virtio-ba= lloon-pci.c')) virtio_pci_ss.add(when: 'CONFIG_VIRTIO_9P', if_true: files('virtio-9p-pci.= c')) diff --git a/hw/virtio/virtio-rtc-pci.c b/hw/virtio/virtio-rtc-pci.c new file mode 100644 index 0000000000..fe25f21fbc --- /dev/null +++ b/hw/virtio/virtio-rtc-pci.c @@ -0,0 +1,65 @@ +/* + * Virtio RTC PCI Bindings + * + * Copyright (c) 2026 Kuan-Wei Chiu + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/virtio/virtio-pci.h" +#include "hw/virtio/virtio-rtc.h" +#include "standard-headers/linux/virtio_ids.h" + +typedef struct VirtIORtcPCI { + VirtIOPCIProxy parent_obj; + VirtIORtc vdev; +} VirtIORtcPCI; + +#define TYPE_VIRTIO_RTC_PCI "virtio-rtc-pci-base" +OBJECT_DECLARE_SIMPLE_TYPE(VirtIORtcPCI, VIRTIO_RTC_PCI) + +static void virtio_rtc_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) +{ + VirtIORtcPCI *dev =3D VIRTIO_RTC_PCI(vpci_dev); + DeviceState *vdev =3D DEVICE(&dev->vdev); + + qdev_realize(vdev, BUS(&vpci_dev->bus), errp); +} + +static void virtio_rtc_pci_class_init(ObjectClass *klass, const void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioPCIClass *k =3D VIRTIO_PCI_CLASS(klass); + PCIDeviceClass *pcidev_k =3D PCI_DEVICE_CLASS(klass); + + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + k->realize =3D virtio_rtc_pci_realize; + + pcidev_k->vendor_id =3D PCI_VENDOR_ID_REDHAT_QUMRANET; + pcidev_k->device_id =3D PCI_DEVICE_ID_VIRTIO_10_BASE + VIRTIO_ID_CLOCK; + pcidev_k->revision =3D 0x00; + pcidev_k->class_id =3D PCI_CLASS_SYSTEM_RTC; +} + +static void virtio_rtc_pci_instance_init(Object *obj) +{ + VirtIORtcPCI *dev =3D VIRTIO_RTC_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VIRTIO_RTC); +} + +static const VirtioPCIDeviceTypeInfo virtio_rtc_pci_info =3D { + .base_name =3D TYPE_VIRTIO_RTC_PCI, + .non_transitional_name =3D "virtio-rtc-pci", + .instance_size =3D sizeof(VirtIORtcPCI), + .instance_init =3D virtio_rtc_pci_instance_init, + .class_init =3D virtio_rtc_pci_class_init, +}; + +static void virtio_rtc_pci_register(void) +{ + virtio_pci_types_register(&virtio_rtc_pci_info); +} + +type_init(virtio_rtc_pci_register); diff --git a/hw/virtio/virtio-rtc.c b/hw/virtio/virtio-rtc.c new file mode 100644 index 0000000000..32de9c1650 --- /dev/null +++ b/hw/virtio/virtio-rtc.c @@ -0,0 +1,190 @@ +/* + * Virtio RTC device core + * + * Copyright (c) 2026 Kuan-Wei Chiu + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/iov.h" +#include "qemu/timer.h" +#include "hw/virtio/virtio.h" +#include "hw/virtio/virtio-rtc.h" +#include "standard-headers/linux/virtio_ids.h" +#include "standard-headers/linux/virtio_rtc.h" + +static void virtio_rtc_handle_request(VirtIODevice *vdev, VirtQueue *vq) +{ + VirtQueueElement *elem; + struct virtio_rtc_req_head req_head; + size_t written; + + while ((elem =3D virtqueue_pop(vq, sizeof(VirtQueueElement)))) { + if (elem->out_num < 1 || elem->in_num < 1) { + virtio_error(vdev, "virtio-rtc: request missing in/out buffers= "); + virtqueue_detach_element(vq, elem, 0); + g_free(elem); + break; + } + + if (iov_to_buf(elem->out_sg, elem->out_num, 0, &req_head, + sizeof(req_head)) !=3D sizeof(req_head)) { + virtio_error(vdev, "virtio-rtc: request header too short"); + virtqueue_detach_element(vq, elem, 0); + g_free(elem); + break; + } + + written =3D 0; + + switch (le16_to_cpu(req_head.msg_type)) { + case VIRTIO_RTC_REQ_CFG: { + struct virtio_rtc_resp_cfg resp =3D {0}; + resp.head.status =3D VIRTIO_RTC_S_OK; + resp.num_clocks =3D cpu_to_le16(1); + written =3D iov_from_buf(elem->in_sg, elem->in_num, 0, &resp, + sizeof(resp)); + break; + } + case VIRTIO_RTC_REQ_CLOCK_CAP: { + struct virtio_rtc_req_clock_cap req; + struct virtio_rtc_resp_clock_cap resp =3D {0}; + + if (iov_to_buf(elem->out_sg, elem->out_num, 0, &req, + sizeof(req)) !=3D sizeof(req)) { + resp.head.status =3D VIRTIO_RTC_S_EINVAL; + written =3D iov_from_buf(elem->in_sg, elem->in_num, 0, &re= sp, + sizeof(resp.head)); + break; + } + + if (le16_to_cpu(req.clock_id) !=3D 0) { + resp.head.status =3D VIRTIO_RTC_S_ENODEV; + } else { + resp.head.status =3D VIRTIO_RTC_S_OK; + resp.type =3D VIRTIO_RTC_CLOCK_UTC; + } + written =3D iov_from_buf(elem->in_sg, elem->in_num, 0, &resp, + sizeof(resp)); + break; + } + case VIRTIO_RTC_REQ_CROSS_CAP: { + struct virtio_rtc_req_cross_cap req; + struct virtio_rtc_resp_cross_cap resp =3D {0}; + + if (iov_to_buf(elem->out_sg, elem->out_num, 0, &req, + sizeof(req)) !=3D sizeof(req)) { + resp.head.status =3D VIRTIO_RTC_S_EINVAL; + written =3D iov_from_buf(elem->in_sg, elem->in_num, 0, &re= sp, + sizeof(resp.head)); + break; + } + + if (le16_to_cpu(req.clock_id) !=3D 0) { + resp.head.status =3D VIRTIO_RTC_S_ENODEV; + } else { + resp.head.status =3D VIRTIO_RTC_S_OK; + } + written =3D iov_from_buf(elem->in_sg, elem->in_num, 0, &resp, + sizeof(resp)); + break; + } + case VIRTIO_RTC_REQ_READ: { + struct virtio_rtc_req_read req; + struct virtio_rtc_resp_read resp =3D {0}; + + if (iov_to_buf(elem->out_sg, elem->out_num, 0, &req, + sizeof(req)) !=3D sizeof(req)) { + resp.head.status =3D VIRTIO_RTC_S_EINVAL; + written =3D iov_from_buf(elem->in_sg, elem->in_num, 0, &re= sp, + sizeof(resp.head)); + break; + } + + if (le16_to_cpu(req.clock_id) !=3D 0) { + resp.head.status =3D VIRTIO_RTC_S_ENODEV; + written =3D iov_from_buf(elem->in_sg, elem->in_num, 0, &re= sp, + sizeof(resp.head)); + } else { + resp.head.status =3D VIRTIO_RTC_S_OK; + resp.clock_reading =3D + cpu_to_le64(qemu_clock_get_ns(QEMU_CLOCK_HOST)); + written =3D iov_from_buf(elem->in_sg, elem->in_num, 0, &re= sp, + sizeof(resp)); + } + break; + } + default: { + struct virtio_rtc_resp_head resp =3D {0}; + resp.status =3D VIRTIO_RTC_S_EOPNOTSUPP; + written =3D iov_from_buf(elem->in_sg, elem->in_num, 0, &resp, + sizeof(resp)); + break; + } + } + + virtqueue_push(vq, elem, written); + virtio_notify(vdev, vq); + g_free(elem); + } +} + +static void virtio_rtc_device_realize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VirtIORtc *vrtc =3D VIRTIO_RTC(dev); + + virtio_init(vdev, VIRTIO_ID_CLOCK, 0); + vrtc->vq =3D virtio_add_queue(vdev, 64, virtio_rtc_handle_request); +} + +static void virtio_rtc_device_unrealize(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VirtIORtc *vrtc =3D VIRTIO_RTC(dev); + + virtio_delete_queue(vrtc->vq); + virtio_cleanup(vdev); +} + +static uint64_t virtio_rtc_get_features(VirtIODevice *vdev, uint64_t f, + Error **errp) +{ + return f; +} + +static const VMStateDescription vmstate_virtio_rtc =3D { + .name =3D "virtio-rtc", + .minimum_version_id =3D 1, + .version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_VIRTIO_DEVICE, + VMSTATE_END_OF_LIST() + }, +}; + +static void virtio_rtc_class_init(ObjectClass *klass, const void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); + + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + vdc->realize =3D virtio_rtc_device_realize; + vdc->unrealize =3D virtio_rtc_device_unrealize; + vdc->get_features =3D virtio_rtc_get_features; + dc->vmsd =3D &vmstate_virtio_rtc; +} + +static const TypeInfo virtio_rtc_info =3D { + .name =3D TYPE_VIRTIO_RTC, + .parent =3D TYPE_VIRTIO_DEVICE, + .instance_size =3D sizeof(VirtIORtc), + .class_init =3D virtio_rtc_class_init, +}; + +static void virtio_rtc_register_types(void) +{ + type_register_static(&virtio_rtc_info); +} + +type_init(virtio_rtc_register_types) diff --git a/include/hw/virtio/virtio-rtc.h b/include/hw/virtio/virtio-rtc.h new file mode 100644 index 0000000000..51aa35201a --- /dev/null +++ b/include/hw/virtio/virtio-rtc.h @@ -0,0 +1,22 @@ +/* + * Virtio RTC device + * + * Copyright (c) 2026 Kuan-Wei Chiu + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef QEMU_VIRTIO_RTC_H +#define QEMU_VIRTIO_RTC_H + +#include "hw/virtio/virtio.h" +#include "qom/object.h" + +#define TYPE_VIRTIO_RTC "virtio-rtc-device" +OBJECT_DECLARE_SIMPLE_TYPE(VirtIORtc, VIRTIO_RTC) + +struct VirtIORtc { + VirtIODevice parent_obj; + VirtQueue *vq; +}; + +#endif --=20 2.53.0.473.g4a7958ca14-goog