11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * ipmi_si_sm.h 31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * State machine interface for low-level IPMI system management 51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * interface state machines. This code is the interface between 61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the ipmi_smi code (that handles the policy of a KCS, SMIC, or 71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * BT interface) and the actual low-level state machine. 81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Author: MontaVista Software, Inc. 101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Corey Minyard <minyard@mvista.com> 111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * source@mvista.com 121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright 2002 MontaVista Software Inc. 141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This program is free software; you can redistribute it and/or modify it 161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * under the terms of the GNU General Public License as published by the 171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Free Software Foundation; either version 2 of the License, or (at your 181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * option) any later version. 191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * You should have received a copy of the GNU General Public License along 331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * with this program; if not, write to the Free Software Foundation, Inc., 341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 675 Mass Ave, Cambridge, MA 02139, USA. 351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 37c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard/* 38c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * This is defined by the state machines themselves, it is an opaque 39c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * data type for them to use. 40c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard */ 411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct si_sm_data; 421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 43c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard/* 44c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * The structure for doing I/O in the state machine. The state 45c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * machine doesn't have the actual I/O routines, they are done through 46c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * this interface. 47c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard */ 48c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyardstruct si_sm_io { 491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned char (*inputb)(struct si_sm_io *io, unsigned int offset); 501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds void (*outputb)(struct si_sm_io *io, 511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int offset, 521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned char b); 531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 54c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard /* 55c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * Generic info used by the actual handling routines, the 56c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * state machine shouldn't touch these. 57c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard */ 581b75d8ba5ea96e174dc2674e01d87ce0d382ee44Al Viro void __iomem *addr; 591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int regspacing; 601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int regsize; 611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int regshift; 62b0defcdbd2b7da7694e2645da92716cea0a3c0ffCorey Minyard int addr_type; 63b0defcdbd2b7da7694e2645da92716cea0a3c0ffCorey Minyard long addr_data; 641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Results of SMI events. */ 67c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyardenum si_sm_result { 681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SI_SM_CALL_WITHOUT_DELAY, /* Call the driver again immediately */ 691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SI_SM_CALL_WITH_DELAY, /* Delay some before calling again. */ 70c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard SI_SM_CALL_WITH_TICK_DELAY,/* Delay >=1 tick before calling again. */ 711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SI_SM_TRANSACTION_COMPLETE, /* A transaction is finished. */ 721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SI_SM_IDLE, /* The SM is in idle state. */ 731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SI_SM_HOSED, /* The hardware violated the state machine. */ 74c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard 75c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard /* 76c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * The hardware is asserting attn and the state machine is 77c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * idle. 78c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard */ 79c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard SI_SM_ATTN 801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Handlers for the SMI state machine. */ 83c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyardstruct si_sm_handlers { 84c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard /* 85c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * Put the version number of the state machine here so the 86c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * upper layer can print it. 87c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard */ 881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char *version; 891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 90c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard /* 91c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * Initialize the data and return the amount of I/O space to 92c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * reserve for the space. 93c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard */ 941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int (*init_data)(struct si_sm_data *smi, 951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct si_sm_io *io); 961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 97c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard /* 98c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * Start a new transaction in the state machine. This will 99c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * return -2 if the state machine is not idle, -1 if the size 100c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * is invalid (to large or too small), or 0 if the transaction 101c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * is successfully completed. 102c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard */ 1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int (*start_transaction)(struct si_sm_data *smi, 1041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned char *data, unsigned int size); 1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 106c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard /* 107c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * Return the results after the transaction. This will return 108c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * -1 if the buffer is too small, zero if no transaction is 109c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * present, or the actual length of the result data. 110c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard */ 1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int (*get_result)(struct si_sm_data *smi, 1121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned char *data, unsigned int length); 1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 114c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard /* 115c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * Call this periodically (for a polled interface) or upon 116c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * receiving an interrupt (for a interrupt-driven interface). 117c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * If interrupt driven, you should probably poll this 118c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * periodically when not in idle state. This should be called 119c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * with the time that passed since the last call, if it is 120c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * significant. Time is in microseconds. 121c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard */ 1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds enum si_sm_result (*event)(struct si_sm_data *smi, long time); 1231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 124c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard /* 125c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * Attempt to detect an SMI. Returns 0 on success or nonzero 126c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard * on failure. 127c305e3d38e5f54a48a4618496cdc1ada970ebf68Corey Minyard */ 1281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int (*detect)(struct si_sm_data *smi); 1291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* The interface is shutting down, so clean it up. */ 1311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds void (*cleanup)(struct si_sm_data *smi); 1321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Return the size of the SMI structure in bytes. */ 1341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int (*size)(void); 1351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 1361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Current state machines that we can use. */ 1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern struct si_sm_handlers kcs_smi_handlers; 1391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern struct si_sm_handlers smic_smi_handlers; 1401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern struct si_sm_handlers bt_smi_handlers; 1411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 142