powernow.h revision 1.2
11.2Sxtraeme/*	$NetBSD: powernow.h,v 1.2 2006/08/07 20:58:23 xtraeme Exp $	*/
21.1Sxtraeme
31.1Sxtraeme/*-
41.1Sxtraeme * Copyright (c) 2004 Martin V�giard.
51.1Sxtraeme * All rights reserved.
61.1Sxtraeme *
71.1Sxtraeme * Redistribution and use in source and binary forms, with or without
81.1Sxtraeme * modification, are permitted provided that the following conditions
91.1Sxtraeme * are met:
101.1Sxtraeme * 1. Redistributions of source code must retain the above copyright
111.1Sxtraeme *    notice, this list of conditions and the following disclaimer.
121.1Sxtraeme * 2. Redistributions in binary form must reproduce the above copyright
131.1Sxtraeme *    notice, this list of conditions and the following disclaimer in the
141.1Sxtraeme *    documentation and/or other materials provided with the distribution.
151.1Sxtraeme * 3. The name of the author may not be used to endorse or promote products
161.1Sxtraeme *    derived from this software without specific prior written permission.
171.1Sxtraeme *
181.1Sxtraeme * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
191.1Sxtraeme * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
201.1Sxtraeme * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
211.1Sxtraeme * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
221.1Sxtraeme * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
231.1Sxtraeme * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
241.1Sxtraeme * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
251.1Sxtraeme * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
261.1Sxtraeme * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
271.1Sxtraeme * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
281.1Sxtraeme */
291.1Sxtraeme
301.1Sxtraeme/*-
311.1Sxtraeme * Copyright (c) 2004-2005 Bruno Ducrot
321.1Sxtraeme * Copyright (c) 2004 FUKUDA Nobuhiko <nfukuda@spa.is.uec.ac.jp>
331.1Sxtraeme *
341.1Sxtraeme * Redistribution and use in source and binary forms, with or without
351.1Sxtraeme * modification, are permitted provided that the following conditions
361.1Sxtraeme * are met:
371.1Sxtraeme * 1. Redistributions of source code must retain the above copyright
381.1Sxtraeme *    notice, this list of conditions and the following disclaimer.
391.1Sxtraeme * 2. Redistributions in binary form must reproduce the above copyright
401.1Sxtraeme *    notice, this list of conditions and the following disclaimer in the
411.1Sxtraeme *    documentation and/or other materials provided with the distribution.
421.1Sxtraeme *
431.1Sxtraeme * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
441.1Sxtraeme * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
451.1Sxtraeme * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
461.1Sxtraeme * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
471.1Sxtraeme * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
481.1Sxtraeme * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
491.1Sxtraeme * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
501.1Sxtraeme * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
511.1Sxtraeme * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
521.1Sxtraeme * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
531.1Sxtraeme */
541.1Sxtraeme
551.1Sxtraeme#ifndef X86_POWERNOW_H
561.1Sxtraeme#define X86_POWERNOW_H
571.1Sxtraeme
581.1Sxtraeme#ifdef POWERNOW_DEBUG
591.1Sxtraeme#define DPRINTF(x)		do { printf x; } while (0)
601.1Sxtraeme#else
611.1Sxtraeme#define DPRINTF(x)
621.1Sxtraeme#endif
631.1Sxtraeme
641.1Sxtraeme#define BIOS_START			0xe0000
651.1Sxtraeme#define BIOS_LEN			0x20000
661.1Sxtraeme#define BIOS_STEP			16
671.1Sxtraeme
681.1Sxtraeme/*
691.1Sxtraeme * MSRs and bits used by Powernow technology
701.1Sxtraeme */
711.1Sxtraeme#define MSR_AMDK7_FIDVID_CTL		0xc0010041
721.1Sxtraeme#define MSR_AMDK7_FIDVID_STATUS		0xc0010042
731.1Sxtraeme#define AMD_PN_FID_VID			0x06
741.1Sxtraeme#define AMD_ERRATA_A0_CPUSIG		0x660
751.1Sxtraeme
761.1Sxtraeme#define PN7_FLAG_ERRATA_A0		0x01
771.1Sxtraeme#define PN7_FLAG_DESKTOP_VRM		0x02
781.1Sxtraeme
791.1Sxtraeme/* Bitfields used by K7 */
801.1Sxtraeme#define PN7_PSB_VERSION			0x12
811.1Sxtraeme#define PN7_CTR_FID(x)			((x) & 0x1f)
821.1Sxtraeme#define PN7_CTR_VID(x)			(((x) & 0x1f) << 8)
831.1Sxtraeme#define PN7_CTR_FIDC			0x00010000
841.1Sxtraeme#define PN7_CTR_VIDC			0x00020000
851.1Sxtraeme#define PN7_CTR_FIDCHRATIO		0x00100000
861.1Sxtraeme#define PN7_CTR_SGTC(x)			(((uint64_t)(x) & 0x000fffff) << 32)
871.1Sxtraeme
881.1Sxtraeme#define PN7_STA_CFID(x)			((x) & 0x1f)
891.1Sxtraeme#define PN7_STA_SFID(x)			(((x) >> 8) & 0x1f)
901.1Sxtraeme#define PN7_STA_MFID(x)			(((x) >> 16) & 0x1f)
911.1Sxtraeme#define PN7_STA_CVID(x)			(((x) >> 32) & 0x1f)
921.1Sxtraeme#define PN7_STA_SVID(x)			(((x) >> 40) & 0x1f)
931.1Sxtraeme#define PN7_STA_MVID(x)			(((x) >> 48) & 0x1f)
941.1Sxtraeme
951.1Sxtraeme/*
961.1Sxtraeme * ACPI ctr_val status register to powernow k7 configuration
971.1Sxtraeme */
981.1Sxtraeme#define PN7_ACPI_CTRL_TO_VID(x)		(((x) >> 5) & 0x1f)
991.1Sxtraeme#define PN7_ACPI_CTRL_TO_SGTC(x)	(((x) >> 10) & 0xffff)
1001.1Sxtraeme
1011.1Sxtraeme/* Bitfields used by K8 */
1021.1Sxtraeme#define PN8_CTR_FID(x)			((x) & 0x3f)
1031.1Sxtraeme#define PN8_CTR_VID(x)			(((x) & 0x1f) << 8)
1041.1Sxtraeme#define PN8_CTR_PENDING(x)		(((x) & 1) << 32)
1051.1Sxtraeme
1061.1Sxtraeme#define PN8_STA_CFID(x)			((x) & 0x3f)
1071.1Sxtraeme#define PN8_STA_SFID(x)			(((x) >> 8) & 0x3f)
1081.1Sxtraeme#define PN8_STA_MFID(x)			(((x) >> 16) & 0x3f)
1091.1Sxtraeme#define PN8_STA_PENDING(x)		(((x) >> 31) & 0x01)
1101.1Sxtraeme#define PN8_STA_CVID(x)			(((x) >> 32) & 0x1f)
1111.1Sxtraeme#define PN8_STA_SVID(x)			(((x) >> 40) & 0x1f)
1121.1Sxtraeme#define PN8_STA_MVID(x)			(((x) >> 48) & 0x1f)
1131.1Sxtraeme
1141.1Sxtraeme#define COUNT_OFF_IRT(irt)		DELAY(10 * (1 << (irt)))
1151.1Sxtraeme#define COUNT_OFF_VST(vst)		DELAY(20 * (vst))
1161.1Sxtraeme
1171.1Sxtraeme#define FID_TO_VCO_FID(fid)	\
1181.1Sxtraeme	(((fid) < 8) ? (8 + ((fid) << 1)) : (fid))
1191.1Sxtraeme
1201.1Sxtraeme/* Reserved1 to powernow k8 configuration */
1211.1Sxtraeme#define PN8_PSB_TO_RVO(x)		((x) & 0x03)
1221.1Sxtraeme#define PN8_PSB_TO_IRT(x)		(((x) >> 2) & 0x03)
1231.1Sxtraeme#define PN8_PSB_TO_MVS(x)		(((x) >> 4) & 0x03)
1241.1Sxtraeme#define PN8_PSB_TO_BATT(x)		(((x) >> 6) & 0x03)
1251.1Sxtraeme
1261.1Sxtraeme/* ACPI ctr_val status register to powernow k8 configuration */
1271.1Sxtraeme#define ACPI_PN8_CTRL_TO_FID(x)		((x) & 0x3f)
1281.1Sxtraeme#define ACPI_PN8_CTRL_TO_VID(x)		(((x) >> 6) & 0x1f)
1291.1Sxtraeme#define ACPI_PN8_CTRL_TO_VST(x)		(((x) >> 11) & 0x1f)
1301.1Sxtraeme#define ACPI_PN8_CTRL_TO_MVS(x)		(((x) >> 18) & 0x03)
1311.1Sxtraeme#define ACPI_PN8_CTRL_TO_PLL(x)		(((x) >> 20) & 0x7f)
1321.1Sxtraeme#define ACPI_PN8_CTRL_TO_RVO(x)		(((x) >> 28) & 0x03)
1331.1Sxtraeme#define ACPI_PN8_CTRL_TO_IRT(x)		(((x) >> 30) & 0x03)
1341.1Sxtraeme
1351.1Sxtraeme
1361.1Sxtraeme#define WRITE_FIDVID(fid, vid, ctrl)	\
1371.1Sxtraeme	wrmsr(MSR_AMDK7_FIDVID_CTL,	\
1381.1Sxtraeme		(((ctrl) << 32) | (1ULL << 16) | ((vid) << 8) | (fid)))
1391.1Sxtraeme
1401.1Sxtraeme#define POWERNOW_MAX_STATES		16
1411.1Sxtraeme
1421.1Sxtraemestruct powernow_state {
1431.2Sxtraeme	int freq;
1441.1Sxtraeme	uint8_t fid;
1451.1Sxtraeme	uint8_t vid;
1461.1Sxtraeme};
1471.1Sxtraeme
1481.1Sxtraemestruct powernow_cpu_state {
1491.1Sxtraeme	struct powernow_state state_table[POWERNOW_MAX_STATES];
1501.1Sxtraeme	unsigned int fsb;
1511.2Sxtraeme	unsigned int n_states;
1521.2Sxtraeme	unsigned int sgtc;
1531.2Sxtraeme	unsigned int vst;
1541.1Sxtraeme	unsigned int mvs;
1551.1Sxtraeme	unsigned int pll;
1561.1Sxtraeme	unsigned int rvo;
1571.2Sxtraeme	unsigned int irt;
1581.1Sxtraeme	int low;
1591.1Sxtraeme};
1601.1Sxtraeme
1611.1Sxtraemestruct powernow_psb_s {
1621.1Sxtraeme	char signature[10];	/* AMDK7PNOW! */
1631.1Sxtraeme	uint8_t version;
1641.1Sxtraeme	uint8_t flags;
1651.1Sxtraeme	uint16_t ttime;		/* Min settling time */
1661.1Sxtraeme	uint8_t reserved;
1671.1Sxtraeme	uint8_t n_pst;
1681.1Sxtraeme};
1691.1Sxtraeme
1701.1Sxtraemestruct powernow_pst_s {
1711.1Sxtraeme	uint32_t signature;
1721.1Sxtraeme	uint8_t pll;
1731.1Sxtraeme	uint8_t fid;
1741.1Sxtraeme	uint8_t vid;
1751.1Sxtraeme	uint8_t n_states;
1761.1Sxtraeme};
1771.1Sxtraeme
1781.1Sxtraemeuint32_t	powernow_probe(struct cpu_info *, uint32_t);
1791.1Sxtraemeint		powernow_extflags(struct cpu_info *, uint32_t);
1801.1Sxtraeme
1811.1Sxtraeme#endif
182