LCOV - code coverage report
Current view: top level - dev/pci - pchtemp.c (source / functions) Hit Total Coverage
Test: 6.4 Lines: 0 30 0.0 %
Date: 2018-10-19 03:25:38 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*      $OpenBSD: pchtemp.c,v 1.4 2016/05/24 07:59:24 reyk Exp $        */
       2             : /*
       3             :  * Copyright (c) 2015 Mark Kettenis
       4             :  *
       5             :  * Permission to use, copy, modify, and distribute this software for any
       6             :  * purpose with or without fee is hereby granted, provided that the above
       7             :  * copyright notice and this permission notice appear in all copies.
       8             :  *
       9             :  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
      10             :  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
      11             :  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
      12             :  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
      13             :  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
      14             :  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
      15             :  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
      16             :  */
      17             : 
      18             : /*
      19             :  * Intel X99, C610, 9 Series and 100 Series PCH thermal sensor
      20             :  * controller driver
      21             :  */
      22             : 
      23             : #include <sys/param.h>
      24             : #include <sys/systm.h>
      25             : #include <sys/device.h>
      26             : #include <sys/sensors.h>
      27             : 
      28             : #include <dev/pci/pcireg.h>
      29             : #include <dev/pci/pcivar.h>
      30             : #include <dev/pci/pcidevs.h>
      31             : 
      32             : #define PCHTEMP_PCI_TBAR        0x10
      33             : 
      34             : #define PCHTEMP_TEMP            0x00
      35             : #define PCHTEMP_TSEL            0x08
      36             : #define  PCHTEMP_TSEL_ETS       0x01
      37             : 
      38             : struct pchtemp_softc {
      39             :         struct device           sc_dev;
      40             : 
      41             :         bus_space_tag_t         sc_memt;
      42             :         bus_space_handle_t      sc_memh;
      43             :         bus_size_t              sc_mems;
      44             : 
      45             :         struct ksensor          sc_sensor;
      46             :         struct ksensordev       sc_sensordev;
      47             : };
      48             : 
      49             : int     pchtemp_match(struct device *, void *, void *);
      50             : void    pchtemp_attach(struct device *, struct device *, void *);
      51             : void    pchtemp_refresh(void *);
      52             : 
      53             : struct cfdriver pchtemp_cd = {
      54             :         NULL, "pchtemp", DV_DULL
      55             : };
      56             : 
      57             : struct cfattach pchtemp_ca = {
      58             :         sizeof(struct pchtemp_softc), pchtemp_match, pchtemp_attach
      59             : };
      60             : 
      61             : const struct pci_matchid pchtemp_devices[] = {
      62             :         { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_C610_THERM },
      63             :         { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_9SERIES_LP_THERM },
      64             :         { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_100SERIES_THERM },
      65             :         { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_100SERIES_LP_THERM },
      66             : };
      67             : 
      68             : int
      69           0 : pchtemp_match(struct device *parent, void *match, void *aux)
      70             : {
      71           0 :         return (pci_matchbyid(aux, pchtemp_devices, nitems(pchtemp_devices)));
      72             : }
      73             : 
      74             : void
      75           0 : pchtemp_attach(struct device *parent, struct device *self, void *aux)
      76             : {
      77           0 :         struct pchtemp_softc *sc = (struct pchtemp_softc *)self;
      78           0 :         struct pci_attach_args *pa = aux;
      79             :         pcireg_t memtype;
      80             :         uint8_t tsel;
      81             : 
      82             :         memtype = PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_64BIT;
      83           0 :         if (pci_mapreg_map(pa, PCHTEMP_PCI_TBAR, memtype, 0,
      84           0 :             &sc->sc_memt, &sc->sc_memh, NULL, &sc->sc_mems, 0)) {
      85           0 :                 printf(": can't map registers\n");
      86           0 :                 return;
      87             :         }
      88             : 
      89           0 :         tsel = bus_space_read_1(sc->sc_memt, sc->sc_memh, PCHTEMP_TSEL);
      90           0 :         if ((tsel & PCHTEMP_TSEL_ETS) == 0) {
      91           0 :                 printf(": disabled\n");
      92           0 :                 goto unmap;
      93             :         }
      94             : 
      95           0 :         pchtemp_refresh(sc);
      96             : 
      97           0 :         strlcpy(sc->sc_sensordev.xname, sc->sc_dev.dv_xname,
      98             :             sizeof(sc->sc_sensordev.xname));
      99             : 
     100           0 :         sc->sc_sensor.type = SENSOR_TEMP;
     101           0 :         sensor_attach(&sc->sc_sensordev, &sc->sc_sensor);
     102             : 
     103           0 :         if (sensor_task_register(sc, pchtemp_refresh, 5) == NULL) {
     104           0 :                 printf(": can't register update task\n");
     105           0 :                 goto unmap;
     106             :         }
     107             : 
     108           0 :         sensordev_install(&sc->sc_sensordev);
     109             : 
     110           0 :         printf("\n");
     111           0 :         return;
     112             : 
     113             :  unmap:
     114           0 :         bus_space_unmap(sc->sc_memt, sc->sc_memh, sc->sc_mems);
     115           0 : }
     116             : 
     117             : void
     118           0 : pchtemp_refresh(void *arg)
     119             : {
     120           0 :         struct pchtemp_softc *sc = arg;
     121             :         uint16_t temp;
     122             : 
     123           0 :         temp = bus_space_read_2(sc->sc_memt, sc->sc_memh, PCHTEMP_TEMP);
     124           0 :         sc->sc_sensor.value = (temp * 500000 - 50000000) + 273150000;
     125           0 : }

Generated by: LCOV version 1.13