tpm_isa.c revision 1.4.2.1 1 1.4.2.1 martin /* $NetBSD: tpm_isa.c,v 1.4.2.1 2019/10/16 09:52:38 martin Exp $ */
2 1.4.2.1 martin
3 1.4.2.1 martin /*
4 1.4.2.1 martin * Copyright (c) 2019 The NetBSD Foundation, Inc.
5 1.4.2.1 martin * All rights reserved.
6 1.4.2.1 martin *
7 1.4.2.1 martin * This code is derived from software contributed to The NetBSD Foundation
8 1.4.2.1 martin * by Maxime Villard.
9 1.4.2.1 martin *
10 1.4.2.1 martin * Redistribution and use in source and binary forms, with or without
11 1.4.2.1 martin * modification, are permitted provided that the following conditions
12 1.4.2.1 martin * are met:
13 1.4.2.1 martin * 1. Redistributions of source code must retain the above copyright
14 1.4.2.1 martin * notice, this list of conditions and the following disclaimer.
15 1.4.2.1 martin * 2. Redistributions in binary form must reproduce the above copyright
16 1.4.2.1 martin * notice, this list of conditions and the following disclaimer in the
17 1.4.2.1 martin * documentation and/or other materials provided with the distribution.
18 1.4.2.1 martin *
19 1.4.2.1 martin * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.4.2.1 martin * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.4.2.1 martin * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.4.2.1 martin * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.4.2.1 martin * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.4.2.1 martin * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.4.2.1 martin * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.4.2.1 martin * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.4.2.1 martin * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.4.2.1 martin * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.4.2.1 martin * POSSIBILITY OF SUCH DAMAGE.
30 1.4.2.1 martin */
31 1.1 christos
32 1.1 christos /*
33 1.1 christos * Copyright (c) 2008, 2009 Michael Shalayeff
34 1.4.2.1 martin * Copyright (c) 2009, 2010 Hans-Joerg Hoexer
35 1.1 christos * All rights reserved.
36 1.1 christos *
37 1.1 christos * Permission to use, copy, modify, and distribute this software for any
38 1.1 christos * purpose with or without fee is hereby granted, provided that the above
39 1.1 christos * copyright notice and this permission notice appear in all copies.
40 1.1 christos *
41 1.1 christos * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
42 1.1 christos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
43 1.1 christos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
44 1.1 christos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
45 1.1 christos * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN
46 1.1 christos * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
47 1.1 christos * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
48 1.1 christos */
49 1.1 christos
50 1.1 christos #include <sys/cdefs.h>
51 1.4.2.1 martin __KERNEL_RCSID(0, "$NetBSD: tpm_isa.c,v 1.4.2.1 2019/10/16 09:52:38 martin Exp $");
52 1.1 christos
53 1.1 christos #include <sys/param.h>
54 1.1 christos #include <sys/systm.h>
55 1.1 christos #include <sys/device.h>
56 1.1 christos #include <sys/bus.h>
57 1.1 christos #include <sys/pmf.h>
58 1.1 christos
59 1.1 christos #include <dev/ic/tpmreg.h>
60 1.1 christos #include <dev/ic/tpmvar.h>
61 1.1 christos
62 1.1 christos #include <dev/isa/isareg.h>
63 1.1 christos #include <dev/isa/isavar.h>
64 1.1 christos
65 1.4.2.1 martin #include "ioconf.h"
66 1.4.2.1 martin
67 1.1 christos static int tpm_isa_match(device_t, cfdata_t, void *);
68 1.1 christos static void tpm_isa_attach(device_t, device_t, void *);
69 1.1 christos
70 1.4.2.1 martin CFATTACH_DECL_NEW(tpm_isa, sizeof(struct tpm_softc), tpm_isa_match,
71 1.4.2.1 martin tpm_isa_attach, NULL, NULL);
72 1.1 christos
73 1.1 christos static int
74 1.1 christos tpm_isa_match(device_t parent, cfdata_t match, void *aux)
75 1.1 christos {
76 1.1 christos struct isa_attach_args *ia = aux;
77 1.1 christos bus_space_tag_t bt = ia->ia_memt;
78 1.1 christos bus_space_handle_t bh;
79 1.1 christos int rv;
80 1.1 christos
81 1.1 christos /* There can be only one. */
82 1.1 christos if (tpm_cd.cd_devs && tpm_cd.cd_devs[0])
83 1.1 christos return 0;
84 1.1 christos
85 1.1 christos if (ia->ia_iomem[0].ir_addr == ISA_UNKNOWN_IOMEM)
86 1.1 christos return 0;
87 1.1 christos
88 1.1 christos /* XXX: integer locator sign extension */
89 1.4.2.1 martin if (bus_space_map(bt, (unsigned int)ia->ia_iomem[0].ir_addr,
90 1.4.2.1 martin TPM_SPACE_SIZE, 0, &bh))
91 1.1 christos return 0;
92 1.1 christos
93 1.4.2.1 martin if ((rv = (*tpm_intf_tis12.probe)(bt, bh)) == 0) {
94 1.1 christos ia->ia_nio = 0;
95 1.1 christos ia->ia_io[0].ir_size = 0;
96 1.4 maxv ia->ia_iomem[0].ir_size = TPM_SPACE_SIZE;
97 1.1 christos }
98 1.1 christos ia->ia_ndrq = 0;
99 1.1 christos
100 1.4 maxv bus_space_unmap(bt, bh, TPM_SPACE_SIZE);
101 1.4.2.1 martin return (rv == 0) ? 1 : 0;
102 1.1 christos }
103 1.1 christos
104 1.1 christos static void
105 1.1 christos tpm_isa_attach(device_t parent, device_t self, void *aux)
106 1.1 christos {
107 1.1 christos struct tpm_softc *sc = device_private(self);
108 1.1 christos struct isa_attach_args *ia = aux;
109 1.4.2.1 martin bus_addr_t base;
110 1.1 christos bus_size_t size;
111 1.1 christos int rv;
112 1.1 christos
113 1.4.2.1 martin base = (unsigned int)ia->ia_iomem[0].ir_addr;
114 1.4.2.1 martin size = TPM_SPACE_SIZE;
115 1.4.2.1 martin
116 1.1 christos sc->sc_dev = self;
117 1.4 maxv sc->sc_ver = TPM_1_2;
118 1.4.2.1 martin mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
119 1.4.2.1 martin sc->sc_busy = false;
120 1.4.2.1 martin sc->sc_intf = &tpm_intf_tis12;
121 1.4 maxv sc->sc_bt = ia->ia_memt;
122 1.4.2.1 martin if (bus_space_map(sc->sc_bt, base, size, 0, &sc->sc_bh)) {
123 1.1 christos aprint_error_dev(sc->sc_dev, "cannot map registers\n");
124 1.1 christos return;
125 1.1 christos }
126 1.1 christos
127 1.4.2.1 martin if ((rv = (*sc->sc_intf->init)(sc)) != 0) {
128 1.4.2.1 martin aprint_error_dev(sc->sc_dev, "cannot init device, rv=%d\n", rv);
129 1.1 christos bus_space_unmap(sc->sc_bt, sc->sc_bh, size);
130 1.1 christos return;
131 1.2 christos }
132 1.1 christos
133 1.4.2.1 martin if (!pmf_device_register(self, tpm_suspend, tpm_resume))
134 1.4.2.1 martin aprint_error_dev(self, "couldn't establish power handler\n");
135 1.1 christos }
136