2022-06-03 00:12:53

by Lee, Kah Jing

[permalink] [raw]
Subject: [PATCH 1/2] drivers: misc: intel_sysid: Add sysid from arch to drivers

From: Kah Jing Lee <[email protected]>

Add sysid driver. The Altera(Intel) Sysid component is generally part of an
FPGA design. The component can be hotplugged when the FPGA is reconfigured.
This patch fixes the driver to support the component being hotplugged.

Usage:
cat /sys/bus/platform/devices/soc:base_fpga_region/
soc:base_fpga_region:fpga_pr_region0/[addr.sysid]/sysid/id
cat /sys/bus/platform/devices/soc:base_fpga_region/
soc:base_fpga_region:fpga_pr_region0/[addr.sysid]/sysid/timestamp

Signed-off-by: Ley Foon Tan <[email protected]>
Signed-off-by: Kah Jing Lee <[email protected]>
---
drivers/misc/Kconfig | 9 +++
drivers/misc/Makefile | 1 +
drivers/misc/intel_sysid.c | 142 +++++++++++++++++++++++++++++++++++++
3 files changed, 152 insertions(+)
create mode 100644 drivers/misc/intel_sysid.c

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 41d2bb0ae23a..a31489cc092c 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -483,6 +483,15 @@ config OPEN_DICE

If unsure, say N.

+config INTEL_SYSID
+ tristate "Intel System ID"
+ help
+ This enables Intel System ID soft core driver.
+ Say Y here if you want to build a driver for Intel System ID driver.
+
+ To compile this driver as a module, choose M here: the
+ module will be called intel_sysid. If unsure, say N here.
+
source "drivers/misc/c2port/Kconfig"
source "drivers/misc/eeprom/Kconfig"
source "drivers/misc/cb710/Kconfig"
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 70e800e9127f..301c854b4cd3 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_PCH_PHUB) += pch_phub.o
obj-y += ti-st/
obj-y += lis3lv02d/
obj-$(CONFIG_ALTERA_STAPL) +=altera-stapl/
+obj-$(CONFIG_INTEL_SYSID) += intel_sysid.o
obj-$(CONFIG_INTEL_MEI) += mei/
obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/
obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lattice-ecp3-config.o
diff --git a/drivers/misc/intel_sysid.c b/drivers/misc/intel_sysid.c
new file mode 100644
index 000000000000..f9ba0ee97c3a
--- /dev/null
+++ b/drivers/misc/intel_sysid.c
@@ -0,0 +1,142 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright Intel Corporation (C) 2022.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Credit:
+ * Walter Goossens
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/io.h>
+#include <linux/of.h>
+
+#define DRV_NAME "intel_sysid"
+
+struct intel_sysid {
+ void __iomem *regs;
+};
+
+/* System ID Registers*/
+#define SYSID_REG_ID (0x0)
+#define SYSID_REG_TIMESTAMP (0x4)
+
+static ssize_t id_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct intel_sysid *sysid = dev_get_drvdata(dev);
+
+ return sprintf(buf, "%u\n", readl(sysid->regs + SYSID_REG_ID));
+}
+
+static ssize_t timestamp_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ unsigned int reg;
+ struct tm timestamp;
+ struct intel_sysid *sysid = dev_get_drvdata(dev);
+
+ reg = readl(sysid->regs + SYSID_REG_TIMESTAMP);
+
+ time64_to_tm(reg, 0, &timestamp);
+
+ return sprintf(buf, "%u (%u-%u-%u %u:%u:%u UTC)\n", reg,
+ (unsigned int)(timestamp.tm_year + 1900),
+ timestamp.tm_mon + 1, timestamp.tm_mday, timestamp.tm_hour,
+ timestamp.tm_min, timestamp.tm_sec);
+}
+
+static DEVICE_ATTR_RO(id);
+static DEVICE_ATTR_RO(timestamp);
+
+static struct attribute *intel_sysid_attrs[] = {
+ &dev_attr_id.attr,
+ &dev_attr_timestamp.attr,
+ NULL,
+};
+
+struct attribute_group intel_sysid_attr_group = {
+ .name = "sysid",
+ .attrs = intel_sysid_attrs,
+};
+
+static int intel_sysid_probe(struct platform_device *pdev)
+{
+ struct intel_sysid *sysid;
+ struct resource *regs;
+
+ sysid = devm_kzalloc(&pdev->dev, sizeof(struct intel_sysid),
+ GFP_KERNEL);
+ if (!sysid)
+ return -ENOMEM;
+
+ regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!regs)
+ return -ENXIO;
+
+ sysid->regs = devm_ioremap_resource(&pdev->dev, regs);
+ if (IS_ERR(sysid->regs))
+ return PTR_ERR(sysid->regs);
+
+ platform_set_drvdata(pdev, sysid);
+
+ return sysfs_create_group(&pdev->dev.kobj, &intel_sysid_attr_group);
+}
+
+static int intel_sysid_remove(struct platform_device *pdev)
+{
+ sysfs_remove_group(&pdev->dev.kobj, &intel_sysid_attr_group);
+
+ platform_set_drvdata(pdev, NULL);
+ return 0;
+}
+
+static const struct of_device_id intel_sysid_match[] = {
+ { .compatible = "intel,socfpga-sysid-1.0" },
+ { /* Sentinel */ }
+};
+
+MODULE_DEVICE_TABLE(of, intel_sysid_match);
+
+static struct platform_driver intel_sysid_platform_driver = {
+ .driver = {
+ .name = DRV_NAME,
+ .owner = THIS_MODULE,
+ .of_match_table = of_match_ptr(intel_sysid_match),
+ },
+ .probe = intel_sysid_probe,
+ .remove = intel_sysid_remove,
+};
+
+static int __init intel_sysid_init(void)
+{
+ return platform_driver_register(&intel_sysid_platform_driver);
+}
+
+static void __exit intel_sysid_exit(void)
+{
+ platform_driver_unregister(&intel_sysid_platform_driver);
+}
+
+module_init(intel_sysid_init);
+module_exit(intel_sysid_exit);
+
+MODULE_AUTHOR("Ley Foon Tan <[email protected]>");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Altera System ID driver");
+MODULE_ALIAS("platform:" DRV_NAME);
--
2.25.1



2022-06-03 17:54:34

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 1/2] drivers: misc: intel_sysid: Add sysid from arch to drivers

On Fri, Jun 03, 2022 at 12:57:33PM +0800, [email protected] wrote:
> From: Kah Jing Lee <[email protected]>
>
> > On Thu, Jun 02, 2022 at 08:22:13PM +0800, [email protected] wrote:
> > > From: Kah Jing Lee <[email protected]>
> > >
> > > Add sysid driver. The Altera(Intel) Sysid component is generally part of an
> > > FPGA design. The component can be hotplugged when the FPGA is reconfigured.
> > > This patch fixes the driver to support the component being hotplugged.
> > >
> > > Usage:
> > > cat /sys/bus/platform/devices/soc:base_fpga_region/
> > > soc:base_fpga_region:fpga_pr_region0/[addr.sysid]/sysid/id
> > > cat /sys/bus/platform/devices/soc:base_fpga_region/
> > > soc:base_fpga_region:fpga_pr_region0/[addr.sysid]/sysid/timestamp
> > >
> > > Signed-off-by: Ley Foon Tan <[email protected]>
> > > Signed-off-by: Kah Jing Lee <[email protected]>
> >
> > Please work with the Intel open source group as there are some internal
> > Intel requirements that you have not met here in order to be able to
> > submit a patch for external people to review. I'll refrain from
> > reviewing or even considering this to be able to be accepted this until
> > that happens.
>
> Will update the license header and commit message, and resent.
> Thanks for pointing out =).

That is not the requirements that you need to follow sorry, please
contact the Intel open source group to find out the rules that Intel
submissions must follow at this point in time.

thanks,

greg k-h

2022-06-04 15:09:29

by Lee, Kah Jing

[permalink] [raw]
Subject: Re: [PATCH 1/2] drivers: misc: intel_sysid: Add sysid from arch to drivers

From: Kah Jing Lee <[email protected]>

> On Thu, Jun 02, 2022 at 08:22:13PM +0800, [email protected] wrote:
> > From: Kah Jing Lee <[email protected]>
> >
> > Add sysid driver. The Altera(Intel) Sysid component is generally part of an
> > FPGA design. The component can be hotplugged when the FPGA is reconfigured.
> > This patch fixes the driver to support the component being hotplugged.
> >
> > Usage:
> > cat /sys/bus/platform/devices/soc:base_fpga_region/
> > soc:base_fpga_region:fpga_pr_region0/[addr.sysid]/sysid/id
> > cat /sys/bus/platform/devices/soc:base_fpga_region/
> > soc:base_fpga_region:fpga_pr_region0/[addr.sysid]/sysid/timestamp
> >
> > Signed-off-by: Ley Foon Tan <[email protected]>
> > Signed-off-by: Kah Jing Lee <[email protected]>
>
> Please work with the Intel open source group as there are some internal
> Intel requirements that you have not met here in order to be able to
> submit a patch for external people to review. I'll refrain from
> reviewing or even considering this to be able to be accepted this until
> that happens.

Will update the license header and commit message, and resent.
Thanks for pointing out =).

> good luck!
>
> greg k-h

2022-06-06 04:20:22

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 1/2] drivers: misc: intel_sysid: Add sysid from arch to drivers

On Thu, Jun 02, 2022 at 08:22:13PM +0800, [email protected] wrote:
> From: Kah Jing Lee <[email protected]>
>
> Add sysid driver. The Altera(Intel) Sysid component is generally part of an
> FPGA design. The component can be hotplugged when the FPGA is reconfigured.
> This patch fixes the driver to support the component being hotplugged.
>
> Usage:
> cat /sys/bus/platform/devices/soc:base_fpga_region/
> soc:base_fpga_region:fpga_pr_region0/[addr.sysid]/sysid/id
> cat /sys/bus/platform/devices/soc:base_fpga_region/
> soc:base_fpga_region:fpga_pr_region0/[addr.sysid]/sysid/timestamp
>
> Signed-off-by: Ley Foon Tan <[email protected]>
> Signed-off-by: Kah Jing Lee <[email protected]>

Please work with the Intel open source group as there are some internal
Intel requirements that you have not met here in order to be able to
submit a patch for external people to review. I'll refrain from
reviewing or even considering this to be able to be accepted this until
that happens.

good luck!

greg k-h

2022-06-08 03:46:09

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 1/2] drivers: misc: intel_sysid: Add sysid from arch to drivers

Hi,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on soc/for-next staging/staging-testing v5.19-rc1 next-20220607]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/intel-lab-lkp/linux/commits/kah-jing-lee-intel-com/New-driver-for-Intel-Altera-FPGA-System-ID-softIP/20220602-202553
base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git 90de6805267f8c79cd2b1a36805071e257c39b5c
config: s390-randconfig-r024-20220607 (https://download.01.org/0day-ci/archive/20220607/[email protected]/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project b92436efcb7813fc481b30f2593a4907568d917a)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install s390 cross compiling tool for clang build
# apt-get install binutils-s390x-linux-gnu
# https://github.com/intel-lab-lkp/linux/commit/bfd40e4202ce67e500bedec9eaaf9b7207f980d0
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review kah-jing-lee-intel-com/New-driver-for-Intel-Altera-FPGA-System-ID-softIP/20220602-202553
git checkout bfd40e4202ce67e500bedec9eaaf9b7207f980d0
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=s390 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

In file included from drivers/misc/intel_sysid.c:26:
In file included from include/linux/io.h:13:
In file included from arch/s390/include/asm/io.h:75:
include/asm-generic/io.h:464:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __raw_readb(PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:477:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:37:59: note: expanded from macro '__le16_to_cpu'
#define __le16_to_cpu(x) __swab16((__force __u16)(__le16)(x))
^
include/uapi/linux/swab.h:102:54: note: expanded from macro '__swab16'
#define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
^
In file included from drivers/misc/intel_sysid.c:26:
In file included from include/linux/io.h:13:
In file included from arch/s390/include/asm/io.h:75:
include/asm-generic/io.h:490:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:35:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:115:54: note: expanded from macro '__swab32'
#define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
^
In file included from drivers/misc/intel_sysid.c:26:
In file included from include/linux/io.h:13:
In file included from arch/s390/include/asm/io.h:75:
include/asm-generic/io.h:501:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writeb(value, PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:511:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:521:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:609:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:617:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:625:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:634:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:643:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:652:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
>> drivers/misc/intel_sysid.c:109:34: warning: unused variable 'intel_sysid_match' [-Wunused-const-variable]
static const struct of_device_id intel_sysid_match[] = {
^
13 warnings generated.


vim +/intel_sysid_match +109 drivers/misc/intel_sysid.c

108
> 109 static const struct of_device_id intel_sysid_match[] = {
110 { .compatible = "intel,socfpga-sysid-1.0" },
111 { /* Sentinel */ }
112 };
113

--
0-DAY CI Kernel Test Service
https://01.org/lkp