Skip to contentSkip to conversation

tpm: move struct tpm_class_ops to drivers/char/tpm/tpm.h

PATCH In review Jarkko Sakkinen 2 participants 9 messages Sep 2, 2016 – Sep 5, 2016 TPM device driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tpm: move struct tpm_class_ops to drivers/char/tpm/tpm.h

The struct tpm_class_ops is not used outside the TPM driver. Thus, it can be safely move to drivers/char/tpm/tpm.h.

---
 drivers/char/tpm/tpm.h | 13 +++++++++++++
 include/linux/tpm.h    | 14 --------------
 2 files changed, 13 insertions(+), 14 deletions(-)
drivers/char/tpm/tpm.h +13 -0
index 3e952fb..e1d277d 100644
@@ -138,6 +138,19 @@ enum tpm2_startup_types {
 
 #define TPM_PPI_VERSION_LEN		3
 
+struct tpm_class_ops {
+	unsigned int flags;
+	const u8 req_complete_mask;
+	const u8 req_complete_val;
+	bool (*req_canceled)(struct tpm_chip *chip, u8 status);
+	int (*recv) (struct tpm_chip *chip, u8 *buf, size_t len);
+	int (*send) (struct tpm_chip *chip, u8 *buf, size_t len);
+	void (*cancel) (struct tpm_chip *chip);
+	u8 (*status) (struct tpm_chip *chip);
+	bool (*update_timeouts)(struct tpm_chip *chip,
+				unsigned long *timeout_cap);
+};
+
 enum tpm_chip_flags {
 	TPM_CHIP_FLAG_REGISTERED	= BIT(0),
 	TPM_CHIP_FLAG_TPM2		= BIT(1),
include/linux/tpm.h +0 -14
index da158f0..76ba592 100644
@@ -37,20 +37,6 @@ enum TPM_OPS_FLAGS {
 	TPM_OPS_AUTO_STARTUP = BIT(0),
 };
 
-struct tpm_class_ops {
-	unsigned int flags;
-	const u8 req_complete_mask;
-	const u8 req_complete_val;
-	bool (*req_canceled)(struct tpm_chip *chip, u8 status);
-	int (*recv) (struct tpm_chip *chip, u8 *buf, size_t len);
-	int (*send) (struct tpm_chip *chip, u8 *buf, size_t len);
-	void (*cancel) (struct tpm_chip *chip);
-	u8 (*status) (struct tpm_chip *chip);
-	bool (*update_timeouts)(struct tpm_chip *chip,
-				unsigned long *timeout_cap);
-
-};
-
 #if defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE)
 
 extern int tpm_is_tpm2(u32 chip_num);
Signature · 1 line
2.7.4
#1 lore raw
Quoted 2 lines · Jarkko Sakkinen

The struct tpm_class_ops is not used outside the TPM driver. Thus, it can be safely move to drivers/char/tpm/tpm.h.

No, this is the wrong direction.

The goal is to make things more like other subsystems, so we should be moving struct tpm_chip into the public header, and that requires ops to be in the public header.

This is why I put ops here in the first place.

Jason

#2 lore raw
Quoted 11 lines · Jason Gunthorpe
Quoted 2 lines · Jarkko Sakkinen

The struct tpm_class_ops is not used outside the TPM driver. Thus, it can be safely move to drivers/char/tpm/tpm.h.

No, this is the wrong direction.

The goal is to make things more like other subsystems, so we should be moving struct tpm_chip into the public header, and that requires ops to be in the public header.

This is why I put ops here in the first place.

I'm OK with it as long as you explain why this is necessary. I see no use for them outside the TPM subsystem.

Quoted 1 line

Jason

/Jarkko

#3 lore raw
Quoted 7 lines · Jarkko Sakkinen
Quoted 6 lines · Jason Gunthorpe
Quoted 2 lines · Jarkko Sakkinen

The struct tpm_class_ops is not used outside the TPM driver. Thus, it can be safely move to drivers/char/tpm/tpm.h.

No, this is the wrong direction.

Quoted 8 lines
Quoted 5 lines

The goal is to make things more like other subsystems, so we should be moving struct tpm_chip into the public header, and that requires ops to be in the public header.

This is why I put ops here in the first place.

I'm OK with it as long as you explain why this is necessary. I see no use for them outside the TPM subsystem.

That is because the users out side the subsystem are Doing it Wrong.

eg this:

extern int tpm_is_tpm2(u32 chip_num);

Should be:

extern int tpm_is_tpm2(struct tpm_chip *chip);

And same for all other examples.

The 'chip_num' thing is bonkers.

Jason

------------------------------------------------------------------------------

#4 lore raw
Quoted 23 lines · Jason Gunthorpe
Quoted 7 lines · Jarkko Sakkinen
Quoted 6 lines · Jason Gunthorpe
Quoted 2 lines · Jarkko Sakkinen

The struct tpm_class_ops is not used outside the TPM driver. Thus, it can be safely move to drivers/char/tpm/tpm.h.

No, this is the wrong direction.

Quoted 8 lines
Quoted 5 lines

The goal is to make things more like other subsystems, so we should be moving struct tpm_chip into the public header, and that requires ops to be in the public header.

This is why I put ops here in the first place.

I'm OK with it as long as you explain why this is necessary. I see no use for them outside the TPM subsystem.

That is because the users out side the subsystem are Doing it Wrong.

eg this:

extern int tpm_is_tpm2(u32 chip_num);

Quoted 7 lines

Should be:

extern int tpm_is_tpm2(struct tpm_chip *chip);

And same for all other examples.

The 'chip_num' thing is bonkers.

OK, how would one get the chip instance?

/Jarkko

------------------------------------------------------------------------------

#5 lore raw
Quoted 26 lines · Jarkko Sakkinen
Quoted 25 lines · Jason Gunthorpe
Quoted 7 lines · Jarkko Sakkinen
Quoted 6 lines · Jason Gunthorpe
Quoted 2 lines · Jarkko Sakkinen

The struct tpm_class_ops is not used outside the TPM driver. Thus, it can be safely move to drivers/char/tpm/tpm.h.

No, this is the wrong direction.

Quoted 8 lines
Quoted 5 lines

The goal is to make things more like other subsystems, so we should be moving struct tpm_chip into the public header, and that requires ops to be in the public header.

This is why I put ops here in the first place.

I'm OK with it as long as you explain why this is necessary. I see no use for them outside the TPM subsystem.

That is because the users out side the subsystem are Doing it Wrong.

eg this:

extern int tpm_is_tpm2(u32 chip_num);

Should be:

Quoted 7 lines
Quoted 5 lines

extern int tpm_is_tpm2(struct tpm_chip *chip);

And same for all other examples.

The 'chip_num' thing is bonkers.

OK, how would one get the chip instance?

This still doesn't explain why moving the structures inside the driver would be wrong. Even if outside callers would use a pointer the structure could be opaque.

/Jarkko

#6 lore raw
Quoted 2 lines · Jarkko Sakkinen
Quoted 2 lines

OK, how would one get the chip instance?

Most subsystems have a get function that returns a kref'd pointer. For TPM all we really need today is a 'get_default_tpm_for_ns' kind of function.

Quoted 3 lines

This still doesn't explain why moving the structures inside the driver would be wrong. Even if outside callers would use a pointer the structure could be opaque.

For instance, if we did a get function then the 'put' function would be an inline around dev_put and that needs to see inside the chip.

This is a well trodden pattern in the kernel, there is no reason to do something different for tpm.

Jason

------------------------------------------------------------------------------

#7 lore raw
Quoted 7 lines · Jason Gunthorpe
Quoted 2 lines · Jarkko Sakkinen
Quoted 2 lines

OK, how would one get the chip instance?

Most subsystems have a get function that returns a kref'd pointer. For TPM all we really need today is a 'get_default_tpm_for_ns' kind of function.

Sorry, but I have no idea what you are talking about.

This does not imply that these structure definitions need to be in include/linux/tpm.h since you are talking something that does not exist.

Quoted 6 lines
Quoted 3 lines

This still doesn't explain why moving the structures inside the driver would be wrong. Even if outside callers would use a pointer the structure could be opaque.

For instance, if we did a get function then the 'put' function would be an inline around dev_put and that needs to see inside the chip.

I do not see any get/put functionality in include/linux/tpm.h.

Quoted 2 lines

This is a well trodden pattern in the kernel, there is no reason to do something different for tpm.

/Jarkko

#8 lore raw
Quoted 10 lines · Jarkko Sakkinen
Quoted 7 lines · Jason Gunthorpe
Quoted 2 lines · Jarkko Sakkinen
Quoted 2 lines

OK, how would one get the chip instance?

Most subsystems have a get function that returns a kref'd pointer. For TPM all we really need today is a 'get_default_tpm_for_ns' kind of function.

Sorry, but I have no idea what you are talking about.

Go look at how rtc or net work.

Quoted 2 lines

This does not imply that these structure definitions need to be in include/linux/tpm.h since you are talking something that does not exist.

Well, I've been slowly pushing tpm to be more like a standard subystem for a long time - not all the parts are there yet. A standard subsystem will have a get/put scheme for tpm_chip.

So, yes, it does not exist, but you should be planning for it to exist someday..

Jason