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