From nobody Thu Mar 13 06:08:00 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FFE31A9B5D; Wed, 19 Feb 2025 04:06:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739937989; cv=none; b=A84VSggr8R5cWOfWbdV0/uqEDAJoR7f7FZh8vc5bhcC0zBT7PPmkb+LoNgZu7vAzT6sziTTLrLcw6sMHQU5el4BQLhv0k9xwpGCyoayT8Xie6Bo4lc71Ev9kDC6ggN5kDQWq7no0lYmhTcAeBAZIm/m6tYmgM9/zsHs+dD5CiUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739937989; c=relaxed/simple; bh=pUkZSj/tfBs/oZt+X70pqcLcwYGtRQ0gQE603IfmtCQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Oqmu5tNFA1PA7uyhAq07C2pjZlgaGVYETSgj60l64AJ33nAe4RAy4KwJMHS66c29snCL1oLWAcei4GiLcJx7BdcIbBlh8fKcqMfSpf5K8SqvAfUW9GXKvEcQjU3eZQywPMvzbhdv9q1+HiCNoVYWj+0BlepVdje1Qdfu+fcgO/E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=iiV0H0xc; arc=none smtp.client-ip=192.198.163.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="iiV0H0xc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739937988; x=1771473988; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pUkZSj/tfBs/oZt+X70pqcLcwYGtRQ0gQE603IfmtCQ=; b=iiV0H0xce7ys+qaN0dgZ3NkE3Xz3aN2P9Jb1shkVa3O95JkuYgO+zokZ qt0pE3IZ4K1sTF+YkckjdHjY9yUXJi0WebgEquj5/NmOk4yuQ/Nx5exRz C8PMmFlDUQCUwLlIazKQo+aZdAlH2TqUuQRzYMl8YhA6OE6+5/zIe5BLl u9/+lsGtBtZ48yF8DCodcuizbfWVoNdecNEXJ3/Yws5fdwtIlZ4MT528L wRSXw/EnDN8wTyivTbf6l5rnWfBRLevmijMcC5rTW8mSbs263jG460VYF W698nAt0iPiJPgw1RYTJKtsy166rzjyOLYWuvxSbeWheOgOcZJVAoSgDs Q==; X-CSE-ConnectionGUID: IS/LYk5nT9+fJcAySYNW1g== X-CSE-MsgGUID: Rda5vMpwT6K/YT2PRYYanw== X-IronPort-AV: E=McAfee;i="6700,10204,11348"; a="44579145" X-IronPort-AV: E=Sophos;i="6.13,296,1732608000"; d="scan'208";a="44579145" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2025 20:06:27 -0800 X-CSE-ConnectionGUID: f6XxMUGfSgSeJqeq0imdoA== X-CSE-MsgGUID: ftxI5lQFSK+pvqUXQRWaVA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,296,1732608000"; d="scan'208";a="119703807" Received: from inlubt0246.iind.intel.com ([10.191.24.87]) by fmviesa004.fm.intel.com with ESMTP; 18 Feb 2025 20:06:23 -0800 From: subramanian.mohan@intel.com To: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, gregkh@linuxfoundation.org, andriy.shevchenko@linux.intel.com, giometti@enneenne.com, tglx@linutronix.de, corbet@lwn.net Cc: eddie.dong@intel.com, christopher.s.hall@intel.com, pandith.n@intel.com, thejesh.reddy.t.r@intel.com, david.zage@intel.com, srinivasan.chinnadurai@intel.com, subramanian.mohan@intel.com Subject: [PATCH v15 1/4] pps: generators: replace copy of pps-gen info struct with const pointer Date: Wed, 19 Feb 2025 09:36:15 +0530 Message-Id: <20250219040618.70962-2-subramanian.mohan@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20250219040618.70962-1-subramanian.mohan@intel.com> References: <20250219040618.70962-1-subramanian.mohan@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Subramanian Mohan Some PPS generator drivers may need to retrieve a pointer to their internal data while executing the PPS generator enable() method. During the driver registration the pps_gen_device pointer is returned from the framework, and for that reason, there is difficulty in getting generator driver data back in the enable function. We won't be able to use container_of macro as it results in static assert, and we might end up in using static pointer. To solve the issue and to get back the generator driver data back, we should not copy the struct pps_gen_source_info within the struct pps_gen_device during the registration stage, but simply save the pointer of the driver one. In this manner, driver may get a pointer to their internal data as shown below: struct pps_gen_foo_data_s { ... struct pps_gen_source_info gen_info; struct pps_gen_device *pps_gen; ... }; static int __init pps_gen_foo_init(void) { struct pps_gen_foo_data_s *foo; ... foo->pps_gen =3D pps_gen_register_source(&foo->gen_info); ... } Then, in the enable() method, we can retrieve the pointer to the main struct by using the code below: static int pps_gen_foo_enable(struct pps_gen_device *pps_gen, bool enable) { struct pps_gen_foo_data_s *foo =3D container_of(pps_gen->info, struct pps_gen_foo_data_s, gen_info); ... } Signed-off-by: Rodolfo Giometti Tested-by: Subramanian Mohan Suggested-by: Andy Shevchenko Reviewed-by: Andy Shevchenko Signed-off-by: Subramanian Mohan --- Documentation/driver-api/pps.rst | 3 +-- drivers/pps/generators/pps_gen-dummy.c | 2 +- drivers/pps/generators/pps_gen.c | 14 +++++++------- drivers/pps/generators/sysfs.c | 6 +++--- include/linux/pps_gen_kernel.h | 4 ++-- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Documentation/driver-api/pps.rst b/Documentation/driver-api/pp= s.rst index 71ad04c82d6c..04f1b88778fc 100644 --- a/Documentation/driver-api/pps.rst +++ b/Documentation/driver-api/pps.rst @@ -206,8 +206,7 @@ To do so the class pps-gen has been added. PPS generato= rs can be registered in the kernel by defining a struct pps_gen_source_info as follows:: =20 - static struct pps_gen_source_info pps_gen_dummy_info =3D { - .name =3D "dummy", + static const struct pps_gen_source_info pps_gen_dummy_info =3D { .use_system_clock =3D true, .get_time =3D pps_gen_dummy_get_time, .enable =3D pps_gen_dummy_enable, diff --git a/drivers/pps/generators/pps_gen-dummy.c b/drivers/pps/generator= s/pps_gen-dummy.c index b284c200cbe5..55de4aecf35e 100644 --- a/drivers/pps/generators/pps_gen-dummy.c +++ b/drivers/pps/generators/pps_gen-dummy.c @@ -61,7 +61,7 @@ static int pps_gen_dummy_enable(struct pps_gen_device *pp= s_gen, bool enable) * The PPS info struct */ =20 -static struct pps_gen_source_info pps_gen_dummy_info =3D { +static const struct pps_gen_source_info pps_gen_dummy_info =3D { .use_system_clock =3D true, .get_time =3D pps_gen_dummy_get_time, .enable =3D pps_gen_dummy_enable, diff --git a/drivers/pps/generators/pps_gen.c b/drivers/pps/generators/pps_= gen.c index ca592f1736f4..5b8bb454913c 100644 --- a/drivers/pps/generators/pps_gen.c +++ b/drivers/pps/generators/pps_gen.c @@ -66,7 +66,7 @@ static long pps_gen_cdev_ioctl(struct file *file, if (ret) return -EFAULT; =20 - ret =3D pps_gen->info.enable(pps_gen, status); + ret =3D pps_gen->info->enable(pps_gen, status); if (ret) return ret; pps_gen->enabled =3D status; @@ -76,7 +76,7 @@ static long pps_gen_cdev_ioctl(struct file *file, case PPS_GEN_USESYSTEMCLOCK: dev_dbg(pps_gen->dev, "PPS_GEN_USESYSTEMCLOCK\n"); =20 - ret =3D put_user(pps_gen->info.use_system_clock, uiuarg); + ret =3D put_user(pps_gen->info->use_system_clock, uiuarg); if (ret) return -EFAULT; =20 @@ -175,7 +175,7 @@ static int pps_gen_register_cdev(struct pps_gen_device = *pps_gen) devt =3D MKDEV(MAJOR(pps_gen_devt), pps_gen->id); =20 cdev_init(&pps_gen->cdev, &pps_gen_cdev_fops); - pps_gen->cdev.owner =3D pps_gen->info.owner; + pps_gen->cdev.owner =3D pps_gen->info->owner; =20 err =3D cdev_add(&pps_gen->cdev, devt, 1); if (err) { @@ -183,8 +183,8 @@ static int pps_gen_register_cdev(struct pps_gen_device = *pps_gen) MAJOR(pps_gen_devt), pps_gen->id); goto free_ida; } - pps_gen->dev =3D device_create(pps_gen_class, pps_gen->info.parent, devt, - pps_gen, "pps-gen%d", pps_gen->id); + pps_gen->dev =3D device_create(pps_gen_class, pps_gen->info->parent, devt, + pps_gen, "pps-gen%d", pps_gen->id); if (IS_ERR(pps_gen->dev)) { err =3D PTR_ERR(pps_gen->dev); goto del_cdev; @@ -225,7 +225,7 @@ static void pps_gen_unregister_cdev(struct pps_gen_devi= ce *pps_gen) * Return: the PPS generator device in case of success, and ERR_PTR(errno) * otherwise. */ -struct pps_gen_device *pps_gen_register_source(struct pps_gen_source_info = *info) +struct pps_gen_device *pps_gen_register_source(const struct pps_gen_source= _info *info) { struct pps_gen_device *pps_gen; int err; @@ -235,7 +235,7 @@ struct pps_gen_device *pps_gen_register_source(struct p= ps_gen_source_info *info) err =3D -ENOMEM; goto pps_gen_register_source_exit; } - pps_gen->info =3D *info; + pps_gen->info =3D info; pps_gen->enabled =3D false; =20 init_waitqueue_head(&pps_gen->queue); diff --git a/drivers/pps/generators/sysfs.c b/drivers/pps/generators/sysfs.c index faf8b1c6d202..6d6bc0006fea 100644 --- a/drivers/pps/generators/sysfs.c +++ b/drivers/pps/generators/sysfs.c @@ -19,7 +19,7 @@ static ssize_t system_show(struct device *dev, struct dev= ice_attribute *attr, { struct pps_gen_device *pps_gen =3D dev_get_drvdata(dev); =20 - return sysfs_emit(buf, "%d\n", pps_gen->info.use_system_clock); + return sysfs_emit(buf, "%d\n", pps_gen->info->use_system_clock); } static DEVICE_ATTR_RO(system); =20 @@ -30,7 +30,7 @@ static ssize_t time_show(struct device *dev, struct devic= e_attribute *attr, struct timespec64 time; int ret; =20 - ret =3D pps_gen->info.get_time(pps_gen, &time); + ret =3D pps_gen->info->get_time(pps_gen, &time); if (ret) return ret; =20 @@ -49,7 +49,7 @@ static ssize_t enable_store(struct device *dev, struct de= vice_attribute *attr, if (ret) return ret; =20 - ret =3D pps_gen->info.enable(pps_gen, status); + ret =3D pps_gen->info->enable(pps_gen, status); if (ret) return ret; pps_gen->enabled =3D status; diff --git a/include/linux/pps_gen_kernel.h b/include/linux/pps_gen_kernel.h index 022ea0ac4440..6214c8aa2e02 100644 --- a/include/linux/pps_gen_kernel.h +++ b/include/linux/pps_gen_kernel.h @@ -43,7 +43,7 @@ struct pps_gen_source_info { =20 /* The main struct */ struct pps_gen_device { - struct pps_gen_source_info info; /* PSS generator info */ + const struct pps_gen_source_info *info; /* PSS generator info */ bool enabled; /* PSS generator status */ =20 unsigned int event; @@ -70,7 +70,7 @@ extern const struct attribute_group *pps_gen_groups[]; */ =20 extern struct pps_gen_device *pps_gen_register_source( - struct pps_gen_source_info *info); + const struct pps_gen_source_info *info); extern void pps_gen_unregister_source(struct pps_gen_device *pps_gen); extern void pps_gen_event(struct pps_gen_device *pps_gen, unsigned int event, void *data); --=20 2.35.3 From nobody Thu Mar 13 06:08:00 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D832316D9AF; Wed, 19 Feb 2025 04:06:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739937994; cv=none; b=mMGcVpg6R+/7ZSakS5E+OPLWdTlp5yqqtBSx5+nt3rUvoV2Wq6xJaLvFANJ56YM1dlgb7DNVVpexyPGurQ9U4QECLkuOz2YJSh8MyGANDm1tdHUyeeKb4kiPi9sBFH1oNNcxSAd9WvRHK/voq258NLb7dyIhvHg5mEpB3N17djk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739937994; c=relaxed/simple; bh=lXnHQogEmGMJQi1neQwdfYeWkUx0B3xCb1duJK0bZjQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UfgZw9oQbyW6Xlrc9mnrvHAkGGfW+aOz9Hxv5Ee3AgE3jbL56dlR68LiKPZBa9UhWYjwuzDy7QlFHQnx5J13PKP9RRZzHcKz9j6ky4vB2zmrISsbxJMwS+akkdRfmbFQcGz7K0cMfW6xuTFuRY9YZGO3uQz7t3qDFRj8sbjHLaQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=YmnNpnT+; arc=none smtp.client-ip=192.198.163.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="YmnNpnT+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739937992; x=1771473992; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lXnHQogEmGMJQi1neQwdfYeWkUx0B3xCb1duJK0bZjQ=; b=YmnNpnT+ItIGWoqjr6nKNPRbeh8YGlcMxuyxVpneoyZD5oTsqEq17PQ0 LC2uakvEUIo70zlrydTwWbqdHUFovsSNJp10XmxRXTjS/eqbzb9qFldyN GdMDO5Sj+ZbT6A0RvFmevYrmWrVrmR7VlODJmn02jZV+7VwzxiJHPyKR1 c3rAovDZVcabrqYK9vXAkbAyv5fvAxA5j8a34WmLqE2FjxtiqbUT+4odX iXZ4JzGxb3cneMyPmITB8sWpgSjU94IddotQjYm0XovFqUA2+q4CMcgok SEKH50t/i5RDDgp5DkSe7QUmdt0riV3BoQLKmlOob4J7EDvxJTiQBCC9m w==; X-CSE-ConnectionGUID: v0Ns4nlsRDS8/Lvtbbii+w== X-CSE-MsgGUID: /yerbthERAOCQs3jzOUAlA== X-IronPort-AV: E=McAfee;i="6700,10204,11348"; a="44579155" X-IronPort-AV: E=Sophos;i="6.13,296,1732608000"; d="scan'208";a="44579155" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2025 20:06:32 -0800 X-CSE-ConnectionGUID: 8pd5GBMaRFSJU58HZSxbOw== X-CSE-MsgGUID: AMeRCDlGQ5igfjfv3PA2AA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,296,1732608000"; d="scan'208";a="119703821" Received: from inlubt0246.iind.intel.com ([10.191.24.87]) by fmviesa004.fm.intel.com with ESMTP; 18 Feb 2025 20:06:27 -0800 From: subramanian.mohan@intel.com To: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, gregkh@linuxfoundation.org, andriy.shevchenko@linux.intel.com, giometti@enneenne.com, tglx@linutronix.de, corbet@lwn.net Cc: eddie.dong@intel.com, christopher.s.hall@intel.com, pandith.n@intel.com, thejesh.reddy.t.r@intel.com, david.zage@intel.com, srinivasan.chinnadurai@intel.com, subramanian.mohan@intel.com Subject: [PATCH v15 2/4] pps: generators: Add PPS Generator TIO Driver Date: Wed, 19 Feb 2025 09:36:16 +0530 Message-Id: <20250219040618.70962-3-subramanian.mohan@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20250219040618.70962-1-subramanian.mohan@intel.com> References: <20250219040618.70962-1-subramanian.mohan@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Subramanian Mohan The Intel Timed IO PPS generator driver outputs a PPS signal using dedicated hardware that is more accurate than software actuated PPS. The Timed IO hardware generates output events using the ART timer. The ART timer period varies based on platform type, but is less than 100 nanoseconds for all current platforms. Timed IO output accuracy is within 1 ART period. PPS output is enabled by writing '1' the 'enable' sysfs attribute. The driver uses hrtimers to schedule a wake-up 10 ms before each event (edge) target time. At wakeup, the driver converts the target time in terms of CLOCK_REALTIME to ART trigger time and writes this to the Timed IO hardware. The Timed IO hardware generates an event precisely at the requested system time without software involvement. Co-developed-by: Christopher Hall Signed-off-by: Christopher Hall Co-developed-by: Pandith N Signed-off-by: Pandith N Co-developed-by: Thejesh Reddy T R Signed-off-by: Thejesh Reddy T R Signed-off-by: Lakshmi Sowjanya D Reviewed-by: Eddie Dong Reviewed-by: Andy Shevchenko Acked-by: Rodolfo Giometti Signed-off-by: Subramanian Mohan --- drivers/pps/generators/Kconfig | 16 ++ drivers/pps/generators/Makefile | 1 + drivers/pps/generators/pps_gen_tio.c | 272 +++++++++++++++++++++++++++ 3 files changed, 289 insertions(+) create mode 100644 drivers/pps/generators/pps_gen_tio.c diff --git a/drivers/pps/generators/Kconfig b/drivers/pps/generators/Kconfig index cd94bf3bfaf2..b3f340ed3163 100644 --- a/drivers/pps/generators/Kconfig +++ b/drivers/pps/generators/Kconfig @@ -31,4 +31,20 @@ config PPS_GENERATOR_PARPORT utilizes STROBE pin of a parallel port to send PPS signals. It uses parport abstraction layer and hrtimers to precisely control the signal. =20 +config PPS_GENERATOR_TIO + tristate "TIO PPS signal generator" + depends on X86 && CPU_SUP_INTEL + help + If you say yes here you get support for a PPS TIO signal generator + which generates a pulse at a prescribed time based on the system clock. + It uses time translation and hrtimers to precisely generate a pulse. + This hardware is present on 2019 and newer Intel CPUs. However, this + driver is not useful without adding highly specialized hardware outside + the Linux system to observe these pulses. + + To compile this driver as a module, choose M here: the module + will be called pps_gen_tio. + + If unsure, say N. + endif # PPS_GENERATOR diff --git a/drivers/pps/generators/Makefile b/drivers/pps/generators/Makef= ile index dc1aa5a4688b..e109920e8a2d 100644 --- a/drivers/pps/generators/Makefile +++ b/drivers/pps/generators/Makefile @@ -8,5 +8,6 @@ obj-$(CONFIG_PPS_GENERATOR) :=3D pps_gen_core.o =20 obj-$(CONFIG_PPS_GENERATOR_DUMMY) +=3D pps_gen-dummy.o obj-$(CONFIG_PPS_GENERATOR_PARPORT) +=3D pps_gen_parport.o +obj-$(CONFIG_PPS_GENERATOR_TIO) +=3D pps_gen_tio.o =20 ccflags-$(CONFIG_PPS_DEBUG) :=3D -DDEBUG diff --git a/drivers/pps/generators/pps_gen_tio.c b/drivers/pps/generators/= pps_gen_tio.c new file mode 100644 index 000000000000..6c46b46c66cd --- /dev/null +++ b/drivers/pps/generators/pps_gen_tio.c @@ -0,0 +1,272 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Intel PPS signal Generator Driver + * + * Copyright (C) 2024 Intel Corporation + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define TIOCTL 0x00 +#define TIOCOMPV 0x10 +#define TIOEC 0x30 + +/* Control Register */ +#define TIOCTL_EN BIT(0) +#define TIOCTL_DIR BIT(1) +#define TIOCTL_EP GENMASK(3, 2) +#define TIOCTL_EP_RISING_EDGE FIELD_PREP(TIOCTL_EP, 0) +#define TIOCTL_EP_FALLING_EDGE FIELD_PREP(TIOCTL_EP, 1) +#define TIOCTL_EP_TOGGLE_EDGE FIELD_PREP(TIOCTL_EP, 2) + +/* Safety time to set hrtimer early */ +#define SAFE_TIME_NS (10 * NSEC_PER_MSEC) + +#define MAGIC_CONST (NSEC_PER_SEC - SAFE_TIME_NS) +#define ART_HW_DELAY_CYCLES 2 + +struct pps_tio { + struct pps_gen_source_info gen_info; + struct pps_gen_device *pps_gen; + struct hrtimer timer; + void __iomem *base; + u32 prev_count; + spinlock_t lock; + struct device *dev; +}; + +static inline u32 pps_tio_read(u32 offset, struct pps_tio *tio) +{ + return readl(tio->base + offset); +} + +static inline void pps_ctl_write(u32 value, struct pps_tio *tio) +{ + writel(value, tio->base + TIOCTL); +} + +/* + * For COMPV register, It's safer to write + * higher 32-bit followed by lower 32-bit + */ +static inline void pps_compv_write(u64 value, struct pps_tio *tio) +{ + hi_lo_writeq(value, tio->base + TIOCOMPV); +} + +static inline ktime_t first_event(struct pps_tio *tio) +{ + return ktime_set(ktime_get_real_seconds() + 1, MAGIC_CONST); +} + +static u32 pps_tio_disable(struct pps_tio *tio) +{ + u32 ctrl; + + ctrl =3D pps_tio_read(TIOCTL, tio); + pps_compv_write(0, tio); + + ctrl &=3D ~TIOCTL_EN; + pps_ctl_write(ctrl, tio); + tio->pps_gen->enabled =3D false; + tio->prev_count =3D 0; + return ctrl; +} + +static void pps_tio_enable(struct pps_tio *tio) +{ + u32 ctrl; + + ctrl =3D pps_tio_read(TIOCTL, tio); + ctrl |=3D TIOCTL_EN; + pps_ctl_write(ctrl, tio); + tio->pps_gen->enabled =3D true; +} + +static void pps_tio_direction_output(struct pps_tio *tio) +{ + u32 ctrl; + + ctrl =3D pps_tio_disable(tio); + + /* + * We enable the device, be sure that the + * 'compare' value is invalid + */ + pps_compv_write(0, tio); + + ctrl &=3D ~(TIOCTL_DIR | TIOCTL_EP); + ctrl |=3D TIOCTL_EP_TOGGLE_EDGE; + pps_ctl_write(ctrl, tio); + pps_tio_enable(tio); +} + +static bool pps_generate_next_pulse(ktime_t expires, struct pps_tio *tio) +{ + u64 art; + + if (!ktime_real_to_base_clock(expires, CSID_X86_ART, &art)) { + pps_tio_disable(tio); + return false; + } + + pps_compv_write(art - ART_HW_DELAY_CYCLES, tio); + return true; +} + +static enum hrtimer_restart hrtimer_callback(struct hrtimer *timer) +{ + ktime_t expires, now; + u32 event_count; + struct pps_tio *tio =3D container_of(timer, struct pps_tio, timer); + + guard(spinlock)(&tio->lock); + + /* + * Check if any event is missed. + * If an event is missed, TIO will be disabled. + */ + event_count =3D pps_tio_read(TIOEC, tio); + if (tio->prev_count && tio->prev_count =3D=3D event_count) + goto err; + tio->prev_count =3D event_count; + + expires =3D hrtimer_get_expires(timer); + + now =3D ktime_get_real(); + if (now - expires >=3D SAFE_TIME_NS) + goto err; + + tio->pps_gen->enabled =3D pps_generate_next_pulse(expires + SAFE_TIME_NS,= tio); + if (!tio->pps_gen->enabled) + return HRTIMER_NORESTART; + + hrtimer_forward(timer, now, NSEC_PER_SEC / 2); + return HRTIMER_RESTART; + +err: + dev_err(tio->dev, "Event missed, Disabling Timed I/O"); + pps_tio_disable(tio); + pps_gen_event(tio->pps_gen, PPS_GEN_EVENT_MISSEDPULSE, NULL); + return HRTIMER_NORESTART; +} + +static int pps_tio_gen_enable(struct pps_gen_device *pps_gen, bool enable) +{ + struct pps_tio *tio =3D container_of(pps_gen->info, struct pps_tio, gen_i= nfo); + + if (!timekeeping_clocksource_has_base(CSID_X86_ART)) { + dev_err_once(tio->dev, "PPS cannot be used as clock is not related to AR= T"); + return -ENODEV; + } + + guard(spinlock_irqsave)(&tio->lock); + if (enable && !pps_gen->enabled) { + pps_tio_direction_output(tio); + hrtimer_start(&tio->timer, first_event(tio), HRTIMER_MODE_ABS); + } else if (!enable && pps_gen->enabled) { + hrtimer_cancel(&tio->timer); + pps_tio_disable(tio); + } + + return 0; +} + +static int pps_tio_get_time(struct pps_gen_device *pps_gen, + struct timespec64 *time) +{ + struct system_time_snapshot snap; + + ktime_get_snapshot(&snap); + *time =3D ktime_to_timespec64(snap.real); + + return 0; +} + +static int pps_gen_tio_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct pps_tio *tio; + + if (!(cpu_feature_enabled(X86_FEATURE_TSC_KNOWN_FREQ) && + cpu_feature_enabled(X86_FEATURE_ART))) { + dev_warn(dev, "TSC/ART is not enabled"); + return -ENODEV; + } + + tio =3D devm_kzalloc(dev, sizeof(*tio), GFP_KERNEL); + if (!tio) + return -ENOMEM; + + tio->gen_info.use_system_clock =3D true; + tio->gen_info.enable =3D pps_tio_gen_enable; + tio->gen_info.get_time =3D pps_tio_get_time; + tio->gen_info.owner =3D THIS_MODULE; + + tio->pps_gen =3D pps_gen_register_source(&tio->gen_info); + if (IS_ERR(tio->pps_gen)) + return PTR_ERR(tio->pps_gen); + + tio->dev =3D dev; + tio->base =3D devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(tio->base)) + return PTR_ERR(tio->base); + + pps_tio_disable(tio); + hrtimer_init(&tio->timer, CLOCK_REALTIME, HRTIMER_MODE_ABS); + tio->timer.function =3D hrtimer_callback; + spin_lock_init(&tio->lock); + platform_set_drvdata(pdev, &tio); + + return 0; +} + +static void pps_gen_tio_remove(struct platform_device *pdev) +{ + struct pps_tio *tio =3D platform_get_drvdata(pdev); + + hrtimer_cancel(&tio->timer); + pps_tio_disable(tio); + pps_gen_unregister_source(tio->pps_gen); +} + +static const struct acpi_device_id intel_pmc_tio_acpi_match[] =3D { + { "INTC1021" }, + { "INTC1022" }, + { "INTC1023" }, + { "INTC1024" }, + {} +}; +MODULE_DEVICE_TABLE(acpi, intel_pmc_tio_acpi_match); + +static struct platform_driver pps_gen_tio_driver =3D { + .probe =3D pps_gen_tio_probe, + .remove =3D pps_gen_tio_remove, + .driver =3D { + .name =3D "intel-pps-gen-tio", + .acpi_match_table =3D intel_pmc_tio_acpi_match, + }, +}; +module_platform_driver(pps_gen_tio_driver); + +MODULE_AUTHOR("Christopher Hall "); +MODULE_AUTHOR("Lakshmi Sowjanya D "); +MODULE_AUTHOR("Pandith N "); +MODULE_AUTHOR("Thejesh Reddy T R "); +MODULE_AUTHOR("Subramanian Mohan "); +MODULE_DESCRIPTION("Intel PMC Time-Aware IO Generator Driver"); +MODULE_LICENSE("GPL"); --=20 2.35.3 From nobody Thu Mar 13 06:08:00 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E145B1AF0BC; Wed, 19 Feb 2025 04:06:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739937997; cv=none; b=T/Fi0OynEgfkJVwm3cC7xu5WAJfmX+B9R+S+OECPa5/g4fYWQOTAl0Tleqlu3S1jM0O6n13V/ZuiSS2WTXLV72GUkJgF+EIdNmCTU16e8tl5TDzT/L0tizynqhFofYEEnqvSYTz7VVXCdVIXMW5Bh5vIs6oqCUa9bGTmCAKr0TU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739937997; c=relaxed/simple; bh=syILJRFICNuwfc1hr1rVckmFJF5JIVDUFUmPw1y28sU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NcbhsnOHfB7IR+wZmJ+vqm5sKqSxlweiRhr9TaLmVjK61qGzudHe2kVleGEJGXsf/uEqavgotqx5bIo2Nt1/f4b+rf/MvByrcvlny9xgucKOIy5yBXjSAuRQ2CFkgKa7i+d+YJY5TozwW1G/ZpF7rU9ltkOGWhCy2fcvMKQ0KX0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=MyurA9Kc; arc=none smtp.client-ip=192.198.163.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MyurA9Kc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739937996; x=1771473996; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=syILJRFICNuwfc1hr1rVckmFJF5JIVDUFUmPw1y28sU=; b=MyurA9KcgBYfK3XOTaOXuTnzdE1y6iJjPyHMLWlvubC505Ps+EVS3JtT WHzxqG2DEFzSZlpOUm0c6Zp5X2cWs7I3wRlLfHt4VQLf8FSihk0abVAYD kDs5hbVIeZHm1NT8d4AP1tZgCIzQPFpZ9m5/NYORmVIWas91FqEvyO92M ElH8GtxSE4fddcBq/886IgUZM7ESTUjTVovZEHkramOWyx3Ypxa4W+xQx Rmmpwu4RSNTTkzKX+x8KSPuTcaOCvvxOiTMdRaBc7TWfGL6mdE5TzI4zS Lk+lFBXraQAQ9y8SBU25cCw1475BmbNczG/bohKHT/21LuAqzbTrmWuHS Q==; X-CSE-ConnectionGUID: bF2uM5nZSUyALFxMf1ZOzA== X-CSE-MsgGUID: bmr8g4NrQz6ANy79NBvYAw== X-IronPort-AV: E=McAfee;i="6700,10204,11348"; a="44579163" X-IronPort-AV: E=Sophos;i="6.13,296,1732608000"; d="scan'208";a="44579163" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2025 20:06:36 -0800 X-CSE-ConnectionGUID: RIQ/jYwtScS0e80qqyim9Q== X-CSE-MsgGUID: zzfwmuvcSJmLCx4Zej6V2w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,296,1732608000"; d="scan'208";a="119703828" Received: from inlubt0246.iind.intel.com ([10.191.24.87]) by fmviesa004.fm.intel.com with ESMTP; 18 Feb 2025 20:06:31 -0800 From: subramanian.mohan@intel.com To: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, gregkh@linuxfoundation.org, andriy.shevchenko@linux.intel.com, giometti@enneenne.com, tglx@linutronix.de, corbet@lwn.net Cc: eddie.dong@intel.com, christopher.s.hall@intel.com, pandith.n@intel.com, thejesh.reddy.t.r@intel.com, david.zage@intel.com, srinivasan.chinnadurai@intel.com, subramanian.mohan@intel.com Subject: [PATCH v15 3/4] Documentation: driver-api: pps: Add Intel Timed I/O PPS generator Date: Wed, 19 Feb 2025 09:36:17 +0530 Message-Id: <20250219040618.70962-4-subramanian.mohan@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20250219040618.70962-1-subramanian.mohan@intel.com> References: <20250219040618.70962-1-subramanian.mohan@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Subramanian Mohan Add Intel Timed I/O PPS usage instructions. Co-developed-by: Pandith N Signed-off-by: Pandith N Signed-off-by: Lakshmi Sowjanya D Reviewed-by: Andy Shevchenko Acked-by: Rodolfo Giometti Signed-off-by: Subramanian Mohan --- Documentation/driver-api/pps.rst | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Documentation/driver-api/pps.rst b/Documentation/driver-api/pp= s.rst index 04f1b88778fc..598729f9cd27 100644 --- a/Documentation/driver-api/pps.rst +++ b/Documentation/driver-api/pps.rst @@ -285,3 +285,27 @@ delay between assert and clear edge as small as possib= le to reduce system latencies. But if it is too small slave won't be able to capture clear edge transition. The default of 30us should be good enough in most situations. The delay can be selected using 'delay' pps_gen_parport module parameter. + + +Intel Timed I/O PPS signal generator +------------------------------------ + +Intel Timed I/O is a high precision device, present on 2019 and newer Intel +CPUs, that can generate PPS signals. + +Timed I/O and system time are both driven by same hardware clock. The sign= al +is generated with a precision of ~20 nanoseconds. The generated PPS signal +is used to synchronize an external device with system clock. For example, +it can be used to share your clock with a device that receives PPS signal, +generated by Timed I/O device. There are dedicated Timed I/O pins to deliv= er +the PPS signal to an external device. + +Usage of Intel Timed I/O as PPS generator: + +Start generating PPS signal:: + + $echo 1 > /sys/class/pps-gen/pps-genx/enable + +Stop generating PPS signal:: + + $echo 0 > /sys/class/pps-gen/pps-genx/enable --=20 2.35.3 From nobody Thu Mar 13 06:08:00 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC2381B3953; Wed, 19 Feb 2025 04:06:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739938001; cv=none; b=CuCbSJJVTxlvyjT115G8Kje5VaGxj1ywAZLJGx0kOvyqwuwf25EmstTHEYZseUj1ccN3NmWApaGpKEHG14dQRd5oACXdW4Edb3oXi4eSjedFbHle+OtjpBv2Sps7KkHGNX5IyRh8h43NXNPQHNOOfK1cmWaCfQcz0U8+NnRLFSo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739938001; c=relaxed/simple; bh=qv6BirrjVU0NWcV17jTzqJq8GK7JkoueKqhKnIlpvlU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Dle2+M3yERjN5RGcQuH8O3zZKMTeLw0gL1ROjExE497Qb3aCgY0d5G+nnOHctj4hVpaekIVCmHmmGPzvOJ5EOS9hv4og0ilod3K/C9buEkB7lXUzEOzW+STtj9SMkadfBsy+PjhRvJ6ewVKfd6pTsgx6n/6JQKXqzYkeiFImAHg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=fwlUtMqE; arc=none smtp.client-ip=192.198.163.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="fwlUtMqE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739938000; x=1771474000; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qv6BirrjVU0NWcV17jTzqJq8GK7JkoueKqhKnIlpvlU=; b=fwlUtMqE5X2oLJragcPxqGRFxaTvtXV6HbqexxNGz/9aVzYYxzI/6AEM xQHlOv3oRYFmemoAgE6CZUVAq8Ci7qNyIYU5T55wlOPT1xhCKgTFiJnIg SF9e7ErJ95pybMbCASLGYikq3IpMhH1bK3KeGyw7frAXXfMXVpTnQNPWc LtltYz8XHDaC5fPELdvzNmYneDKMYEWgOeudKqL/KoFRAJMnXT04UFHcB BTSY8xxpn3tCb6ktAkaE3qfwpNSsya6M0mocqmdYvow1wmtsszJwlPE7x uYNXJNykCZtWF9yDHVkw9PGP0SQlWbWvlBKlwNIaPdt7D1Af0yMr2wy/P g==; X-CSE-ConnectionGUID: KFHQory9QgSOtAoMfKC15g== X-CSE-MsgGUID: WlHa29ziRZCk+7F8hIYsTA== X-IronPort-AV: E=McAfee;i="6700,10204,11348"; a="44579171" X-IronPort-AV: E=Sophos;i="6.13,296,1732608000"; d="scan'208";a="44579171" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2025 20:06:40 -0800 X-CSE-ConnectionGUID: Qy/EUbnCTFuWIl/l5kQjHw== X-CSE-MsgGUID: eY1chkT4Ssasj26Y1d4uug== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,296,1732608000"; d="scan'208";a="119703838" Received: from inlubt0246.iind.intel.com ([10.191.24.87]) by fmviesa004.fm.intel.com with ESMTP; 18 Feb 2025 20:06:36 -0800 From: subramanian.mohan@intel.com To: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, gregkh@linuxfoundation.org, andriy.shevchenko@linux.intel.com, giometti@enneenne.com, tglx@linutronix.de, corbet@lwn.net Cc: eddie.dong@intel.com, christopher.s.hall@intel.com, pandith.n@intel.com, thejesh.reddy.t.r@intel.com, david.zage@intel.com, srinivasan.chinnadurai@intel.com, subramanian.mohan@intel.com Subject: [PATCH v15 4/4] ABI: pps: Add ABI documentation for Intel TIO Date: Wed, 19 Feb 2025 09:36:18 +0530 Message-Id: <20250219040618.70962-5-subramanian.mohan@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20250219040618.70962-1-subramanian.mohan@intel.com> References: <20250219040618.70962-1-subramanian.mohan@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Subramanian Mohan Document sysfs interface for Intel Timed I/O PPS driver. Signed-off-by: Lakshmi Sowjanya D Signed-off-by: Subramanian Mohan --- Documentation/ABI/testing/sysfs-pps-gen-tio | 6 ++++++ MAINTAINERS | 1 + 2 files changed, 7 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-pps-gen-tio diff --git a/Documentation/ABI/testing/sysfs-pps-gen-tio b/Documentation/AB= I/testing/sysfs-pps-gen-tio new file mode 100644 index 000000000000..3c34ff17a335 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-pps-gen-tio @@ -0,0 +1,6 @@ +What: /sys/class/pps-gen/pps-genx/enable +Date: April 2025 +KernelVersion: 6.15 +Contact: Subramanian Mohan +Description: + Enable or disable PPS TIO generator output. diff --git a/MAINTAINERS b/MAINTAINERS index efee40ea589f..35e254d0a9db 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18912,6 +18912,7 @@ S: Maintained W: http://wiki.enneenne.com/index.php/LinuxPPS_support F: Documentation/ABI/testing/sysfs-pps F: Documentation/ABI/testing/sysfs-pps-gen +F: Documentation/ABI/testing/sysfs-pps-gen-tio F: Documentation/devicetree/bindings/pps/pps-gpio.yaml F: Documentation/driver-api/pps.rst F: drivers/pps/ --=20 2.35.3