xref: /openbmc/linux/drivers/char/ipmi/ipmi_si_sm.h (revision 7e6f7d24)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * ipmi_si_sm.h
4  *
5  * State machine interface for low-level IPMI system management
6  * interface state machines.  This code is the interface between
7  * the ipmi_smi code (that handles the policy of a KCS, SMIC, or
8  * BT interface) and the actual low-level state machine.
9  *
10  * Author: MontaVista Software, Inc.
11  *         Corey Minyard <minyard@mvista.com>
12  *         source@mvista.com
13  *
14  * Copyright 2002 MontaVista Software Inc.
15  */
16 
17 #include <linux/ipmi.h>
18 
19 /*
20  * This is defined by the state machines themselves, it is an opaque
21  * data type for them to use.
22  */
23 struct si_sm_data;
24 
25 enum si_type {
26 	SI_TYPE_INVALID, SI_KCS, SI_SMIC, SI_BT
27 };
28 
29 /*
30  * The structure for doing I/O in the state machine.  The state
31  * machine doesn't have the actual I/O routines, they are done through
32  * this interface.
33  */
34 struct si_sm_io {
35 	unsigned char (*inputb)(const struct si_sm_io *io, unsigned int offset);
36 	void (*outputb)(const struct si_sm_io *io,
37 			unsigned int  offset,
38 			unsigned char b);
39 
40 	/*
41 	 * Generic info used by the actual handling routines, the
42 	 * state machine shouldn't touch these.
43 	 */
44 	void __iomem *addr;
45 	int  regspacing;
46 	int  regsize;
47 	int  regshift;
48 	int addr_type;
49 	long addr_data;
50 	enum ipmi_addr_src addr_source; /* ACPI, PCI, SMBIOS, hardcode, etc. */
51 	void (*addr_source_cleanup)(struct si_sm_io *io);
52 	void *addr_source_data;
53 	union ipmi_smi_info_union addr_info;
54 
55 	int (*io_setup)(struct si_sm_io *info);
56 	void (*io_cleanup)(struct si_sm_io *info);
57 	unsigned int io_size;
58 
59 	int irq;
60 	int (*irq_setup)(struct si_sm_io *io);
61 	void *irq_handler_data;
62 	void (*irq_cleanup)(struct si_sm_io *io);
63 
64 	u8 slave_addr;
65 	enum si_type si_type;
66 	struct device *dev;
67 };
68 
69 /* Results of SMI events. */
70 enum si_sm_result {
71 	SI_SM_CALL_WITHOUT_DELAY, /* Call the driver again immediately */
72 	SI_SM_CALL_WITH_DELAY,	/* Delay some before calling again. */
73 	SI_SM_CALL_WITH_TICK_DELAY,/* Delay >=1 tick before calling again. */
74 	SI_SM_TRANSACTION_COMPLETE, /* A transaction is finished. */
75 	SI_SM_IDLE,		/* The SM is in idle state. */
76 	SI_SM_HOSED,		/* The hardware violated the state machine. */
77 
78 	/*
79 	 * The hardware is asserting attn and the state machine is
80 	 * idle.
81 	 */
82 	SI_SM_ATTN
83 };
84 
85 /* Handlers for the SMI state machine. */
86 struct si_sm_handlers {
87 	/*
88 	 * Put the version number of the state machine here so the
89 	 * upper layer can print it.
90 	 */
91 	char *version;
92 
93 	/*
94 	 * Initialize the data and return the amount of I/O space to
95 	 * reserve for the space.
96 	 */
97 	unsigned int (*init_data)(struct si_sm_data *smi,
98 				  struct si_sm_io   *io);
99 
100 	/*
101 	 * Start a new transaction in the state machine.  This will
102 	 * return -2 if the state machine is not idle, -1 if the size
103 	 * is invalid (to large or too small), or 0 if the transaction
104 	 * is successfully completed.
105 	 */
106 	int (*start_transaction)(struct si_sm_data *smi,
107 				 unsigned char *data, unsigned int size);
108 
109 	/*
110 	 * Return the results after the transaction.  This will return
111 	 * -1 if the buffer is too small, zero if no transaction is
112 	 * present, or the actual length of the result data.
113 	 */
114 	int (*get_result)(struct si_sm_data *smi,
115 			  unsigned char *data, unsigned int length);
116 
117 	/*
118 	 * Call this periodically (for a polled interface) or upon
119 	 * receiving an interrupt (for a interrupt-driven interface).
120 	 * If interrupt driven, you should probably poll this
121 	 * periodically when not in idle state.  This should be called
122 	 * with the time that passed since the last call, if it is
123 	 * significant.  Time is in microseconds.
124 	 */
125 	enum si_sm_result (*event)(struct si_sm_data *smi, long time);
126 
127 	/*
128 	 * Attempt to detect an SMI.  Returns 0 on success or nonzero
129 	 * on failure.
130 	 */
131 	int (*detect)(struct si_sm_data *smi);
132 
133 	/* The interface is shutting down, so clean it up. */
134 	void (*cleanup)(struct si_sm_data *smi);
135 
136 	/* Return the size of the SMI structure in bytes. */
137 	int (*size)(void);
138 };
139 
140 /* Current state machines that we can use. */
141 extern const struct si_sm_handlers kcs_smi_handlers;
142 extern const struct si_sm_handlers smic_smi_handlers;
143 extern const struct si_sm_handlers bt_smi_handlers;
144 
145