xref: /netbsd-src/sys/arch/x86/include/via_padlock.h (revision 4509949ad106f7217b9ab7d14e10e286a13be2e9)
1 /*	$NetBSD: via_padlock.h,v 1.10 2020/06/29 23:38:02 riastradh Exp $	*/
2 
3 /*-
4  * Copyright (c) 2003 Jason Wright
5  * Copyright (c) 2003, 2004 Theo de Raadt
6  * All rights reserved.
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 #ifndef _X86_VIA_PADLOCK_H_
22 #define _X86_VIA_PADLOCK_H_
23 
24 #if defined(_KERNEL)
25 
26 #include <sys/rndsource.h>
27 #include <sys/callout.h>
28 
29 #include <crypto/aes/aes.h>
30 
31 /* VIA C3 xcrypt-* instruction context control options */
32 #define C3_CRYPT_CWLO_ROUND_M		0x0000000f
33 #define C3_CRYPT_CWLO_ALG_M		0x00000070
34 #define C3_CRYPT_CWLO_ALG_AES		0x00000000
35 #define C3_CRYPT_CWLO_KEYGEN_M		0x00000080
36 #define C3_CRYPT_CWLO_KEYGEN_HW		0x00000000
37 #define C3_CRYPT_CWLO_KEYGEN_SW		0x00000080
38 #define C3_CRYPT_CWLO_NORMAL		0x00000000
39 #define C3_CRYPT_CWLO_INTERMEDIATE	0x00000100
40 #define C3_CRYPT_CWLO_ENCRYPT		0x00000000
41 #define C3_CRYPT_CWLO_DECRYPT		0x00000200
42 #define C3_CRYPT_CWLO_KEY128		0x0000000a      /* 128bit, 10 rds */
43 #define C3_CRYPT_CWLO_KEY192		0x0000040c      /* 192bit, 12 rds */
44 #define C3_CRYPT_CWLO_KEY256		0x0000080e      /* 256bit, 15 rds */
45 
46 struct via_padlock_session {
47         uint32_t	ses_ekey[4*(AES_256_NROUNDS + 1)];
48         uint32_t	ses_dkey[4*(AES_256_NROUNDS + 1)];
49         uint32_t	ses_cw0;
50         struct swcr_data	*swd;
51         int	ses_klen;
52         int	ses_used;
53 };
54 
55 struct via_padlock_softc {
56 	device_t	sc_dev;
57 
58 	uint32_t	op_cw[4];	/* 128 bit aligned */
59 	uint8_t	op_iv[16];	/* 128 bit aligned */
60 	void		*op_buf;
61 
62 	/* normal softc stuff */
63 	int32_t		sc_cid;
64 	bool		sc_cid_attached;
65 	int		sc_nsessions;
66 	struct via_padlock_session *sc_sessions;
67 };
68 
69 #define VIAC3_SESSION(sid)	((sid) & 0x0fffffff)
70 #define VIAC3_SID(crd,ses)	(((crd) << 28) | ((ses) & 0x0fffffff))
71 
72 #endif /* _KERNEL */
73 
74 #if defined(_KERNEL) || defined(_KMEMUSER)
75 struct cpu_info;
76 
77 struct via_padlock {
78 	struct cpu_info		*vp_ci;
79 	int			vp_freq;
80 };
81 
82 #endif /* _KERNEL || _KMEMUSER */
83 #endif /* _X86_VIA_PADLOCK_H_ */
84