tpm: Add support for Atmel I2C TPMs
Subsystems (4)
PATCH 1/1 tpm: Add support for Atmel I2C TPMs
This is based on the work of Teddy Reed <[email protected]> published on GitHub:
https://github.com/theopolis/tpm-i2c-atmel.git
34894b988b67e0ae55088d6388e77b0dbf10c07d
That driver was never merged, I have taken it as a starting point, forward ported, tested and revised the driver:
- Make it broadly textually similar to the Infineon and Nuvoton I2C driver
- Place everything in a format suitable for mainline inclusion
- Use high level I2C functions i2c_smbus_write_i2c_block_data and i2c_master_recv for data xfer
- Use the timeout system from the core code, by faking out a status register
- checkpatch cleanups
- Testing on ARM Kirkwood, with this device tree, using a AT97SC3204T-X1A180
tpm@29 {
compatible = "atmel,at97sc3204t";
reg = <0x29>;
};PENDING: Teddy will need to provide a Signed-Off line for this driver, although very little of his original text remained unchanged, the work to discover the protocol is entirely his and he will need to certify the Developer Certification of Origin that it is suitable for mainline inclusion.
--- .../devicetree/bindings/i2c/trivial-devices.txt | 1 + drivers/char/tpm/Kconfig | 9 + drivers/char/tpm/Makefile | 1 + drivers/char/tpm/tpm_i2c_atmel.c | 276 +++++++++++++++++++++ 4 files changed, 287 insertions(+) create mode 100644 drivers/char/tpm/tpm_i2c_atmel.c
This has been compile tested on 3.11 x86-64 and runtime tested on 3.7 ARM
I'm not yet 100% certain this driver works perfectly, for some reason my TPM will not create an EK, which is either due to a larger sent TPM messages becoming corrupt (combined with a TPM bug to not report an error code) or something wrong with the TPM itself.
There is already evidence that this TPM has non-compliant firmware, since several other commands do not work as the spec defines them to (eg something as simple as reading TPM_PERMANENT_FLAGS has problems).
I have chips with newer firmware, and will test with those soon...
Documentation/devicetree/bindings/i2c/trivial-devices.txt +1 -0
@@ -15,6 +15,7 @@ adi,adt7461 +/-1C TDM Extended Temp Range I.C adt7461 +/-1C TDM Extended Temp Range I.C at,24c08 i2c serial eeprom (24cxx) atmel,24c02 i2c serial eeprom (24cxx) +atmel,at97sc3204t i2c trusted platform module (TPM) catalyst,24c32 i2c serial eeprom dallas,ds1307 64 x 8, Serial, I2C Real-Time Clock dallas,ds1338 I2C RTC with 56-Byte NV RAM
drivers/char/tpm/Kconfig +9 -0
@@ -33,6 +33,15 @@ config TCG_TIS from within Linux. To compile this driver as a module, choose M here; the module will be called tpm_tis. +config TCG_TIS_I2C_ATMEL + tristate "TPM Interface Specification 1.2 Interface (I2C - Atmel)" + depends on I2C + ---help--- + If you have an Atmel I2C TPM security chip say Yes and it will be + accessible from within Linux. + To compile this driver as a module, choose M here; the module will + be called tpm_tis_i2c_atmel. + config TCG_TIS_I2C_INFINEON tristate "TPM Interface Specification 1.2 Interface (I2C - Infineon)" depends on I2C
drivers/char/tpm/Makefile +1 -0
@@ -12,6 +12,7 @@ ifdef CONFIG_TCG_IBMVTPM endif endif obj-$(CONFIG_TCG_TIS) += tpm_tis.o +obj-$(CONFIG_TCG_TIS_I2C_ATMEL) += tpm_i2c_atmel.o obj-$(CONFIG_TCG_TIS_I2C_INFINEON) += tpm_i2c_infineon.o obj-$(CONFIG_TCG_NUVOTON_I2C) += tpm_nuvoton_i2c.o obj-$(CONFIG_TCG_NSC) += tpm_nsc.o
drivers/char/tpm/tpm_i2c_atmel.c new file +276 -0
276 lines not on this page · raw message
Signature · 1 line
1.8.1.2
drivers/char/tpm/tpm_i2c_atmel.c line 61
Quoted 8 lines · Jason Gunthorpe
I'm not yet 100% certain this driver works perfectly, for some reason my TPM will not create an EK, which is either due to a larger sent TPM messages becoming corrupt (combined with a TPM bug to not report an error code) or something wrong with the TPM itself.
drivers/char/tpm/tpm_i2c_atmel.c new file +3
-0+ + status =i2c_smbus_write_i2c_block_data (client, buf[0 ], len -1 , + buf +1 );
Thankfully Peter pointed out that these calls only transfer 32 bytes, which causes the problem I observed. The TPM returns success with a corrupted response when you truncate the request, apparently.
Fixing it with:
+ status = i2c_master_send(client, buf, len);
Has the driver pass all my tests. I will post a v1 after a few days and collect any other comments.
Jason
Peter Hüwe
maintainerHi Jason,
Am Donnerstag, 12. September 2013, 01:08:41 schrieb Jason Gunthorpe:
Quoted 18 lines · Jason Gunthorpe
drivers/char/tpm/tpm_i2c_atmel.c line 61
Quoted 8 lines
I'm not yet 100% certain this driver works perfectly, for some reason my TPM will not create an EK, which is either due to a larger sent TPM messages becoming corrupt (combined with a TPM bug to not report an error code) or something wrong with the TPM itself.
drivers/char/tpm/tpm_i2c_atmel.c new file +3
-0+ + status =i2c_smbus_write_i2c_block_data (client, buf[0 ], len -1 , + buf +1 );Thankfully Peter pointed out that these calls only transfer 32 bytes, which causes the problem I observed. The TPM returns success with a corrupted response when you truncate the request, apparently.
Fixing it with:
(quoted diff) +1
-0+ status = i2c_master_send(client, buf, len);
Quoted 2 lines
Has the driver pass all my tests. I will post a v1 after a few days and collect any other comments.
Yes this should probably do the thing ;)
Thanks for porting yet another driver.
I think I'll stage them (nuvoton, st and atmel) all in a temporary branch "testing-and-review" so it's easier for people to try them out. This branch might rebase and change all the time, but maybe it makes things easier (and patches can be squashed afterwards easily if needed).
But since you'll be sending a v2, I'll wait until the v2.
Thanks,
Peter
Peter Hüwe
maintainerAm Mittwoch, 11. September 2013, 22:58:07 schrieb Jason Gunthorpe:
Quoted 22 lines
This is based on the work of Teddy Reed <[email protected]> published on GitHub:
https://github.com/theopolis/tpm-i2c-atmel.git
34894b988b67e0ae55088d6388e77b0dbf10c07dThat driver was never merged, I have taken it as a starting point, forward ported, tested and revised the driver:
- Make it broadly textually similar to the Infineon and Nuvoton I2C driver
- Place everything in a format suitable for mainline inclusion
- Use high level I2C functionsi2c_smbus_write_i2c_block_dataandi2c_master_recvfor data xfer
- Use the timeout system from the core code, by faking out a status register
- checkpatch cleanups
- Testing on ARM Kirkwood, with this device tree, using a AT97SC3204T-X1A180tpm@29 { compatible = "atmel,at97sc3204t"; reg = <0x29>; };
Quoted 8 lines
PENDING: Teddy will need to provide a Signed-Off line for this driver, although very little of his original text remained unchanged, the work to discover the protocol is entirely his and he will need to certify the Developer Certification of Origin that it is suitable for mainline inclusion.
[jgg: revised and tested]Signed-off-by Jason Gunthorpe <[email protected]>
Hi Jason,
thanks for porting yet another driver.
I think I'll stage them (nuvoton, st and atmel) all in a temporary branch "testing-and-review" so it's easier for people to try them out.
Thanks,
Peter
Peter Hüwe
maintainerHi,
Quoted 7 lines
I think I'll stage them (nuvoton, st and atmel) all in a temporary branch "testing-and-review" so it's easier for people to try them out. This branch might rebase and change all the time, but maybe it makes things easier (and patches can be squashed afterwards easily if needed).
But since you'll be sending a v2, I'll wait until the v2.
I staged everything here for the moment
https://github.com/PeterHuewe/linux-tpmdd/tree/testing-and-review
All three are not ready yet though.
Will rebase/update when the new versions come up.
Thanks,
Peter
Quoted 9 lines · Peter H?we
Hi,
Quoted 6 lines
I think I'll stage them (nuvoton, st and atmel) all in a temporary branch "testing-and-review" so it's easier for people to try them out. This branch might rebase and change all the time, but maybe it makes things easier (and patches can be squashed afterwards easily if needed).
Quoted 3 lines
Quoted 1 line
But since you'll be sending a v2, I'll wait until the v2.
I staged everything here for the moment
https://github.com/PeterHuewe/linux-tpmdd/tree/testing-and-review
I put up a branch on my github that has the drivers as well as parts of a major cleanup as we both vaugely discussed.
Not finished yet, but maybe by the time you get back. It is big, I'm just going to keep it on github for the moment.
commit dfd68b37beb8806b0a061af71436017d0b6c577e
Author: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org> Date: Sat Sep 14 19:21:12 2013 -0600
tpm: Pull everything related to /dev/tpmX into tpm-dev.c
This cleans up all the identical file_operations sprinkled about in the drivers.
To support this the way the chip structure is recovered in tpm_open is switched to use container_of rather than searching, otherwise this is just a copy of function content from tpm.c to tpm-dev.c and the resulting cleanup from making the functions static.
commit 9d83865080be4fce23c3247754c640aacd30c25e
Author: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org> Date: Sat Sep 14 18:51:54 2013 -0600
tpm: Store devname in the tpm_chip
Just put the memory directly in the chip structure, rather than a 2nd dedicated kalloc.
commit 4b05342eb38db16afb5698dd7b79ce21b56e669b
Author: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org> Date: Sat Sep 14 18:47:43 2013 -0600
tpm: Create a tpm_class_ops structure and use it
This replaces the static initialization of a tpm_vendor_specific structure in the drivers with the standard Linux idiom of providing a const structure of function pointers.
As the first clean up step this just changes the names and copies ops into chip->vendor exactly as before.
commit 4e1a392500e4f588ec685703d0c1066c93135eaa
Author: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org> Date: Sat Sep 14 17:55:30 2013 -0600
tpm: xen-tpmfront: Fix default durations
All the default durations were being set to 10 minutes which is way too long for the timeouts. Normal values for the longest duration are around 5 mins, and short duration ar around .5s.
Further, these are just the default, tpm_get_timeouts will set them to values from the TPM (or throw an error).
Just remove them.
commit 181416f763b9adf2cf8f9cf0ca4d377a16b255d7
Author: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org> Date: Sat Sep 14 17:36:29 2013 -0600
tpm atmel: Call request_region with the correct base
Commit e0dd03caf20d040a0a86b6bd74028ec9bda545f5 changed the code path here so that ateml_get_base_addr no longer directly altered the tpm_vendor_specific structure, and instead placed the base address on the stack.
The commit missed updating the request_region call, which would have resulted in request_region being called with 0 as the base address.
I don't know if request_region(0, ..) will fail, if so the driver has been broken since 2006 and we should remove it from the tree as it has no users.
commit c41042057dc3fd156c8cb264a18dac1ce2bdf90a
Author: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org> Date: Sat Sep 14 16:57:58 2013 -0600
tpm: ibmvtpm: Use %zd formatting for size_t format arguments
This suppresses compile warnings on 32 bit builds.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 6 lines · Teddy Reed
Looks great, thanks again Jason!
Also, if anyone would like some TSSOP AT97SC3204T's, please email me and I will send you a few along with breakouts and programmable crystal so you can test/play/break/etc, no charge, but I'd rather only ship within the USA.Signed-off-by Teddy Reed <[email protected]>
Thanks Teddy,
I've updated the series with the revised commit message:
https://github.com/jgunthorpe/linux/commit/4378757fbf7771ffecc3b8779856dcc938f45234
tpm: Add support for Atmel I2C TPMs
This is based on the work of Teddy Reed <[email protected]> published on GitHub:
https://github.com/theopolis/tpm-i2c-atmel.git
34894b9
That driver was never merged, I have taken it as a starting port, forward ported, tested and revised the driver:
- Make it broadly textually similar to the Infineon and Nuvoton I2C driver
- Place everything in a format suitable for mainline inclusion
- Use high level I2C functions i2c_master_send and i2c_master_recv for data xfer
- Use the timeout system from the core code, by faking out a status register
- Only I2C transfer the number of bytes in the reply, not a fixed message size.
- checkpatch cleanups
- Testing on ARM Kirkwood, with this device tree, using a AT97SC3204T-X1A180
tpm@29 {
compatible = "atmel,at97sc3204t";
reg = <0x29>;
};Jason
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html