Skip to content

Commit

Permalink
ipmi: kcs_bmc: Add a "raw" character device interface
Browse files Browse the repository at this point in the history
The existing IPMI chardev encodes IPMI behaviours as the name suggests.
However, KCS devices are useful beyond IPMI (or keyboards), as they
provide a means to generate IRQs and exchange arbitrary data between a
BMC and its host system.

Implement a "raw" KCS character device that exposes the IDR, ODR and STR
registers to userspace via read() and write() implemented on a character
device:

+--------+--------+---------+
| Offset | read() | write() |
+--------+--------+---------+
|   0    |   IDR  |   ODR   |
+--------+--------+---------+
|   1    |   STR  |   STR   |
+--------+--------+---------+

This interface allows userspace to implement arbitrary (though somewhat
inefficient) protocols for exchanging information between a BMC and host
firmware. Conceptually the KCS interface can be used as an out-of-band
mechanism for interrupt-signaled control messages while bulk data
transfers occur over more appropriate interfaces between the BMC and the
host (which may lack their own interrupt mechanism, e.g. LPC FW cycles).

poll() is provided, which will wait for IBF or OBE conditions for data
reads and writes respectively. Reads of STR on its own never blocks,
though accessing both offsets in the one system call may block if the
data registers are not ready.

OpenBMC-Staging-Count: 6
Signed-off-by: Andrew Jeffery <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Joel Stanley <[email protected]>
  • Loading branch information
amboar authored and shenki committed Sep 22, 2023
1 parent f0a14a9 commit c32ad4b
Show file tree
Hide file tree
Showing 4 changed files with 490 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Documentation/ABI/testing/dev-raw-kcs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
What: /dev/raw-kcs*
Date: 2021-02-15
KernelVersion: 5.13
Contact: [email protected]
Contact: [email protected]
Contact: Andrew Jeffery <[email protected]>
Description: ``/dev/raw-kcs*`` exposes to userspace the data and
status registers of Keyboard-Controller-Style (KCS) IPMI
interfaces via read() and write() syscalls. Direct
exposure of the data and status registers enables
inefficient but arbitrary protocols to be implemented
over the device. A typical approach is to use KCS
devices for out-of-band signalling for bulk data
transfers over other interfaces between a Baseboard
Management Controller and its host.

+--------+--------+---------+
| Offset | read() | write() |
+--------+--------+---------+
| 0 | IDR | ODR |
+--------+--------+---------+
| 1 | STR | STR |
+--------+--------+---------+

Users: libmctp: https://github.com/openbmc/libmctp
17 changes: 17 additions & 0 deletions drivers/char/ipmi/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,23 @@ config IPMI_KCS_BMC_SERIO
This support is also available as a module. The module will be
called kcs_bmc_serio.

config IPMI_KCS_BMC_CDEV_RAW
depends on IPMI_KCS_BMC
tristate "Raw character device interface for BMC KCS devices"
help
Provides a BMC-side character device directly exposing the
data and status registers of a KCS device to userspace. While
KCS devices are commonly used to implement IPMI message
passing, they provide a general interface for exchange of
interrupts, data and status information between the BMC and
its host.

Say YES if you wish to use the KCS devices to implement
protocols that are not IPMI.

This support is also available as a module. The module will be
called kcs_bmc_cdev_raw.

config ASPEED_BT_IPMI_BMC
depends on ARCH_ASPEED || COMPILE_TEST
depends on MFD_SYSCON
Expand Down
1 change: 1 addition & 0 deletions drivers/char/ipmi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o
obj-$(CONFIG_IPMI_KCS_BMC_SERIO) += kcs_bmc_serio.o
obj-$(CONFIG_IPMI_KCS_BMC_CDEV_IPMI) += kcs_bmc_cdev_ipmi.o
obj-$(CONFIG_IPMI_KCS_BMC_CDEV_RAW) += kcs_bmc_cdev_raw.o
obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
obj-$(CONFIG_ASPEED_KCS_IPMI_BMC) += kcs_bmc_aspeed.o
obj-$(CONFIG_NPCM7XX_KCS_IPMI_BMC) += kcs_bmc_npcm7xx.o
Expand Down
Loading

0 comments on commit c32ad4b

Please sign in to comment.