Home | History | Annotate | Line # | Download | only in ic
      1 /*	$NetBSD: tpmvar.h,v 1.10 2021/12/20 23:05:55 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2019 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Maxime Villard.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #ifndef	DEV_IC_TPMVAR_H
     33 #define	DEV_IC_TPMVAR_H
     34 
     35 #include <sys/types.h>
     36 
     37 #define TPM_API_VERSION		1
     38 
     39 enum tpm_version {
     40 	TPM_1_2,
     41 	TPM_2_0
     42 };
     43 
     44 enum itf_version {
     45 	TIS_1_2,
     46 	CRB
     47 };
     48 
     49 struct tpm_ioc_getinfo {
     50 	uint32_t api_version;
     51 	uint32_t tpm_version;
     52 	uint32_t itf_version;
     53 	uint32_t device_id;
     54 	uint32_t device_rev;
     55 	uint32_t device_caps;
     56 };
     57 
     58 #define TPM_IOC_GETINFO		_IOR ('N',  0, struct tpm_ioc_getinfo)
     59 
     60 #ifdef _KERNEL
     61 
     62 #include <sys/bus.h>
     63 #include <sys/device_if.h>
     64 #include <sys/mutex.h>
     65 #include <sys/rndsource.h>
     66 #include <sys/workqueue.h>
     67 
     68 struct tpm_softc;
     69 
     70 struct tpm_intf {
     71 	enum itf_version version;
     72 	int (*probe)(bus_space_tag_t, bus_space_handle_t);
     73 	int (*init)(struct tpm_softc *);
     74 	int (*start)(struct tpm_softc *, int);
     75 	int (*read)(struct tpm_softc *, void *, size_t, size_t *, int);
     76 	int (*write)(struct tpm_softc *, const void *, size_t);
     77 	int (*end)(struct tpm_softc *, int, int);
     78 };
     79 
     80 extern const struct tpm_intf tpm_intf_tis12;
     81 
     82 struct tpm_softc {
     83 	device_t sc_dev;
     84 	enum tpm_version sc_ver;
     85 	kmutex_t sc_lock;
     86 	bool sc_busy;
     87 
     88 	const struct tpm_intf *sc_intf;
     89 	bus_space_tag_t sc_bt;
     90 	bus_space_handle_t sc_bh;
     91 
     92 	uint32_t sc_devid;
     93 	uint32_t sc_rev;
     94 	uint32_t sc_status;
     95 	uint32_t sc_caps;
     96 
     97 	struct krndsource sc_rnd;
     98 	struct workqueue *sc_rndwq;
     99 	struct work sc_rndwk;
    100 	volatile unsigned sc_rndpending;
    101 	bool sc_rnddisabled;
    102 };
    103 
    104 bool tpm_suspend(device_t, const pmf_qual_t *);
    105 bool tpm_resume(device_t, const pmf_qual_t *);
    106 
    107 #endif
    108 
    109 #endif	/* DEV_IC_TPMVAR_H */
    110