blob: df89f73475fb996770bfeae8f3710038feabb825 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Minyardc305e3d2008-04-29 01:01:10 -070037/*
38 * This is defined by the state machines themselves, it is an opaque
39 * data type for them to use.
40 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070041struct si_sm_data;
42
Corey Minyardc305e3d2008-04-29 01:01:10 -070043/*
44 * The structure for doing I/O in the state machine. The state
45 * machine doesn't have the actual I/O routines, they are done through
46 * this interface.
47 */
48struct si_sm_io {
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 unsigned char (*inputb)(struct si_sm_io *io, unsigned int offset);
50 void (*outputb)(struct si_sm_io *io,
51 unsigned int offset,
52 unsigned char b);
53
Corey Minyardc305e3d2008-04-29 01:01:10 -070054 /*
55 * Generic info used by the actual handling routines, the
56 * state machine shouldn't touch these.
57 */
Al Viro1b75d8b2005-05-04 05:40:22 +010058 void __iomem *addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 int regspacing;
60 int regsize;
61 int regshift;
Corey Minyardb0defcd2006-03-26 01:37:20 -080062 int addr_type;
63 long addr_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064};
65
66/* Results of SMI events. */
Corey Minyardc305e3d2008-04-29 01:01:10 -070067enum si_sm_result {
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 SI_SM_CALL_WITHOUT_DELAY, /* Call the driver again immediately */
69 SI_SM_CALL_WITH_DELAY, /* Delay some before calling again. */
Corey Minyardc305e3d2008-04-29 01:01:10 -070070 SI_SM_CALL_WITH_TICK_DELAY,/* Delay >=1 tick before calling again. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 SI_SM_TRANSACTION_COMPLETE, /* A transaction is finished. */
72 SI_SM_IDLE, /* The SM is in idle state. */
73 SI_SM_HOSED, /* The hardware violated the state machine. */
Corey Minyardc305e3d2008-04-29 01:01:10 -070074
75 /*
76 * The hardware is asserting attn and the state machine is
77 * idle.
78 */
79 SI_SM_ATTN
Linus Torvalds1da177e2005-04-16 15:20:36 -070080};
81
82/* Handlers for the SMI state machine. */
Corey Minyardc305e3d2008-04-29 01:01:10 -070083struct si_sm_handlers {
84 /*
85 * Put the version number of the state machine here so the
86 * upper layer can print it.
87 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 char *version;
89
Corey Minyardc305e3d2008-04-29 01:01:10 -070090 /*
91 * Initialize the data and return the amount of I/O space to
92 * reserve for the space.
93 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 unsigned int (*init_data)(struct si_sm_data *smi,
95 struct si_sm_io *io);
96
Corey Minyardc305e3d2008-04-29 01:01:10 -070097 /*
98 * Start a new transaction in the state machine. This will
99 * return -2 if the state machine is not idle, -1 if the size
100 * is invalid (to large or too small), or 0 if the transaction
101 * is successfully completed.
102 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 int (*start_transaction)(struct si_sm_data *smi,
104 unsigned char *data, unsigned int size);
105
Corey Minyardc305e3d2008-04-29 01:01:10 -0700106 /*
107 * Return the results after the transaction. This will return
108 * -1 if the buffer is too small, zero if no transaction is
109 * present, or the actual length of the result data.
110 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 int (*get_result)(struct si_sm_data *smi,
112 unsigned char *data, unsigned int length);
113
Corey Minyardc305e3d2008-04-29 01:01:10 -0700114 /*
115 * Call this periodically (for a polled interface) or upon
116 * receiving an interrupt (for a interrupt-driven interface).
117 * If interrupt driven, you should probably poll this
118 * periodically when not in idle state. This should be called
119 * with the time that passed since the last call, if it is
120 * significant. Time is in microseconds.
121 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 enum si_sm_result (*event)(struct si_sm_data *smi, long time);
123
Corey Minyardc305e3d2008-04-29 01:01:10 -0700124 /*
125 * Attempt to detect an SMI. Returns 0 on success or nonzero
126 * on failure.
127 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 int (*detect)(struct si_sm_data *smi);
129
130 /* The interface is shutting down, so clean it up. */
131 void (*cleanup)(struct si_sm_data *smi);
132
133 /* Return the size of the SMI structure in bytes. */
134 int (*size)(void);
135};
136
137/* Current state machines that we can use. */
138extern struct si_sm_handlers kcs_smi_handlers;
139extern struct si_sm_handlers smic_smi_handlers;
140extern struct si_sm_handlers bt_smi_handlers;
141