xref: /illumos-gate/usr/src/uts/intel/io/intel_nhm/intel_nhm.h (revision 6e375c8351497b82ffa4f33cbf61d712999b4605)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _INTEL_NHM_H
28 #define	_INTEL_NHM_H
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #define	NHM_CPU	0x2c408086
35 
36 #define	MAX_CPU_NODES	2
37 #define	CPU_PCI_DEVS	6
38 #define	CPU_PCI_FUNCS	6
39 
40 #define	MAX_BUS_NUMBER	max_bus_number
41 
42 #define	SOCKET_BUS(cpu) (MAX_BUS_NUMBER - (cpu))
43 #define	CPU_ID_RD(cpu)  nhm_pci_getl(SOCKET_BUS(cpu), 0, 0, 0, 0)
44 #define	MC_CONTROL_RD(cpu) \
45     nhm_pci_getl(SOCKET_BUS(cpu), 3, 0, 0x48, 0)
46 #define	MC_STATUS_RD(cpu) \
47     nhm_pci_getl(SOCKET_BUS(cpu), 3, 0, 0x4c, 0)
48 #define	MC_SMI_SPARE_DIMM_ERROR_STATUS_RD(cpu) \
49     nhm_pci_getl(SOCKET_BUS(cpu), 3, 0, 0x50, 0)
50 #define	MC_SCRUB_CONTROL_RD(cpu) \
51     nhm_pci_getl(SOCKET_BUS(cpu), 3, 2, 0x4c, 0)
52 #define	MC_SCRUB_CONTROL_WR(cpu, reg) nhm_pci_putl(SOCKET_BUS(cpu), 3, 2, \
53     0x4c, reg);
54 #define	MC_RAS_STATUS_RD(cpu) \
55     nhm_pci_getl(SOCKET_BUS(cpu), 3, 2, 0x54, 0)
56 #define	MC_SSR_CONTROL_RD(cpu)	nhm_pci_getl(SOCKET_BUS(cpu), 3, 2, 0x48, 0)
57 #define	MC_SSR_CONTROL_WR(cpu, reg) nhm_pci_putl(SOCKET_BUS(cpu), 3, 2, 0x48, \
58     reg);
59 #define	MC_SSR_SCRUB_CONTROL_RD(cpu)	nhm_pci_getl(SOCKET_BUS(cpu), 3, 2, \
60     0x4c, 0)
61 #define	MC_RAS_ENABLES_RD(cpu)	nhm_pci_getl(SOCKET_BUS(cpu), 3, 2, 0x50, 0)
62 #define	MC_RAS_STATUS_RD(cpu)	nhm_pci_getl(SOCKET_BUS(cpu), 3, 2, 0x54, 0)
63 #define	MC_SSR_STATUS_RD(cpu)	nhm_pci_getl(SOCKET_BUS(cpu), 3, 2, 0x60, 0)
64 #define	MC_CHANNEL_MAPPER_RD(cpu)	nhm_pci_getl(SOCKET_BUS(cpu), 3, 0, \
65     0x60, 0)
66 #define	MC_COR_ECC_CNT_RD(cpu, select) \
67     nhm_pci_getl(SOCKET_BUS(cpu), 3, 2, 0x80 + ((select) * 4), 0)
68 #define	MC_CHANNEL_RANK_PRESENT_RD(cpu, channel) \
69     nhm_pci_getl(SOCKET_BUS(cpu), (channel) + 4, 0, 0x7c, 0)
70 #define	MC_DOD_RD(cpu, channel, select) \
71     nhm_pci_getl(SOCKET_BUS(cpu), (channel) + 4, 1, 0x48 + ((select) * 4), 0)
72 #define	MC_SAG_RD(cpu, channel, select) \
73     nhm_pci_getl(SOCKET_BUS(cpu), (channel) + 4, 1, 0x80 + ((select) * 4), 0)
74 #define	MC_RIR_LIMIT_RD(cpu, channel, select) \
75     nhm_pci_getl(SOCKET_BUS(cpu), (channel) + 4, 2, 0x40 + ((select) * 4), 0)
76 #define	MC_RIR_WAY_RD(cpu, channel, select) \
77     nhm_pci_getl(SOCKET_BUS(cpu), (channel) + 4, 2, 0x80 + ((select) * 4), 0)
78 #define	MC_CHANNEL_DIMM_INIT_PARAMS_RD(cpu, channel) \
79     nhm_pci_getl(SOCKET_BUS(cpu), (channel) + 4, 0, 0x58, 0)
80 #define	SAD_DRAM_RULE_RD(cpu, rule) \
81     nhm_pci_getl(SOCKET_BUS(cpu), 0, 1, 0x80 + (4 * (rule)), 0)
82 #define	SAD_INTERLEAVE_LIST_RD(cpu, rule) \
83     nhm_pci_getl(SOCKET_BUS(cpu), 0, 1, 0xc0 + (4 * (rule)), 0)
84 #define	TAD_DRAM_RULE_RD(cpu, rule) \
85     nhm_pci_getl(SOCKET_BUS(cpu), 3, 1, 0x80 + (4 * (rule)), 0)
86 #define	TAD_INTERLEAVE_LIST_RD(cpu, rule) \
87     nhm_pci_getl(SOCKET_BUS(cpu), 3, 1, 0xc0 + (4 * (rule)), 0)
88 #define	MC_DIMM_CLK_RATIO_STATUS(cpu) \
89     nhm_pci_getl(SOCKET_BUS(cpu), 3, 4, 0x50, 0)
90 
91 /*
92  * MC_CONTROL
93  */
94 #define	MC_CONTROL_CHANNEL_ACTIVE(reg, channel) \
95 	((reg) & (1 << (8 + (channel))) != 0)
96 #define	MC_CONTROL_ECCEN(reg) (((reg) >> 1) & 1)
97 #define	MC_CONTROL_CLOSED_PAGE(reg) ((reg) & 1)
98 /*
99  * MC_STATUS
100  */
101 #define	CHANNEL_DISABLED(reg, channel) ((reg) & (1 << (channel)))
102 /*
103  * MC_CHANNEL_DIMM_INIT_PARAMS
104  */
105 #define	THREE_DIMMS_PRESENT		(1 << 24) /* not quad rank */
106 #define	SINGLE_QUAD_RANK_PRESENT	(1 << 23)
107 #define	QUAD_RANK_PRESENT		(1 << 22) /* 1 or 2 quad rank dimms */
108 #define	REGISTERED_DIMM			(1 << 15)
109 
110 /*
111  * MC_DOD_CH
112  */
113 #define	RANKOFFSET(reg)	(((reg) >> 10) & 7)
114 #define	DIMMPRESENT(reg) (((reg) & (1 << 9)) != 0)
115 #define	NUMBANK(reg) (((reg) & (3 << 7)) == 0 ? 4 : (((reg) >> 7) & 3) * 8)
116 #define	NUMRANK(reg) (((reg) & (3 << 5)) == 0 ? 1 : (((reg) >> 5) & 3) * 2)
117 #define	NUMROW(reg) ((((reg) >> 2) & 7) + 12)
118 #define	NUMCOL(reg) (((reg) & 3) + 10)
119 #define	DIMMWIDTH	8
120 #define	DIMMSIZE(reg) ((1ULL << (NUMCOL(reg) + NUMROW(reg))) * NUMRANK(reg) \
121 	* NUMBANK(reg) * DIMMWIDTH)
122 
123 /*
124  * MC_SAG_CH
125  */
126 #define	DIVBY3(reg)	(((reg) >> 27) & 1)	/* 3 or 6 way interleave */
127 #define	REMOVE_6(reg)	(((reg) >> 24) & 1)
128 #define	REMOVE_7(reg)	(((reg) >> 25) & 1)
129 #define	REMOVE_8(reg)	(((reg) >> 26) & 1)
130 #define	CH_ADDRESS_OFFSET(reg) \
131 	((int64_t)(((uint64_t)(reg) & 0x00ffffff) << 40) >> 40)
132 /*
133  * MC_RIR_LIMIT_CH
134  */
135 #define	RIR_LIMIT(reg)	((((uint64_t)(reg) & 0x000003ff) + 1) << 28)
136 /*
137  * MC_RIR_WAY_CH
138  */
139 #define	RIR_OFFSET(reg) ((int64_t)(((uint64_t)(reg) & 0x3ff0) << 50) >> 54)
140 #define	RIR_RANK(reg) ((reg) & 0xf)
141 
142 #define	MAX_RIR_WAY 4
143 
144 /*
145  * MC_RAS_ENABLES
146  */
147 #define	RAS_LOCKSTEP_ENABLE(reg) (((reg) & 2) != 0)
148 #define	RAS_MIRROR_MEM_ENABLE(reg) (((reg) & 1) != 0)
149 /*
150  * MC_RAS_STATUS
151  */
152 #define	REDUNDANCY_LOSS(reg) (((reg) & 1) != 0)
153 /*
154  * MC_SSRSTATUS
155  */
156 #define	SPAREING_IN_PROGRESS(reg) (((reg) & 2) != 0)
157 #define	SPAREING_COMPLETE(reg) (((reg) & 1) != 0)
158 
159 /*
160  * MC_SSR_CONTROL
161  */
162 #define	SSR_MODE(reg) ((reg) & 3)
163 #define	SSR_IDLE	0
164 #define	SSR_SCRUB	1
165 #define	SSR_SPARE	2
166 #define	DEMAND_SCRUB_ENABLE	(1 << 6)
167 /*
168  * MC_SCRUB_CONTROL
169  */
170 #define	STARTSCRUB	(1 << 24)
171 /*
172  * MC_DIMM_CLK_RATIO_STATUS
173  */
174 #define	MAX_DIMM_CLK_RATIO(reg) (((reg) >> 24) & 0x1f)
175 /*
176  * MC_SMI_SPARE_DIMM_ERROR_STATUS_RD
177  */
178 #define	REDUNDANCY_LOSS_FAILING_DIMM(status) (((status) >> 12) & 3)
179 #define	DIMM_ERROR_OVERFLOW_STATUS(status) ((status) & 0xfff)
180 
181 #define	MAX_MEMORY_CONTROLLERS	MAX_CPU_NODES
182 #define	CHANNELS_PER_MEMORY_CONTROLLER	3
183 #define	MAX_DIMMS_PER_CHANNEL	3
184 
185 /*
186  * SAD_DRAM_RULE
187  */
188 #define	SAD_DRAM_LIMIT(sad) ((((uint64_t)(sad) & 0x000fffc0ULL) + 0x40) << 20)
189 #define	SAD_DRAM_MODE(sad) (((sad) >> 1) & 3)
190 #define	SAD_DRAM_RULE_ENABLE(sad) ((sad) & 1)
191 
192 #define	SAD_INTERLEAVE(list, num) (((list) >> ((num) * 4)) & 0x3)
193 #define	INTERLEAVE_NWAY 8
194 #define	MAX_SAD_DRAM_RULE 8
195 
196 /*
197  * TAD_DRAM_RULE
198  */
199 #define	TAD_DRAM_LIMIT(tad) ((((uint64_t)(tad) & 0x000fffc0ULL) + 0x40) << 20)
200 #define	TAD_DRAM_MODE(tad) (((tad) >> 1) & 3)
201 #define	TAD_DRAM_RULE_ENABLE(tad) ((tad) & 1)
202 
203 #define	TAD_INTERLEAVE(list, channel) (((list) >> ((channel) * 4)) & 3)
204 
205 #define	MAX_TAD_DRAM_RULE 8
206 
207 #define	VRANK_SZ 0x40000000
208 
209 /*
210  * MC_CHANNEL_MAPPER
211  */
212 #define	CHANNEL_MAP(reg, channel, write) (((reg) >> ((channel) * 6 + \
213 	((write) ? 0 : 3))) & 7)
214 
215 extern int max_bus_number;
216 
217 #ifdef __cplusplus
218 }
219 #endif
220 
221 #endif /* _INTEL_NHM_H */
222