xref: /freebsd/sys/dev/tpm/tpm_isa.c (revision 2008043f386721d58158e37e0d7e50df8095942d)
1 /*
2  * Copyright (c) 2008, 2009 Michael Shalayeff
3  * Copyright (c) 2009, 2010 Hans-Joerg Hoexer
4  * All rights reserved.
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN
15  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
16  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #include <sys/cdefs.h>
20 #include <sys/param.h>
21 #include <sys/systm.h>
22 #include <sys/kernel.h>
23 #include <sys/malloc.h>
24 #include <sys/proc.h>
25 
26 #ifdef __FreeBSD__
27 #include <sys/module.h>
28 #include <sys/conf.h>
29 #include <sys/uio.h>
30 #include <sys/bus.h>
31 
32 #include <machine/bus.h>
33 #include <sys/rman.h>
34 #include <machine/resource.h>
35 
36 #include <machine/md_var.h>
37 
38 #include <isa/isareg.h>
39 #include <isa/isavar.h>
40 #else
41 #include <sys/device.h>
42 
43 #include <machine/cpu.h>
44 #include <machine/bus.h>
45 #include <machine/intr.h>
46 #include <machine/conf.h>
47 
48 #include <dev/isa/isareg.h>
49 #include <dev/isa/isavar.h>
50 #endif
51 #include "tpmvar.h"
52 
53 static int
54 tpm_isa_probe(device_t dev)
55 {
56 	bus_space_tag_t iot;
57 	bus_space_handle_t ioh;
58 	struct resource *mem_res;
59 	int rv, mem_rid;
60 
61 	mem_rid = 0;
62 	mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &mem_rid,
63 	    RF_ACTIVE);
64 	if (mem_res == NULL)
65 		return (ENXIO);
66 	iot = rman_get_bustag(mem_res);
67 	ioh = rman_get_bushandle(mem_res);
68 
69 	if ((rv = tpm_tis12_probe(iot, ioh)))
70 		device_set_desc(dev, "Trusted Platform Module");
71 
72 	bus_release_resource(dev, SYS_RES_MEMORY, mem_rid, mem_res);
73 	return rv ? 0 : ENXIO;
74 }
75 
76 static device_method_t tpm_methods[] = {
77 #if 0
78 	DEVMETHOD(device_identify,	tpm_identify),
79 #endif
80 	DEVMETHOD(device_probe,		tpm_isa_probe),
81 	DEVMETHOD(device_attach,	tpm_attach),
82 	DEVMETHOD(device_detach,	tpm_detach),
83 	DEVMETHOD(device_suspend,	tpm_suspend),
84 	DEVMETHOD(device_resume,	tpm_resume),
85 	{ 0, 0 }
86 };
87 
88 static driver_t tpm_driver = {
89 	"tpm", tpm_methods, sizeof(struct tpm_softc),
90 };
91 
92 DRIVER_MODULE(tpm, isa, tpm_driver, 0, 0);
93