xref: /minix3/sys/arch/x86/include/powernow.h (revision 1cd76c751364e6270e8d5a0daebc6d3d169baf4d)
1*1cd76c75SBen Gras /*	$NetBSD: powernow.h,v 1.13 2011/02/24 10:56:02 jruoho Exp $	*/
2*1cd76c75SBen Gras 
3*1cd76c75SBen Gras /*-
4*1cd76c75SBen Gras  * Copyright (c) 2004 Martin V�giard.
5*1cd76c75SBen Gras  * All rights reserved.
6*1cd76c75SBen Gras  *
7*1cd76c75SBen Gras  * Redistribution and use in source and binary forms, with or without
8*1cd76c75SBen Gras  * modification, are permitted provided that the following conditions
9*1cd76c75SBen Gras  * are met:
10*1cd76c75SBen Gras  * 1. Redistributions of source code must retain the above copyright
11*1cd76c75SBen Gras  *    notice, this list of conditions and the following disclaimer.
12*1cd76c75SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
13*1cd76c75SBen Gras  *    notice, this list of conditions and the following disclaimer in the
14*1cd76c75SBen Gras  *    documentation and/or other materials provided with the distribution.
15*1cd76c75SBen Gras  * 3. The name of the author may not be used to endorse or promote products
16*1cd76c75SBen Gras  *    derived from this software without specific prior written permission.
17*1cd76c75SBen Gras  *
18*1cd76c75SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19*1cd76c75SBen Gras  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20*1cd76c75SBen Gras  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21*1cd76c75SBen Gras  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22*1cd76c75SBen Gras  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23*1cd76c75SBen Gras  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24*1cd76c75SBen Gras  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25*1cd76c75SBen Gras  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26*1cd76c75SBen Gras  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27*1cd76c75SBen Gras  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*1cd76c75SBen Gras  */
29*1cd76c75SBen Gras 
30*1cd76c75SBen Gras /*-
31*1cd76c75SBen Gras  * Copyright (c) 2004-2005 Bruno Ducrot
32*1cd76c75SBen Gras  * Copyright (c) 2004 FUKUDA Nobuhiko <nfukuda@spa.is.uec.ac.jp>
33*1cd76c75SBen Gras  *
34*1cd76c75SBen Gras  * Redistribution and use in source and binary forms, with or without
35*1cd76c75SBen Gras  * modification, are permitted provided that the following conditions
36*1cd76c75SBen Gras  * are met:
37*1cd76c75SBen Gras  * 1. Redistributions of source code must retain the above copyright
38*1cd76c75SBen Gras  *    notice, this list of conditions and the following disclaimer.
39*1cd76c75SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
40*1cd76c75SBen Gras  *    notice, this list of conditions and the following disclaimer in the
41*1cd76c75SBen Gras  *    documentation and/or other materials provided with the distribution.
42*1cd76c75SBen Gras  *
43*1cd76c75SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
44*1cd76c75SBen Gras  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
45*1cd76c75SBen Gras  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
46*1cd76c75SBen Gras  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
47*1cd76c75SBen Gras  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48*1cd76c75SBen Gras  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49*1cd76c75SBen Gras  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50*1cd76c75SBen Gras  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51*1cd76c75SBen Gras  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
52*1cd76c75SBen Gras  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53*1cd76c75SBen Gras  */
54*1cd76c75SBen Gras 
55*1cd76c75SBen Gras #ifndef _X86_POWERNOW_H
56*1cd76c75SBen Gras #define _X86_POWERNOW_H
57*1cd76c75SBen Gras 
58*1cd76c75SBen Gras #ifdef POWERNOW_DEBUG
59*1cd76c75SBen Gras #define DPRINTF(x)		do { printf x; } while (0)
60*1cd76c75SBen Gras #else
61*1cd76c75SBen Gras #define DPRINTF(x)
62*1cd76c75SBen Gras #endif
63*1cd76c75SBen Gras 
64*1cd76c75SBen Gras #define BIOS_START			0xe0000
65*1cd76c75SBen Gras #define BIOS_LEN			0x20000
66*1cd76c75SBen Gras #define BIOS_STEP			16
67*1cd76c75SBen Gras 
68*1cd76c75SBen Gras /*
69*1cd76c75SBen Gras  * MSRs and bits used by Powernow technology
70*1cd76c75SBen Gras  */
71*1cd76c75SBen Gras #define MSR_AMDK7_FIDVID_CTL		0xc0010041
72*1cd76c75SBen Gras #define MSR_AMDK7_FIDVID_STATUS		0xc0010042
73*1cd76c75SBen Gras #define AMD_PN_FID_VID			0x06
74*1cd76c75SBen Gras #define AMD_ERRATA_A0_CPUSIG		0x660
75*1cd76c75SBen Gras 
76*1cd76c75SBen Gras #define PN7_FLAG_ERRATA_A0		0x01
77*1cd76c75SBen Gras #define PN7_FLAG_DESKTOP_VRM		0x02
78*1cd76c75SBen Gras 
79*1cd76c75SBen Gras /* Bitfields used by K7 */
80*1cd76c75SBen Gras #define PN7_PSB_VERSION			0x12
81*1cd76c75SBen Gras #define PN7_CTR_FID(x)			((x) & 0x1f)
82*1cd76c75SBen Gras #define PN7_CTR_VID(x)			(((x) & 0x1f) << 8)
83*1cd76c75SBen Gras #define PN7_CTR_FIDC			0x00010000
84*1cd76c75SBen Gras #define PN7_CTR_VIDC			0x00020000
85*1cd76c75SBen Gras #define PN7_CTR_FIDCHRATIO		0x00100000
86*1cd76c75SBen Gras #define PN7_CTR_SGTC(x)			(((uint64_t)(x) & 0x000fffff) << 32)
87*1cd76c75SBen Gras 
88*1cd76c75SBen Gras #define PN7_STA_CFID(x)			((x) & 0x1f)
89*1cd76c75SBen Gras #define PN7_STA_SFID(x)			(((x) >> 8) & 0x1f)
90*1cd76c75SBen Gras #define PN7_STA_MFID(x)			(((x) >> 16) & 0x1f)
91*1cd76c75SBen Gras #define PN7_STA_CVID(x)			(((x) >> 32) & 0x1f)
92*1cd76c75SBen Gras #define PN7_STA_SVID(x)			(((x) >> 40) & 0x1f)
93*1cd76c75SBen Gras #define PN7_STA_MVID(x)			(((x) >> 48) & 0x1f)
94*1cd76c75SBen Gras 
95*1cd76c75SBen Gras /* Bitfields used by K8 */
96*1cd76c75SBen Gras #define PN8_CTR_FID(x)			((x) & 0x3f)
97*1cd76c75SBen Gras #define PN8_CTR_VID(x)			(((x) & 0x1f) << 8)
98*1cd76c75SBen Gras #define PN8_CTR_PENDING(x)		(((x) & 1) << 32)
99*1cd76c75SBen Gras 
100*1cd76c75SBen Gras #define PN8_STA_CFID(x)			((x) & 0x3f)
101*1cd76c75SBen Gras #define PN8_STA_SFID(x)			(((x) >> 8) & 0x3f)
102*1cd76c75SBen Gras #define PN8_STA_MFID(x)			(((x) >> 16) & 0x3f)
103*1cd76c75SBen Gras #define PN8_STA_PENDING(x)		(((x) >> 31) & 0x01)
104*1cd76c75SBen Gras #define PN8_STA_CVID(x)			(((x) >> 32) & 0x1f)
105*1cd76c75SBen Gras #define PN8_STA_SVID(x)			(((x) >> 40) & 0x1f)
106*1cd76c75SBen Gras #define PN8_STA_MVID(x)			(((x) >> 48) & 0x1f)
107*1cd76c75SBen Gras 
108*1cd76c75SBen Gras #define COUNT_OFF_IRT(irt)		DELAY(10 * (1 << (irt)))
109*1cd76c75SBen Gras #define COUNT_OFF_VST(vst)		DELAY(20 * (vst))
110*1cd76c75SBen Gras 
111*1cd76c75SBen Gras #define FID_TO_VCO_FID(fid)	\
112*1cd76c75SBen Gras 	(((fid) < 8) ? (8 + ((fid) << 1)) : (fid))
113*1cd76c75SBen Gras 
114*1cd76c75SBen Gras /* Reserved1 to powernow k8 configuration */
115*1cd76c75SBen Gras #define PN8_PSB_TO_RVO(x)		((x) & 0x03)
116*1cd76c75SBen Gras #define PN8_PSB_TO_IRT(x)		(((x) >> 2) & 0x03)
117*1cd76c75SBen Gras #define PN8_PSB_TO_MVS(x)		(((x) >> 4) & 0x03)
118*1cd76c75SBen Gras #define PN8_PSB_TO_BATT(x)		(((x) >> 6) & 0x03)
119*1cd76c75SBen Gras 
120*1cd76c75SBen Gras #define POWERNOW_MAX_STATES		16
121*1cd76c75SBen Gras 
122*1cd76c75SBen Gras struct powernow_state {
123*1cd76c75SBen Gras 	int freq;
124*1cd76c75SBen Gras 	uint8_t fid;
125*1cd76c75SBen Gras 	uint8_t vid;
126*1cd76c75SBen Gras };
127*1cd76c75SBen Gras 
128*1cd76c75SBen Gras struct powernow_cpu_state {
129*1cd76c75SBen Gras 	struct powernow_state	state_table[POWERNOW_MAX_STATES];
130*1cd76c75SBen Gras 	unsigned int fsb;
131*1cd76c75SBen Gras 	unsigned int n_states;
132*1cd76c75SBen Gras 	unsigned int sgtc;
133*1cd76c75SBen Gras 	unsigned int vst;
134*1cd76c75SBen Gras 	unsigned int mvs;
135*1cd76c75SBen Gras 	unsigned int pll;
136*1cd76c75SBen Gras 	unsigned int rvo;
137*1cd76c75SBen Gras 	unsigned int irt;
138*1cd76c75SBen Gras 	int low;
139*1cd76c75SBen Gras };
140*1cd76c75SBen Gras 
141*1cd76c75SBen Gras struct powernow_psb_s {
142*1cd76c75SBen Gras 	char signature[10];	/* AMDK7PNOW! */
143*1cd76c75SBen Gras 	uint8_t version;
144*1cd76c75SBen Gras 	uint8_t flags;
145*1cd76c75SBen Gras 	uint16_t ttime;		/* Min settling time */
146*1cd76c75SBen Gras 	uint8_t reserved;
147*1cd76c75SBen Gras 	uint8_t n_pst;
148*1cd76c75SBen Gras };
149*1cd76c75SBen Gras 
150*1cd76c75SBen Gras struct powernow_pst_s {
151*1cd76c75SBen Gras 	uint32_t signature;
152*1cd76c75SBen Gras 	uint8_t pll;
153*1cd76c75SBen Gras 	uint8_t fid;
154*1cd76c75SBen Gras 	uint8_t vid;
155*1cd76c75SBen Gras 	uint8_t n_states;
156*1cd76c75SBen Gras };
157*1cd76c75SBen Gras 
158*1cd76c75SBen Gras #endif	/* !_X86_POWERNOW_H */
159