diff --git a/sys/arch/amd64/amd64/identcpu.c b/sys/arch/amd64/amd64/identcpu.c index fc52e6c117a4..b31b98cd8fc0 100644 --- a/sys/arch/amd64/amd64/identcpu.c +++ b/sys/arch/amd64/amd64/identcpu.c @@ -1,4 +1,4 @@ -/* $NetBSD: identcpu.c,v 1.5 2006/08/06 15:37:21 xtraeme Exp $ */ +/* $NetBSD: identcpu.c,v 1.6 2006/08/07 20:58:23 xtraeme Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.5 2006/08/06 15:37:21 xtraeme Exp $"); +__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.6 2006/08/07 20:58:23 xtraeme Exp $"); #include "opt_powernow_k8.h" @@ -45,6 +45,7 @@ __KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.5 2006/08/06 15:37:21 xtraeme Exp $") #include #include +#include #include /* sysctl wants this. */ @@ -102,15 +103,16 @@ identifycpu(struct cpu_info *ci) x86_print_cacheinfo(ci); #ifdef POWERNOW_K8 - uint32_t rval; - int featflag; - - rval = powernow_probe(ci, 0xf00); - - if (rval) { - featflag = powernow_extflags(ci, rval); - if (featflag) - k8_powernow_init(); + if (cpu_model[0] == 'A' || cpu_model[0] == 'O') { + uint32_t rval; + uint8_t featflag; + + rval = powernow_probe(ci, 0xf00); + if (rval) { + featflag = powernow_extflags(ci, rval); + if (featflag) + k8_powernow_init(); + } } #endif } diff --git a/sys/arch/amd64/conf/files.amd64 b/sys/arch/amd64/conf/files.amd64 index 53877f30d7a2..4e448d8a42c1 100644 --- a/sys/arch/amd64/conf/files.amd64 +++ b/sys/arch/amd64/conf/files.amd64 @@ -1,4 +1,4 @@ -# $NetBSD: files.amd64,v 1.26 2006/08/06 15:37:21 xtraeme Exp $ +# $NetBSD: files.amd64,v 1.27 2006/08/07 20:58:23 xtraeme Exp $ # # new style config file for amd64 architecture # @@ -17,10 +17,6 @@ defflag LARGEPAGES # The REAL{BASE,EXT}MEM options defparam opt_realmem.h REALBASEMEM REALEXTMEM - -# AMD Powernow/Cool`n'Quiet Technology -defflag opt_powernow_k8.h POWERNOW_K8 - # # XXX these are just here at the moment so that we can share files # with the i386 (they include the opt_*.h for these) @@ -38,7 +34,6 @@ file arch/amd64/amd64/db_trace.c ddb file arch/amd64/amd64/kgdb_machdep.c kgdb file kern/subr_disk_mbr.c disk file arch/amd64/amd64/gdt.c -file arch/amd64/amd64/powernow_k8.c powernow_k8 # # XXXfvdl write the optimized versions for these. # diff --git a/sys/arch/i386/i386/identcpu.c b/sys/arch/i386/i386/identcpu.c index 4d84b7330a17..a3233ec6a2f5 100644 --- a/sys/arch/i386/i386/identcpu.c +++ b/sys/arch/i386/i386/identcpu.c @@ -1,4 +1,4 @@ -/* $NetBSD: identcpu.c,v 1.35 2006/08/07 17:41:54 oster Exp $ */ +/* $NetBSD: identcpu.c,v 1.36 2006/08/07 20:58:23 xtraeme Exp $ */ /*- * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc. @@ -37,11 +37,12 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.35 2006/08/07 17:41:54 oster Exp $"); +__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.36 2006/08/07 20:58:23 xtraeme Exp $"); #include "opt_cputype.h" #include "opt_enhanced_speedstep.h" #include "opt_powernow_k7.h" +#include "opt_powernow_k8.h" #include #include @@ -53,6 +54,8 @@ __KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.35 2006/08/07 17:41:54 oster Exp $"); #include #include #include +#include +#include static const struct x86_cache_info intel_cpuid_cache_info[] = { @@ -1446,17 +1449,26 @@ identifycpu(struct cpu_info *ci) } #endif /* ENHANCED_SPEEDSTEP */ -#ifdef POWERNOW_K7 -#include - uint32_t rval; - int featflag; +#if defined(POWERNOW_K7) || defined(POWERNOW_K8) + if (vendor == CPUVENDOR_AMD) { + uint32_t rval; + uint8_t featflag; - rval = powernow_probe(ci, 0x600); - if (rval) { - featflag = powernow_extflags(ci, rval); - if (featflag) - k7_powernow_init(); + rval = powernow_probe(ci, 0x600); + if (rval) { + featflag = powernow_extflags(ci, rval); + switch (featflag) { + case 6: + k7_powernow_init(); + break; + case 15: + k8_powernow_init(); + break; + default: + break; + } + } } -#endif /* POWERNOW_K7 */ +#endif /* POWERNOW_K7 || POWERNOW_K8 */ } diff --git a/sys/arch/x86/conf/files.x86 b/sys/arch/x86/conf/files.x86 index bc48cd884e98..2979bab60bb9 100644 --- a/sys/arch/x86/conf/files.x86 +++ b/sys/arch/x86/conf/files.x86 @@ -1,4 +1,4 @@ -# $NetBSD: files.x86,v 1.18 2006/08/06 15:37:21 xtraeme Exp $ +# $NetBSD: files.x86,v 1.19 2006/08/07 20:58:23 xtraeme Exp $ # options for MP configuration through the MP spec defflag opt_mpbios.h MPBIOS MPVERBOSE MPDEBUG MPBIOS_SCANPCI @@ -10,6 +10,9 @@ defflag MTRR defflag opt_pcifixup.h PCI_ADDR_FIXUP PCI_BUS_FIXUP PCI_INTR_FIXUP PCI_INTR_FIXUP_FORCE +# AMD Powernow/Cool`n'Quiet Technology +defflag opt_powernow_k8.h POWERNOW_K8 + define cpubus { [apid = -1] } file arch/x86/x86/apic.c ioapic | lapic @@ -49,4 +52,5 @@ file arch/x86/isa/isa_machdep.c isa file arch/x86/pci/pciide_machdep.c pciide_common # Powernow common functions +file arch/x86/x86/powernow_k8.c powernow_k8 file arch/x86/x86/powernow_common.c powernow_k8 | powernow_k7 diff --git a/sys/arch/x86/include/cpuvar.h b/sys/arch/x86/include/cpuvar.h index e2549cdbf002..dae6222182f2 100644 --- a/sys/arch/x86/include/cpuvar.h +++ b/sys/arch/x86/include/cpuvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: cpuvar.h,v 1.3 2003/10/27 13:43:48 junyoung Exp $ */ +/* $NetBSD: cpuvar.h,v 1.4 2006/08/07 20:58:23 xtraeme Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -107,4 +107,10 @@ void identifycpu(struct cpu_info *); void cpu_init(struct cpu_info *); void cpu_init_first(void); +#include "opt_powernow_k8.h" + +#ifdef POWERNOW_K8 +void k8_powernow_init(void); +#endif + #endif diff --git a/sys/arch/x86/include/powernow.h b/sys/arch/x86/include/powernow.h index 8702511dbe1f..350af3b381ba 100644 --- a/sys/arch/x86/include/powernow.h +++ b/sys/arch/x86/include/powernow.h @@ -1,4 +1,4 @@ -/* $NetBSD: powernow.h,v 1.1 2006/08/06 15:37:21 xtraeme Exp $ */ +/* $NetBSD: powernow.h,v 1.2 2006/08/07 20:58:23 xtraeme Exp $ */ /*- * Copyright (c) 2004 Martin Végiard. @@ -140,22 +140,21 @@ #define POWERNOW_MAX_STATES 16 struct powernow_state { - unsigned int freq; + int freq; uint8_t fid; uint8_t vid; }; struct powernow_cpu_state { struct powernow_state state_table[POWERNOW_MAX_STATES]; - unsigned int flags; unsigned int fsb; - unsigned int irt; - unsigned int mvs; unsigned int n_states; - unsigned int pll; - unsigned int rvo; unsigned int sgtc; unsigned int vst; + unsigned int mvs; + unsigned int pll; + unsigned int rvo; + unsigned int irt; int low; }; @@ -170,7 +169,6 @@ struct powernow_psb_s { struct powernow_pst_s { uint32_t signature; - uint8_t fsb; uint8_t pll; uint8_t fid; uint8_t vid; diff --git a/sys/arch/x86/x86/powernow_common.c b/sys/arch/x86/x86/powernow_common.c index 78951e5e819e..bbd9280273bd 100644 --- a/sys/arch/x86/x86/powernow_common.c +++ b/sys/arch/x86/x86/powernow_common.c @@ -1,4 +1,4 @@ -/* $NetBSD: powernow_common.c,v 1.1 2006/08/06 15:37:21 xtraeme Exp $ */ +/* $NetBSD: powernow_common.c,v 1.2 2006/08/07 20:58:23 xtraeme Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: powernow_common.c,v 1.1 2006/08/06 15:37:21 xtraeme Exp $"); +__KERNEL_RCSID(0, "$NetBSD: powernow_common.c,v 1.2 2006/08/07 20:58:23 xtraeme Exp $"); #include #include @@ -93,9 +93,12 @@ powernow_probe(struct cpu_info *ci, uint32_t val) int powernow_extflags(struct cpu_info *ci, uint32_t feature_flag) { - int j; + int family, j, rval; char *cpuname; + rval = 0; + + family = (ci->ci_signature >> 8) & 15; cpuname = ci->ci_dev->dv_xname; /* Print out available cpuid extended features. */ @@ -111,8 +114,19 @@ powernow_extflags(struct cpu_info *ci, uint32_t feature_flag) * are available, it's ok to continue enabling powernow. */ if ((feature_flag & pnow_extflag[1].mask) && - (feature_flag & pnow_extflag[2].mask)) - return 1; + (feature_flag & pnow_extflag[2].mask)) { + switch (family) { + case 6: + rval = 6; + break; + case 15: + rval = 15; + break; + default: + rval = 0; + break; + } + } - return 0; + return rval; } diff --git a/sys/arch/amd64/amd64/powernow_k8.c b/sys/arch/x86/x86/powernow_k8.c similarity index 92% rename from sys/arch/amd64/amd64/powernow_k8.c rename to sys/arch/x86/x86/powernow_k8.c index be22fbc66245..31a1e781491e 100644 --- a/sys/arch/amd64/amd64/powernow_k8.c +++ b/sys/arch/x86/x86/powernow_k8.c @@ -1,4 +1,4 @@ -/* $NetBSD: powernow_k8.c,v 1.3 2006/08/07 11:39:30 cube Exp $ */ +/* $NetBSD: powernow_k8.c,v 1.1 2006/08/07 20:58:23 xtraeme Exp $ */ /* $OpenBSD: powernow-k8.c,v 1.8 2006/06/16 05:58:50 gwk Exp $ */ /*- @@ -89,7 +89,7 @@ /* AMD POWERNOW K8 driver */ #include -__KERNEL_RCSID(0, "$NetBSD: powernow_k8.c,v 1.3 2006/08/07 11:39:30 cube Exp $"); +__KERNEL_RCSID(0, "$NetBSD: powernow_k8.c,v 1.1 2006/08/07 20:58:23 xtraeme Exp $"); #include #include @@ -97,6 +97,7 @@ __KERNEL_RCSID(0, "$NetBSD: powernow_k8.c,v 1.3 2006/08/07 11:39:30 cube Exp $") #include #include +#include #include #include @@ -318,9 +319,12 @@ k8pnow_states(struct powernow_cpu_state *cstate, uint32_t cpusig, uint8_t *p; int i; + DPRINTF(("%s: before the for loop\n", __func__)); + for (p = (uint8_t *)ISA_HOLE_VADDR(BIOS_START); p < (uint8_t *)ISA_HOLE_VADDR(BIOS_START + BIOS_LEN); p += 16) { if (memcmp(p, "AMDK7PNOW!", 10) == 0) { + DPRINTF(("%s: inside the for loop\n", __func__)); psb = (struct powernow_psb_s *)p; if (psb->version != 0x14) { DPRINTF(("%s: psb->version != 0x14\n", @@ -342,15 +346,18 @@ k8pnow_states(struct powernow_cpu_state *cstate, uint32_t cpusig, cstate->n_states = pst->n_states; if (cpusig == pst->signature && pst->fid == fid && pst->vid == vid) { + DPRINTF(("%s: cpusig = signature\n", + __func__)); return (k8pnow_decode_pst(cstate, p+= sizeof(struct powernow_pst_s))); } - p += sizeof(struct powernow_pst_s) + 2 * - cstate->n_states; + p += sizeof(struct powernow_pst_s) + + 2 * cstate->n_states; } } } + DPRINTF(("%s: returns 0!\n", __func__)); return 0; } @@ -360,7 +367,7 @@ k8_powernow_init(void) { uint64_t status; uint32_t maxfid, maxvid, i; - const struct sysctlnode *node, *pnownode; + const struct sysctlnode *freqnode, *node, *pnownode; struct powernow_cpu_state *cstate; struct cpu_info *ci; char *cpuname; @@ -416,9 +423,11 @@ k8_powernow_init(void) k8pnow_current_state = cstate; DPRINTF(("%s: freq_names=%s\n", __func__, freq_names)); } - } + } else + DPRINTF(("%s: returned 0!\n", __func__)); if (k8pnow_current_state == NULL) { + DPRINTF(("%s: k8pnow_current_state is NULL!\n", __func__)); free(cstate, M_DEVBUF); if (freq_names) free(freq_names, M_SYSCTLDATA); @@ -426,43 +435,50 @@ k8_powernow_init(void) } /* Create sysctl machdep.powernow.frequency. */ - if ((sysctl_createv(NULL, 0, NULL, &node, + if (sysctl_createv(NULL, 0, NULL, &node, CTLFLAG_PERMANENT, CTLTYPE_NODE, "machdep", NULL, NULL, 0, NULL, 0, - CTL_MACHDEP, CTL_EOL)) != 0) + CTL_MACHDEP, CTL_EOL) != 0) goto err; - if ((sysctl_createv(NULL, 0, &node, &pnownode, + if (sysctl_createv(NULL, 0, &node, &pnownode, 0, CTLTYPE_NODE, "powernow", NULL, NULL, 0, NULL, 0, - CTL_CREATE, CTL_EOL)) != 0) + CTL_CREATE, CTL_EOL) != 0) goto err; - if ((sysctl_createv(NULL, 0, &pnownode, &node, + if (sysctl_createv(NULL, 0, &pnownode, &freqnode, + 0, + CTLTYPE_NODE, "frequency", NULL, + NULL, 0, NULL, 0, + CTL_CREATE, CTL_EOL) != 0) + goto err; + + if (sysctl_createv(NULL, 0, &freqnode, &node, CTLFLAG_READWRITE, CTLTYPE_INT, "target", NULL, k8pnow_sysctl_helper, 0, NULL, 0, - CTL_CREATE, CTL_EOL)) != 0) + CTL_CREATE, CTL_EOL) != 0) goto err; powernow_node_target = node->sysctl_num; - if ((sysctl_createv(NULL, 0, &pnownode, &node, + if (sysctl_createv(NULL, 0, &freqnode, &node, 0, CTLTYPE_INT, "current", NULL, k8pnow_sysctl_helper, 0, NULL, 0, - CTL_CREATE, CTL_EOL)) != 0) + CTL_CREATE, CTL_EOL) != 0) goto err; powernow_node_current = node->sysctl_num; - if ((sysctl_createv(NULL, 0, &pnownode, &node, + if (sysctl_createv(NULL, 0, &pnownode, &node, 0, CTLTYPE_STRING, "available", NULL, NULL, 0, freq_names, freq_names_len, - CTL_CREATE, CTL_EOL)) != 0) + CTL_CREATE, CTL_EOL) != 0) goto err; cur_freq = cstate->state_table[cstate->n_states-1].freq;