drivers/char/ipmi/ipmi_si_ls2k.c

Source file repositories/reference/linux-study-clean/drivers/char/ipmi/ipmi_si_ls2k.c

File Facts

System
Linux kernel
Corpus path
drivers/char/ipmi/ipmi_si_ls2k.c
Extension
.c
Size
4633 bytes
Lines
190
Domain
Driver Families
Bucket
drivers/char
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0+
/*
 * Driver for Loongson-2K BMC IPMI interface
 *
 * Copyright (C) 2024-2025 Loongson Technology Corporation Limited.
 *
 * Authors:
 *	Chong Qiao <qiaochong@loongson.cn>
 *	Binbin Zhou <zhoubinbin@loongson.cn>
 */

#include <linux/bitfield.h>
#include <linux/ioport.h>
#include <linux/module.h>
#include <linux/types.h>

#include "ipmi_si.h"

#define LS2K_KCS_FIFO_IBFH	0x0
#define LS2K_KCS_FIFO_IBFT	0x1
#define LS2K_KCS_FIFO_OBFH	0x2
#define LS2K_KCS_FIFO_OBFT	0x3

/* KCS registers */
#define LS2K_KCS_REG_STS	0x4
#define LS2K_KCS_REG_DATA_OUT	0x5
#define LS2K_KCS_REG_DATA_IN	0x6
#define LS2K_KCS_REG_CMD	0x8

#define LS2K_KCS_CMD_DATA	0xa
#define LS2K_KCS_VERSION	0xb
#define LS2K_KCS_WR_REQ		0xc
#define LS2K_KCS_WR_ACK		0x10

#define LS2K_KCS_STS_OBF	BIT(0)
#define LS2K_KCS_STS_IBF	BIT(1)
#define LS2K_KCS_STS_SMS_ATN	BIT(2)
#define LS2K_KCS_STS_CMD	BIT(3)

#define LS2K_KCS_DATA_MASK	(LS2K_KCS_STS_OBF | LS2K_KCS_STS_IBF | LS2K_KCS_STS_CMD)

static bool ls2k_registered;

static unsigned char ls2k_mem_inb_v0(const struct si_sm_io *io, unsigned int offset)
{
	void __iomem *addr = io->addr;
	int reg_offset;

	if (offset & BIT(0)) {
		reg_offset = LS2K_KCS_REG_STS;
	} else {
		writeb(readb(addr + LS2K_KCS_REG_STS) & ~LS2K_KCS_STS_OBF, addr + LS2K_KCS_REG_STS);
		reg_offset = LS2K_KCS_REG_DATA_OUT;
	}

	return readb(addr + reg_offset);
}

static unsigned char ls2k_mem_inb_v1(const struct si_sm_io *io, unsigned int offset)
{
	void __iomem *addr = io->addr;
	unsigned char inb = 0, cmd;
	bool obf, ibf;

	obf = readb(addr + LS2K_KCS_FIFO_OBFH) ^ readb(addr + LS2K_KCS_FIFO_OBFT);
	ibf = readb(addr + LS2K_KCS_FIFO_IBFH) ^ readb(addr + LS2K_KCS_FIFO_IBFT);
	cmd = readb(addr + LS2K_KCS_CMD_DATA);

	if (offset & BIT(0)) {
		inb = readb(addr + LS2K_KCS_REG_STS) & ~LS2K_KCS_DATA_MASK;
		inb |= FIELD_PREP(LS2K_KCS_STS_OBF, obf)
		    | FIELD_PREP(LS2K_KCS_STS_IBF, ibf)
		    | FIELD_PREP(LS2K_KCS_STS_CMD, cmd);
	} else {
		inb = readb(addr + LS2K_KCS_REG_DATA_OUT);
		writeb(readb(addr + LS2K_KCS_FIFO_OBFH), addr + LS2K_KCS_FIFO_OBFT);
	}

	return inb;
}

static void ls2k_mem_outb_v0(const struct si_sm_io *io, unsigned int offset,
			     unsigned char val)
{
	void __iomem *addr = io->addr;
	unsigned char sts = readb(addr + LS2K_KCS_REG_STS);
	int reg_offset;

	if (sts & LS2K_KCS_STS_IBF)
		return;

Annotation

Implementation Notes