xref: /netbsd-src/sys/arch/x86/include/powernow.h (revision ad932f2c3578b113c7cf5b3e3d5f468105c4ba8b)
1*ad932f2cSjruoho /*	$NetBSD: powernow.h,v 1.13 2011/02/24 10:56:02 jruoho Exp $	*/
29c74798bSxtraeme 
39c74798bSxtraeme /*-
49c74798bSxtraeme  * Copyright (c) 2004 Martin V�giard.
59c74798bSxtraeme  * All rights reserved.
69c74798bSxtraeme  *
79c74798bSxtraeme  * Redistribution and use in source and binary forms, with or without
89c74798bSxtraeme  * modification, are permitted provided that the following conditions
99c74798bSxtraeme  * are met:
109c74798bSxtraeme  * 1. Redistributions of source code must retain the above copyright
119c74798bSxtraeme  *    notice, this list of conditions and the following disclaimer.
129c74798bSxtraeme  * 2. Redistributions in binary form must reproduce the above copyright
139c74798bSxtraeme  *    notice, this list of conditions and the following disclaimer in the
149c74798bSxtraeme  *    documentation and/or other materials provided with the distribution.
159c74798bSxtraeme  * 3. The name of the author may not be used to endorse or promote products
169c74798bSxtraeme  *    derived from this software without specific prior written permission.
179c74798bSxtraeme  *
189c74798bSxtraeme  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
199c74798bSxtraeme  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
209c74798bSxtraeme  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
219c74798bSxtraeme  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
229c74798bSxtraeme  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
239c74798bSxtraeme  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
249c74798bSxtraeme  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
259c74798bSxtraeme  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
269c74798bSxtraeme  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
279c74798bSxtraeme  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
289c74798bSxtraeme  */
299c74798bSxtraeme 
309c74798bSxtraeme /*-
319c74798bSxtraeme  * Copyright (c) 2004-2005 Bruno Ducrot
329c74798bSxtraeme  * Copyright (c) 2004 FUKUDA Nobuhiko <nfukuda@spa.is.uec.ac.jp>
339c74798bSxtraeme  *
349c74798bSxtraeme  * Redistribution and use in source and binary forms, with or without
359c74798bSxtraeme  * modification, are permitted provided that the following conditions
369c74798bSxtraeme  * are met:
379c74798bSxtraeme  * 1. Redistributions of source code must retain the above copyright
389c74798bSxtraeme  *    notice, this list of conditions and the following disclaimer.
399c74798bSxtraeme  * 2. Redistributions in binary form must reproduce the above copyright
409c74798bSxtraeme  *    notice, this list of conditions and the following disclaimer in the
419c74798bSxtraeme  *    documentation and/or other materials provided with the distribution.
429c74798bSxtraeme  *
439c74798bSxtraeme  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
449c74798bSxtraeme  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
459c74798bSxtraeme  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
469c74798bSxtraeme  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
479c74798bSxtraeme  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
489c74798bSxtraeme  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
499c74798bSxtraeme  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
509c74798bSxtraeme  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
519c74798bSxtraeme  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
529c74798bSxtraeme  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
539c74798bSxtraeme  */
549c74798bSxtraeme 
55*ad932f2cSjruoho #ifndef _X86_POWERNOW_H
56*ad932f2cSjruoho #define _X86_POWERNOW_H
579c74798bSxtraeme 
589c74798bSxtraeme #ifdef POWERNOW_DEBUG
599c74798bSxtraeme #define DPRINTF(x)		do { printf x; } while (0)
609c74798bSxtraeme #else
619c74798bSxtraeme #define DPRINTF(x)
629c74798bSxtraeme #endif
639c74798bSxtraeme 
649c74798bSxtraeme #define BIOS_START			0xe0000
659c74798bSxtraeme #define BIOS_LEN			0x20000
669c74798bSxtraeme #define BIOS_STEP			16
679c74798bSxtraeme 
689c74798bSxtraeme /*
699c74798bSxtraeme  * MSRs and bits used by Powernow technology
709c74798bSxtraeme  */
719c74798bSxtraeme #define MSR_AMDK7_FIDVID_CTL		0xc0010041
729c74798bSxtraeme #define MSR_AMDK7_FIDVID_STATUS		0xc0010042
739c74798bSxtraeme #define AMD_PN_FID_VID			0x06
749c74798bSxtraeme #define AMD_ERRATA_A0_CPUSIG		0x660
759c74798bSxtraeme 
769c74798bSxtraeme #define PN7_FLAG_ERRATA_A0		0x01
779c74798bSxtraeme #define PN7_FLAG_DESKTOP_VRM		0x02
789c74798bSxtraeme 
799c74798bSxtraeme /* Bitfields used by K7 */
809c74798bSxtraeme #define PN7_PSB_VERSION			0x12
819c74798bSxtraeme #define PN7_CTR_FID(x)			((x) & 0x1f)
829c74798bSxtraeme #define PN7_CTR_VID(x)			(((x) & 0x1f) << 8)
839c74798bSxtraeme #define PN7_CTR_FIDC			0x00010000
849c74798bSxtraeme #define PN7_CTR_VIDC			0x00020000
859c74798bSxtraeme #define PN7_CTR_FIDCHRATIO		0x00100000
869c74798bSxtraeme #define PN7_CTR_SGTC(x)			(((uint64_t)(x) & 0x000fffff) << 32)
879c74798bSxtraeme 
889c74798bSxtraeme #define PN7_STA_CFID(x)			((x) & 0x1f)
899c74798bSxtraeme #define PN7_STA_SFID(x)			(((x) >> 8) & 0x1f)
909c74798bSxtraeme #define PN7_STA_MFID(x)			(((x) >> 16) & 0x1f)
919c74798bSxtraeme #define PN7_STA_CVID(x)			(((x) >> 32) & 0x1f)
929c74798bSxtraeme #define PN7_STA_SVID(x)			(((x) >> 40) & 0x1f)
939c74798bSxtraeme #define PN7_STA_MVID(x)			(((x) >> 48) & 0x1f)
949c74798bSxtraeme 
959c74798bSxtraeme /* Bitfields used by K8 */
969c74798bSxtraeme #define PN8_CTR_FID(x)			((x) & 0x3f)
979c74798bSxtraeme #define PN8_CTR_VID(x)			(((x) & 0x1f) << 8)
989c74798bSxtraeme #define PN8_CTR_PENDING(x)		(((x) & 1) << 32)
999c74798bSxtraeme 
1009c74798bSxtraeme #define PN8_STA_CFID(x)			((x) & 0x3f)
1019c74798bSxtraeme #define PN8_STA_SFID(x)			(((x) >> 8) & 0x3f)
1029c74798bSxtraeme #define PN8_STA_MFID(x)			(((x) >> 16) & 0x3f)
1039c74798bSxtraeme #define PN8_STA_PENDING(x)		(((x) >> 31) & 0x01)
1049c74798bSxtraeme #define PN8_STA_CVID(x)			(((x) >> 32) & 0x1f)
1059c74798bSxtraeme #define PN8_STA_SVID(x)			(((x) >> 40) & 0x1f)
1069c74798bSxtraeme #define PN8_STA_MVID(x)			(((x) >> 48) & 0x1f)
1079c74798bSxtraeme 
1089c74798bSxtraeme #define COUNT_OFF_IRT(irt)		DELAY(10 * (1 << (irt)))
1099c74798bSxtraeme #define COUNT_OFF_VST(vst)		DELAY(20 * (vst))
1109c74798bSxtraeme 
1119c74798bSxtraeme #define FID_TO_VCO_FID(fid)	\
1129c74798bSxtraeme 	(((fid) < 8) ? (8 + ((fid) << 1)) : (fid))
1139c74798bSxtraeme 
1149c74798bSxtraeme /* Reserved1 to powernow k8 configuration */
1159c74798bSxtraeme #define PN8_PSB_TO_RVO(x)		((x) & 0x03)
1169c74798bSxtraeme #define PN8_PSB_TO_IRT(x)		(((x) >> 2) & 0x03)
1179c74798bSxtraeme #define PN8_PSB_TO_MVS(x)		(((x) >> 4) & 0x03)
1189c74798bSxtraeme #define PN8_PSB_TO_BATT(x)		(((x) >> 6) & 0x03)
1199c74798bSxtraeme 
1209c74798bSxtraeme #define POWERNOW_MAX_STATES		16
1219c74798bSxtraeme 
1229c74798bSxtraeme struct powernow_state {
123a4a1d218Sxtraeme 	int freq;
1249c74798bSxtraeme 	uint8_t fid;
1259c74798bSxtraeme 	uint8_t vid;
1269c74798bSxtraeme };
1279c74798bSxtraeme 
1289c74798bSxtraeme struct powernow_cpu_state {
1299c74798bSxtraeme 	struct powernow_state	state_table[POWERNOW_MAX_STATES];
1309c74798bSxtraeme 	unsigned int fsb;
1319c74798bSxtraeme 	unsigned int n_states;
1329c74798bSxtraeme 	unsigned int sgtc;
1339c74798bSxtraeme 	unsigned int vst;
134a4a1d218Sxtraeme 	unsigned int mvs;
135a4a1d218Sxtraeme 	unsigned int pll;
136a4a1d218Sxtraeme 	unsigned int rvo;
137a4a1d218Sxtraeme 	unsigned int irt;
1389c74798bSxtraeme 	int low;
1399c74798bSxtraeme };
1409c74798bSxtraeme 
1419c74798bSxtraeme struct powernow_psb_s {
1429c74798bSxtraeme 	char signature[10];	/* AMDK7PNOW! */
1439c74798bSxtraeme 	uint8_t version;
1449c74798bSxtraeme 	uint8_t flags;
1459c74798bSxtraeme 	uint16_t ttime;		/* Min settling time */
1469c74798bSxtraeme 	uint8_t reserved;
1479c74798bSxtraeme 	uint8_t n_pst;
1489c74798bSxtraeme };
1499c74798bSxtraeme 
1509c74798bSxtraeme struct powernow_pst_s {
1519c74798bSxtraeme 	uint32_t signature;
1529c74798bSxtraeme 	uint8_t pll;
1539c74798bSxtraeme 	uint8_t fid;
1549c74798bSxtraeme 	uint8_t vid;
1559c74798bSxtraeme 	uint8_t n_states;
1569c74798bSxtraeme };
1579c74798bSxtraeme 
158*ad932f2cSjruoho #endif	/* !_X86_POWERNOW_H */
159