From owner-svn-src-head@freebsd.org Tue Sep 5 15:13:43 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8FBA9E0DF15; Tue, 5 Sep 2017 15:13:43 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 46714808FA; Tue, 5 Sep 2017 15:13:43 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v85FDg5M016277; Tue, 5 Sep 2017 15:13:42 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v85FDfCN016267; Tue, 5 Sep 2017 15:13:41 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201709051513.v85FDfCN016267@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: Conrad Meyer Date: Tue, 5 Sep 2017 15:13:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r323184 - in head: share/man/man4 sys/amd64/conf sys/boot/forth sys/conf sys/dev/amdsmn sys/modules sys/modules/amdsmn X-SVN-Group: head X-SVN-Commit-Author: cem X-SVN-Commit-Paths: in head: share/man/man4 sys/amd64/conf sys/boot/forth sys/conf sys/dev/amdsmn sys/modules sys/modules/amdsmn X-SVN-Commit-Revision: 323184 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 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: Tue, 05 Sep 2017 15:13:43 -0000 Author: cem Date: Tue Sep 5 15:13:41 2017 New Revision: 323184 URL: https://svnweb.freebsd.org/changeset/base/323184 Log: Add smn(4) driver for AMD System Management Network AMD Family 17h CPUs have an internal network used to communicate between the host CPU and the PSP and SMU coprocessors. It exposes a simple 32-bit register space. Reviewed by: avg (no +1), mjoras, truckman Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D12217 Added: head/share/man/man4/amdsmn.4 (contents, props changed) head/sys/dev/amdsmn/ head/sys/dev/amdsmn/amdsmn.c (contents, props changed) head/sys/dev/amdsmn/amdsmn.h (contents, props changed) head/sys/modules/amdsmn/ head/sys/modules/amdsmn/Makefile (contents, props changed) Modified: head/share/man/man4/Makefile head/sys/amd64/conf/NOTES head/sys/boot/forth/loader.conf head/sys/conf/files.amd64 head/sys/conf/files.i386 head/sys/modules/Makefile Modified: head/share/man/man4/Makefile ============================================================================== --- head/share/man/man4/Makefile Tue Sep 5 14:32:56 2017 (r323183) +++ head/share/man/man4/Makefile Tue Sep 5 15:13:41 2017 (r323184) @@ -46,6 +46,7 @@ MAN= aac.4 \ amdpm.4 \ ${_amdsbwd.4} \ ${_amdsmb.4} \ + ${_amdsmn.4} \ ${_amdtemp.4} \ ${_bxe.4} \ amr.4 \ @@ -769,6 +770,7 @@ _attimer.4= attimer.4 _aibs.4= aibs.4 _amdsbwd.4= amdsbwd.4 _amdsmb.4= amdsmb.4 +_amdsmn.4= amdsmn.4 _amdtemp.4= amdtemp.4 _asmc.4= asmc.4 _bxe.4= bxe.4 Added: head/share/man/man4/amdsmn.4 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/share/man/man4/amdsmn.4 Tue Sep 5 15:13:41 2017 (r323184) @@ -0,0 +1,64 @@ +.\"- +.\" Copyright (c) 2017 Conrad Meyer +.\" 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 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 AUTHOR 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. +.\" +.\" $FreeBSD$ +.\" +.Dd September 5, 2017 +.Dt AMDSMN 4 +.Os +.Sh NAME +.Nm amdsmn +.Nd device driver for +.Tn AMD +processor System Management Network +.Sh SYNOPSIS +To compile this driver into the kernel, place the following line in your +kernel configuration file: +.Bd -ragged -offset indent +.Cd "device amdsmn" +.Ed +.Pp +Alternatively, to load the driver as a module at boot time, place the +following line in +.Xr loader.conf 5 : +.Bd -literal -offset indent +amdsmn_load="YES" +.Ed +.Sh DESCRIPTION +The +.Nm +driver provides support for resources on the System Management Network bus +in +.Tn AMD +Family 17h processors. +.Sh SEE ALSO +.Xr loader 8 +.Sh HISTORY +The +.Nm +driver first appeared in +.Fx 12.0 . +.Sh AUTHORS +.An Conrad Meyer Aq Mt cem@FreeBSD.org Modified: head/sys/amd64/conf/NOTES ============================================================================== --- head/sys/amd64/conf/NOTES Tue Sep 5 14:32:56 2017 (r323183) +++ head/sys/amd64/conf/NOTES Tue Sep 5 15:13:41 2017 (r323184) @@ -589,6 +589,11 @@ device cpuctl options ENABLE_ALART # Control alarm on Intel intpm driver # +# AMD System Management Network (SMN) +# +device amdsmn + +# # Number of initial kernel page table pages used for early bootstrap. # This number should include enough pages to map the kernel and any # modules or other data loaded with the kernel by the loader. Each Modified: head/sys/boot/forth/loader.conf ============================================================================== --- head/sys/boot/forth/loader.conf Tue Sep 5 14:32:56 2017 (r323183) +++ head/sys/boot/forth/loader.conf Tue Sep 5 15:13:41 2017 (r323184) @@ -525,6 +525,7 @@ coretemp_load="NO" # Intel Core CPU temperature monit vkbd_load="NO" # Virtual AT keyboard interface vpd_load="NO" # Vital Product Data kernel interface vpo_load="NO" # Parallel to SCSI interface driver +amdsmn_load="NO" # AMD Family 17h System Management Network amdtemp_load="NO" # AMD K8/K10/K11 temperature monitor tpm_load="NO" # Trusted Platform Module wbwd_load="NO" # Winbond watchdog Modified: head/sys/conf/files.amd64 ============================================================================== --- head/sys/conf/files.amd64 Tue Sep 5 14:32:56 2017 (r323183) +++ head/sys/conf/files.amd64 Tue Sep 5 15:13:41 2017 (r323184) @@ -198,6 +198,7 @@ dev/agp/agp_amd64.c optional agp dev/agp/agp_i810.c optional agp dev/agp/agp_via.c optional agp dev/amdsbwd/amdsbwd.c optional amdsbwd +dev/amdsmn/amdsmn.c optional amdsmn dev/amdtemp/amdtemp.c optional amdtemp dev/arcmsr/arcmsr.c optional arcmsr pci dev/asmc/asmc.c optional asmc isa Modified: head/sys/conf/files.i386 ============================================================================== --- head/sys/conf/files.i386 Tue Sep 5 14:32:56 2017 (r323183) +++ head/sys/conf/files.i386 Tue Sep 5 15:13:41 2017 (r323184) @@ -152,6 +152,7 @@ dev/agp/agp_sis.c optional agp dev/agp/agp_via.c optional agp dev/aic/aic_isa.c optional aic isa dev/amdsbwd/amdsbwd.c optional amdsbwd +dev/amdsmn/amdsmn.c optional amdsmn dev/amdtemp/amdtemp.c optional amdtemp dev/arcmsr/arcmsr.c optional arcmsr pci dev/asmc/asmc.c optional asmc isa Added: head/sys/dev/amdsmn/amdsmn.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/amdsmn/amdsmn.c Tue Sep 5 15:13:41 2017 (r323184) @@ -0,0 +1,186 @@ +/*- + * Copyright (c) 2017 Conrad Meyer + * 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 Family 17h CPU System Management Network. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include + +#define SMN_ADDR_REG 0x60 +#define SMN_DATA_REG 0x64 + +struct amdsmn_softc { + struct mtx smn_lock; +}; + +static struct pciid { + uint32_t device_id; +} amdsmn_ids[] = { + { 0x14501022 }, +}; + +/* + * Device methods. + */ +static void amdsmn_identify(driver_t *driver, device_t parent); +static int amdsmn_probe(device_t dev); +static int amdsmn_attach(device_t dev); +static int amdsmn_detach(device_t dev); + +static device_method_t amdsmn_methods[] = { + /* Device interface */ + DEVMETHOD(device_identify, amdsmn_identify), + DEVMETHOD(device_probe, amdsmn_probe), + DEVMETHOD(device_attach, amdsmn_attach), + DEVMETHOD(device_detach, amdsmn_detach), + DEVMETHOD_END +}; + +static driver_t amdsmn_driver = { + "amdsmn", + amdsmn_methods, + sizeof(struct amdsmn_softc), +}; + +static devclass_t amdsmn_devclass; +DRIVER_MODULE(amdsmn, hostb, amdsmn_driver, amdsmn_devclass, NULL, NULL); +MODULE_VERSION(amdsmn, 1); + +static void +amdsmn_identify(driver_t *driver, device_t parent) +{ + device_t child; + uint32_t devid; + size_t i; + + /* Make sure we're not being doubly invoked. */ + if (device_find_child(parent, "amdsmn", -1) != NULL) + return; + + devid = pci_get_devid(parent); + for (i = 0; i < nitems(amdsmn_ids); i++) + if (amdsmn_ids[i].device_id == devid) + break; + + if (i >= nitems(amdsmn_ids)) + return; + + child = device_add_child(parent, "amdsmn", -1); + if (child == NULL) + device_printf(parent, "add amdsmn child failed\n"); +} + +static int +amdsmn_probe(device_t dev) +{ + uint32_t family; + + if (resource_disabled("amdsmn", 0)) + return (ENXIO); + + family = CPUID_TO_FAMILY(cpu_id); + + switch (family) { + case 0x17: + break; + default: + return (ENXIO); + } + device_set_desc(dev, "AMD Family 17h System Management Network"); + + return (BUS_PROBE_GENERIC); +} + +static int +amdsmn_attach(device_t dev) +{ + struct amdsmn_softc *sc = device_get_softc(dev); + + mtx_init(&sc->smn_lock, "SMN mtx", "SMN", MTX_DEF); + return (0); +} + +int +amdsmn_detach(device_t dev) +{ + struct amdsmn_softc *sc = device_get_softc(dev); + + mtx_destroy(&sc->smn_lock); + return (0); +} + +int +amdsmn_read(device_t dev, uint32_t addr, uint32_t *value) +{ + struct amdsmn_softc *sc = device_get_softc(dev); + device_t parent; + + parent = device_get_parent(dev); + + mtx_lock(&sc->smn_lock); + pci_write_config(parent, SMN_ADDR_REG, addr, 4); + *value = pci_read_config(parent, SMN_DATA_REG, 4); + mtx_unlock(&sc->smn_lock); + + return (0); +} + +int +amdsmn_write(device_t dev, uint32_t addr, uint32_t value) +{ + struct amdsmn_softc *sc = device_get_softc(dev); + device_t parent; + + parent = device_get_parent(dev); + + mtx_lock(&sc->smn_lock); + pci_write_config(parent, SMN_ADDR_REG, addr, 4); + pci_write_config(parent, SMN_DATA_REG, value, 4); + mtx_unlock(&sc->smn_lock); + + return (0); +} Added: head/sys/dev/amdsmn/amdsmn.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/amdsmn/amdsmn.h Tue Sep 5 15:13:41 2017 (r323184) @@ -0,0 +1,32 @@ +/*- + * Copyright (c) 2017 Conrad Meyer + * 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$ + */ + +#pragma once + +int amdsmn_read(device_t dev, uint32_t addr, uint32_t *value); +int amdsmn_write(device_t dev, uint32_t addr, uint32_t value); Modified: head/sys/modules/Makefile ============================================================================== --- head/sys/modules/Makefile Tue Sep 5 14:32:56 2017 (r323183) +++ head/sys/modules/Makefile Tue Sep 5 15:13:41 2017 (r323184) @@ -35,6 +35,7 @@ SUBDIR= \ alq \ ${_amd_ecc_inject} \ ${_amdsbwd} \ + ${_amdsmn} \ ${_amdtemp} \ amr \ ${_an} \ @@ -626,6 +627,7 @@ _aesni= aesni .endif _amd_ecc_inject=amd_ecc_inject _amdsbwd= amdsbwd +_amdsmn= amdsmn _amdtemp= amdtemp _arcmsr= arcmsr _asmc= asmc Added: head/sys/modules/amdsmn/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/modules/amdsmn/Makefile Tue Sep 5 15:13:41 2017 (r323184) @@ -0,0 +1,8 @@ +# $FreeBSD$ + +.PATH: ${SRCTOP}/sys/dev/amdsmn + +KMOD= amdsmn +SRCS= amdsmn.c bus_if.h device_if.h pci_if.h + +.include