Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/x86/pci Add amdzentemp from FreeBSD via Ian Clark
details: https://anonhg.NetBSD.org/src/rev/bbf0bbb3ee10
branches: trunk
changeset: 358991:bbf0bbb3ee10
user: christos <christos%NetBSD.org@localhost>
date: Thu Jan 25 01:22:21 2018 +0000
description:
Add amdzentemp from FreeBSD via Ian Clark
diffstat:
sys/arch/x86/pci/amdsmn.c | 138 ++++++++++++++++++++++
sys/arch/x86/pci/amdsmn.h | 32 +++++
sys/arch/x86/pci/amdzentemp.c | 254 ++++++++++++++++++++++++++++++++++++++++++
sys/arch/x86/pci/files.pci | 12 +-
4 files changed, 435 insertions(+), 1 deletions(-)
diffs (truncated from 462 to 300 lines):
diff -r a3e7930e8472 -r bbf0bbb3ee10 sys/arch/x86/pci/amdsmn.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/x86/pci/amdsmn.c Thu Jan 25 01:22:21 2018 +0000
@@ -0,0 +1,138 @@
+/* $NetBSD: amdsmn.c,v 1.1 2018/01/25 01:22:21 christos Exp $ */
+
+/*-
+ * Copyright (c) 2017 Conrad Meyer <cem%FreeBSD.org@localhost>
+ * All rights reserved.
+ *
+ * NetBSD port by Ian Clark <mrrooster%gmail.com@localhost>
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: amdsmn.c,v 1.1 2018/01/25 01:22:21 christos Exp $ ");
+
+/*
+ * Driver for the AMD Family 17h CPU System Management Network.
+ */
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/errno.h>
+#include <sys/mutex.h>
+#include <sys/systm.h>
+#include <sys/cpu.h>
+
+#include <machine/specialreg.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcidevs.h>
+
+#include "amdsmn.h"
+
+#define SMN_ADDR_REG 0x60
+#define SMN_DATA_REG 0x64
+#define AMD_17H_MANAGEMENT_NETWORK_PCI_ID 0x14501022
+
+struct amdsmn_softc {
+ kmutex_t smn_lock;
+ struct pci_attach_args pa;
+ pci_chipset_tag_t pc;
+ pcitag_t pcitag;
+};
+
+static int amdsmn_match(device_t, cfdata_t, void *);
+static void amdsmn_attach(device_t, device_t, void *);
+static int amdsmn_detach(device_t, int);
+static int amdsmn_misc_search(device_t, cfdata_t, const int *, void *);
+
+CFATTACH_DECL_NEW(amdsmn, sizeof(struct amdsmn_softc), amdsmn_match,
+ amdsmn_attach, amdsmn_detach, NULL);
+
+static int
+amdsmn_match(device_t parent, cfdata_t match, void *aux)
+{
+ struct pci_attach_args *pa = aux;
+
+ return pa->pa_id == AMD_17H_MANAGEMENT_NETWORK_PCI_ID ? 2 : 0;
+}
+
+static int
+amdsmn_misc_search(device_t parent, cfdata_t cf, const int *locs, void *aux)
+{
+ if (config_match(parent, cf, aux))
+ config_attach_loc(parent, cf, locs, aux, NULL);
+
+ return 0;
+}
+
+static void
+amdsmn_attach(device_t parent, device_t self, void *aux)
+{
+ struct amdsmn_softc *sc = device_private(self);
+ struct pci_attach_args *pa = aux;
+
+ mutex_init(&sc->smn_lock, MUTEX_DEFAULT, IPL_NONE);
+ sc->pa = *pa;
+ sc->pc = pa->pa_pc;
+ sc->pcitag = pa->pa_tag;
+ aprint_normal(": AMD Family 17h System Management Network\n");
+ config_search_loc(amdsmn_misc_search, self, "amdsmn", NULL, &sc->pa);
+}
+
+static int
+amdsmn_detach(device_t self, int flags)
+{
+ struct amdsmn_softc *sc = device_private(self);
+
+ mutex_destroy(&sc->smn_lock);
+ aprint_normal_dev(self,"detach!\n");
+
+ return 0;
+}
+
+int
+amdsmn_read(device_t dev, uint32_t addr, uint32_t *value)
+{
+ struct amdsmn_softc *sc = device_private(dev);
+
+ mutex_enter(&sc->smn_lock);
+ pci_conf_write(sc->pc, sc->pcitag, SMN_ADDR_REG, addr);
+ *value = pci_conf_read(sc->pc, sc->pcitag, SMN_DATA_REG);
+ mutex_exit(&sc->smn_lock);
+
+ return 0;
+}
+
+int
+amdsmn_write(device_t dev, uint32_t addr, uint32_t value)
+{
+ struct amdsmn_softc *sc = device_private(dev);
+
+ mutex_enter(&sc->smn_lock);
+ pci_conf_write(sc->pc, sc->pcitag, SMN_ADDR_REG, addr);
+ pci_conf_write(sc->pc, sc->pcitag, SMN_DATA_REG, value);
+ mutex_exit(&sc->smn_lock);
+
+ return 0;
+}
diff -r a3e7930e8472 -r bbf0bbb3ee10 sys/arch/x86/pci/amdsmn.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/x86/pci/amdsmn.h Thu Jan 25 01:22:21 2018 +0000
@@ -0,0 +1,32 @@
+/* $NetBSD: amdsmn.h,v 1.1 2018/01/25 01:22:21 christos Exp $ */
+
+/*-
+ * Copyright (c) 2017 Conrad Meyer <cem%FreeBSD.org@localhost>
+ * 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.
+ *
+ * $FreeBSD: head/sys/dev/amdsmn/amdsmn.h 323184 2017-09-05 15:13:41Z cem $
+ */
+
+int amdsmn_read(device_t, uint32_t, uint32_t *);
+int amdsmn_write(device_t, uint32_t, uint32_t);
diff -r a3e7930e8472 -r bbf0bbb3ee10 sys/arch/x86/pci/amdzentemp.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/x86/pci/amdzentemp.c Thu Jan 25 01:22:21 2018 +0000
@@ -0,0 +1,254 @@
+/* $NetBSD: amdzentemp.c,v 1.1 2018/01/25 01:22:21 christos Exp $ */
+/* $OpenBSD: kate.c,v 1.2 2008/03/27 04:52:03 cnst Exp $ */
+
+/*
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christoph Egger.
+ *
+ * NetBSD port by Ian Clark <mrrooster%gmail.com@localhost>
+ *
+ * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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.
+ */
+
+/*
+ * Copyright (c) 2008 Constantine A. Murenin <cnst+openbsd%bugmail.mojo.ru@localhost>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: amdzentemp.c,v 1.1 2018/01/25 01:22:21 christos Exp $ ");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/cpu.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/kmem.h>
+#include <sys/module.h>
+
+#include <machine/specialreg.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcidevs.h>
+
+#include <dev/sysmon/sysmonvar.h>
+
+#include "amdsmn.h"
+
+/* Address to query for temp on family 17h */
+#define AMD_17H_CUR_TMP 0x59800
+
+struct amdzentemp_softc {
+ pci_chipset_tag_t sc_pc;
+ pcitag_t sc_pcitag;
+ struct sysmon_envsys *sc_sme;
+ device_t sc_smn;
+ envsys_data_t *sc_sensor;
+ size_t sc_sensor_len;
+ size_t sc_numsensors;
+};
+
+
+static int amdzentemp_match(device_t, cfdata_t, void *);
+static void amdzentemp_attach(device_t, device_t, void *);
+static int amdzentemp_detach(device_t, int);
+
+static void amdzentemp_family17_init(struct amdzentemp_softc *);
+static void amdzentemp_family17_setup_sensors(struct amdzentemp_softc *, int);
+static void amdzentemp_family17_refresh(struct sysmon_envsys *, envsys_data_t *);
+
+CFATTACH_DECL_NEW(amdzentemp, sizeof(struct amdzentemp_softc),
+ amdzentemp_match, amdzentemp_attach, amdzentemp_detach, NULL);
+
+static int
+amdzentemp_match(device_t parent, cfdata_t match, void *aux)
+{
+ struct pci_attach_args *pa = aux;
+
+ KASSERT(PCI_VENDOR(pa->pa_id) == PCI_VENDOR_AMD);
+
+ cfdata_t parent_cfdata = device_cfdata(parent);
+
+ /* Got AMD family 17h system management network */
+ return parent_cfdata->cf_name &&
+ memcmp(parent_cfdata->cf_name, "amdsmn", 6) == 0;
+}
+
+static void
+amdzentemp_attach(device_t parent, device_t self, void *aux)
+{
+ struct amdzentemp_softc *sc = device_private(self);
+ struct pci_attach_args *pa = aux;
+ int error;
+ size_t i;
Home |
Main Index |
Thread Index |
Old Index