1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Authors: Joe Kloss; Ravi Pokala (rpokala@freebsd.org) 5 * 6 * Copyright (c) 2017-2018 Panasas 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * $FreeBSD$ 30 */ 31 32 #ifndef _DEV__IMCSMB__IMCSMB_VAR_H_ 33 #define _DEV__IMCSMB__IMCSMB_VAR_H_ 34 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/kernel.h> 38 #include <sys/module.h> 39 #include <sys/endian.h> 40 #include <sys/errno.h> 41 #include <sys/lock.h> 42 #include <sys/mutex.h> 43 #include <sys/syslog.h> 44 #include <sys/bus.h> 45 46 #include <machine/bus.h> 47 #include <machine/atomic.h> 48 49 #include <dev/pci/pcivar.h> 50 #include <dev/pci/pcireg.h> 51 52 #include <dev/smbus/smbconf.h> 53 54 #include "smbus_if.h" 55 56 /* A detailed description of this device is present in imcsmb_pci.c */ 57 58 /** 59 * The softc for a particular instance of the PCI device associated with a pair 60 * of iMC-SMB controllers. 61 * 62 * Ordinarily, locking would be done with a mutex. However, we might have an 63 * NVDIMM connected to this SMBus, and we might need to issue the SAVE command 64 * to the NVDIMM from a panic context. Mutex operations are not allowed while 65 * the scheduler is stopped, so just use a simple semaphore. 66 * 67 * If, as described in the manpage, additional steps are needed to stop/restart 68 * firmware operations before/after using the controller, then additional fields 69 * can be added to this softc. 70 */ 71 struct imcsmb_pci_softc { 72 device_t dev; 73 volatile int semaphore; 74 }; 75 76 void imcsmb_pci_release_bus(device_t dev); 77 int imcsmb_pci_request_bus(device_t dev); 78 79 /** 80 * PCI config registers for each individual SMBus controller within the iMC. 81 * Each iMC-SMB has a separate set of registers. There is an array of these 82 * structures for the PCI device, and one of them is passed to driver for the 83 * actual iMC-SMB as the IVAR. 84 */ 85 struct imcsmb_reg_set { 86 uint16_t smb_stat; 87 uint16_t smb_cmd; 88 uint16_t smb_cntl; 89 }; 90 91 /** 92 * The softc for the device associated with a particular iMC-SMB controller. 93 * There are two such controllers for each of the PCI devices. The PCI driver 94 * tells the iMC-SMB driver which set of registers to use via the IVAR. This 95 * technique was suggested by John Baldwin (jhb@). 96 */ 97 struct imcsmb_softc { 98 device_t dev; 99 device_t imcsmb_pci; /* The SMBus controller's parent iMC */ 100 device_t smbus; /* The child smbusX interface */ 101 struct imcsmb_reg_set *regs; /* The registers this controller uses */ 102 }; 103 104 #endif /* _DEV__IMCSMB__IMCSMB_VAR_H_ */ 105 106 /* vi: set ts=8 sw=4 sts=8 noet: */ 107