xref: /netbsd-src/sys/arch/x86/pci/imcsmb/imcsmb_var.h (revision 82ae8dd180cc6a638127f185d3ba129258cd61fc)
1 /* $NetBSD: imcsmb_var.h,v 1.1 2018/03/01 04:45:06 pgoyette Exp $ */
2 
3 /*-
4  * Copyright (c) 2018 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Paul Goyette
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*-
33  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
34  *
35  * Authors: Joe Kloss; Ravi Pokala (rpokala@freebsd.org)
36  *
37  * Copyright (c) 2017-2018 Panasas
38  * All rights reserved.
39  *
40  * Redistribution and use in source and binary forms, with or without
41  * modification, are permitted provided that the following conditions
42  * are met:
43  * 1. Redistributions of source code must retain the above copyright
44  *    notice, this list of conditions and the following disclaimer.
45  * 2. Redistributions in binary form must reproduce the above copyright
46  *    notice, this list of conditions and the following disclaimer in the
47  *    documentation and/or other materials provided with the distribution.
48  *
49  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
50  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
53  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59  * SUCH DAMAGE.
60  */
61 
62 #ifndef _DEV__IMCSMB__IMCSMB_VAR_H_
63 #define _DEV__IMCSMB__IMCSMB_VAR_H_
64 
65 #include <sys/param.h>
66 #include <sys/mutex.h>
67 #include <sys/bus.h>
68 
69 #include <dev/i2c/i2cvar.h>
70 
71 #include <dev/pci/pcivar.h>
72 /* #include <dev/pci/pcireg.h> PRG */
73 
74 /* A detailed description of this device is present in imcsmb_pci.c */
75 
76 /**
77  * The softc for a particular instance of the PCI device associated with a pair
78  * of iMC-SMB controllers.
79  *
80  * Ordinarily, locking would be done with a mutex. However, we might have an
81  * NVDIMM connected to this SMBus, and we might need to issue the SAVE command
82  * to the NVDIMM from a panic context. Mutex operations are not allowed while
83  * the scheduler is stopped, so just use a simple semaphore.
84  *
85  * If, as described in the manpage, additional steps are needed to stop/restart
86  * firmware operations before/after using the controller, then additional fields
87  * can be added to this softc.
88  */
89 struct imc_softc {
90 	device_t	sc_dev;
91 	device_t	sc_smbchild[2];
92 	pcitag_t	sc_pci_tag;	/* pci config space info */
93 	pci_chipset_tag_t sc_pci_chipset_tag;
94 };
95 
96 void imcsmb_pci_release_bus(device_t dev);
97 int imcsmb_pci_request_bus(device_t dev);
98 
99 /**
100  * PCI config registers for each individual SMBus controller within the iMC.
101  * Each iMC-SMB has a separate set of registers. There is an array of these
102  * structures for the PCI device, and one of them is passed to driver for the
103  * actual iMC-SMB as the IVAR.
104  */
105 struct imcsmb_reg_set {
106 	uint16_t smb_stat;
107 	uint16_t smb_cmd;
108 	uint16_t smb_cntl;
109 };
110 
111 /**
112  * The softc for the device associated with a particular iMC-SMB controller.
113  * There are two such controllers for each of the PCI devices. The PCI driver
114  * tells the iMC-SMB driver which set of registers to use via the IVAR. This
115  * technique was suggested by John Baldwin (jhb@).
116  */
117 struct imcsmb_softc {
118 	device_t		sc_dev;
119 	device_t		sc_smbus;	/* child smbusX interface */
120 	struct imcsmb_reg_set	*sc_regs;	/* regs for this controller */
121 	struct i2c_controller	sc_i2c_tag;	/* i2c tag info */
122 	pcitag_t		sc_pci_tag;	/* pci config space info */
123 	pci_chipset_tag_t	sc_pci_chipset_tag;
124 	kmutex_t		sc_i2c_mutex;
125 };
126 
127 struct imc_attach_args {
128 	int			ia_unit;
129 	struct imcsmb_reg_set	*ia_regs;
130 	pci_chipset_tag_t	ia_pci_pc;
131 	pcitag_t		ia_pci_tag;
132 	pci_chipset_tag_t	ia_pci_chipset_tag;
133 
134 };
135 
136 /* Interface for enable/disable BIOS or other motherboard access to IMC */
137 
138 typedef enum {
139 	IMC_BIOS_ENABLE,
140 	IMC_BIOS_DISABLE
141 } imc_bios_control ;
142 
143 void imc_callback(struct imcsmb_softc *, imc_bios_control);
144 
145 #endif /* _DEV__IMCSMB__IMCSMB_VAR_H_ */
146