From owner-freebsd-current@FreeBSD.ORG Thu Mar 12 17:58:10 2009 Return-Path: Delivered-To: freebsd-current@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 30431106566C; Thu, 12 Mar 2009 17:58:10 +0000 (UTC) (envelope-from nork@FreeBSD.org) Received: from sakura.ninth-nine.com (unknown [IPv6:2001:2f0:104:80a0:230:48ff:fe41:2455]) by mx1.freebsd.org (Postfix) with ESMTP id A07288FC20; Thu, 12 Mar 2009 17:58:09 +0000 (UTC) (envelope-from nork@FreeBSD.org) Received: from nadesico.ninth-nine.com (nadesico.ninth-nine.com [219.127.74.122]) by sakura.ninth-nine.com (8.14.1/8.14.1/NinthNine) with SMTP id n2CHw8bB059151; Fri, 13 Mar 2009 02:58:08 +0900 (JST) (envelope-from nork@FreeBSD.org) Date: Fri, 13 Mar 2009 02:58:08 +0900 From: Norikatsu Shigemura To: Rui Paulo Message-Id: <20090313025808.89b7eb94.nork@FreeBSD.org> In-Reply-To: <46A6E01C-5BE7-4619-8D67-F7135AD7B26E@FreeBSD.org> References: <20090301181631.d2e3c89e.nork@FreeBSD.org> <554FEBB3-CB69-4502-9728-C4735B29F784@FreeBSD.org> <20090301234328.9aa4237c.nork@FreeBSD.org> <69C4F850-1DCC-4E15-84E7-1B0E7C656CE6@FreeBSD.org> <20090302003904.12d683c1.nork@FreeBSD.org> <87F4F8E8-CB5A-476D-A57B-A3EBF44272EF@FreeBSD.org> <20090310020627.4482190d.nork@FreeBSD.org> <20090313024149.d4cceaf6.nork@FreeBSD.org> <46A6E01C-5BE7-4619-8D67-F7135AD7B26E@FreeBSD.org> X-Mailer: Sylpheed 2.6.0 (GTK+ 2.14.7; i386-portbld-freebsd8.0) Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Multipart=_Fri__13_Mar_2009_02_58_08_+0900_u/yV0oF_ZtODnYbi" X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0.2 (sakura.ninth-nine.com [219.127.74.121]); Fri, 13 Mar 2009 02:58:08 +0900 (JST) Cc: freebsd-current@FreeBSD.org, nork@FreeBSD.org Subject: Re: ktemp(8) on Phenom II X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Mar 2009 17:58:10 -0000 This is a multi-part message in MIME format. --Multipart=_Fri__13_Mar_2009_02_58_08_+0900_u/yV0oF_ZtODnYbi Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Hi Rui! On Thu, 12 Mar 2009 17:47:33 +0000 Rui Paulo wrote: > Ok, then send the patch to me in mime format and I'll do it. Thank you, please! --Multipart=_Fri__13_Mar_2009_02_58_08_+0900_u/yV0oF_ZtODnYbi Content-Type: text/plain; name="k8temp.diff" Content-Disposition: attachment; filename="k8temp.diff" Content-Transfer-Encoding: 7bit --- sys/dev/k8temp/k8temp.c.orig 2008-11-29 23:26:22.000000000 +0900 +++ sys/dev/k8temp/k8temp.c 2009-03-10 01:04:54.908034051 +0900 @@ -48,6 +48,15 @@ #include #include +typedef enum { + SENSOR0_CORE0, + SENSOR0_CORE1, + SENSOR1_CORE0, + SENSOR1_CORE1, + CORE0, + CORE1 +} k8sensor_t; + struct k8temp_softc { device_t sc_dev; int sc_temps[4]; @@ -55,36 +64,38 @@ struct sysctl_oid *sc_oid; struct sysctl_oid *sc_sysctl_cpu[2]; struct intr_config_hook sc_ich; + int32_t (*sc_gettemp)(device_t, k8sensor_t); }; #define VENDORID_AMD 0x1022 -#define DEVICEID_AMD_MISC 0x1103 +#define DEVICEID_AMD_MISC0F 0x1103 +#define DEVICEID_AMD_MISC10 0x1203 +#define DEVICEID_AMD_MISC11 0x1303 static struct k8temp_product { uint16_t k8temp_vendorid; uint16_t k8temp_deviceid; } k8temp_products[] = { - { VENDORID_AMD, DEVICEID_AMD_MISC }, + { VENDORID_AMD, DEVICEID_AMD_MISC0F }, + { VENDORID_AMD, DEVICEID_AMD_MISC10 }, + { VENDORID_AMD, DEVICEID_AMD_MISC11 }, { 0, 0 } }; /* * Register control */ -#define K8TEMP_REG 0xe4 +#define K8TEMP_REG0F 0xe4 #define K8TEMP_REG_SELSENSOR 0x40 #define K8TEMP_REG_SELCORE 0x04 -#define K8TEMP_MINTEMP 49 /* -49 C is the mininum temperature */ +#define K8TEMP_REG 0xa4 -typedef enum { - SENSOR0_CORE0, - SENSOR0_CORE1, - SENSOR1_CORE0, - SENSOR1_CORE1, - CORE0, - CORE1 -} k8sensor_t; +#define TZ_ZEROC 2732 + + /* -49 C is the mininum temperature */ +#define K8TEMP_OFFSET0F (TZ_ZEROC-490) +#define K8TEMP_OFFSET (TZ_ZEROC) /* * Device methods. @@ -95,6 +106,7 @@ static void k8temp_intrhook(void *arg); static int k8temp_detach(device_t dev); static int k8temp_match(device_t dev); +static int32_t k8temp_gettemp0f(device_t dev, k8sensor_t sensor); static int32_t k8temp_gettemp(device_t dev, k8sensor_t sensor); static int k8temp_sysctl(SYSCTL_HANDLER_ARGS); @@ -193,6 +205,13 @@ return (ENXIO); } + if (pci_get_device(dev) == DEVICEID_AMD_MISC0F) + sc->sc_gettemp = k8temp_gettemp0f; + else { + sc->sc_gettemp = k8temp_gettemp; + return (0); + } + /* * dev.k8temp.N tree. */ @@ -204,13 +223,13 @@ SYSCTL_ADD_PROC(sysctlctx, SYSCTL_CHILDREN(sysctlnode), OID_AUTO, "core0", CTLTYPE_INT | CTLFLAG_RD, - dev, SENSOR0_CORE0, k8temp_sysctl, "I", + dev, SENSOR0_CORE0, k8temp_sysctl, "IK", "Sensor 0 / Core 0 temperature"); SYSCTL_ADD_PROC(sysctlctx, SYSCTL_CHILDREN(sysctlnode), OID_AUTO, "core1", CTLTYPE_INT | CTLFLAG_RD, - dev, SENSOR0_CORE1, k8temp_sysctl, "I", + dev, SENSOR0_CORE1, k8temp_sysctl, "IK", "Sensor 0 / Core 1 temperature"); sysctlnode = SYSCTL_ADD_NODE(sysctlctx, @@ -220,13 +239,13 @@ SYSCTL_ADD_PROC(sysctlctx, SYSCTL_CHILDREN(sysctlnode), OID_AUTO, "core0", CTLTYPE_INT | CTLFLAG_RD, - dev, SENSOR1_CORE0, k8temp_sysctl, "I", + dev, SENSOR1_CORE0, k8temp_sysctl, "IK", "Sensor 1 / Core 0 temperature"); SYSCTL_ADD_PROC(sysctlctx, SYSCTL_CHILDREN(sysctlnode), OID_AUTO, "core1", CTLTYPE_INT | CTLFLAG_RD, - dev, SENSOR1_CORE1, k8temp_sysctl, "I", + dev, SENSOR1_CORE1, k8temp_sysctl, "IK", "Sensor 1 / Core 1 temperature"); return (0); @@ -258,7 +277,7 @@ sc->sc_sysctl_cpu[i] = SYSCTL_ADD_PROC(sysctlctx, SYSCTL_CHILDREN(device_get_sysctl_tree(cpu)), OID_AUTO, "temperature", CTLTYPE_INT | CTLFLAG_RD, - dev, CORE0, k8temp_sysctl, "I", + dev, CORE0, k8temp_sysctl, "IK", "Max of sensor 0 / 1"); } } @@ -285,22 +304,23 @@ k8temp_sysctl(SYSCTL_HANDLER_ARGS) { device_t dev = (device_t) arg1; + struct k8temp_softc *sc = device_get_softc(dev); int error; int32_t temp, auxtemp[2]; switch (arg2) { case CORE0: - auxtemp[0] = k8temp_gettemp(dev, SENSOR0_CORE0); - auxtemp[1] = k8temp_gettemp(dev, SENSOR1_CORE0); + auxtemp[0] = sc->sc_gettemp(dev, SENSOR0_CORE0); + auxtemp[1] = sc->sc_gettemp(dev, SENSOR1_CORE0); temp = imax(auxtemp[0], auxtemp[1]); break; case CORE1: - auxtemp[0] = k8temp_gettemp(dev, SENSOR0_CORE1); - auxtemp[1] = k8temp_gettemp(dev, SENSOR1_CORE1); + auxtemp[0] = sc->sc_gettemp(dev, SENSOR0_CORE1); + auxtemp[1] = sc->sc_gettemp(dev, SENSOR1_CORE1); temp = imax(auxtemp[0], auxtemp[1]); break; default: - temp = k8temp_gettemp(dev, arg2); + temp = sc->sc_gettemp(dev, arg2); break; } error = sysctl_handle_int(oidp, &temp, 0, req); @@ -309,12 +329,12 @@ } static int32_t -k8temp_gettemp(device_t dev, k8sensor_t sensor) +k8temp_gettemp0f(device_t dev, k8sensor_t sensor) { uint8_t cfg; uint32_t temp; - cfg = pci_read_config(dev, K8TEMP_REG, 1); + cfg = pci_read_config(dev, K8TEMP_REG0F, 1); switch (sensor) { case SENSOR0_CORE0: cfg &= ~(K8TEMP_REG_SELSENSOR | K8TEMP_REG_SELCORE); @@ -334,9 +354,20 @@ cfg = 0; break; } - pci_write_config(dev, K8TEMP_REG, cfg, 1); - temp = pci_read_config(dev, K8TEMP_REG, 4); - temp = ((temp >> 16) & 0xff) - K8TEMP_MINTEMP; + pci_write_config(dev, K8TEMP_REG0F, cfg, 1); + temp = pci_read_config(dev, K8TEMP_REG0F, 4); + temp = ((temp >> 16) & 0xff) * 10 + K8TEMP_OFFSET0F; return (temp); } + +static int32_t +k8temp_gettemp(device_t dev, k8sensor_t sensor) +{ + uint32_t temp; + + temp = pci_read_config(dev, K8TEMP_REG, 4); + temp = ((temp >> 21) & 0x3ff) * 10 / 8 + K8TEMP_OFFSET; + + return (temp); +} --Multipart=_Fri__13_Mar_2009_02_58_08_+0900_u/yV0oF_ZtODnYbi--