xref: /freebsd/sys/dev/tpm/tpm_isa.c (revision e28a4053)
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 __FBSDID("$FreeBSD$");
21 
22 #include <sys/param.h>
23 #include <sys/systm.h>
24 #include <sys/kernel.h>
25 #include <sys/malloc.h>
26 #include <sys/proc.h>
27 
28 #ifdef __FreeBSD__
29 #include <sys/module.h>
30 #include <sys/conf.h>
31 #include <sys/uio.h>
32 #include <sys/bus.h>
33 
34 #include <machine/bus.h>
35 #include <sys/rman.h>
36 #include <machine/resource.h>
37 
38 #include <machine/md_var.h>
39 
40 #include <isa/isareg.h>
41 #include <isa/isavar.h>
42 #else
43 #include <sys/device.h>
44 
45 #include <machine/cpu.h>
46 #include <machine/bus.h>
47 #include <machine/intr.h>
48 #include <machine/conf.h>
49 
50 #include <dev/isa/isareg.h>
51 #include <dev/isa/isavar.h>
52 #endif
53 #include "tpmvar.h"
54 
55 static int
56 tpm_isa_probe(device_t dev)
57 {
58 	bus_space_tag_t iot;
59 	bus_space_handle_t ioh;
60 	struct resource *mem_res;
61 	int rv, mem_rid;
62 
63 	mem_rid = 0;
64 	mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &mem_rid,
65 	    RF_ACTIVE);
66 	if (mem_res == NULL)
67 		return (ENXIO);
68 	iot = rman_get_bustag(mem_res);
69 	ioh = rman_get_bushandle(mem_res);
70 
71 	if ((rv = tpm_tis12_probe(iot, ioh)))
72 		device_set_desc(dev, "Trusted Platform Module");
73 
74 	bus_release_resource(dev, SYS_RES_MEMORY, mem_rid, mem_res);
75 	return rv ? 0 : ENXIO;
76 }
77 
78 static device_method_t tpm_methods[] = {
79 #if 0
80 	DEVMETHOD(device_identify,	tpm_identify),
81 #endif
82 	DEVMETHOD(device_probe,		tpm_isa_probe),
83 	DEVMETHOD(device_attach,	tpm_attach),
84 	DEVMETHOD(device_detach,	tpm_detach),
85 	DEVMETHOD(device_suspend,	tpm_suspend),
86 	DEVMETHOD(device_resume,	tpm_resume),
87 	{ 0, 0 }
88 };
89 
90 static driver_t tpm_driver = {
91 	"tpm", tpm_methods, sizeof(struct tpm_softc),
92 };
93 
94 static devclass_t tpm_devclass;
95 
96 DRIVER_MODULE(tpm, isa, tpm_driver, tpm_devclass, 0, 0);
97