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