From nobody Thu Dec 18 14:44:52 2025 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1652698592; cv=none; d=zohomail.com; s=zohoarc; b=j1cfjjYAICQE3A03re9iG3ypJ14IsrpWdlom9MHI+xTU9MfGNC5mHCd1eN0A6WXWOH7dsC6hFpobdIP+Nf4ZKf7JkUlSIaZoPwKH3YfsBvOM9zOLaiJnKjJCijS/0cTr1DrVfnIMLhs+waSlJwVqvA2ZMxA/gP4dFraLcQILIBo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652698592; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IFG9Wcb2I+Dwof4JoAiK8doNzqoFhr25ibITD6Homqo=; b=dKrzoj+TVFKDvQpgo0fiE4enwM1dzdp4wJCEe67ShCOf/Hxq39sGjAInwagRA7X+Gs0x+RMCXaa07wlK4rFvkgxctIXsAGLpD06sMO08/kC/lSWufvtAWqd3hn8JmC3/dl08uYkeoIA9ldMrm4o616EMF+lgIaf6I1jh9bsxsDQ= 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 1652698592681923.7110212133998; Mon, 16 May 2022 03:56:32 -0700 (PDT) Received: from localhost ([::1]:38344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nqYOt-0001HL-Bb for importer@patchew.org; Mon, 16 May 2022 06:56:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nqY5Q-000613-C3 for qemu-devel@nongnu.org; Mon, 16 May 2022 06:36:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:57153) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nqY5M-0005BP-83 for qemu-devel@nongnu.org; Mon, 16 May 2022 06:36:23 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-577-VbMUz2-mOpW164Mw3GIvtg-1; Mon, 16 May 2022 06:36:17 -0400 Received: by mail-wr1-f69.google.com with SMTP id s16-20020adfeb10000000b0020cc4e5e683so3800778wrn.6 for ; Mon, 16 May 2022 03:36:17 -0700 (PDT) Received: from redhat.com ([2.55.141.66]) by smtp.gmail.com with ESMTPSA id d9-20020adfc089000000b0020cf071a168sm8662890wrf.29.2022.05.16.03.36.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 03:36:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652697378; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IFG9Wcb2I+Dwof4JoAiK8doNzqoFhr25ibITD6Homqo=; b=WJvgSWepGdbxx0bkTtZOF9l3eoASNqOO4nGlCZ2CrQZYvLK9nlSu9orFqPcAGLmgFX5ubp 4Pg2KXqMg+ZbWJRf34lZ4X16+bdT6oMAIeLLM8khGrYCFeGJpFwAqF6RVWdHjstd9oDuUE XV/byumq3w7HBRvZSYP33b+Z4wf2KCQ= X-MC-Unique: VbMUz2-mOpW164Mw3GIvtg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=IFG9Wcb2I+Dwof4JoAiK8doNzqoFhr25ibITD6Homqo=; b=uJSVDpV9l0c5fSEpJbxVuWuYNncvLjW18Ieo1OEsKifBzr39Rkigmk169mhG6r8X9v foyKoSGysT8AD6bgHrG40DH7Ea+yvqMX1Ag+4Fhw8HGyBa3iBYpHQ/MDv8K5Jn9aLKc4 rHtn/PXpYAI61yDSHZFwJ+DmNbl6+gQ10tfU3qrY9N5BhBwv+PXcRcL0oXPc/ZKgDvl/ MdDYDMfvLk3Cddt1MJAein3TPSz94Kq6fhQVK48xCXR+CcTMurIS/6ZCIQwefi2tgFP7 66J7jc4hlOPZRW8DPE5a4rTpqShGQXU41OaI8hqVwcFk4fkewvqebyOgU/oPCEcTju31 WMyQ== X-Gm-Message-State: AOAM533vY2PZWvQnlhDCGhAnc+NwgvMts4BeNSvsNSjZXI9J873a02aO pPgmbiL+ueL5C/vkxdTb1Gt6Ul+tHG7BEQtVIMX5QoTh25qrln9qc0oWJG4xNmHdbKTfOMssagq y3bXph4WjBN5zAr0zaz7v4KEaMu0stn1bAGlCKeG0BXzCiIlDhjGWr2xvfUph X-Received: by 2002:a5d:5887:0:b0:20c:83c9:b72 with SMTP id n7-20020a5d5887000000b0020c83c90b72mr13582625wrf.588.1652697376255; Mon, 16 May 2022 03:36:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWQoOeV9UJK3JOykUanwleO4b1I407FmfTqXTrdEqSxlXdOyIAl/Oq64O/Cf33WhOKGMRB/w== X-Received: by 2002:a5d:5887:0:b0:20c:83c9:b72 with SMTP id n7-20020a5d5887000000b0020c83c90b72mr13582600wrf.588.1652697375997; Mon, 16 May 2022 03:36:15 -0700 (PDT) Date: Mon, 16 May 2022 06:36:12 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Ben Widawsky , Jonathan Cameron , Alex =?utf-8?Q?Benn=C3=A9e?= Subject: [PULL 11/91] hw/cxl/device: Timestamp implementation (8.2.9.3) Message-ID: <20220516095448.507876-12-mst@redhat.com> References: <20220516095448.507876-1-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <20220516095448.507876-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent 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=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1652698594513100003 From: Ben Widawsky Errata F4 to CXL 2.0 clarified the meaning of the timer as the sum of the value set with the timestamp set command and the number of nano seconds since it was last set. Signed-off-by: Ben Widawsky Signed-off-by: Jonathan Cameron Reviewed-by: Alex Benn=C3=A9e Message-Id: <20220429144110.25167-10-Jonathan.Cameron@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/cxl/cxl_device.h | 6 ++++++ hw/cxl/cxl-mailbox-utils.c | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index 954205653e..797a22ddb4 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -111,6 +111,12 @@ typedef struct cxl_device_state { size_t cel_size; }; =20 + struct { + bool set; + uint64_t last_set; + uint64_t host_set; + } timestamp; + /* memory region for persistent memory, HDM */ uint64_t pmem_size; } CXLDeviceState; diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index fb1f53f48e..4584aa31f7 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -44,6 +44,9 @@ enum { #define CLEAR_RECORDS 0x1 #define GET_INTERRUPT_POLICY 0x2 #define SET_INTERRUPT_POLICY 0x3 + TIMESTAMP =3D 0x03, + #define GET 0x0 + #define SET 0x1 }; =20 /* 8.2.8.4.5.1 Command Return Codes */ @@ -106,9 +109,46 @@ DEFINE_MAILBOX_HANDLER_NOP(events_clear_records); DEFINE_MAILBOX_HANDLER_ZEROED(events_get_interrupt_policy, 4); DEFINE_MAILBOX_HANDLER_NOP(events_set_interrupt_policy); =20 +/* 8.2.9.3.1 */ +static ret_code cmd_timestamp_get(struct cxl_cmd *cmd, + CXLDeviceState *cxl_dstate, + uint16_t *len) +{ + uint64_t time, delta; + uint64_t final_time =3D 0; + + if (cxl_dstate->timestamp.set) { + /* First find the delta from the last time the host set the time. = */ + time =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + delta =3D time - cxl_dstate->timestamp.last_set; + final_time =3D cxl_dstate->timestamp.host_set + delta; + } + + /* Then adjust the actual time */ + stq_le_p(cmd->payload, final_time); + *len =3D 8; + + return CXL_MBOX_SUCCESS; +} + +/* 8.2.9.3.2 */ +static ret_code cmd_timestamp_set(struct cxl_cmd *cmd, + CXLDeviceState *cxl_dstate, + uint16_t *len) +{ + cxl_dstate->timestamp.set =3D true; + cxl_dstate->timestamp.last_set =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUA= L); + + cxl_dstate->timestamp.host_set =3D le64_to_cpu(*(uint64_t *)cmd->paylo= ad); + + *len =3D 0; + return CXL_MBOX_SUCCESS; +} + static QemuUUID cel_uuid; =20 #define IMMEDIATE_CONFIG_CHANGE (1 << 1) +#define IMMEDIATE_POLICY_CHANGE (1 << 3) #define IMMEDIATE_LOG_CHANGE (1 << 4) =20 static struct cxl_cmd cxl_cmd_set[256][256] =3D { @@ -120,6 +160,8 @@ static struct cxl_cmd cxl_cmd_set[256][256] =3D { cmd_events_get_interrupt_policy, 0, 0 }, [EVENTS][SET_INTERRUPT_POLICY] =3D { "EVENTS_SET_INTERRUPT_POLICY", cmd_events_set_interrupt_policy, 4, IMMEDIATE_CONFIG_CHANGE }, + [TIMESTAMP][GET] =3D { "TIMESTAMP_GET", cmd_timestamp_get, 0, 0 }, + [TIMESTAMP][SET] =3D { "TIMESTAMP_SET", cmd_timestamp_set, 8, IMMEDIAT= E_POLICY_CHANGE }, }; =20 void cxl_process_mailbox(CXLDeviceState *cxl_dstate) --=20 MST