svn commit: r343438 - in head: sys/dev/tpm usr.sbin/acpi/acpidump

Takanori Watanabe takawata at FreeBSD.org
Fri Jan 25 16:16:12 UTC 2019


Author: takawata
Date: Fri Jan 25 16:16:10 2019
New Revision: 343438
URL: https://svnweb.freebsd.org/changeset/base/343438

Log:
  Use ACPI TPM2 table to probe tpmtis and tpmcrb device.
  
  Differential Revision: https://reviews.freebsd.org/D18937

Modified:
  head/sys/dev/tpm/tpm20.h
  head/sys/dev/tpm/tpm_crb.c
  head/sys/dev/tpm/tpm_tis.c
  head/usr.sbin/acpi/acpidump/acpi.c

Modified: head/sys/dev/tpm/tpm20.h
==============================================================================
--- head/sys/dev/tpm/tpm20.h	Fri Jan 25 15:48:00 2019	(r343437)
+++ head/sys/dev/tpm/tpm20.h	Fri Jan 25 16:16:10 2019	(r343438)
@@ -93,6 +93,12 @@ __FBSDID("$FreeBSD$");
 #define	TPM_CDEV_NAME		"tpm0"
 #define	TPM_CDEV_PERM_FLAG	0600
 
+
+#define TPM2_START_METHOD_ACPI 2
+#define TPM2_START_METHOD_TIS 6
+#define TPM2_START_METHOD_CRB 7
+#define TPM2_START_METHOD_CRB_ACPI 8
+
 struct tpm_sc {
 	device_t	dev;
 

Modified: head/sys/dev/tpm/tpm_crb.c
==============================================================================
--- head/sys/dev/tpm/tpm_crb.c	Fri Jan 25 15:48:00 2019	(r343437)
+++ head/sys/dev/tpm/tpm_crb.c	Fri Jan 25 16:16:10 2019	(r343438)
@@ -104,27 +104,20 @@ char *tpmcrb_ids[] = {"MSFT0101", NULL};
 static int
 tpmcrb_acpi_probe(device_t dev)
 {
-	struct resource *res;
-	int err, rid = 0;
-	uint32_t caps;
-
+	int err;
+	ACPI_TABLE_TPM23 *tbl;
+	ACPI_STATUS status;
 	err = ACPI_ID_PROBE(device_get_parent(dev), dev, tpmcrb_ids, NULL);
 	if (err > 0)
 		return (err);
+	/*Find TPM2 Header*/
+	status = AcpiGetTable(ACPI_SIG_TPM2, 1, (ACPI_TABLE_HEADER **) &tbl);
+	if(ACPI_FAILURE(status) ||
+	   tbl->StartMethod != TPM2_START_METHOD_CRB)
+		err = ENXIO;
 
-	/* Check if device is in CRB mode */
-	res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
-	if (res == NULL)
-		return (ENXIO);
-
-	caps = bus_read_4(res, TPM_CRB_INTF_ID);
-	bus_release_resource(dev, SYS_RES_MEMORY, rid, res);
-
-	if ((caps & TPM_CRB_INTF_ID_TYPE) != TPM_CRB_INTF_ID_TYPE_CRB)
-		return (ENXIO);
-
 	device_set_desc(dev, "Trusted Platform Module 2.0, CRB mode");
-	return (BUS_PROBE_DEFAULT);
+	return (err);
 }
 
 static ACPI_STATUS

Modified: head/sys/dev/tpm/tpm_tis.c
==============================================================================
--- head/sys/dev/tpm/tpm_tis.c	Fri Jan 25 15:48:00 2019	(r343437)
+++ head/sys/dev/tpm/tpm_tis.c	Fri Jan 25 16:16:10 2019	(r343438)
@@ -100,26 +100,21 @@ char *tpmtis_ids[] = {"MSFT0101", NULL};
 static int
 tpmtis_acpi_probe(device_t dev)
 {
-	struct resource *res;
-	int err, rid = 0;
-	uint32_t caps;
+	int err;
+	ACPI_TABLE_TPM23 *tbl;
+	ACPI_STATUS status;
 
 	err = ACPI_ID_PROBE(device_get_parent(dev), dev, tpmtis_ids, NULL);
 	if (err > 0)
 		return (err);
+	/*Find TPM2 Header*/
+	status = AcpiGetTable(ACPI_SIG_TPM2, 1, (ACPI_TABLE_HEADER **) &tbl);
+	if(ACPI_FAILURE(status) ||
+	   tbl->StartMethod != TPM2_START_METHOD_TIS)
+	    err = ENXIO;
 
-	/* Check if device is in TPM 2.0 TIS mode */
-	res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
-	if (res == NULL)
-		return (ENXIO);
-
-	caps = bus_read_4(res, TPM_INTF_CAPS);
-	bus_release_resource(dev, SYS_RES_MEMORY, rid, res);
-	if ((caps & TPM_INTF_CAPS_VERSION) != TPM_INTF_CAPS_TPM20)
-		return (ENXIO);
-
 	device_set_desc(dev, "Trusted Platform Module 2.0, FIFO mode");
-	return (BUS_PROBE_DEFAULT);
+	return (err);
 }
 
 static int

Modified: head/usr.sbin/acpi/acpidump/acpi.c
==============================================================================
--- head/usr.sbin/acpi/acpidump/acpi.c	Fri Jan 25 15:48:00 2019	(r343437)
+++ head/usr.sbin/acpi/acpidump/acpi.c	Fri Jan 25 16:16:10 2019	(r343438)
@@ -970,7 +970,18 @@ acpi_handle_tcpa(ACPI_TABLE_HEADER *sdp)
 
 	printf(END_COMMENT);
 }
-
+static void acpi_handle_tpm2(ACPI_TABLE_HEADER *sdp)
+{
+	ACPI_TABLE_TPM2 *tpm2;
+	
+	printf (BEGIN_COMMENT);
+	acpi_print_sdt(sdp);
+	tpm2 = (ACPI_TABLE_TPM2 *) sdp;
+	printf ("\t\tControlArea=%lx\n", tpm2->ControlAddress);
+	printf ("\t\tStartMethod=%x\n", tpm2->StartMethod);	
+	printf (END_COMMENT);
+}
+	
 static const char *
 devscope_type2str(int type)
 {
@@ -1769,6 +1780,8 @@ acpi_handle_rsdt(ACPI_TABLE_HEADER *rsdp)
 			acpi_handle_wddt(sdp);
 		else if (!memcmp(sdp->Signature, ACPI_SIG_LPIT, 4))
 			acpi_handle_lpit(sdp);
+		else if (!memcmp(sdp->Signature, ACPI_SIG_TPM2, 4))
+			acpi_handle_tpm2(sdp);
 		else {
 			printf(BEGIN_COMMENT);
 			acpi_print_sdt(sdp);


More information about the svn-src-all mailing list