From owner-svn-src-head@FreeBSD.ORG Fri Mar 13 16:08:09 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3CA85106566C; Fri, 13 Mar 2009 16:08:09 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 28B848FC12; Fri, 13 Mar 2009 16:08:09 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n2DG89LT067231; Fri, 13 Mar 2009 16:08:09 GMT (envelope-from rpaulo@svn.freebsd.org) Received: (from rpaulo@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n2DG88Fa067228; Fri, 13 Mar 2009 16:08:09 GMT (envelope-from rpaulo@svn.freebsd.org) Message-Id: <200903131608.n2DG88Fa067228@svn.freebsd.org> From: Rui Paulo Date: Fri, 13 Mar 2009 16:08:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r189768 - in head/sys: conf dev/amdtemp dev/k8temp modules modules/amdtemp modules/k8temp X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Mar 2009 16:08:09 -0000 Author: rpaulo Date: Fri Mar 13 16:08:08 2009 New Revision: 189768 URL: http://svn.freebsd.org/changeset/base/189768 Log: Rename the k8temp driver to amdtemp. MFC after: 2 weeks Added: head/sys/dev/amdtemp/ - copied from r189489, head/sys/dev/k8temp/ head/sys/dev/amdtemp/amdtemp.c - copied unchanged from r189489, head/sys/dev/k8temp/k8temp.c head/sys/modules/amdtemp/ - copied from r189489, head/sys/modules/k8temp/ Deleted: head/sys/dev/amdtemp/k8temp.c head/sys/dev/k8temp/ head/sys/modules/k8temp/ Modified: head/sys/conf/files.amd64 head/sys/conf/files.i386 head/sys/modules/Makefile head/sys/modules/amdtemp/Makefile Modified: head/sys/conf/files.amd64 ============================================================================== --- head/sys/conf/files.amd64 Fri Mar 13 14:35:58 2009 (r189767) +++ head/sys/conf/files.amd64 Fri Mar 13 16:08:08 2009 (r189768) @@ -136,6 +136,7 @@ dev/agp/agp_amd64.c optional agp dev/agp/agp_i810.c optional agp dev/agp/agp_intel.c optional agp dev/agp/agp_via.c optional agp +dev/amdtemp/amdtemp.c optional amdtemp dev/arcmsr/arcmsr.c optional arcmsr pci dev/asmc/asmc.c optional asmc isa dev/atkbdc/atkbd.c optional atkbd atkbdc @@ -187,7 +188,6 @@ dev/hwpmc/hwpmc_core.c optional hwpmc dev/hwpmc/hwpmc_piv.c optional hwpmc dev/hwpmc/hwpmc_tsc.c optional hwpmc dev/hwpmc/hwpmc_x86.c optional hwpmc -dev/k8temp/k8temp.c optional k8temp dev/kbd/kbd.c optional atkbd | sc | ukbd | usb2_input_kbd dev/mem/memutil.c optional mem dev/nfe/if_nfe.c optional nfe pci Modified: head/sys/conf/files.i386 ============================================================================== --- head/sys/conf/files.i386 Fri Mar 13 14:35:58 2009 (r189767) +++ head/sys/conf/files.i386 Fri Mar 13 16:08:08 2009 (r189768) @@ -128,6 +128,7 @@ dev/agp/agp_nvidia.c optional agp dev/agp/agp_sis.c optional agp dev/agp/agp_via.c optional agp dev/aic/aic_isa.c optional aic isa +dev/amdtemp/amdtemp.c optional amdtemp dev/arcmsr/arcmsr.c optional arcmsr pci dev/ar/if_ar.c optional ar dev/ar/if_ar_isa.c optional ar isa @@ -198,7 +199,6 @@ dev/ipmi/ipmi_smbus.c optional ipmi smb dev/ipmi/ipmi_smbios.c optional ipmi dev/ipmi/ipmi_ssif.c optional ipmi smbus dev/ipmi/ipmi_pci.c optional ipmi pci -dev/k8temp/k8temp.c optional k8temp dev/kbd/kbd.c optional atkbd | sc | ukbd | usb2_input_kbd dev/le/if_le_isa.c optional le isa dev/mem/memutil.c optional mem Copied: head/sys/dev/amdtemp/amdtemp.c (from r189489, head/sys/dev/k8temp/k8temp.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/amdtemp/amdtemp.c Fri Mar 13 16:08:08 2009 (r189768, copy of r189489, head/sys/dev/k8temp/k8temp.c) @@ -0,0 +1,342 @@ +/*- + * Copyright (c) 2008 Rui Paulo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Driver for the AMD K8 thermal sensors. Based on a Linux driver by the + * same name. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +struct k8temp_softc { + device_t sc_dev; + int sc_temps[4]; + int sc_ntemps; + struct sysctl_oid *sc_oid; + struct sysctl_oid *sc_sysctl_cpu[2]; + struct intr_config_hook sc_ich; +}; + +#define VENDORID_AMD 0x1022 +#define DEVICEID_AMD_MISC 0x1103 + +static struct k8temp_product { + uint16_t k8temp_vendorid; + uint16_t k8temp_deviceid; +} k8temp_products[] = { + { VENDORID_AMD, DEVICEID_AMD_MISC }, + { 0, 0 } +}; + +/* + * Register control + */ +#define K8TEMP_REG 0xe4 +#define K8TEMP_REG_SELSENSOR 0x40 +#define K8TEMP_REG_SELCORE 0x04 + +#define K8TEMP_MINTEMP 49 /* -49 C is the mininum temperature */ + +typedef enum { + SENSOR0_CORE0, + SENSOR0_CORE1, + SENSOR1_CORE0, + SENSOR1_CORE1, + CORE0, + CORE1 +} k8sensor_t; + +/* + * Device methods. + */ +static void k8temp_identify(driver_t *driver, device_t parent); +static int k8temp_probe(device_t dev); +static int k8temp_attach(device_t dev); +static void k8temp_intrhook(void *arg); +static int k8temp_detach(device_t dev); +static int k8temp_match(device_t dev); +static int32_t k8temp_gettemp(device_t dev, k8sensor_t sensor); +static int k8temp_sysctl(SYSCTL_HANDLER_ARGS); + +static device_method_t k8temp_methods[] = { + /* Device interface */ + DEVMETHOD(device_identify, k8temp_identify), + DEVMETHOD(device_probe, k8temp_probe), + DEVMETHOD(device_attach, k8temp_attach), + DEVMETHOD(device_detach, k8temp_detach), + + {0, 0} +}; + +static driver_t k8temp_driver = { + "k8temp", + k8temp_methods, + sizeof(struct k8temp_softc), +}; + +static devclass_t k8temp_devclass; +DRIVER_MODULE(k8temp, hostb, k8temp_driver, k8temp_devclass, NULL, NULL); + +static int +k8temp_match(device_t dev) +{ + int i; + uint16_t vendor, devid; + + vendor = pci_get_vendor(dev); + devid = pci_get_device(dev); + + for (i = 0; k8temp_products[i].k8temp_vendorid != 0; i++) { + if (vendor == k8temp_products[i].k8temp_vendorid && + devid == k8temp_products[i].k8temp_deviceid) + return (1); + } + + return (0); +} + +static void +k8temp_identify(driver_t *driver, device_t parent) +{ + device_t child; + + /* Make sure we're not being doubly invoked. */ + if (device_find_child(parent, "k8temp", -1) != NULL) + return; + + if (k8temp_match(parent)) { + child = device_add_child(parent, "k8temp", -1); + if (child == NULL) + device_printf(parent, "add k8temp child failed\n"); + } + +} + +static int +k8temp_probe(device_t dev) +{ + uint32_t regs[4]; + + if (resource_disabled("k8temp", 0)) + return (ENXIO); + + do_cpuid(1, regs); + switch (regs[0]) { + case 0xf40: + case 0xf50: + case 0xf51: + return (ENXIO); + } + device_set_desc(dev, "AMD K8 Thermal Sensors"); + + return (BUS_PROBE_GENERIC); +} + +static int +k8temp_attach(device_t dev) +{ + struct k8temp_softc *sc = device_get_softc(dev); + struct sysctl_ctx_list *sysctlctx; + struct sysctl_oid *sysctlnode; + + + /* + * Setup intrhook function to create dev.cpu sysctl entries. This is + * needed because the cpu driver may be loaded late on boot, after + * us. + */ + sc->sc_ich.ich_func = k8temp_intrhook; + sc->sc_ich.ich_arg = dev; + if (config_intrhook_establish(&sc->sc_ich) != 0) { + device_printf(dev, "config_intrhook_establish " + "failed!\n"); + return (ENXIO); + } + + /* + * dev.k8temp.N tree. + */ + sysctlctx = device_get_sysctl_ctx(dev); + sysctlnode = SYSCTL_ADD_NODE(sysctlctx, + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "sensor0", + CTLFLAG_RD, 0, "Sensor 0"); + + SYSCTL_ADD_PROC(sysctlctx, + SYSCTL_CHILDREN(sysctlnode), + OID_AUTO, "core0", CTLTYPE_INT | CTLFLAG_RD, + dev, SENSOR0_CORE0, k8temp_sysctl, "I", + "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", + "Sensor 0 / Core 1 temperature"); + + sysctlnode = SYSCTL_ADD_NODE(sysctlctx, + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "sensor1", + CTLFLAG_RD, 0, "Sensor 1"); + + SYSCTL_ADD_PROC(sysctlctx, + SYSCTL_CHILDREN(sysctlnode), + OID_AUTO, "core0", CTLTYPE_INT | CTLFLAG_RD, + dev, SENSOR1_CORE0, k8temp_sysctl, "I", + "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", + "Sensor 1 / Core 1 temperature"); + + return (0); +} + +void +k8temp_intrhook(void *arg) +{ + int i; + device_t nexus, acpi, cpu; + device_t dev = (device_t) arg; + struct k8temp_softc *sc; + struct sysctl_ctx_list *sysctlctx; + + sc = device_get_softc(dev); + + /* + * dev.cpu.N.temperature. + */ + nexus = device_find_child(root_bus, "nexus", 0); + acpi = device_find_child(nexus, "acpi", 0); + + for (i = 0; i < 2; i++) { + cpu = device_find_child(acpi, "cpu", + device_get_unit(dev) * 2 + i); + if (cpu) { + sysctlctx = device_get_sysctl_ctx(cpu); + + 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", + "Max of sensor 0 / 1"); + } + } + config_intrhook_disestablish(&sc->sc_ich); +} + +int +k8temp_detach(device_t dev) +{ + int i; + struct k8temp_softc *sc = device_get_softc(dev); + + for (i = 0; i < 2; i++) { + if (sc->sc_sysctl_cpu[i]) + sysctl_remove_oid(sc->sc_sysctl_cpu[i], 1, 0); + } + + /* NewBus removes the dev.k8temp.N tree by itself. */ + + return (0); +} + +static int +k8temp_sysctl(SYSCTL_HANDLER_ARGS) +{ + device_t dev = (device_t) arg1; + 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); + temp = imax(auxtemp[0], auxtemp[1]); + break; + case CORE1: + auxtemp[0] = k8temp_gettemp(dev, SENSOR0_CORE1); + auxtemp[1] = k8temp_gettemp(dev, SENSOR1_CORE1); + temp = imax(auxtemp[0], auxtemp[1]); + break; + default: + temp = k8temp_gettemp(dev, arg2); + break; + } + error = sysctl_handle_int(oidp, &temp, 0, req); + + return (error); +} + +static int32_t +k8temp_gettemp(device_t dev, k8sensor_t sensor) +{ + uint8_t cfg; + uint32_t temp; + + cfg = pci_read_config(dev, K8TEMP_REG, 1); + switch (sensor) { + case SENSOR0_CORE0: + cfg &= ~(K8TEMP_REG_SELSENSOR | K8TEMP_REG_SELCORE); + break; + case SENSOR0_CORE1: + cfg &= ~K8TEMP_REG_SELSENSOR; + cfg |= K8TEMP_REG_SELCORE; + break; + case SENSOR1_CORE0: + cfg &= ~K8TEMP_REG_SELCORE; + cfg |= K8TEMP_REG_SELSENSOR; + break; + case SENSOR1_CORE1: + cfg |= (K8TEMP_REG_SELSENSOR | K8TEMP_REG_SELCORE); + break; + default: + 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; + + return (temp); +} Modified: head/sys/modules/Makefile ============================================================================== --- head/sys/modules/Makefile Fri Mar 13 14:35:58 2009 (r189767) +++ head/sys/modules/Makefile Fri Mar 13 16:08:08 2009 (r189768) @@ -18,6 +18,7 @@ SUBDIR= ${_3dfx} \ aic7xxx \ aio \ ${_amd} \ + ${_amdtemp} \ ale \ amr \ ${_an} \ @@ -137,7 +138,6 @@ SUBDIR= ${_3dfx} \ ${_ixgb} \ jme \ joy \ - ${_k8temp} \ kbdmux \ krpc \ le \ @@ -409,6 +409,7 @@ _zfs= zfs _aac= aac _acpi= acpi _ahb= ahb +_amdtemp= amdtemp _arcmsr= arcmsr _asmc= asmc _asr= asr @@ -435,7 +436,6 @@ _iwifw= iwifw _iwn= iwn _iwnfw= iwnfw _ixgb= ixgb -_k8temp= k8temp _mly= mly _nfe= nfe _nve= nve @@ -464,6 +464,7 @@ _aac= aac _acpi= acpi _agp= agp _an= an +_amdtemp= amdtemp _arcmsr= arcmsr _asmc= asmc _cardbus= cardbus @@ -502,7 +503,6 @@ _ipwfw= ipwfw _iwn= iwn _iwnfw= iwnfw _ixgb= ixgb -_k8temp= k8temp _linprocfs= linprocfs _linsysfs= linsysfs _linux= linux Modified: head/sys/modules/amdtemp/Makefile ============================================================================== --- head/sys/modules/k8temp/Makefile Sat Mar 7 10:21:37 2009 (r189489) +++ head/sys/modules/amdtemp/Makefile Fri Mar 13 16:08:08 2009 (r189768) @@ -1,8 +1,8 @@ # $FreeBSD$ -.PATH: ${.CURDIR}/../../dev/k8temp +.PATH: ${.CURDIR}/../../dev/amdtemp -KMOD= k8temp -SRCS= k8temp.c bus_if.h device_if.h pci_if.h +KMOD= amdtemp +SRCS= amdtemp.c bus_if.h device_if.h pci_if.h .include