Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ipmi_si_sm.h |
| 3 | * |
| 4 | * State machine interface for low-level IPMI system management |
| 5 | * interface state machines. This code is the interface between |
| 6 | * the ipmi_smi code (that handles the policy of a KCS, SMIC, or |
| 7 | * BT interface) and the actual low-level state machine. |
| 8 | * |
| 9 | * Author: MontaVista Software, Inc. |
| 10 | * Corey Minyard <minyard@mvista.com> |
| 11 | * source@mvista.com |
| 12 | * |
| 13 | * Copyright 2002 MontaVista Software Inc. |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or modify it |
| 16 | * under the terms of the GNU General Public License as published by the |
| 17 | * Free Software Foundation; either version 2 of the License, or (at your |
| 18 | * option) any later version. |
| 19 | * |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 23 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 24 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 28 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
| 29 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 30 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | * You should have received a copy of the GNU General Public License along |
| 33 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 34 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
| 35 | */ |
| 36 | |
Corey Minyard | 910840f | 2017-09-12 14:41:56 -0500 | [diff] [blame] | 37 | #include <linux/ipmi.h> |
| 38 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 39 | /* |
| 40 | * This is defined by the state machines themselves, it is an opaque |
| 41 | * data type for them to use. |
| 42 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | struct si_sm_data; |
| 44 | |
Corey Minyard | 910840f | 2017-09-12 14:41:56 -0500 | [diff] [blame] | 45 | enum si_type { |
| 46 | SI_KCS, SI_SMIC, SI_BT |
| 47 | }; |
| 48 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 49 | /* |
| 50 | * The structure for doing I/O in the state machine. The state |
| 51 | * machine doesn't have the actual I/O routines, they are done through |
| 52 | * this interface. |
| 53 | */ |
| 54 | struct si_sm_io { |
Corey Minyard | 81d02b7 | 2015-06-13 10:34:25 -0500 | [diff] [blame] | 55 | unsigned char (*inputb)(const struct si_sm_io *io, unsigned int offset); |
| 56 | void (*outputb)(const struct si_sm_io *io, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | unsigned int offset, |
| 58 | unsigned char b); |
| 59 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 60 | /* |
| 61 | * Generic info used by the actual handling routines, the |
| 62 | * state machine shouldn't touch these. |
| 63 | */ |
Al Viro | 1b75d8b | 2005-05-04 05:40:22 +0100 | [diff] [blame] | 64 | void __iomem *addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | int regspacing; |
| 66 | int regsize; |
| 67 | int regshift; |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 68 | int addr_type; |
| 69 | long addr_data; |
Corey Minyard | 910840f | 2017-09-12 14:41:56 -0500 | [diff] [blame] | 70 | enum ipmi_addr_src addr_source; /* ACPI, PCI, SMBIOS, hardcode, etc. */ |
| 71 | void (*addr_source_cleanup)(struct si_sm_io *io); |
| 72 | void *addr_source_data; |
Corey Minyard | bb398a4 | 2017-09-12 21:37:02 -0500 | [diff] [blame^] | 73 | union ipmi_smi_info_union addr_info; |
Corey Minyard | 910840f | 2017-09-12 14:41:56 -0500 | [diff] [blame] | 74 | |
Corey Minyard | e1eeb7f | 2017-09-12 15:40:53 -0500 | [diff] [blame] | 75 | int (*io_setup)(struct si_sm_io *info); |
| 76 | void (*io_cleanup)(struct si_sm_io *info); |
| 77 | unsigned int io_size; |
| 78 | |
Corey Minyard | 910840f | 2017-09-12 14:41:56 -0500 | [diff] [blame] | 79 | int irq; |
Corey Minyard | 4f3e819 | 2017-09-12 15:10:22 -0500 | [diff] [blame] | 80 | int (*irq_setup)(struct si_sm_io *io); |
| 81 | void *irq_handler_data; |
| 82 | void (*irq_cleanup)(struct si_sm_io *io); |
| 83 | |
Corey Minyard | 910840f | 2017-09-12 14:41:56 -0500 | [diff] [blame] | 84 | u8 slave_addr; |
| 85 | enum si_type si_type; |
| 86 | struct device *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | /* Results of SMI events. */ |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 90 | enum si_sm_result { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | SI_SM_CALL_WITHOUT_DELAY, /* Call the driver again immediately */ |
| 92 | SI_SM_CALL_WITH_DELAY, /* Delay some before calling again. */ |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 93 | SI_SM_CALL_WITH_TICK_DELAY,/* Delay >=1 tick before calling again. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | SI_SM_TRANSACTION_COMPLETE, /* A transaction is finished. */ |
| 95 | SI_SM_IDLE, /* The SM is in idle state. */ |
| 96 | SI_SM_HOSED, /* The hardware violated the state machine. */ |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 97 | |
| 98 | /* |
| 99 | * The hardware is asserting attn and the state machine is |
| 100 | * idle. |
| 101 | */ |
| 102 | SI_SM_ATTN |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | /* Handlers for the SMI state machine. */ |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 106 | struct si_sm_handlers { |
| 107 | /* |
| 108 | * Put the version number of the state machine here so the |
| 109 | * upper layer can print it. |
| 110 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | char *version; |
| 112 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 113 | /* |
| 114 | * Initialize the data and return the amount of I/O space to |
| 115 | * reserve for the space. |
| 116 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | unsigned int (*init_data)(struct si_sm_data *smi, |
| 118 | struct si_sm_io *io); |
| 119 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 120 | /* |
| 121 | * Start a new transaction in the state machine. This will |
| 122 | * return -2 if the state machine is not idle, -1 if the size |
| 123 | * is invalid (to large or too small), or 0 if the transaction |
| 124 | * is successfully completed. |
| 125 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | int (*start_transaction)(struct si_sm_data *smi, |
| 127 | unsigned char *data, unsigned int size); |
| 128 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 129 | /* |
| 130 | * Return the results after the transaction. This will return |
| 131 | * -1 if the buffer is too small, zero if no transaction is |
| 132 | * present, or the actual length of the result data. |
| 133 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | int (*get_result)(struct si_sm_data *smi, |
| 135 | unsigned char *data, unsigned int length); |
| 136 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 137 | /* |
| 138 | * Call this periodically (for a polled interface) or upon |
| 139 | * receiving an interrupt (for a interrupt-driven interface). |
| 140 | * If interrupt driven, you should probably poll this |
| 141 | * periodically when not in idle state. This should be called |
| 142 | * with the time that passed since the last call, if it is |
| 143 | * significant. Time is in microseconds. |
| 144 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | enum si_sm_result (*event)(struct si_sm_data *smi, long time); |
| 146 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 147 | /* |
| 148 | * Attempt to detect an SMI. Returns 0 on success or nonzero |
| 149 | * on failure. |
| 150 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | int (*detect)(struct si_sm_data *smi); |
| 152 | |
| 153 | /* The interface is shutting down, so clean it up. */ |
| 154 | void (*cleanup)(struct si_sm_data *smi); |
| 155 | |
| 156 | /* Return the size of the SMI structure in bytes. */ |
| 157 | int (*size)(void); |
| 158 | }; |
| 159 | |
| 160 | /* Current state machines that we can use. */ |
Corey Minyard | 81d02b7 | 2015-06-13 10:34:25 -0500 | [diff] [blame] | 161 | extern const struct si_sm_handlers kcs_smi_handlers; |
| 162 | extern const struct si_sm_handlers smic_smi_handlers; |
| 163 | extern const struct si_sm_handlers bt_smi_handlers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |