Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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 */
23struct si_sm_data;
24
25enum si_type {
26 SI_TYPE_INVALID, SI_KCS, SI_SMIC, SI_BT
27};
28
29enum ipmi_addr_space {
30 IPMI_IO_ADDR_SPACE, IPMI_MEM_ADDR_SPACE
31};
32
33/*
34 * The structure for doing I/O in the state machine. The state
35 * machine doesn't have the actual I/O routines, they are done through
36 * this interface.
37 */
38struct si_sm_io {
39 unsigned char (*inputb)(const struct si_sm_io *io, unsigned int offset);
40 void (*outputb)(const struct si_sm_io *io,
41 unsigned int offset,
42 unsigned char b);
43
44 /*
45 * Generic info used by the actual handling routines, the
46 * state machine shouldn't touch these.
47 */
48 void __iomem *addr;
49 unsigned int regspacing;
50 unsigned int regsize;
51 unsigned int regshift;
52 enum ipmi_addr_space addr_space;
53 unsigned long addr_data;
54 enum ipmi_addr_src addr_source; /* ACPI, PCI, SMBIOS, hardcode, etc. */
55 void (*addr_source_cleanup)(struct si_sm_io *io);
56 void *addr_source_data;
57 union ipmi_smi_info_union addr_info;
58
59 int (*io_setup)(struct si_sm_io *info);
60 void (*io_cleanup)(struct si_sm_io *info);
61 unsigned int io_size;
62
63 int irq;
64 int (*irq_setup)(struct si_sm_io *io);
65 void *irq_handler_data;
66 void (*irq_cleanup)(struct si_sm_io *io);
67
68 u8 slave_addr;
69 enum si_type si_type;
70 struct device *dev;
71};
72
73/* Results of SMI events. */
74enum si_sm_result {
75 SI_SM_CALL_WITHOUT_DELAY, /* Call the driver again immediately */
76 SI_SM_CALL_WITH_DELAY, /* Delay some before calling again. */
77 SI_SM_CALL_WITH_TICK_DELAY,/* Delay >=1 tick before calling again. */
78 SI_SM_TRANSACTION_COMPLETE, /* A transaction is finished. */
79 SI_SM_IDLE, /* The SM is in idle state. */
80 SI_SM_HOSED, /* The hardware violated the state machine. */
81
82 /*
83 * The hardware is asserting attn and the state machine is
84 * idle.
85 */
86 SI_SM_ATTN
87};
88
89/* Handlers for the SMI state machine. */
90struct si_sm_handlers {
91 /*
92 * Put the version number of the state machine here so the
93 * upper layer can print it.
94 */
95 char *version;
96
97 /*
98 * Initialize the data and return the amount of I/O space to
99 * reserve for the space.
100 */
101 unsigned int (*init_data)(struct si_sm_data *smi,
102 struct si_sm_io *io);
103
104 /*
105 * Start a new transaction in the state machine. This will
106 * return -2 if the state machine is not idle, -1 if the size
107 * is invalid (to large or too small), or 0 if the transaction
108 * is successfully completed.
109 */
110 int (*start_transaction)(struct si_sm_data *smi,
111 unsigned char *data, unsigned int size);
112
113 /*
114 * Return the results after the transaction. This will return
115 * -1 if the buffer is too small, zero if no transaction is
116 * present, or the actual length of the result data.
117 */
118 int (*get_result)(struct si_sm_data *smi,
119 unsigned char *data, unsigned int length);
120
121 /*
122 * Call this periodically (for a polled interface) or upon
123 * receiving an interrupt (for a interrupt-driven interface).
124 * If interrupt driven, you should probably poll this
125 * periodically when not in idle state. This should be called
126 * with the time that passed since the last call, if it is
127 * significant. Time is in microseconds.
128 */
129 enum si_sm_result (*event)(struct si_sm_data *smi, long time);
130
131 /*
132 * Attempt to detect an SMI. Returns 0 on success or nonzero
133 * on failure.
134 */
135 int (*detect)(struct si_sm_data *smi);
136
137 /* The interface is shutting down, so clean it up. */
138 void (*cleanup)(struct si_sm_data *smi);
139
140 /* Return the size of the SMI structure in bytes. */
141 int (*size)(void);
142};
143
144/* Current state machines that we can use. */
145extern const struct si_sm_handlers kcs_smi_handlers;
146extern const struct si_sm_handlers smic_smi_handlers;
147extern const struct si_sm_handlers bt_smi_handlers;
148