[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v10 09/45] hw/cxl/device: Timestamp implementation (8.2.9.3)
From: |
Jonathan Cameron |
Subject: |
[PATCH v10 09/45] hw/cxl/device: Timestamp implementation (8.2.9.3) |
Date: |
Fri, 29 Apr 2022 15:40:34 +0100 |
From: Ben Widawsky <ben.widawsky@intel.com>
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 <ben.widawsky@intel.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
---
hw/cxl/cxl-mailbox-utils.c | 42 +++++++++++++++++++++++++++++++++++++
include/hw/cxl/cxl_device.h | 6 ++++++
2 files changed, 48 insertions(+)
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 = 0x03,
+ #define GET 0x0
+ #define SET 0x1
};
/* 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);
+/* 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 = 0;
+
+ if (cxl_dstate->timestamp.set) {
+ /* First find the delta from the last time the host set the time. */
+ time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
+ delta = time - cxl_dstate->timestamp.last_set;
+ final_time = cxl_dstate->timestamp.host_set + delta;
+ }
+
+ /* Then adjust the actual time */
+ stq_le_p(cmd->payload, final_time);
+ *len = 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 = true;
+ cxl_dstate->timestamp.last_set = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
+
+ cxl_dstate->timestamp.host_set = le64_to_cpu(*(uint64_t *)cmd->payload);
+
+ *len = 0;
+ return CXL_MBOX_SUCCESS;
+}
+
static QemuUUID cel_uuid;
#define IMMEDIATE_CONFIG_CHANGE (1 << 1)
+#define IMMEDIATE_POLICY_CHANGE (1 << 3)
#define IMMEDIATE_LOG_CHANGE (1 << 4)
static struct cxl_cmd cxl_cmd_set[256][256] = {
@@ -120,6 +160,8 @@ static struct cxl_cmd cxl_cmd_set[256][256] = {
cmd_events_get_interrupt_policy, 0, 0 },
[EVENTS][SET_INTERRUPT_POLICY] = { "EVENTS_SET_INTERRUPT_POLICY",
cmd_events_set_interrupt_policy, 4, IMMEDIATE_CONFIG_CHANGE },
+ [TIMESTAMP][GET] = { "TIMESTAMP_GET", cmd_timestamp_get, 0, 0 },
+ [TIMESTAMP][SET] = { "TIMESTAMP_SET", cmd_timestamp_set, 8,
IMMEDIATE_POLICY_CHANGE },
};
void cxl_process_mailbox(CXLDeviceState *cxl_dstate)
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;
};
+ struct {
+ bool set;
+ uint64_t last_set;
+ uint64_t host_set;
+ } timestamp;
+
/* memory region for persistent memory, HDM */
uint64_t pmem_size;
} CXLDeviceState;
--
2.32.0
- [PATCH v10 00/45] CXl 2.0 emulation Support, Jonathan Cameron, 2022/04/29
- [PATCH v10 01/45] hw/pci/cxl: Add a CXL component type (interface), Jonathan Cameron, 2022/04/29
- [PATCH v10 02/45] hw/cxl/component: Introduce CXL components (8.1.x, 8.2.5), Jonathan Cameron, 2022/04/29
- [PATCH v10 03/45] MAINTAINERS: Add entry for Compute Express Link Emulation, Jonathan Cameron, 2022/04/29
- [PATCH v10 04/45] hw/cxl/device: Introduce a CXL device (8.2.8), Jonathan Cameron, 2022/04/29
- [PATCH v10 05/45] hw/cxl/device: Implement the CAP array (8.2.8.1-2), Jonathan Cameron, 2022/04/29
- [PATCH v10 06/45] hw/cxl/device: Implement basic mailbox (8.2.8.4), Jonathan Cameron, 2022/04/29
- [PATCH v10 07/45] hw/cxl/device: Add memory device utilities, Jonathan Cameron, 2022/04/29
- [PATCH v10 08/45] hw/cxl/device: Add cheap EVENTS implementation (8.2.9.1), Jonathan Cameron, 2022/04/29
- [PATCH v10 09/45] hw/cxl/device: Timestamp implementation (8.2.9.3),
Jonathan Cameron <=
- [PATCH v10 10/45] hw/cxl/device: Add log commands (8.2.9.4) + CEL, Jonathan Cameron, 2022/04/29
- [PATCH v10 11/45] hw/pxb: Use a type for realizing expanders, Jonathan Cameron, 2022/04/29
- [PATCH v10 12/45] hw/pci/cxl: Create a CXL bus type, Jonathan Cameron, 2022/04/29
- [PATCH v10 13/45] cxl: Machine level control on whether CXL support is enabled, Jonathan Cameron, 2022/04/29
- [PATCH v10 14/45] hw/pxb: Allow creation of a CXL PXB (host bridge), Jonathan Cameron, 2022/04/29
- [PATCH v10 15/45] qtest/cxl: Introduce initial test for pxb-cxl only., Jonathan Cameron, 2022/04/29
- [PATCH v10 16/45] hw/cxl/rp: Add a root port, Jonathan Cameron, 2022/04/29
- [PATCH v10 17/45] hw/cxl/device: Add a memory device (8.2.8.5), Jonathan Cameron, 2022/04/29
- [PATCH v10 18/45] hw/cxl/device: Implement MMIO HDM decoding (8.2.5.12), Jonathan Cameron, 2022/04/29
- [PATCH v10 19/45] hw/cxl/device: Add some trivial commands, Jonathan Cameron, 2022/04/29