[U-Boot] [PATCH v1 2/2] tpm: Add i2c TPM driver

2011-12-14 Thread Che-Liang Chiou
Peter Huewe implemented the original driver; this patch only reorganizes
the code structure of the driver, and does not make logical changes.

tpm.c implements the interface defined in tpm.h based on underlying
LPC or i2C TPM driver.  tpm.c and the underlying driver communicate
throught tpm_private.h.

This patch is tested on a tegra2-based machine, where the i2c driver is
not upstreamed yet.

Note: Merging the LPC driver with tpm.c is left to future patches.

Signed-off-by: Peter Huewe 
Signed-off-by: Che-Liang Chiou 
---
Changes in v1:
- Squash patch #3 into patch #2

 README|   13 +
 drivers/tpm/Makefile  |5 +-
 drivers/tpm/tpm.c |  457 +++
 drivers/tpm/tpm_private.h |  131 ++
 drivers/tpm/tpm_tis_i2c.c |  584 +
 5 files changed, 1189 insertions(+), 1 deletions(-)
 create mode 100644 drivers/tpm/tpm.c
 create mode 100644 drivers/tpm/tpm_private.h
 create mode 100644 drivers/tpm/tpm_tis_i2c.c

diff --git a/README b/README
index 434384c..badb834 100644
--- a/README
+++ b/README
@@ -1076,6 +1076,19 @@ The following options need to be configured:
CONFIG_TPM
Support TPM devices.
 
+   CONFIG_TPM_TIS_I2C
+   Support for i2c bus TPM devices. Only one device
+   per system is supported at this time.
+
+   CONFIG_TPM_TIS_I2C_BUS_NUMBER
+   Define the the i2c bus number for the TPM device
+
+   CONFIG_TPM_TIS_I2C_SLAVE_ADDRESS
+   Define the TPM's address on the i2c bus
+
+   CONFIG_TPM_TIS_I2C_BURST_LIMITATION
+   Define the burst count bytes upper limit
+
CONFIG_TPM_TIS_LPC
Support for generic parallel port TPM devices. Only one device
per system is supported at this time.
diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile
index 47d09de..cb29bab 100644
--- a/drivers/tpm/Makefile
+++ b/drivers/tpm/Makefile
@@ -23,7 +23,10 @@ include $(TOPDIR)/config.mk
 
 LIB := $(obj)libtpm.o
 
-COBJS-$(CONFIG_TPM_TIS_LPC) = tpm_tis_lpc.o
+# TODO(clchiou): Merge tpm_tis_lpc.c with tpm.c
+COBJS-$(CONFIG_TPM_TIS_I2C) += tpm.o
+COBJS-$(CONFIG_TPM_TIS_I2C) += tpm_tis_i2c.o
+COBJS-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o
 
 COBJS  := $(COBJS-y)
 SRCS   := $(COBJS:.o=.c)
diff --git a/drivers/tpm/tpm.c b/drivers/tpm/tpm.c
new file mode 100644
index 000..457deaa
--- /dev/null
+++ b/drivers/tpm/tpm.c
@@ -0,0 +1,457 @@
+/*
+ * Copyright (C) 2011 Infineon Technologies
+ *
+ * Authors:
+ * Peter Huewe 
+ *
+ * Description:
+ * Device driver for TCG/TCPA TPM (trusted platform module).
+ * Specifications at www.trustedcomputinggroup.org
+ *
+ * It is based on the Linux kernel driver tpm.c from Leendert van
+ * Dorn, Dave Safford, Reiner Sailer, and Kyleen Hall.
+ *
+ * Version: 2.1.1
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2 of the
+ * License.
+ *
+ * This program is distributed in the hope that 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "tpm_private.h"
+
+/* Global structure for tpm chip data */
+static struct tpm_chip tpm_chip;
+
+enum tpm_duration {
+   TPM_SHORT = 0,
+   TPM_MEDIUM = 1,
+   TPM_LONG = 2,
+   TPM_UNDEFINED,
+};
+
+/* Extended error numbers from linux (see errno.h) */
+#defineECANCELED   125 /* Operation Canceled */
+
+/* Timer frequency. Corresponds to msec timer resolution*/
+#define HZ 1000
+
+#define TPM_MAX_ORDINAL243
+#define TPM_MAX_PROTECTED_ORDINAL  12
+#define TPM_PROTECTED_ORDINAL_MASK 0xFF
+
+#define TPM_CMD_COUNT_BYTE 2
+#define TPM_CMD_ORDINAL_BYTE   6
+
+/*
+ * Array with one entry per ordinal defining the maximum amount
+ * of time the chip could take to return the result.  The ordinal
+ * designation of short, medium or long is defined in a table in
+ * TCG Specification TPM Main Part 2 TPM Structures Section 17. The
+ * values of the SHORT, MEDIUM, and LONG durations are retrieved
+ * from the chip during initialization with a call to tpm_get_timeouts.
+ */
+static const u8 tpm_protected_ordinal_duration[TPM_MAX_PROTECTED_ORDINAL] = {
+   TPM_UNDEFINED,  /* 0 */
+   TPM_UND

Re: [U-Boot] [PATCH v1 2/2] tpm: Add i2c TPM driver

2011-12-16 Thread Mike Frysinger
On Wednesday 14 December 2011 03:48:24 Che-Liang Chiou wrote:
> --- /dev/null
> +++ b/drivers/tpm/tpm.c
>
> +int tis_sendrecv(const uint8_t *sendbuf, size_t send_size, uint8_t
> *recvbuf, +   size_t *recv_len)
> +{
> + error("%s: invalid send_size %zx\n", __func__, send_size);

using __func__ with error() makes no sense as error() already includes that

> --- /dev/null
> +++ b/drivers/tpm/tpm_private.h

this should probably include linux/types.h and linux/compiler.h since it uses 
__be32 and __packed

> --- /dev/null
> +++ b/drivers/tpm/tpm_tis_i2c.c
>
> + if (burstcnt > (len-1-count))
> + burstcnt = len-1-count;

add some spaces around those "-"
-mike


signature.asc
Description: This is a digitally signed message part.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v1 2/2] tpm: Add i2c TPM driver

2011-12-17 Thread Wolfgang Denk
Dear Che-Liang Chiou,

In message <1323852504-19954-3-git-send-email-clch...@chromium.org> you wrote:
> Peter Huewe implemented the original driver; this patch only reorganizes
> the code structure of the driver, and does not make logical changes.
> 
> tpm.c implements the interface defined in tpm.h based on underlying
> LPC or i2C TPM driver.  tpm.c and the underlying driver communicate
> throught tpm_private.h.
> 
> This patch is tested on a tegra2-based machine, where the i2c driver is
> not upstreamed yet.
> 
> Note: Merging the LPC driver with tpm.c is left to future patches.
> 
> Signed-off-by: Peter Huewe 
> Signed-off-by: Che-Liang Chiou 

...
> + if (ordinal < TPM_MAX_ORDINAL)
> + duration_idx = tpm_ordinal_duration[ordinal];
> + else if ((ordinal & TPM_PROTECTED_ORDINAL_MASK) <
> + TPM_MAX_PROTECTED_ORDINAL)
> + duration_idx = tpm_protected_ordinal_duration[ordinal &
> + TPM_PROTECTED_ORDINAL_MASK];

Braces needed around multiline statement.

> + if (duration_idx != TPM_UNDEFINED)
> + duration = chip->vendor.duration[duration_idx];
> + if (duration <= 0)

Readability could be improved by inserting a blank line before this
one.

...
> + debug("%s: waiting for status...\n", __func__);
> + u8 status = tpm_chip.vendor.status(&tpm_chip);
> + if ((status & tpm_chip.vendor.req_complete_mask) ==

Please always seaprate declarations and code by one blank line.
Please fix globally.


Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
Yes, it's a technical challenge, and  you  have  to  kind  of  admire
people  who go to the lengths of actually implementing it, but at the
same time you wonder about their IQ...
 --  Linus Torvalds in <5phda5$ml6$1...@palladium.transmeta.com>
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v1 2/2] tpm: Add i2c TPM driver

2011-12-19 Thread Che-liang Chiou
On Sat, Dec 17, 2011 at 1:21 AM, Mike Frysinger  wrote:
> On Wednesday 14 December 2011 03:48:24 Che-Liang Chiou wrote:
>> --- /dev/null
>> +++ b/drivers/tpm/tpm.c
>>
>> +int tis_sendrecv(const uint8_t *sendbuf, size_t send_size, uint8_t
>> *recvbuf, +           size_t *recv_len)
>> +{
>> +             error("%s: invalid send_size %zx\n", __func__, send_size);
>
> using __func__ with error() makes no sense as error() already includes that

Done.

>> --- /dev/null
>> +++ b/drivers/tpm/tpm_private.h
>
> this should probably include linux/types.h and linux/compiler.h since it uses
> __be32 and __packed

Done.

>> --- /dev/null
>> +++ b/drivers/tpm/tpm_tis_i2c.c
>>
>> +             if (burstcnt > (len-1-count))
>> +                     burstcnt = len-1-count;
>
> add some spaces around those "-"

Done.

> -mike
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v1 2/2] tpm: Add i2c TPM driver

2011-12-19 Thread Che-liang Chiou
On Sun, Dec 18, 2011 at 4:33 AM, Wolfgang Denk  wrote:
> Dear Che-Liang Chiou,
>
> In message <1323852504-19954-3-git-send-email-clch...@chromium.org> you wrote:
>> Peter Huewe implemented the original driver; this patch only reorganizes
>> the code structure of the driver, and does not make logical changes.
>>
>> tpm.c implements the interface defined in tpm.h based on underlying
>> LPC or i2C TPM driver.  tpm.c and the underlying driver communicate
>> throught tpm_private.h.
>>
>> This patch is tested on a tegra2-based machine, where the i2c driver is
>> not upstreamed yet.
>>
>> Note: Merging the LPC driver with tpm.c is left to future patches.
>>
>> Signed-off-by: Peter Huewe 
>> Signed-off-by: Che-Liang Chiou 
>
> ...
>> +     if (ordinal < TPM_MAX_ORDINAL)
>> +             duration_idx = tpm_ordinal_duration[ordinal];
>> +     else if ((ordinal & TPM_PROTECTED_ORDINAL_MASK) <
>> +                     TPM_MAX_PROTECTED_ORDINAL)
>> +             duration_idx = tpm_protected_ordinal_duration[ordinal &
>> +                     TPM_PROTECTED_ORDINAL_MASK];
>
> Braces needed around multiline statement.

Done.

>> +     if (duration_idx != TPM_UNDEFINED)
>> +             duration = chip->vendor.duration[duration_idx];
>> +     if (duration <= 0)
>
> Readability could be improved by inserting a blank line before this
> one.

Done.

> ...
>> +             debug("%s: waiting for status...\n", __func__);
>> +             u8 status = tpm_chip.vendor.status(&tpm_chip);
>> +             if ((status & tpm_chip.vendor.req_complete_mask) ==
>
> Please always seaprate declarations and code by one blank line.
> Please fix globally.

Done. I found as many cases as possible, and inserted a few more blank
lines. I hope that would increase readability.

>
> Best regards,
>
> Wolfgang Denk
>
> --
> DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
> Yes, it's a technical challenge, and  you  have  to  kind  of  admire
> people  who go to the lengths of actually implementing it, but at the
> same time you wonder about their IQ...
>         --  Linus Torvalds in <5phda5$ml6$1...@palladium.transmeta.com>
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot