diff mbox series

[v2,1/3] platform/x86/intel/tpmi: Add defines to get version information

Message ID 20231003184916.1860084-2-srinivas.pandruvada@linux.intel.com (mailing list archive)
State Accepted, archived
Headers show
Series TPMI feature major/minor version check | expand

Commit Message

srinivas pandruvada Oct. 3, 2023, 6:49 p.m. UTC
Add defines to get major and minor version from a TPMI version field
value. This will avoid code duplication to convert in every feature
driver. Also add define for invalid version field.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
v2:
No change

 include/linux/intel_tpmi.h | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Andy Shevchenko Oct. 4, 2023, 12:59 p.m. UTC | #1
On Tue, Oct 03, 2023 at 11:49:14AM -0700, Srinivas Pandruvada wrote:
> Add defines to get major and minor version from a TPMI version field
> value. This will avoid code duplication to convert in every feature
> driver. Also add define for invalid version field.

...

> +#define TPMI_VERSION_INVALID	0xff

I would make it clearer with (GENMASK(7, 5) | GENMASK(4, 0))
or even with specific masks defined and used in both cases:
#def

#define TPMI_MINVER_MASK	GENMASK(4, 0)
#define TPMI_MAJVER_MASK	GENMASK(7, 5)

#define TPMI_VERSION_INVALID	(TPMI_MINVER_MASK | TPMI_MAJVER_MASK)

#define TPMI_MINOR_VERSION(val)	FIELD_GET(TPMI_MINVER_MASK, val)
#define TPMI_MAJOR_VERSION(val)	FIELD_GET(TPMI_MAJVER_MASK, val)

> +#define TPMI_MINOR_VERSION(val)	FIELD_GET(GENMASK(4, 0), val)
> +#define TPMI_MAJOR_VERSION(val)	FIELD_GET(GENMASK(7, 5), val)
Ilpo Järvinen Oct. 4, 2023, 1:03 p.m. UTC | #2
On Wed, 4 Oct 2023, Andy Shevchenko wrote:

> On Tue, Oct 03, 2023 at 11:49:14AM -0700, Srinivas Pandruvada wrote:
> > Add defines to get major and minor version from a TPMI version field
> > value. This will avoid code duplication to convert in every feature
> > driver. Also add define for invalid version field.
> 
> ...
> 
> > +#define TPMI_VERSION_INVALID	0xff
> 
> I would make it clearer with (GENMASK(7, 5) | GENMASK(4, 0))
> or even with specific masks defined and used in both cases:
> #def
> 
> #define TPMI_MINVER_MASK	GENMASK(4, 0)
> #define TPMI_MAJVER_MASK	GENMASK(7, 5)
> 
> #define TPMI_VERSION_INVALID	(TPMI_MINVER_MASK | TPMI_MAJVER_MASK)
> 
> #define TPMI_MINOR_VERSION(val)	FIELD_GET(TPMI_MINVER_MASK, val)
> #define TPMI_MAJOR_VERSION(val)	FIELD_GET(TPMI_MAJVER_MASK, val)
> 
> > +#define TPMI_MINOR_VERSION(val)	FIELD_GET(GENMASK(4, 0), val)
> > +#define TPMI_MAJOR_VERSION(val)	FIELD_GET(GENMASK(7, 5), val)

In case somebody does, please do it on top of the existing changes as
I already applied the series.
srinivas pandruvada Oct. 4, 2023, 6:37 p.m. UTC | #3
On Wed, 2023-10-04 at 15:59 +0300, Andy Shevchenko wrote:
> On Tue, Oct 03, 2023 at 11:49:14AM -0700, Srinivas Pandruvada wrote:
> > Add defines to get major and minor version from a TPMI version
> > field
> > value. This will avoid code duplication to convert in every feature
> > driver. Also add define for invalid version field.
> 
> ...
> 
> > +#define TPMI_VERSION_INVALID   0xff
> 
> I would make it clearer with (GENMASK(7, 5) | GENMASK(4, 0))
> or even with specific masks defined and used in both cases:
> #def
> 
> #define TPMI_MINVER_MASK        GENMASK(4, 0)
> #define TPMI_MAJVER_MASK        GENMASK(7, 5)
> 
> #define TPMI_VERSION_INVALID    (TPMI_MINVER_MASK | TPMI_MAJVER_MASK)
> 
> #define TPMI_MINOR_VERSION(val) FIELD_GET(TPMI_MINVER_MASK, val)
> #define TPMI_MAJOR_VERSION(val) FIELD_GET(TPMI_MAJVER_MASK, val)
> 
> > +#define TPMI_MINOR_VERSION(val)        FIELD_GET(GENMASK(4, 0),
> > val)
> > +#define TPMI_MAJOR_VERSION(val)        FIELD_GET(GENMASK(7, 5),
> > val)

OK. Will add another patch on top.

Thanks,
Srinivas

>
diff mbox series

Patch

diff --git a/include/linux/intel_tpmi.h b/include/linux/intel_tpmi.h
index 04d937ad4dc4..ee07393445f9 100644
--- a/include/linux/intel_tpmi.h
+++ b/include/linux/intel_tpmi.h
@@ -6,6 +6,12 @@ 
 #ifndef _INTEL_TPMI_H_
 #define _INTEL_TPMI_H_
 
+#include <linux/bitfield.h>
+
+#define TPMI_VERSION_INVALID	0xff
+#define TPMI_MINOR_VERSION(val)	FIELD_GET(GENMASK(4, 0), val)
+#define TPMI_MAJOR_VERSION(val)	FIELD_GET(GENMASK(7, 5), val)
+
 /**
  * struct intel_tpmi_plat_info - Platform information for a TPMI device instance
  * @package_id:	CPU Package id