⬢ DragonFlyBSD Kernel Audit
DF-4978 / ipmivars.h
← back to finding ↓ download raw
/*
 * Mock <ipmivars.h> for the DF-4978 ssifshock harness.
 *
 * Provides exactly the subset of sys/dev/misc/ipmi/ipmivars.h that the
 * verbatim ipmi_ssif.c (compiled with -DLOCAL_MODULE) references:
 *   - struct ipmi_request      : field-for-field copy of the real struct
 *                                (ipmivars.h:42-55)
 *   - struct ipmi_softc        : minimal mock (only ipmi_dev, ipmi_lock,
 *                                ipmi_kthread and the SSIF ivars are
 *                                referenced by ipmi_ssif.c)
 *   - ipmi_ssif_smbus_address / ipmi_ssif_smbus macros: verbatim
 *                                (ipmivars.h:122-123)
 *   - IPMI_REPLY_ADDR          : verbatim (ipmivars.h:188)
 * There is NO INB/OUTB substitution here (unlike the KCS/SMIC harnesses):
 * the SSIF transport talks to the bus, not to registers, so the mock
 * point is the SMBus layer (see mock/bus/smbus/smbconf.h).  The driver
 * logic under test is byte-for-byte the kernel source.
 */
#ifndef __POC_MOCK_IPMIVARS_H__
#define	__POC_MOCK_IPMIVARS_H__

#include <sys/queue.h>
#include <sys/lock.h>
#include <sys/bus.h>
#include <sys/thread.h>

/* verbatim ipmivars.h:42-55 */
struct ipmi_device;

struct ipmi_request {
	TAILQ_ENTRY(ipmi_request) ir_link;
	struct ipmi_device *ir_owner;	/* Driver uses NULL. */
	u_char		*ir_request;	/* Request is data to send to BMC. */
	size_t		 ir_requestlen;
	u_char		*ir_reply;	/* Reply is data read from BMC. */
	size_t		 ir_replybuflen;	/* Length of ir_reply[] buffer. */
	int		 ir_replylen;	/* Length of reply from BMC. */
	int		 ir_error;
	long		 ir_msgid;
	uint8_t		 ir_addr;
	uint8_t		 ir_command;
	uint8_t		 ir_compcode;
};

/* verbatim ipmivars.h:83-86 */
struct ipmi_ssif {
	device_t smbus;
	int	smbus_address;
};

/* minimal mock softc: everything ipmi_ssif.c touches */
struct ipmi_softc {
	device_t		ipmi_dev;
	union {
		struct ipmi_ssif ssif;
	} _iface;
	struct lock		ipmi_lock;
	struct thread		*ipmi_kthread;

	int			(*ipmi_startup)(struct ipmi_softc *);
	int			(*ipmi_enqueue_request)(struct ipmi_softc *,
				    struct ipmi_request *);
};

/* verbatim ipmivars.h:122-123 */
#define	ipmi_ssif_smbus_address		_iface.ssif.smbus_address
#define	ipmi_ssif_smbus			_iface.ssif.smbus

/* verbatim ipmivars.h:188 */
#define	IPMI_REPLY_ADDR(addr)		((addr) + 0x4)

/* verbatim ipmivars.h:190-191 (used only by ssif_loop(), never run) */
#define	IPMI_LOCK(sc)			lockmgr(&(sc)->ipmi_lock, LK_EXCLUSIVE)
#define	IPMI_UNLOCK(sc)			lockmgr(&(sc)->ipmi_lock, LK_RELEASE)

/* verbatim ipmivars.h:228-231,245 (implemented in ssifshock.c as stubs) */
struct ipmi_request *ipmi_dequeue_request(struct ipmi_softc *);
void	ipmi_complete_request(struct ipmi_softc *, struct ipmi_request *);
int	ipmi_polled_enqueue_request(struct ipmi_softc *,
	    struct ipmi_request *);
int	ipmi_ssif_attach(struct ipmi_softc *, device_t, int);

/* the mock softc has no real device_t; route diagnostics to the console */
#define	device_printf(dev, fmt, ...)	kprintf("ssifshock: " fmt, ##__VA_ARGS__)

#endif	/* !__POC_MOCK_IPMIVARS_H__ */