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