xref: /freebsd/sys/dev/imcsmb/imcsmb_var.h (revision 02e9120893770924227138ba49df1edb3896112a)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
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 
30 #ifndef _DEV__IMCSMB__IMCSMB_VAR_H_
31 #define _DEV__IMCSMB__IMCSMB_VAR_H_
32 
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/module.h>
37 #include <sys/endian.h>
38 #include <sys/errno.h>
39 #include <sys/lock.h>
40 #include <sys/mutex.h>
41 #include <sys/syslog.h>
42 #include <sys/bus.h>
43 
44 #include <machine/bus.h>
45 #include <machine/atomic.h>
46 
47 #include <dev/pci/pcivar.h>
48 #include <dev/pci/pcireg.h>
49 
50 #include <dev/smbus/smbconf.h>
51 
52 #include "smbus_if.h"
53 
54 /* A detailed description of this device is present in imcsmb_pci.c */
55 
56 /**
57  * The softc for a particular instance of the PCI device associated with a pair
58  * of iMC-SMB controllers.
59  *
60  * Ordinarily, locking would be done with a mutex. However, we might have an
61  * NVDIMM connected to this SMBus, and we might need to issue the SAVE command
62  * to the NVDIMM from a panic context. Mutex operations are not allowed while
63  * the scheduler is stopped, so just use a simple semaphore.
64  *
65  * If, as described in the manpage, additional steps are needed to stop/restart
66  * firmware operations before/after using the controller, then additional fields
67  * can be added to this softc.
68  */
69 struct imcsmb_pci_softc {
70 	device_t dev;
71 	volatile int semaphore;
72 };
73 
74 void imcsmb_pci_release_bus(device_t dev);
75 int imcsmb_pci_request_bus(device_t dev);
76 
77 /**
78  * PCI config registers for each individual SMBus controller within the iMC.
79  * Each iMC-SMB has a separate set of registers. There is an array of these
80  * structures for the PCI device, and one of them is passed to driver for the
81  * actual iMC-SMB as the IVAR.
82  */
83 struct imcsmb_reg_set {
84 	uint16_t smb_stat;
85 	uint16_t smb_cmd;
86 	uint16_t smb_cntl;
87 };
88 
89 /**
90  * The softc for the device associated with a particular iMC-SMB controller.
91  * There are two such controllers for each of the PCI devices. The PCI driver
92  * tells the iMC-SMB driver which set of registers to use via the IVAR. This
93  * technique was suggested by John Baldwin (jhb@).
94  */
95 struct imcsmb_softc {
96 	device_t dev;
97 	device_t imcsmb_pci;	/* The SMBus controller's parent iMC */
98 	device_t smbus;		/* The child smbusX interface */
99 	struct imcsmb_reg_set *regs;	/* The registers this controller uses */
100 };
101 
102 #endif /* _DEV__IMCSMB__IMCSMB_VAR_H_ */
103 
104 /* vi: set ts=8 sw=4 sts=8 noet: */
105