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