xref: /freebsd/sys/dev/tpm/tpm_tis_acpi.c (revision bbecd3148abf68918b1aa5fc7750dd8ec17fea72)
1c2e9c5bbSJustin Hibbits /*-
2c2e9c5bbSJustin Hibbits  * Copyright (c) 2018 Stormshield.
3c2e9c5bbSJustin Hibbits  * Copyright (c) 2018 Semihalf.
4c2e9c5bbSJustin Hibbits  * Copyright (c) 2023 Juniper Networks, Inc.
5c2e9c5bbSJustin Hibbits  * All rights reserved.
6c2e9c5bbSJustin Hibbits  *
7c2e9c5bbSJustin Hibbits  * Redistribution and use in source and binary forms, with or without
8c2e9c5bbSJustin Hibbits  * modification, are permitted provided that the following conditions
9c2e9c5bbSJustin Hibbits  * are met:
10c2e9c5bbSJustin Hibbits  * 1. Redistributions of source code must retain the above copyright
11c2e9c5bbSJustin Hibbits  *    notice, this list of conditions and the following disclaimer.
12c2e9c5bbSJustin Hibbits  * 2. Redistributions in binary form must reproduce the above copyright
13c2e9c5bbSJustin Hibbits  *    notice, this list of conditions and the following disclaimer in the
14c2e9c5bbSJustin Hibbits  *    documentation and/or other materials provided with the distribution.
15c2e9c5bbSJustin Hibbits  *
16c2e9c5bbSJustin Hibbits  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17c2e9c5bbSJustin Hibbits  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18c2e9c5bbSJustin Hibbits  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19c2e9c5bbSJustin Hibbits  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20c2e9c5bbSJustin Hibbits  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21c2e9c5bbSJustin Hibbits  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22c2e9c5bbSJustin Hibbits  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23c2e9c5bbSJustin Hibbits  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24c2e9c5bbSJustin Hibbits  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25c2e9c5bbSJustin Hibbits  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26c2e9c5bbSJustin Hibbits  * POSSIBILITY OF SUCH DAMAGE.
27c2e9c5bbSJustin Hibbits  */
28c2e9c5bbSJustin Hibbits 
29c2e9c5bbSJustin Hibbits #include <sys/cdefs.h>
30c2e9c5bbSJustin Hibbits #include "tpm20.h"
31c2e9c5bbSJustin Hibbits #include "tpm_if.h"
32c2e9c5bbSJustin Hibbits 
33c2e9c5bbSJustin Hibbits static int tpmtis_acpi_probe(device_t dev);
34c2e9c5bbSJustin Hibbits 
35c2e9c5bbSJustin Hibbits char *tpmtis_ids[] = {"MSFT0101", NULL};
36c2e9c5bbSJustin Hibbits 
37c2e9c5bbSJustin Hibbits static int
38c2e9c5bbSJustin Hibbits tpmtis_acpi_probe(device_t dev)
39c2e9c5bbSJustin Hibbits {
40c2e9c5bbSJustin Hibbits 	int err;
41c2e9c5bbSJustin Hibbits 	ACPI_TABLE_TPM23 *tbl;
42c2e9c5bbSJustin Hibbits 	ACPI_STATUS status;
43c2e9c5bbSJustin Hibbits 
44c2e9c5bbSJustin Hibbits 	err = ACPI_ID_PROBE(device_get_parent(dev), dev, tpmtis_ids, NULL);
45c2e9c5bbSJustin Hibbits 	if (err > 0)
46c2e9c5bbSJustin Hibbits 		return (err);
47c2e9c5bbSJustin Hibbits 	/*Find TPM2 Header*/
48c2e9c5bbSJustin Hibbits 	status = AcpiGetTable(ACPI_SIG_TPM2, 1, (ACPI_TABLE_HEADER **) &tbl);
49c2e9c5bbSJustin Hibbits 	if(ACPI_FAILURE(status) ||
50c2e9c5bbSJustin Hibbits 	   tbl->StartMethod != TPM2_START_METHOD_TIS)
51c2e9c5bbSJustin Hibbits 	    err = ENXIO;
52c2e9c5bbSJustin Hibbits 
53c2e9c5bbSJustin Hibbits 	device_set_desc(dev, "Trusted Platform Module 2.0, FIFO mode");
54c2e9c5bbSJustin Hibbits 	return (err);
55c2e9c5bbSJustin Hibbits }
56c2e9c5bbSJustin Hibbits 
57c2e9c5bbSJustin Hibbits static int
58c2e9c5bbSJustin Hibbits tpmtis_acpi_attach(device_t dev)
59c2e9c5bbSJustin Hibbits {
60c2e9c5bbSJustin Hibbits 	struct tpm_sc *sc = device_get_softc(dev);
61c2e9c5bbSJustin Hibbits 
62c2e9c5bbSJustin Hibbits 	sc->mem_rid = 0;
63c2e9c5bbSJustin Hibbits 	sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->mem_rid,
64c2e9c5bbSJustin Hibbits 		    RF_ACTIVE);
65c2e9c5bbSJustin Hibbits 	if (sc->mem_res == NULL) {
66c2e9c5bbSJustin Hibbits 		return (ENXIO);
67c2e9c5bbSJustin Hibbits 	}
68c2e9c5bbSJustin Hibbits 
69c2e9c5bbSJustin Hibbits 	/*
70c2e9c5bbSJustin Hibbits 	 * If tpmtis_attach() fails, tpmtis_detach() will automatically free
71c2e9c5bbSJustin Hibbits 	 * sc->mem_res (not-NULL).
72c2e9c5bbSJustin Hibbits 	 */
73c2e9c5bbSJustin Hibbits 	return (tpmtis_attach(dev));
74c2e9c5bbSJustin Hibbits }
75c2e9c5bbSJustin Hibbits 
76c2e9c5bbSJustin Hibbits /* ACPI Driver */
77c2e9c5bbSJustin Hibbits static device_method_t tpmtis_methods[] = {
78c2e9c5bbSJustin Hibbits 	DEVMETHOD(device_attach,	tpmtis_acpi_attach),
79c2e9c5bbSJustin Hibbits 	DEVMETHOD(device_probe,		tpmtis_acpi_probe),
80c2e9c5bbSJustin Hibbits 	DEVMETHOD_END
81c2e9c5bbSJustin Hibbits };
82c2e9c5bbSJustin Hibbits 
83c2e9c5bbSJustin Hibbits DEFINE_CLASS_2(tpmtis, tpmtis_acpi_driver, tpmtis_methods,
84c2e9c5bbSJustin Hibbits     sizeof(struct tpm_sc), tpmtis_driver, tpm_bus_driver);
85c2e9c5bbSJustin Hibbits 
86*bbecd314SWarner Losh DRIVER_MODULE(tpmtis, acpi, tpmtis_acpi_driver, 0, 0);
87