0
     CˆËÎ„ZeßÊÃÐ ,­    C/* SPDX-License-Identifier: GPL-2.0+ */
/*
 * ipmi.h
 *
 * MontaVista IPMI interface
 *
 * Author: MontaVista Software, Inc.
 *         Corey Minyard <minyard@mvista.com>
 *         source@mvista.com
 *
 * Copyright 2002 MontaVista Software Inc.
 *
 */
#ifndef __LINUX_IPMI_H
#define __LINUX_IPMI_H

#include <uapi/linux/ipmi.h>

#include <linux/list.h>
#include <linux/proc_fs.h>
#include <linux/acpi.h> /* For acpi_handle */

struct module;
struct device;

/*
 * Opaque type for a IPMI message user.  One of these is needed to
 * send and receive messages.
 */
struct ipmi_user;

/*
 * Stuff coming from the receive interface comes as one of these.
 * They are allocated, the receiver must free them with
 * ipmi_free_recv_msg() when done with the message.  The link is not
 * used after the message is delivered, so the upper layer may use the
 * link to build a linked list, if it likes.
 */
struct ipmi_recv_msg {
	struct list_head link;

	/*
	 * The type of message as defined in the "Receive Types"
	 * defines above.
	 */
	int              recv_type;

	struct ipmi_user *user;
	struct ipmi_addr addr;
	long             msgid;
	struct kernel_ipmi_msg  msg;

	/*
	 * The user_msg_data is the data supplied when a message was
	 * sent, if this is a response to a sent message.  If this is
	 * not a response to a sent message, then user_msg_data will
	 * be NULL.  If the user above is NULL, then this will be the
	 * intf.
	 */
	void             *user_msg_data;

	/*
	 * Call this when done with the message.  It will presumably free
	 * the message and do any other necessary cleanup.
	 */
	void (*done)(struct ipmi_recv_msg *msg);

	/*
	 * Place-holder for the data, don't make any assumptions about
	 * the size or existence of this, since it may change.
	 */
	unsigned char   msg_data[IPMI_MAX_MSG_LENGTH];

	RH_KABI_RESERVE(1)
	RH_KABI_RESERVE(2)
};

#define INIT_IPMI_RECV_MSG(done_handler) \
{					\
	.done = done_handler		\
}

/* Allocate and free the receive message. */
void ipmi_free_recv_msg(struct ipmi_recv_msg *msg);

struct ipmi_user_hndl {
	/*
	 * Routine type to call when a message needs to be routed to
	 * the upper layer.  This will be called with some locks held,
	 * the only IPMI routines that can be called are ipmi_request
	 * and the alloc/free operations.  The handler_data is the
	 * variable supplied when the receive handler was registered.
	 */
	void (*ipmi_recv_hndl)(struct ipmi_recv_msg *msg,
			       void                 *user_msg_data);

	/*
	 * Called when the interface detects a watchdog pre-timeout.  If
	 * this is NULL, it will be ignored for the user.
	 */
	void (*ipmi_watchdog_pretimeout)(void *handler_data);

	/*
	 * If not NULL, called at panic time after the interface has
	 * been set up to handle run to completion.
	 */
	void (*ipmi_panic_handler)(void *handler_data);

	/*
	 * Called when the interface has been removed.  After this returns
	 * the user handle will be invalid.  The interface may or may
	 * not be usable when this is called, but it will return errors
	 * if it is not usable.
	 */
	void (*shutdown)(void *handler_data);

	RH_KABI_RESERVE(1)
	RH_KABI_RESERVE(2)
};

/* Create a new user of the IPMI layer on the given interface number. */
int ipmi_create_user(unsigned int          if_num,
		     const struct ipmi_user_hndl *handler,
		     void                  *handler_data,
		     struct ipmi_user      **user);

/*
 * Destroy the given user of the IPMI layer.  Note that after this
 * function returns, the system is guaranteed to not call any
 * callbacks for the user.  Thus as long as you destroy all the users
 * before you unload a module, you will be safe.  And if you destroy
 * the users before you destroy the callback structures, it should be
 * safe, too.
 */
void ipmi_destroy_user(struct ipmi_user *user);

/* Get the IPMI version of the BMC we are talking to. */
int ipmi_get_version(struct ipmi_user *user,
		     unsigned char *major,
		     unsigned char *minor);

/*
 * Set and get the slave address and LUN that we will use for our
 * source messages.  Note 