Date: Thu, 21 May 2009 17:09:24 +0000 (UTC) From: Rui Paulo <rpaulo@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org Subject: svn commit: r192548 - in stable/7/sys: . conf contrib/pf dev/amdtemp dev/ath/ath_hal dev/cxgb dev/k8temp modules modules/amdtemp modules/k8temp Message-ID: <200905211709.n4LH9O6G073003@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: rpaulo Date: Thu May 21 17:09:23 2009 New Revision: 192548 URL: http://svn.freebsd.org/changeset/base/192548 Log: MFC 189748, 189768, 189769, 189774: Rename k8temp to amdtemp and add support for the 10h and 11h families. Added: stable/7/sys/dev/amdtemp/ - copied from r189768, head/sys/dev/amdtemp/ stable/7/sys/modules/amdtemp/ - copied from r189768, head/sys/modules/amdtemp/ Deleted: stable/7/sys/dev/k8temp/ stable/7/sys/modules/k8temp/ Modified: stable/7/sys/ (props changed) stable/7/sys/conf/files.amd64 stable/7/sys/conf/files.i386 stable/7/sys/contrib/pf/ (props changed) stable/7/sys/dev/amdtemp/amdtemp.c stable/7/sys/dev/ath/ath_hal/ (props changed) stable/7/sys/dev/cxgb/ (props changed) stable/7/sys/modules/Makefile Modified: stable/7/sys/conf/files.amd64 ============================================================================== --- stable/7/sys/conf/files.amd64 Thu May 21 17:01:38 2009 (r192547) +++ stable/7/sys/conf/files.amd64 Thu May 21 17:09:23 2009 (r192548) @@ -131,6 +131,7 @@ amd64/pci/pci_cfgreg.c optional pci crypto/blowfish/bf_enc.c optional crypto | ipsec crypto/des/des_enc.c optional crypto | ipsec | netsmb dev/acpica/acpi_if.m standard +dev/amdtemp/amdtemp.c optional amdtemp dev/arcmsr/arcmsr.c optional arcmsr pci dev/atkbdc/atkbd.c optional atkbd atkbdc dev/atkbdc/atkbd_atkbdc.c optional atkbd atkbdc @@ -178,7 +179,6 @@ dev/hptrr/hptrr_config.c optional hptrr dev/hwpmc/hwpmc_amd.c optional hwpmc dev/hwpmc/hwpmc_piv.c optional hwpmc dev/hwpmc/hwpmc_x86.c optional hwpmc -dev/k8temp/k8temp.c optional k8temp dev/kbd/kbd.c optional atkbd | sc | ukbd dev/mem/memutil.c optional mem dev/nfe/if_nfe.c optional nfe pci Modified: stable/7/sys/conf/files.i386 ============================================================================== --- stable/7/sys/conf/files.i386 Thu May 21 17:01:38 2009 (r192547) +++ stable/7/sys/conf/files.i386 Thu May 21 17:09:23 2009 (r192548) @@ -132,6 +132,7 @@ crypto/via/padlock_cipher.c optional pad crypto/via/padlock_hash.c optional padlock dev/advansys/adv_isa.c optional adv isa 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 Modified: stable/7/sys/dev/amdtemp/amdtemp.c ============================================================================== --- head/sys/dev/amdtemp/amdtemp.c Fri Mar 13 16:08:08 2009 (r189768) +++ stable/7/sys/dev/amdtemp/amdtemp.c Thu May 21 17:09:23 2009 (r192548) @@ -1,5 +1,6 @@ /*- - * Copyright (c) 2008 Rui Paulo <rpaulo@FreeBSD.org> + * Copyright (c) 2008, 2009 Rui Paulo <rpaulo@FreeBSD.org> + * Copyright (c) 2009 Norikatsu Shigemura <nork@FreeBSD.org> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,8 +26,8 @@ */ /* - * Driver for the AMD K8 thermal sensors. Based on a Linux driver by the - * same name. + * Driver for the AMD K8/K10/K11 thermal sensors. Initially based on the + * k8temp Linux driver. */ #include <sys/cdefs.h> @@ -48,77 +49,92 @@ __FBSDID("$FreeBSD$"); #include <dev/pci/pcireg.h> #include <dev/pci/pcivar.h> -struct k8temp_softc { +typedef enum { + SENSOR0_CORE0, + SENSOR0_CORE1, + SENSOR1_CORE0, + SENSOR1_CORE1, + CORE0, + CORE1 +} amdsensor_t; + +struct amdtemp_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; + int32_t (*sc_gettemp)(device_t, amdsensor_t); }; #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 }, +#define DEVICEID_AMD_MISC0F 0x1103 +#define DEVICEID_AMD_MISC10 0x1203 +#define DEVICEID_AMD_MISC11 0x1303 + +static struct amdtemp_product { + uint16_t amdtemp_vendorid; + uint16_t amdtemp_deviceid; +} amdtemp_products[] = { + { VENDORID_AMD, DEVICEID_AMD_MISC0F }, + { VENDORID_AMD, DEVICEID_AMD_MISC10 }, + { VENDORID_AMD, DEVICEID_AMD_MISC11 }, { 0, 0 } }; /* - * Register control + * Register control (K8 family) */ -#define K8TEMP_REG 0xe4 -#define K8TEMP_REG_SELSENSOR 0x40 -#define K8TEMP_REG_SELCORE 0x04 +#define AMDTEMP_REG0F 0xe4 +#define AMDTEMP_REG_SELSENSOR 0x40 +#define AMDTEMP_REG_SELCORE 0x04 -#define K8TEMP_MINTEMP 49 /* -49 C is the mininum temperature */ +/* + * Register control (K10 & K11) family + */ +#define AMDTEMP_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 AMDTEMP_OFFSET0F (TZ_ZEROC-490) +#define AMDTEMP_OFFSET (TZ_ZEROC) /* * 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 void amdtemp_identify(driver_t *driver, device_t parent); +static int amdtemp_probe(device_t dev); +static int amdtemp_attach(device_t dev); +static void amdtemp_intrhook(void *arg); +static int amdtemp_detach(device_t dev); +static int amdtemp_match(device_t dev); +static int32_t amdtemp_gettemp0f(device_t dev, amdsensor_t sensor); +static int32_t amdtemp_gettemp(device_t dev, amdsensor_t sensor); +static int amdtemp_sysctl(SYSCTL_HANDLER_ARGS); -static device_method_t k8temp_methods[] = { +static device_method_t amdtemp_methods[] = { /* Device interface */ - DEVMETHOD(device_identify, k8temp_identify), - DEVMETHOD(device_probe, k8temp_probe), - DEVMETHOD(device_attach, k8temp_attach), - DEVMETHOD(device_detach, k8temp_detach), + DEVMETHOD(device_identify, amdtemp_identify), + DEVMETHOD(device_probe, amdtemp_probe), + DEVMETHOD(device_attach, amdtemp_attach), + DEVMETHOD(device_detach, amdtemp_detach), {0, 0} }; -static driver_t k8temp_driver = { - "k8temp", - k8temp_methods, - sizeof(struct k8temp_softc), +static driver_t amdtemp_driver = { + "amdtemp", + amdtemp_methods, + sizeof(struct amdtemp_softc), }; -static devclass_t k8temp_devclass; -DRIVER_MODULE(k8temp, hostb, k8temp_driver, k8temp_devclass, NULL, NULL); +static devclass_t amdtemp_devclass; +DRIVER_MODULE(amdtemp, hostb, amdtemp_driver, amdtemp_devclass, NULL, NULL); static int -k8temp_match(device_t dev) +amdtemp_match(device_t dev) { int i; uint16_t vendor, devid; @@ -126,9 +142,9 @@ k8temp_match(device_t dev) 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) + for (i = 0; amdtemp_products[i].amdtemp_vendorid != 0; i++) { + if (vendor == amdtemp_products[i].amdtemp_vendorid && + devid == amdtemp_products[i].amdtemp_deviceid) return (1); } @@ -136,28 +152,28 @@ k8temp_match(device_t dev) } static void -k8temp_identify(driver_t *driver, device_t parent) +amdtemp_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) + if (device_find_child(parent, "amdtemp", -1) != NULL) return; - if (k8temp_match(parent)) { - child = device_add_child(parent, "k8temp", -1); + if (amdtemp_match(parent)) { + child = device_add_child(parent, "amdtemp", -1); if (child == NULL) - device_printf(parent, "add k8temp child failed\n"); + device_printf(parent, "add amdtemp child failed\n"); } } static int -k8temp_probe(device_t dev) +amdtemp_probe(device_t dev) { uint32_t regs[4]; - if (resource_disabled("k8temp", 0)) + if (resource_disabled("amdtemp", 0)) return (ENXIO); do_cpuid(1, regs); @@ -173,9 +189,9 @@ k8temp_probe(device_t dev) } static int -k8temp_attach(device_t dev) +amdtemp_attach(device_t dev) { - struct k8temp_softc *sc = device_get_softc(dev); + struct amdtemp_softc *sc = device_get_softc(dev); struct sysctl_ctx_list *sysctlctx; struct sysctl_oid *sysctlnode; @@ -185,7 +201,7 @@ k8temp_attach(device_t dev) * needed because the cpu driver may be loaded late on boot, after * us. */ - sc->sc_ich.ich_func = k8temp_intrhook; + sc->sc_ich.ich_func = amdtemp_intrhook; sc->sc_ich.ich_arg = dev; if (config_intrhook_establish(&sc->sc_ich) != 0) { device_printf(dev, "config_intrhook_establish " @@ -193,8 +209,15 @@ k8temp_attach(device_t dev) return (ENXIO); } + if (pci_get_device(dev) == DEVICEID_AMD_MISC0F) + sc->sc_gettemp = amdtemp_gettemp0f; + else { + sc->sc_gettemp = amdtemp_gettemp; + return (0); + } + /* - * dev.k8temp.N tree. + * dev.amdtemp.N tree. */ sysctlctx = device_get_sysctl_ctx(dev); sysctlnode = SYSCTL_ADD_NODE(sysctlctx, @@ -204,13 +227,13 @@ k8temp_attach(device_t dev) SYSCTL_ADD_PROC(sysctlctx, SYSCTL_CHILDREN(sysctlnode), OID_AUTO, "core0", CTLTYPE_INT | CTLFLAG_RD, - dev, SENSOR0_CORE0, k8temp_sysctl, "I", + dev, SENSOR0_CORE0, amdtemp_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, amdtemp_sysctl, "IK", "Sensor 0 / Core 1 temperature"); sysctlnode = SYSCTL_ADD_NODE(sysctlctx, @@ -220,25 +243,25 @@ k8temp_attach(device_t dev) SYSCTL_ADD_PROC(sysctlctx, SYSCTL_CHILDREN(sysctlnode), OID_AUTO, "core0", CTLTYPE_INT | CTLFLAG_RD, - dev, SENSOR1_CORE0, k8temp_sysctl, "I", + dev, SENSOR1_CORE0, amdtemp_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, amdtemp_sysctl, "IK", "Sensor 1 / Core 1 temperature"); return (0); } void -k8temp_intrhook(void *arg) +amdtemp_intrhook(void *arg) { int i; device_t nexus, acpi, cpu; device_t dev = (device_t) arg; - struct k8temp_softc *sc; + struct amdtemp_softc *sc; struct sysctl_ctx_list *sysctlctx; sc = device_get_softc(dev); @@ -258,7 +281,7 @@ k8temp_intrhook(void *arg) 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, amdtemp_sysctl, "IK", "Max of sensor 0 / 1"); } } @@ -266,41 +289,42 @@ k8temp_intrhook(void *arg) } int -k8temp_detach(device_t dev) +amdtemp_detach(device_t dev) { int i; - struct k8temp_softc *sc = device_get_softc(dev); + struct amdtemp_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. */ + /* NewBus removes the dev.amdtemp.N tree by itself. */ return (0); } static int -k8temp_sysctl(SYSCTL_HANDLER_ARGS) +amdtemp_sysctl(SYSCTL_HANDLER_ARGS) { device_t dev = (device_t) arg1; + struct amdtemp_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,34 +333,45 @@ k8temp_sysctl(SYSCTL_HANDLER_ARGS) } static int32_t -k8temp_gettemp(device_t dev, k8sensor_t sensor) +amdtemp_gettemp0f(device_t dev, amdsensor_t sensor) { uint8_t cfg; uint32_t temp; - cfg = pci_read_config(dev, K8TEMP_REG, 1); + cfg = pci_read_config(dev, AMDTEMP_REG0F, 1); switch (sensor) { case SENSOR0_CORE0: - cfg &= ~(K8TEMP_REG_SELSENSOR | K8TEMP_REG_SELCORE); + cfg &= ~(AMDTEMP_REG_SELSENSOR | AMDTEMP_REG_SELCORE); break; case SENSOR0_CORE1: - cfg &= ~K8TEMP_REG_SELSENSOR; - cfg |= K8TEMP_REG_SELCORE; + cfg &= ~AMDTEMP_REG_SELSENSOR; + cfg |= AMDTEMP_REG_SELCORE; break; case SENSOR1_CORE0: - cfg &= ~K8TEMP_REG_SELCORE; - cfg |= K8TEMP_REG_SELSENSOR; + cfg &= ~AMDTEMP_REG_SELCORE; + cfg |= AMDTEMP_REG_SELSENSOR; break; case SENSOR1_CORE1: - cfg |= (K8TEMP_REG_SELSENSOR | K8TEMP_REG_SELCORE); + cfg |= (AMDTEMP_REG_SELSENSOR | AMDTEMP_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; + pci_write_config(dev, AMDTEMP_REG0F, cfg, 1); + temp = pci_read_config(dev, AMDTEMP_REG0F, 4); + temp = ((temp >> 16) & 0xff) * 10 + AMDTEMP_OFFSET0F; return (temp); } + +static int32_t +amdtemp_gettemp(device_t dev, amdsensor_t sensor) +{ + uint32_t temp; + + temp = pci_read_config(dev, AMDTEMP_REG, 4); + temp = ((temp >> 21) & 0x3ff) * 10 / 8 + AMDTEMP_OFFSET; + + return (temp); +} Modified: stable/7/sys/modules/Makefile ============================================================================== --- stable/7/sys/modules/Makefile Thu May 21 17:01:38 2009 (r192547) +++ stable/7/sys/modules/Makefile Thu May 21 17:09:23 2009 (r192548) @@ -17,6 +17,7 @@ SUBDIR= ${_3dfx} \ aic7xxx \ aio \ ${_amd} \ + ${_amdtemp} \ ale \ amr \ ${_an} \ @@ -143,7 +144,6 @@ SUBDIR= ${_3dfx} \ ${_ixgb} \ jme \ joy \ - ${_k8temp} \ kbdmux \ krpc \ kue \ @@ -455,6 +455,7 @@ _zfs= zfs _aac= aac _acpi= acpi _ahb= ahb +_amdtemp= amdtemp _arcmsr= arcmsr _arl= arl _asr= asr @@ -479,7 +480,7 @@ _ipw= ipw _ipwfw= ipwfw _iwi= iwi _iwifw= iwifw -_ixgb= ixgb +_ixgb= ixgb _mly= mly _nfe= nfe _nve= nve @@ -508,6 +509,7 @@ _aac= aac _acpi= acpi _agp= agp _an= an +_amdtemp= amdtemp _arcmsr= arcmsr _cardbus= cardbus _cbb= cbb @@ -544,7 +546,6 @@ _ips= ips _ipw= ipw _ipwfw= ipwfw _ixgb= ixgb -_k8temp= k8temp _linprocfs= linprocfs _linsysfs= linsysfs _linux= linux
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905211709.n4LH9O6G073003>