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