1 /* $NetBSD: powernow.h,v 1.9 2007/03/24 15:35:15 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 #define POWERNOW_MAX_STATES 16 136 137 struct powernow_state { 138 int freq; 139 uint8_t fid; 140 uint8_t vid; 141 }; 142 143 struct powernow_cpu_state { 144 struct powernow_state state_table[POWERNOW_MAX_STATES]; 145 unsigned int fsb; 146 unsigned int n_states; 147 unsigned int sgtc; 148 unsigned int vst; 149 unsigned int mvs; 150 unsigned int pll; 151 unsigned int rvo; 152 unsigned int irt; 153 int low; 154 }; 155 156 struct powernow_psb_s { 157 char signature[10]; /* AMDK7PNOW! */ 158 uint8_t version; 159 uint8_t flags; 160 uint16_t ttime; /* Min settling time */ 161 uint8_t reserved; 162 uint8_t n_pst; 163 }; 164 165 struct powernow_pst_s { 166 uint32_t signature; 167 uint8_t pll; 168 uint8_t fid; 169 uint8_t vid; 170 uint8_t n_states; 171 }; 172 173 int powernow_probe(struct cpu_info *); 174 175 /* i386/i386/powernow_k7.c */ 176 void k7_powernow_init(void); 177 void k7_powernow_destroy(void); 178 179 /* x86/x86/powernow_k8.c */ 180 void k8_powernow_init(void); 181 void k8_powernow_destroy(void); 182 183 #endif 184