tpm_isa.c revision 1.4 1 1.4 maxv /* $NetBSD: tpm_isa.c,v 1.4 2019/06/22 12:57:41 maxv Exp $ */
2 1.1 christos
3 1.1 christos /*
4 1.1 christos * Copyright (c) 2008, 2009 Michael Shalayeff
5 1.1 christos * Copyright (c) 2009, 2010 Hans-Jrg Hxer
6 1.1 christos * All rights reserved.
7 1.1 christos *
8 1.1 christos * Permission to use, copy, modify, and distribute this software for any
9 1.1 christos * purpose with or without fee is hereby granted, provided that the above
10 1.1 christos * copyright notice and this permission notice appear in all copies.
11 1.1 christos *
12 1.1 christos * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 1.1 christos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 1.1 christos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 1.1 christos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 1.1 christos * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN
17 1.1 christos * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
18 1.1 christos * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 1.1 christos */
20 1.1 christos
21 1.1 christos #include <sys/cdefs.h>
22 1.4 maxv __KERNEL_RCSID(0, "$NetBSD: tpm_isa.c,v 1.4 2019/06/22 12:57:41 maxv Exp $");
23 1.1 christos
24 1.1 christos #include <sys/param.h>
25 1.1 christos #include <sys/systm.h>
26 1.1 christos #include <sys/kernel.h>
27 1.1 christos #include <sys/malloc.h>
28 1.1 christos #include <sys/proc.h>
29 1.1 christos #include <sys/device.h>
30 1.1 christos #include <sys/bus.h>
31 1.1 christos #include <sys/pmf.h>
32 1.1 christos
33 1.1 christos #include <dev/ic/tpmreg.h>
34 1.1 christos #include <dev/ic/tpmvar.h>
35 1.1 christos
36 1.1 christos #include <dev/isa/isareg.h>
37 1.1 christos #include <dev/isa/isavar.h>
38 1.1 christos
39 1.1 christos static int tpm_isa_match(device_t, cfdata_t, void *);
40 1.1 christos static void tpm_isa_attach(device_t, device_t, void *);
41 1.1 christos
42 1.1 christos CFATTACH_DECL_NEW(tpm_isa, sizeof(struct tpm_softc),
43 1.1 christos tpm_isa_match, tpm_isa_attach, NULL, NULL);
44 1.1 christos
45 1.1 christos extern struct cfdriver tpm_cd;
46 1.1 christos
47 1.1 christos static int
48 1.1 christos tpm_isa_match(device_t parent, cfdata_t match, void *aux)
49 1.1 christos {
50 1.1 christos struct isa_attach_args *ia = aux;
51 1.1 christos bus_space_tag_t bt = ia->ia_memt;
52 1.1 christos bus_space_handle_t bh;
53 1.1 christos int rv;
54 1.1 christos
55 1.1 christos /* There can be only one. */
56 1.1 christos if (tpm_cd.cd_devs && tpm_cd.cd_devs[0])
57 1.1 christos return 0;
58 1.1 christos
59 1.1 christos if (ia->ia_iomem[0].ir_addr == ISA_UNKNOWN_IOMEM)
60 1.1 christos return 0;
61 1.1 christos
62 1.1 christos /* XXX: integer locator sign extension */
63 1.4 maxv if (bus_space_map(bt, (unsigned int)ia->ia_iomem[0].ir_addr, TPM_SPACE_SIZE,
64 1.1 christos 0, &bh))
65 1.1 christos return 0;
66 1.1 christos
67 1.1 christos if ((rv = tpm_tis12_probe(bt, bh))) {
68 1.1 christos ia->ia_nio = 0;
69 1.1 christos ia->ia_io[0].ir_size = 0;
70 1.4 maxv ia->ia_iomem[0].ir_size = TPM_SPACE_SIZE;
71 1.1 christos }
72 1.1 christos ia->ia_ndrq = 0;
73 1.1 christos
74 1.4 maxv bus_space_unmap(bt, bh, TPM_SPACE_SIZE);
75 1.1 christos return rv;
76 1.1 christos }
77 1.1 christos
78 1.1 christos static void
79 1.1 christos tpm_isa_attach(device_t parent, device_t self, void *aux)
80 1.1 christos {
81 1.1 christos struct tpm_softc *sc = device_private(self);
82 1.1 christos struct isa_attach_args *ia = aux;
83 1.1 christos bus_addr_t iobase;
84 1.1 christos bus_size_t size;
85 1.1 christos int rv;
86 1.1 christos
87 1.1 christos sc->sc_dev = self;
88 1.4 maxv sc->sc_ver = TPM_1_2;
89 1.1 christos
90 1.4 maxv sc->sc_bt = ia->ia_memt;
91 1.4 maxv iobase = (unsigned int)ia->ia_iomem[0].ir_addr;
92 1.4 maxv size = TPM_SPACE_SIZE;
93 1.4 maxv sc->sc_init = tpm_tis12_init;
94 1.4 maxv sc->sc_start = tpm_tis12_start;
95 1.4 maxv sc->sc_read = tpm_tis12_read;
96 1.4 maxv sc->sc_write = tpm_tis12_write;
97 1.4 maxv sc->sc_end = tpm_tis12_end;
98 1.1 christos
99 1.1 christos if (bus_space_map(sc->sc_bt, iobase, size, 0, &sc->sc_bh)) {
100 1.1 christos aprint_error_dev(sc->sc_dev, "cannot map registers\n");
101 1.1 christos return;
102 1.1 christos }
103 1.1 christos
104 1.4 maxv if ((rv = (*sc->sc_init)(sc, ia->ia_irq[0].ir_irq)) != 0) {
105 1.1 christos bus_space_unmap(sc->sc_bt, sc->sc_bh, size);
106 1.1 christos return;
107 1.2 christos }
108 1.1 christos
109 1.1 christos /*
110 1.1 christos * Only setup interrupt handler when we have a vector and the
111 1.1 christos * chip is TIS 1.2 compliant.
112 1.1 christos */
113 1.1 christos if (sc->sc_init == tpm_tis12_init &&
114 1.1 christos ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ &&
115 1.3 msaitoh (sc->sc_ih = isa_intr_establish_xname(ia->ia_ic,
116 1.3 msaitoh ia->ia_irq[0].ir_irq, IST_EDGE, IPL_TTY, tpm_intr, sc,
117 1.3 msaitoh device_xname(sc->sc_dev))) == NULL) {
118 1.4 maxv bus_space_unmap(sc->sc_bt, sc->sc_bh, TPM_SPACE_SIZE);
119 1.1 christos aprint_error_dev(sc->sc_dev, "cannot establish interrupt\n");
120 1.1 christos return;
121 1.1 christos }
122 1.1 christos
123 1.4 maxv if (!pmf_device_register(sc->sc_dev, tpm12_suspend, tpm12_resume))
124 1.4 maxv aprint_error_dev(sc->sc_dev, "cannot set power mgmt handler\n");
125 1.1 christos }
126