Home | History | Annotate | Line # | Download | only in ic
tpmreg.h revision 1.8.4.1
      1  1.8.4.1   thorpej /*	$NetBSD: tpmreg.h,v 1.8.4.1 2021/06/17 04:46:28 thorpej Exp $	*/
      2      1.1  christos 
      3      1.1  christos /*
      4      1.4      maxv  * Copyright (c) 2019 The NetBSD Foundation, Inc.
      5      1.1  christos  * All rights reserved.
      6      1.1  christos  *
      7      1.4      maxv  * This code is derived from software contributed to The NetBSD Foundation
      8      1.4      maxv  * by Maxime Villard.
      9      1.1  christos  *
     10      1.4      maxv  * Redistribution and use in source and binary forms, with or without
     11      1.4      maxv  * modification, are permitted provided that the following conditions
     12      1.4      maxv  * are met:
     13      1.4      maxv  * 1. Redistributions of source code must retain the above copyright
     14      1.4      maxv  *    notice, this list of conditions and the following disclaimer.
     15      1.4      maxv  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.4      maxv  *    notice, this list of conditions and the following disclaimer in the
     17      1.4      maxv  *    documentation and/or other materials provided with the distribution.
     18      1.4      maxv  *
     19      1.4      maxv  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20      1.4      maxv  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21      1.4      maxv  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22      1.4      maxv  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23      1.4      maxv  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24      1.4      maxv  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25      1.4      maxv  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26      1.4      maxv  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27      1.4      maxv  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28      1.4      maxv  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29      1.4      maxv  * POSSIBILITY OF SUCH DAMAGE.
     30      1.1  christos  */
     31      1.1  christos 
     32      1.7  riastrad #ifndef	DEV_IC_TPMREG_H
     33      1.7  riastrad #define	DEV_IC_TPMREG_H
     34      1.7  riastrad 
     35      1.7  riastrad #include <sys/types.h>
     36      1.7  riastrad 
     37      1.7  riastrad #include <sys/cdefs.h>
     38      1.7  riastrad #include <sys/endian.h>
     39      1.7  riastrad 
     40      1.7  riastrad #if (_BYTE_ORDER == _LITTLE_ENDIAN)
     41      1.6      maxv #define TPM_BE16(a)	bswap16(a)
     42      1.6      maxv #define TPM_BE32(a)	bswap32(a)
     43      1.6      maxv #else
     44      1.6      maxv #define TPM_BE16(a)	(a)
     45      1.6      maxv #define TPM_BE32(a)	(a)
     46      1.6      maxv #endif
     47      1.6      maxv 
     48      1.6      maxv struct tpm_header {
     49      1.6      maxv 	uint16_t tag;
     50      1.6      maxv 	uint32_t length;
     51      1.6      maxv 	uint32_t code;
     52      1.6      maxv } __packed;
     53      1.6      maxv 
     54      1.6      maxv /* -------------------------------------------------------------------------- */
     55      1.6      maxv 
     56      1.4      maxv /*
     57      1.4      maxv  * TPM Interface Specification 1.2 (TIS12).
     58      1.4      maxv  */
     59      1.1  christos 
     60      1.4      maxv #define	TPM_ACCESS			0x0000	/* 8bit register */
     61      1.4      maxv #define		TPM_ACCESS_VALID		__BIT(7)
     62      1.4      maxv #define		TPM_ACCESS_ACTIVE_LOCALITY	__BIT(5)
     63      1.4      maxv #define		TPM_ACCESS_BEEN_SEIZED		__BIT(4)
     64      1.4      maxv #define		TPM_ACCESS_SEIZE		__BIT(3)
     65      1.4      maxv #define		TPM_ACCESS_PENDING_REQUEST	__BIT(2)
     66      1.4      maxv #define		TPM_ACCESS_REQUEST_USE		__BIT(1)
     67      1.4      maxv #define		TPM_ACCESS_ESTABLISHMENT	__BIT(0)
     68      1.4      maxv 
     69      1.4      maxv #define	TPM_INT_ENABLE			0x0008	/* 32bit register */
     70      1.4      maxv #define		TPM_GLOBAL_INT_ENABLE		__BIT(31)
     71      1.4      maxv #define		TPM_CMD_READY_INT		__BIT(7)
     72      1.4      maxv #define		TPM_TYPE_POLARITY		__BITS(4,3)
     73      1.4      maxv #define		TPM_INT_LEVEL_HIGH		__SHIFTIN(0, TPM_TYPE_POLARITY)
     74      1.4      maxv #define		TPM_INT_LEVEL_LOW		__SHIFTIN(1, TPM_TYPE_POLARITY)
     75      1.4      maxv #define		TPM_INT_EDGE_RISING		__SHIFTIN(2, TPM_TYPE_POLARITY)
     76      1.4      maxv #define		TPM_INT_EDGE_FALLING		__SHIFTIN(3, TPM_TYPE_POLARITY)
     77      1.4      maxv #define		TPM_LOCALITY_CHANGE_INT		__BIT(2)
     78      1.4      maxv #define		TPM_STS_VALID_INT		__BIT(1)
     79      1.4      maxv #define		TPM_DATA_AVAIL_INT		__BIT(0)
     80      1.4      maxv 
     81      1.4      maxv #define	TPM_INT_VECTOR			0x000c	/* 8bit register */
     82      1.4      maxv #define	TPM_INT_STATUS			0x0010	/* 32bit register */
     83      1.4      maxv 
     84      1.4      maxv #define	TPM_INTF_CAPABILITY		0x0014	/* 32bit register */
     85      1.4      maxv #define		TPM_INTF_BURST_COUNT_STATIC	__BIT(8)
     86      1.4      maxv #define		TPM_INTF_CMD_READY_INT		__BIT(7)
     87      1.4      maxv #define		TPM_INTF_INT_EDGE_FALLING	__BIT(6)
     88      1.4      maxv #define		TPM_INTF_INT_EDGE_RISING	__BIT(5)
     89      1.4      maxv #define		TPM_INTF_INT_LEVEL_LOW		__BIT(4)
     90      1.4      maxv #define		TPM_INTF_INT_LEVEL_HIGH		__BIT(3)
     91      1.4      maxv #define		TPM_INTF_LOCALITY_CHANGE_INT	__BIT(2)
     92      1.4      maxv #define		TPM_INTF_STS_VALID_INT		__BIT(1)
     93      1.4      maxv #define		TPM_INTF_DATA_AVAIL_INT		__BIT(0)
     94      1.4      maxv #define	TPM_INTF_CAPABILITY_BITS \
     95      1.4      maxv     "\020\01IDRDY\02ISTSV\03ILOCH\04IHIGH\05ILOW\06IRISE\07IFALL\010IRDY\011BCST"
     96      1.4      maxv 
     97      1.4      maxv #define	TPM_STS				0x0018	/* 24bit register */
     98      1.4      maxv #define		TPM_STS_BURST_COUNT		__BITS(23,8)
     99      1.4      maxv #define		TPM_STS_STATUS_BITS		__BITS(7,0)
    100      1.4      maxv #define		TPM_STS_VALID			__BIT(7)
    101      1.4      maxv #define		TPM_STS_CMD_READY		__BIT(6)
    102      1.4      maxv #define		TPM_STS_GO			__BIT(5)
    103      1.4      maxv #define		TPM_STS_DATA_AVAIL		__BIT(4)
    104      1.4      maxv #define		TPM_STS_DATA_EXPECT		__BIT(3)
    105      1.5      maxv #define		TPM_STS_SELFTEST_DONE		__BIT(2)
    106      1.4      maxv #define		TPM_STS_RESP_RETRY		__BIT(1)
    107      1.4      maxv 
    108      1.4      maxv #define	TPM_DATA			0x0024	/* 32bit register */
    109      1.4      maxv #define	TPM_ID				0x0f00	/* 32bit register */
    110      1.4      maxv #define	TPM_REV				0x0f04	/* 8bit register */
    111      1.1  christos 
    112      1.4      maxv /*
    113      1.4      maxv  * Five localities, 4K per locality.
    114      1.4      maxv  */
    115      1.4      maxv #define	TPM_SPACE_SIZE	0x5000
    116      1.7  riastrad 
    117      1.8  riastrad #define	TPM_TAG_RQU_COMMAND		0x00c1
    118      1.8  riastrad #define	TPM_TAG_RSP_COMMAND		0x00c4
    119      1.8  riastrad 
    120      1.8  riastrad #define	TPM_ORD_GetRandom		0x00000046
    121      1.8  riastrad 
    122      1.8  riastrad /* TPM_RESULT return codes */
    123      1.8  riastrad #define	TPM_AUTHFAIL			1
    124      1.8  riastrad #define	TPM_BADINDEX			2
    125      1.8  riastrad #define	TPM_BAD_PARAMETER		3
    126      1.8  riastrad #define	TPM_AUDITFAILURE		4
    127      1.8  riastrad #define	TPM_CLEAR_DISABLED		5
    128      1.8  riastrad #define	TPM_DEACTIVATED			6
    129      1.8  riastrad #define	TPM_DISABLED			7
    130      1.8  riastrad #define	TPM_DISABLED_CMD		8
    131      1.8  riastrad #define	TPM_FAIL			9
    132      1.8  riastrad #define	TPM_BAD_ORDINAL			10
    133      1.8  riastrad /* ... */
    134      1.8  riastrad 
    135      1.8  riastrad #define	TPM_NON_FATAL			0x800
    136      1.8  riastrad 
    137  1.8.4.1   thorpej /* -------------------------------------------------------------------------- */
    138  1.8.4.1   thorpej 
    139  1.8.4.1   thorpej /*
    140  1.8.4.1   thorpej  * Trusted Platform Module Library Specification, Family "2.0",
    141  1.8.4.1   thorpej  * Level 00, Revision 01.59 -- November 2019
    142  1.8.4.1   thorpej  *
    143  1.8.4.1   thorpej  * https://trustedcomputinggroup.org/resource/tpm-library-specification/
    144  1.8.4.1   thorpej  *
    145  1.8.4.1   thorpej  * Where this spec names things TPM_* that don't obviously coincide
    146  1.8.4.1   thorpej  * with the 1.2 things, we name them TPM2_*.
    147  1.8.4.1   thorpej  */
    148  1.8.4.1   thorpej 
    149  1.8.4.1   thorpej /* https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-4-Supporting-Routines-01.38-code.pdf#page=172 */
    150  1.8.4.1   thorpej #define	TPM2_ST_RSP_COMMAND		0x00c4
    151  1.8.4.1   thorpej #define	TPM2_ST_NULL			0x8000
    152  1.8.4.1   thorpej #define	TPM2_ST_NO_SESSIONS		0x8001
    153  1.8.4.1   thorpej #define	TPM2_ST_SESSIONS		0x8002
    154  1.8.4.1   thorpej /* ... */
    155  1.8.4.1   thorpej 
    156  1.8.4.1   thorpej /* https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-01.38.pdf#page=45 */
    157  1.8.4.1   thorpej #define	TPM2_CC_GetRandom		0x0000017b
    158  1.8.4.1   thorpej 
    159  1.8.4.1   thorpej /* https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-01.38.pdf#page=53 */
    160  1.8.4.1   thorpej #define	TPM2_RC_SUCCESS			0x000
    161  1.8.4.1   thorpej #define	TPM2_RC_BAD_TAG			0x01e
    162  1.8.4.1   thorpej 
    163  1.8.4.1   thorpej #define	TPM2_RC_VER1			0x100
    164  1.8.4.1   thorpej 
    165  1.8.4.1   thorpej #define	TPM2_RC_FMT1			0x080
    166  1.8.4.1   thorpej 
    167  1.8.4.1   thorpej #define	TPM2_RC_WARN			0x900
    168  1.8.4.1   thorpej #define	TPM2_RC_TESTING			(TPM2_RC_WARN + 0x00a)
    169  1.8.4.1   thorpej #define	TPM2_RC_RETRY			(TPM2_RC_WARN + 0x022)
    170  1.8.4.1   thorpej 
    171      1.7  riastrad #endif	/* DEV_IC_TPMREG_H */
    172