xref: /titanic_50/usr/src/uts/sun4u/io/px/px_csr.h (revision b86efd96f8acd85ddaa930a2f0c1d664237e4aaf)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_PX_CSR_H
28 #define	_SYS_PX_CSR_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /* To read and write whole register */
37 #define	CSR_XR(base, off) \
38 	(*(volatile uint64_t *)((base) + ((off))))
39 
40 #define	CSRA_XR(base, off, index) \
41 	(*(volatile uint64_t *)((base) + ((off) + ((index) * 8))))
42 
43 #define	CSR_XS(base, off, val) \
44 	((*(volatile uint64_t *)((base) + ((off)))) = (val))
45 
46 #define	CSRA_XS(base, off, index, val) \
47 	((*(volatile uint64_t *)((base) + ((off) + ((index) * 8)))) = (val))
48 
49 /* To read, set and clear specific fields within a register */
50 #define	CSR_FR(base, off, bit) \
51 	(((*(volatile uint64_t *) ((base) + ((off)))) >> \
52 	(off ## _ ## bit)) & (off ## _ ## bit ## _MASK))
53 
54 #define	CSRA_FR(base, off, index, bit) \
55 	(((*(volatile uint64_t *) ((base) + ((off) + ((index) * 8)))) >> \
56 	(off ## _ ## bit)) & (off ## _ ## bit ## _MASK))
57 
58 #define	CSR_FS(base, off, bit, val) \
59 	((*(volatile uint64_t *) ((base) + ((off)))) = \
60 	(((*(volatile uint64_t *) ((base) + ((off)))) & \
61 	~(((uint64_t)(off ## _ ## bit ## _MASK)) << \
62 	(off ## _ ## bit))) | (((uint64_t)(val)) << (off ## _ ## bit))))
63 
64 #define	CSRA_FS(base, off, index, bit, val) \
65 	((*(volatile uint64_t *) ((base) + ((off) + ((index) * 8)))) = \
66 	(((*(volatile uint64_t *) ((base) + ((off) + ((index) * 8)))) & \
67 	~(((uint64_t)(off ## _ ## bit ## _MASK)) << \
68 	(off ## _ ## bit))) | (((uint64_t)(val)) << (off ## _ ## bit))))
69 
70 #define	CSR_FC(base, off, bit) \
71 	((*(volatile uint64_t *) ((base) + ((off)))) = \
72 	((*(volatile uint64_t *)((base) + ((off)))) & \
73 	~(((uint64_t)(off ## _ ## bit ## _MASK)) << (off ## _ ## bit))))
74 
75 #define	CSRA_FC(base, off, index, bit) \
76 	((*(volatile uint64_t *) ((base) + ((off) + ((index) * 8)))) = \
77 	((*(volatile uint64_t *)((base) + ((off) + ((index) * 8)))) & \
78 	~(((uint64_t)(off ## _ ## bit ## _MASK)) << (off ## _ ## bit))))
79 
80 /* To read, set and clear specific bit within a register */
81 #define	CSR_BR(base, off, bit) \
82 	(((*(volatile uint64_t *)((base) + ((off)))) >> \
83 	(off ## _ ## bit)) & 0x1)
84 
85 #define	CSRA_BR(base, off, index, bit) \
86 	(((*(volatile uint64_t *)((base) + ((off) + ((index) * 8)))) >> \
87 	(off ## _ ## bit)) & 0x1)
88 
89 #define	CSR_BS(base, off, bit) \
90 	((*(volatile uint64_t *)((base) + ((off)))) = \
91 	((*(volatile uint64_t *)((base) + ((off)))) | \
92 	(1ull<<(off ## _ ## bit))))
93 
94 #define	CSRA_BS(base, off, index, bit) \
95 	((*(volatile uint64_t *)((base) + ((off) + ((index) * 8)))) = \
96 	((*(volatile uint64_t *)((base) + ((off) + ((index) * 8)))) | \
97 	(1ull<<(off ## _ ## bit))))
98 
99 #define	CSR_BC(base, off, bit) \
100 	((*(volatile uint64_t *)((base) + ((off)))) = \
101 	((*(volatile uint64_t *)((base) + ((off)))) & \
102 	~(1ull<<(off ## _ ## bit))))
103 
104 #define	CSRA_BC(base, off, index, bit) \
105 	((*(volatile uint64_t *)((base) + ((off) + ((index) * 8)))) = \
106 	((*(volatile uint64_t *)((base) + ((off) + ((index) * 8)))) & \
107 	~(1ull<<(off ## _ ## bit))))
108 
109 #define	BIT_TST(reg, bitno)	(reg & (1ull << bitno))
110 #define	BITMASK(bitno)		(1ull << bitno)
111 
112 #ifdef	__cplusplus
113 }
114 #endif
115 
116 #endif	/* _SYS_PX_CSR_H */
117