ipmi: Add StarFive JHB100 KCS BMC driver
Subsystems (2)
cover ipmi: Add StarFive JHB100 KCS BMC driver
This series adds support for the KCS (Keyboard Controller Style) interface of the StarFive JHB100 SoC, a RISC-V SoC used as a BMC on server boards. KCS is used for in-band IPMI communication between the host and the BMC.
The KCS channels are functions of a Super I/O (SIO) block which the host accesses over the eSPI bus. The driver is a backend for the existing KCS BMC core, like the ASPEED and Nuvoton drivers.
Notes for review:
- The channel number is not described in the devicetree. It is derived from the register offset of the channel and the "starfive,sio-id" property of the parent SIO node.
- The hardware has an IBF interrupt only, there is no OBE interrupt.
- The "espi_rst" interrupt fires when the host de-asserts the eSPI bus reset. The reset clears the KCS interrupt enable register, so the driver restores it from a shadow copy.
Mason Huo (2):
dt-bindings: ipmi: Convert starfive,kcs-bmc to DT schema
ipmi: add a StarFive KCS BMC driver
.../bindings/ipmi/starfive,kcs-bmc.yaml | 53 +++ MAINTAINERS | 6 + drivers/char/ipmi/Kconfig | 15 + drivers/char/ipmi/Makefile | 1 + drivers/char/ipmi/kcs_bmc_starfive.c | 311 ++++++++++++++++++ 5 files changed, 386 insertions(+) create mode 100644 Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml create mode 100644 drivers/char/ipmi/kcs_bmc_starfive.c
PATCH 1/2 dt-bindings: ipmi: Convert starfive,kcs-bmc to DT schema
Convert the starfive,kcs-bmc binding to DT schema format.
--- .../bindings/ipmi/starfive,kcs-bmc.yaml | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml new file +53 -0
@@ -0,0 +1,53 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/ipmi/starfive,kcs-bmc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: StarFive BMC KCS Devices + +maintainers: + - Mason Huo <[email protected]> + +description: + The StarFive BMC SoCs use Keyboard-Controller-Style (KCS) interfaces on + the eSPI bus for in-band IPMI communication with their host. The KCS + channels are part of a Super I/O (SIO) block and each channel occupies a + 0x100 byte register window, starting at offset 0x200 of the SIO register + space. A channel is identified by its register offset and the + "starfive,sio-id" of the parent SIO node. + +properties: + compatible: + enum: + - starfive,jhb100-kcs-bmc + + reg: + maxItems: 1 + + interrupts: + items: + - description: KCS channel interrupt + - description: eSPI bus reset de-assertion interrupt + + interrupt-names: + items: + - const: kcs + - const: espi_rst + +required: + - compatible + - reg + - interrupts + - interrupt-names + +additionalProperties: false + +examples: + - | + kcs@200 { + compatible = "starfive,jhb100-kcs-bmc"; + reg = <0x200 0x100>; + interrupts = <282>, <57>; + interrupt-names = "kcs", "espi_rst"; + };
Signature · 1 line
2.50.1
[email protected]
AI reviewRe: [PATCH vV 1/2] dt-bindings: ipmi: Convert starfive,kcs-bmc to DT schema
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Low] dt-bindings: ipmi: wrong conversion commit message and schema filename/$id - [Low] dt-bindings: ipmi…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Low] dt-bindings: ipmi: wrong conversion commit message and schema filename/$id
- [Low] dt-bindings: ipmi: starfive,kcs-bmc relies on undocumented starfive,sio-id
--
commit fc7a7047c07e19a8497c2d87d2a38e97878efe8c
Author: Mason Huo <[email protected]>
dt-bindings: ipmi: Convert starfive,kcs-bmc to DT schema
This commit adds a DT schema binding for StarFive JHB100 BMC KCS devices.
Quoted 14 lines
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml new file +8
-0@@ -0,0 +1,53 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/ipmi/starfive,kcs-bmc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: StarFive BMC KCS Devices +
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml line 18
Quoted 10 lines
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml new file +10
-0+maintainers: + - Mason Huo <[email protected]> + +description: + The StarFive BMC SoCs use Keyboard-Controller-Style (KCS) interfaces on + the eSPI bus for in-band IPMI communication with their host. The KCS + channels are part of a Super I/O (SIO) block and each channel occupies a + 0x100 byte register window, starting at offset 0x200 of the SIO register + space. A channel is identified by its register offset and the + "starfive,sio-id" of the parent SIO node.
[Severity: Low]
Where are the parent SIO node and its starfive,sio-id property documented? Neither the parent StarFive SIO binding nor starfive,sio-id exists in any DT schema, the example below omits the parent node, and Documentation/devicetree/bindings/writing-bindings.rst advises against adding custom instance index properties.
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml line 23
Quoted 5 lines
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml new file +5
-0+ +properties: + compatible: + enum: + - starfive,jhb100-kcs-bmc
[Severity: Low]
Should the schema filename and $id be starfive,jhb100-kcs-bmc.yaml to match the sole compatible string, as required by Documentation/devicetree/bindings/writing-bindings.rst?
Also, the commit subject and message state that this converts an existing starfive,kcs-bmc binding to DT schema format, but no prior StarFive KCS binding existed in the tree.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH vV 1/2] dt-bindings: ipmi: Convert starfive,kcs-bmc to DT schema
In reply to Mason HuoQuoted 1 line · Mason Huo
Convert the starfive,kcs-bmc binding to DT schema format.
This is not a conversion since you are not deleting anything?
Quoted 21 lines
Signed-off-by Mason Huo <[email protected]>--- .../bindings/ipmi/starfive,kcs-bmc.yaml | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yamlDocumentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml new file +8
-0@@ -0,0 +1,53 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/ipmi/starfive,kcs-bmc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: StarFive BMC KCS Devices +
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml line 18
Quoted 10 lines
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml new file +10
-0+maintainers: + - Mason Huo <[email protected]> + +description: + The StarFive BMC SoCs use Keyboard-Controller-Style (KCS) interfaces on + the eSPI bus for in-band IPMI communication with their host. The KCS + channels are part of a Super I/O (SIO) block and each channel occupies a + 0x100 byte register window, starting at offset 0x200 of the SIO register + space. A channel is identified by its register offset and the + "starfive,sio-id" of the parent SIO node.
Where is the binding for the parent SIO node? Hard to review this without that I think.
Quoted 8 lines
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml new file +8
-0+ +properties: + compatible: + enum: + - starfive,jhb100-kcs-bmc + + reg: + maxItems: 1
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml line 36
Quoted 10 lines
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml new file +10
-0+ + interrupts: + items: + - description: KCS channel interrupt + - description: eSPI bus reset de-assertion interrupt + + interrupt-names: + items: + - const: kcs + - const: espi_rst
No need to have "rst" since this is a reset by nature ;)
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml line 48
Quoted 12 lines
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml new file +12
-0+ +required: + - compatible + - reg + - interrupts + - interrupt-names + +additionalProperties: false + +examples: + - | + kcs@200 {
s/kcs/ipmi/?
Quoted 8 lines
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml new file +5
-0+ compatible = "starfive,jhb100-kcs-bmc"; + reg = <0x200 0x100>; + interrupts = <282>, <57>; + interrupt-names = "kcs", "espi_rst"; + };Signature · 1 line
2.50.1
RE: [PATCH v1 1/2] dt-bindings: ipmi: Convert starfive,kcs-bmc to DT schema
Quoted 10 lines
From: Conor Dooley <[email protected]>
Sent: 2026年11月19日 1:58
To: Mason Huo <[email protected]>
Cc: Corey Minyard <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v1 1/2] dt-bindings: ipmi: Convert starfive,kcs-bmc to DT schema
Quoted 5 lines
Quoted 1 line · Mason Huo
Convert the starfive,kcs-bmc binding to DT schema format.
This is not a conversion since you are not deleting anything?
Thanks for the correction, will update the commit message in v2.
Quoted 30 lines
Quoted 6 lines
Signed-off-by Mason Huo <[email protected]>--- .../bindings/ipmi/starfive,kcs-bmc.yaml | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yamlReview
Quoted 2 lines
(quoted diff) +0
-0
bmc.yamlb/Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yamlQuoted 8 lines
new file mode 100644
index 000000000000..2cb91d321a32Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml new file +3
-0@@ -0,0 +1,53 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +---Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml line 13
Quoted 10 lines
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml new file +10
-0+$id: http://devicetree.org/schemas/ipmi/starfive,kcs-bmc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: StarFive BMC KCS Devices + +maintainers: + - Mason Huo <[email protected]> + +description: + The StarFive BMC SoCs use Keyboard-Controller-Style (KCS) interfaceson
Quoted 9 lines
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml line 18
Quoted 5 lines
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml new file +5
-0+ the eSPI bus for in-band IPMI communication with their host. The KCS + channels are part of a Super I/O (SIO) block and each channel occupies a + 0x100 byte register window, starting at offset 0x200 of the SIO register + space. A channel is identified by its register offset and the + "starfive,sio-id" of the parent SIO node.Where is the binding for the parent SIO node? Hard to review this without that I think.
Sorry for missing the SIO node commit, will add it next version, and it looks like:
+ superio@10582000 {
+ compatible = "starfive,jhb100-sio", "simple-mfd", "syscon";
+ reg = <0x0 0x10582000 0x0 0x1000>;
+ #address-cells = <2>;
+ #size-cells = <2>;
+ ranges = <0x0 0x0 0x0 0x10582000 0x0 0x1000>;
+ starfive,sio-id = <0>;
+
+ kcs@200 {
+ compatible = "starfive,jhb100-kcs-bmc";
+ reg = <0x0 0x200 0x0 0x100>;
+ interrupts = <282>, <57>;
+ interrupt-names = "kcs", "espi_rst";+ };
+ };
Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml new file +12
-0+ +properties: + compatible: + enum: + - starfive,jhb100-kcs-bmc + + reg: + maxItems: 1 + + interrupts: + items: + - description: KCS channel interrupt
Quoted 9 lines
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml line 36
Quoted 6 lines
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml new file +6
-0+ - description: eSPI bus reset de-assertion interrupt + + interrupt-names: + items: + - const: kcs + - const: espi_rstNo need to have "rst" since this is a reset by nature ;)
OK, will remove it.
Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml new file +6
-0+ +required: + - compatible + - reg + - interrupts + - interrupt-names
Quoted 9 lines
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml line 48
Quoted 6 lines
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml new file +6
-0+ +additionalProperties: false + +examples: + - | + kcs@200 {s/kcs/ipmi/?
Referred to the other kcs binding, and kcs is one of the system interfaces of ipmi protocol.
Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml new file +5
-1+ compatible = "starfive,jhb100-kcs-bmc"; + reg = <0x200 0x100>; + interrupts = <282>, <57>; + interrupt-names = "kcs", "espi_rst"; + }; --2.50.1
Re: [PATCH v1 1/2] dt-bindings: ipmi: Convert starfive,kcs-bmc to DT schema
Quoted 62 lines · Mason Huo
Quoted 10 lines
From: Conor Dooley <[email protected]>
Sent: 2026年11月19日 1:58
To: Mason Huo <[email protected]>
Cc: Corey Minyard <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v1 1/2] dt-bindings: ipmi: Convert starfive,kcs-bmc to DT schemaQuoted 5 lines
Quoted 1 line · Mason Huo
Convert the starfive,kcs-bmc binding to DT schema format.
This is not a conversion since you are not deleting anything?
Thanks for the correction, will update the commit message in v2.
Quoted 30 lines
Quoted 6 lines
Signed-off-by Mason Huo <[email protected]>--- .../bindings/ipmi/starfive,kcs-bmc.yaml | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yamlReview
Quoted 2 lines
(quoted diff) +0
-0
bmc.yamlb/Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yamlQuoted 8 lines
new file mode 100644
index 000000000000..2cb91d321a32Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml new file +3
-0@@ -0,0 +1,53 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +---Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml line 13
Quoted 10 lines
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml new file +10
-0+$id: http://devicetree.org/schemas/ipmi/starfive,kcs-bmc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: StarFive BMC KCS Devices + +maintainers: + - Mason Huo <[email protected]> + +description: + The StarFive BMC SoCs use Keyboard-Controller-Style (KCS) interfaceson
Quoted 9 lines
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml line 18
Quoted 5 lines
Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml new file +5
-0+ the eSPI bus for in-band IPMI communication with their host. The KCS + channels are part of a Super I/O (SIO) block and each channel occupies a + 0x100 byte register window, starting at offset 0x200 of the SIO register + space. A channel is identified by its register offset and the + "starfive,sio-id" of the parent SIO node.Where is the binding for the parent SIO node? Hard to review this without that I think.
Sorry for missing the SIO node commit, will add it next version, and it looks like:
(quoted diff) +5
-0+ superio@10582000 { + compatible = "starfive,jhb100-sio", "simple-mfd", "syscon"; + reg = <0x0 0x10582000 0x0 0x1000>; + #address-cells = <2>; + #size-cells = <2>;
Review
Quoted 10 lines
(quoted diff) +10
-0+ ranges = <0x0 0x0 0x0 0x10582000 0x0 0x1000>; + starfive,sio-id = <0>; + + kcs@200 { + compatible = "starfive,jhb100-kcs-bmc"; + reg = <0x0 0x200 0x0 0x100>; + interrupts = <282>, <57>; + interrupt-names = "kcs", "espi_rst"; + }; + };
Why can this ipmi device not just be part of the parent node?
PATCH 2/2 ipmi: add StarFive KCS BMC driver
In reply to Mason HuoThis driver exposes the Keyboard Controller Style (KCS) interface on StarFive SoCs as a character device. Such SOCs are commonly used as a BaseBoard Management Controller (BMC) on a server board, and KCS interface is commonly used to perform the in-band IPMI communication between the server and its BMC.
--- MAINTAINERS | 6 + drivers/char/ipmi/Kconfig | 15 ++ drivers/char/ipmi/Makefile | 1 + drivers/char/ipmi/kcs_bmc_starfive.c | 311 +++++++++++++++++++++++++++ 4 files changed, 333 insertions(+) create mode 100644 drivers/char/ipmi/kcs_bmc_starfive.c
MAINTAINERS +6 -0
@@ -26923,6 +26923,12 @@ S: Maintained F: Documentation/devicetree/bindings/pinctrl/starfive,jhb1*.yaml F: drivers/pinctrl/starfive/pinctrl-starfive-jhb1* +STARFIVE KCS-BMC DRIVER +M: Mason Huo <[email protected]> +S: Supported +F: Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml +F: drivers/char/ipmi/kcs_bmc_starfive.c + STATIC BRANCH/CALL M: Peter Zijlstra <[email protected]> M: Josh Poimboeuf <[email protected]>
drivers/char/ipmi/Kconfig +15 -0
@@ -149,6 +149,21 @@ config NPCM7XX_KCS_IPMI_BMC This support is also available as a module. If so, the module will be called kcs_bmc_npcm7xx. +config STARFIVE_KCS_IPMI_BMC + depends on ARCH_STARFIVE || COMPILE_TEST + select IPMI_KCS_BMC + select MFD_SYSCON + tristate "StarFive KCS IPMI BMC driver" + help + Provides a driver for the KCS (Keyboard Controller Style) IPMI + interface found on StarFive SoCs. + + The driver implements the BMC side of the KCS controller, it + provides the access of KCS IO space for BMC side. + + This support is also available as a module. If so, the module + will be called kcs_bmc_starfive. + config IPMI_KCS_BMC_CDEV_IPMI depends on IPMI_KCS_BMC tristate "IPMI character device interface for BMC KCS devices"
drivers/char/ipmi/Makefile +1 -0
@@ -27,5 +27,6 @@ obj-$(CONFIG_IPMI_KCS_BMC_CDEV_IPMI) += kcs_bmc_cdev_ipmi.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 +obj-$(CONFIG_STARFIVE_KCS_IPMI_BMC) += kcs_bmc_starfive.o obj-$(CONFIG_IPMB_DEVICE_INTERFACE) += ipmb_dev_int.o obj-$(CONFIG_SSIF_IPMI_BMC) += ssif_bmc.o
drivers/char/ipmi/kcs_bmc_starfive.c new file +311 -0
311 lines not on this page · raw message
Signature · 1 line
2.50.1
Corey Minyard
maintainerRe: [PATCH vV 2/2] ipmi: add StarFive KCS BMC driver
Adding Andrew, hopefully he's still available to review.
A few questions inline, but I don't see any big issues in first review.
-corey
Quoted 127 lines · Mason Huo
This driver exposes the Keyboard Controller Style (KCS) interface on StarFive SoCs as a character device. Such SOCs are commonly used as a BaseBoard Management Controller (BMC) on a server board, and KCS interface is commonly used to perform the in-band IPMI communication between the server and its BMC.
Signed-off-by Mason Huo <[email protected]>--- MAINTAINERS | 6 + drivers/char/ipmi/Kconfig | 15 ++ drivers/char/ipmi/Makefile | 1 + drivers/char/ipmi/kcs_bmc_starfive.c | 311 +++++++++++++++++++++++++++ 4 files changed, 333 insertions(+) create mode 100644 drivers/char/ipmi/kcs_bmc_starfive.cMAINTAINERS +6
-0@@ -26923,6 +26923,12 @@ S: Maintained F: Documentation/devicetree/bindings/pinctrl/starfive,jhb1*.yaml F: drivers/pinctrl/starfive/pinctrl-starfive-jhb1* +STARFIVE KCS-BMC DRIVER +M: Mason Huo <[email protected]> +S: Supported +F: Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml +F: drivers/char/ipmi/kcs_bmc_starfive.c + STATIC BRANCH/CALL M: Peter Zijlstra <[email protected]> M: Josh Poimboeuf <[email protected]>drivers/char/ipmi/Kconfig +15
-0@@ -149,6 +149,21 @@ config NPCM7XX_KCS_IPMI_BMC This support is also available as a module. If so, the module will be called kcs_bmc_npcm7xx. +config STARFIVE_KCS_IPMI_BMC + depends on ARCH_STARFIVE || COMPILE_TEST + select IPMI_KCS_BMC + select MFD_SYSCON + tristate "StarFive KCS IPMI BMC driver" + help + Provides a driver for the KCS (Keyboard Controller Style) IPMI + interface found on StarFive SoCs. + + The driver implements the BMC side of the KCS controller, it + provides the access of KCS IO space for BMC side. + + This support is also available as a module. If so, the module + will be called kcs_bmc_starfive. + config IPMI_KCS_BMC_CDEV_IPMI depends on IPMI_KCS_BMC tristate "IPMI character device interface for BMC KCS devices"drivers/char/ipmi/Makefile +1
-0@@ -27,5 +27,6 @@ obj-$(CONFIG_IPMI_KCS_BMC_CDEV_IPMI) += kcs_bmc_cdev_ipmi.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 +obj-$(CONFIG_STARFIVE_KCS_IPMI_BMC) += kcs_bmc_starfive.o obj-$(CONFIG_IPMB_DEVICE_INTERFACE) += ipmb_dev_int.o obj-$(CONFIG_SSIF_IPMI_BMC) += ssif_bmc.odrivers/char/ipmi/kcs_bmc_starfive.c new file +52
-0@@ -0,0 +1,311 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2024 StarFive Technology Co., Ltd. +*/ + +#include <linux/bits.h> +#include <linux/errno.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/mfd/syscon.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_address.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/spinlock.h> + +#include "kcs_bmc_device.h" + +#define DEVICE_NAME "starfive-kcs-bmc" + +/* +* Every SIO block of the SoC provides KCS_CHANNELS_PER_SIO KCS channels, each +* occupying a KCS_CHANNEL_STRIDE byte register window, starting at offset +* KCS_CHANNEL_BASE of the SIO register space. +*/ +#define KCS_CHANNELS_PER_SIO 4 +#define KCS_CHANNEL_BASE 0x200 +#define KCS_CHANNEL_STRIDE 0x100 +#define KCS_SIO_MAX 2 + +#define KCS_DO 0x0 +#define KCS_DI 0x4 +#define KCS_STS 0x8 + +#define KCS_INT 0xc +#define KCS_INT_IBF_EN BIT(0) +#define KCS_INT_IBF_STS BIT(1) + +struct starfive_kcs_bmc { +struct kcs_bmc_device kcs_bmc; +struct regmap *map; +/* Protects ie_en and serialises every write to KCS_INT */ +spinlock_t ie_lock; +/* Shadow of the KCS_INT enable bits, restored after eSPI bus reset */ +u32 ie_en; +}; + +static inline struct starfive_kcs_bmc * +to_starfive_kcs_bmc (struct kcs_bmc_device *kcs_bmc) +{ + return container_of(kcs_bmc, struct starfive_kcs_bmc, kcs_bmc);
drivers/char/ipmi/kcs_bmc_starfive.c line 62
Quoted 10 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +10
-0+} + +static u8 starfive_kcs_inb (struct kcs_bmc_device *kcs_bmc,u32 reg) +{ +struct starfive_kcs_bmc *priv =to_starfive_kcs_bmc (kcs_bmc); +u32 val =0 ; +int rc; + + rc =regmap_read (priv->map, reg, &val); +WARN (rc !=0 ,"regmap_read() failed: %d\n" , rc);
The WARNs here seem a little heavy, but there is precedent, so I'm ok with it.
You probably want to print the register, though, on all of these.
Quoted 78 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +78
-0+ +return rc ==0 ? (u8 )val :0 ; +} + +static void starfive_kcs_outb (struct kcs_bmc_device *kcs_bmc,u32 reg,u8 data) +{ +struct starfive_kcs_bmc *priv =to_starfive_kcs_bmc (kcs_bmc); +int rc; + + rc =regmap_write (priv->map, reg, data); +WARN (rc !=0 ,"regmap_write() failed: %d\n" , rc); +} + +static void starfive_kcs_updateb (struct kcs_bmc_device *kcs_bmc, +u32 reg,u8 mask,u8 data) +{ +struct starfive_kcs_bmc *priv =to_starfive_kcs_bmc (kcs_bmc); +int rc; + + rc =regmap_update_bits (priv->map, reg, mask, data); +WARN (rc !=0 ,"regmap_update_bits() failed: %d\n" , rc); +} + +/* +* Write the shadow of the enable bits to KCS_INT. KCS_INT_IBF_STS is a +* read-only mirror of the IBF flag in KCS_STS, which the hardware clears +* once KCS_DI has been read, so only the enable bits are ever written. +*/ +static void starfive_kcs_write_ie (struct starfive_kcs_bmc *priv) +{ +int rc; + +lockdep_assert_held (&priv->ie_lock); + + rc =regmap_write (priv->map,KCS_INT , priv->ie_en); +WARN (rc !=0 ,"regmap_write() failed: %d\n" , rc); +} + +static void starfive_kcs_irq_mask_update (struct kcs_bmc_device *kcs_bmc, +u8 mask,u8 state) +{ +struct starfive_kcs_bmc *priv =to_starfive_kcs_bmc (kcs_bmc); +unsigned long flags; + +/* The hardware has no OBE interrupt */ +if (!(mask &KCS_BMC_EVENT_TYPE_IBF )) +return ; + +spin_lock_irqsave (&priv->ie_lock, flags); +if (state &KCS_BMC_EVENT_TYPE_IBF ) + priv->ie_en |=KCS_INT_IBF_EN ; +else + priv->ie_en &= ~KCS_INT_IBF_EN ; +starfive_kcs_write_ie (priv); +spin_unlock_irqrestore (&priv->ie_lock, flags); +} + +static void starfive_kcs_hw_init (struct starfive_kcs_bmc *priv) +{ +unsigned long flags; + +/* Restore the enables, e.g. after an eSPI bus reset */ +spin_lock_irqsave (&priv->ie_lock, flags); +starfive_kcs_write_ie (priv); +spin_unlock_irqrestore (&priv->ie_lock, flags); +} + +static irqreturn_t starfive_kcs_irq (int irq,void *arg) +{ +/* The interrupt deasserts once the client has read IDR */ +return kcs_bmc_handle_event (arg); +} + +/* +* "espi_rst" is a dedicated interrupt line which carries a single event: the +* host has de-asserted the eSPI bus reset of the SIO block this channel +* belongs to. The line is requested with IRQF_SHARED only because every +* function of that SIO block (KCS, BT, mailbox, ...) listens to the same
drivers/char/ipmi/kcs_bmc_starfive.c line 150
Quoted 10 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +10
-0+* event and has to reprogram its own registers when it fires. It is not +* shared with unrelated interrupt sources and there is no per-function +* status bit to test, so each occurrence is relevant to all handlers and is +* claimed unconditionally. Rewriting KCS_INT from the shadow is idempotent. +*/ +static irqreturn_t starfive_espi_rst_deassert_irq (int irq,void *arg) +{ +struct kcs_bmc_device *kcs_bmc = arg; +struct starfive_kcs_bmc *priv =to_starfive_kcs_bmc (kcs_bmc); +
I'm not sure what the hardware does, just making sure you don't want to set ie_en to zero or something here.
Quoted 106 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +106
-0+starfive_kcs_hw_init (priv); + +return IRQ_HANDLED ; +} + +static int starfive_kcs_config_irq (struct kcs_bmc_device *kcs_bmc, +struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +int rc, irq; + + irq =platform_get_irq_byname (pdev,"kcs" ); +if (irq <0 ) +return irq; + + rc =devm_request_irq (dev, irq, starfive_kcs_irq,0 , +dev_name (dev), kcs_bmc); +if (rc <0 ) +return dev_err_probe (dev, rc, +"Unable to request kcs IRQ %d\n" , irq); + + irq =platform_get_irq_byname (pdev,"espi_rst" ); +if (irq <0 ) +return irq; + + rc =devm_request_irq (dev, irq, starfive_espi_rst_deassert_irq, +IRQF_SHARED |IRQF_TRIGGER_RISING , +dev_name (dev), kcs_bmc); +if (rc <0 ) +return dev_err_probe (dev, rc, +"Unable to request espi reset IRQ %d\n" , irq); + +return 0 ; +} + +static const struct kcs_bmc_device_ops starfive_kcs_ops = { + .irq_mask_update = starfive_kcs_irq_mask_update, + .io_inputb = starfive_kcs_inb, + .io_outputb = starfive_kcs_outb, + .io_updateb = starfive_kcs_updateb, +}; + +/* +* The channel number is not described in the devicetree, it follows from the +* position of the channel in the SIO block and from the id of that block. +*/ +static int starfive_kcs_of_get_channel (struct device *dev,u32 *chan) +{ +struct device_node *np = dev->of_node; +u32 sio_id, idx; +u64 offset; +int rc; + + struct device_node *sio __free(device_node) = of_get_parent(np); + +/* Don't translate the address, the offset in the SIO block is wanted */ + rc =of_property_read_reg (np,0 , &offset,NULL ); +if (rc) +return rc; + +if (offset <KCS_CHANNEL_BASE || + offset >=KCS_CHANNEL_BASE +KCS_CHANNELS_PER_SIO *KCS_CHANNEL_STRIDE || + offset %KCS_CHANNEL_STRIDE ) +return -EINVAL ; + + idx = ((u32 )offset -KCS_CHANNEL_BASE ) /KCS_CHANNEL_STRIDE ; + + rc =of_property_read_u32 (sio,"starfive,sio-id" , &sio_id); +if (rc) +return rc; + +if (sio_id >=KCS_SIO_MAX ) +return -EINVAL ; + + *chan = sio_id *KCS_CHANNELS_PER_SIO + idx; + +return 0 ; +} + +static int starfive_kcs_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct starfive_kcs_bmc *priv; +struct kcs_bmc_device *kcs_bmc; +u32 chan; +int rc; + + rc =starfive_kcs_of_get_channel (dev, &chan); +if (rc) +return dev_err_probe (dev, rc,"Unable to determine the channel\n" ); + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + +spin_lock_init (&priv->ie_lock); + + priv->map =device_node_to_regmap (dev->of_node); +if (IS_ERR (priv->map)) +return dev_err_probe (dev,PTR_ERR (priv->map), +"Couldn't get regmap\n" ); + + kcs_bmc = &priv->kcs_bmc; + kcs_bmc->dev = dev; + kcs_bmc->channel = chan; + kcs_bmc->ioreg.idr =KCS_DI ;
drivers/char/ipmi/kcs_bmc_starfive.c line 266
Quoted 10 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +10
-0+ kcs_bmc->ioreg.odr =KCS_DO ; + kcs_bmc->ioreg.str =KCS_STS ; + kcs_bmc->ops = &starfive_kcs_ops; + +platform_set_drvdata (pdev, priv); + +starfive_kcs_hw_init (priv); + rc =starfive_kcs_config_irq (kcs_bmc, pdev); +if (rc) +return rc;
Can order matter here? Can an interrupt come in between the above and below calls?
Quoted 13 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +13
-0+ + rc =kcs_bmc_add_device (kcs_bmc); +if (rc) +return dev_err_probe (dev, rc,"Failed to register channel %u\n" , + kcs_bmc->channel); + +dev_dbg (dev,"Channel=%u idr=0x%x odr=0x%x str=0x%x\n" , chan, + kcs_bmc->ioreg.idr, kcs_bmc->ioreg.odr, kcs_bmc->ioreg.str); + +return 0 ; +} + +static void starfive_kcs_remove (struct platform_device *pdev)
drivers/char/ipmi/kcs_bmc_starfive.c line 289
Quoted 10 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +10
-0+{ +struct starfive_kcs_bmc *priv =platform_get_drvdata (pdev); +struct kcs_bmc_device *kcs_bmc = &priv->kcs_bmc; + +kcs_bmc_remove_device (kcs_bmc); + +starfive_kcs_irq_mask_update (kcs_bmc, + (KCS_BMC_EVENT_TYPE_IBF | +KCS_BMC_EVENT_TYPE_OBE ), +0 );
Would order matter in the above two? Can an interrupt come in after the BMC has been removed?
Also, starfive_espi_rst_deassert_irq()?
Quoted 25 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +22
-0+} + +static const struct of_device_id starfive_kcs_bmc_match[] = { + { .compatible ="starfive,jhb100-kcs-bmc" }, + { } +}; +MODULE_DEVICE_TABLE (of, starfive_kcs_bmc_match); + +static struct platform_driver starfive_kcs_bmc_driver = { + .driver = { + .name =DEVICE_NAME , + .of_match_table = starfive_kcs_bmc_match, + .suppress_bind_attrs = true, + }, + .probe = starfive_kcs_probe, + .remove = starfive_kcs_remove, +}; +module_platform_driver (starfive_kcs_bmc_driver); + +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Mason Huo <[email protected]>" ); +MODULE_DESCRIPTION ("StarFive device interface to the KCS BMC device" );Signature · 1 line
2.50.1
RE: [PATCH v1 2/2] ipmi: add StarFive KCS BMC driver
Hi Corey,
Thanks for review.
Quoted 253 lines
From: Corey Minyard <[email protected]>
Sent: 2026年11月18日 22:01
To: Mason Huo <[email protected]>; Andrew Jeffery <[email protected]>
Cc: Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; linux- [email protected]; [email protected]; openipmi- [email protected]
Subject: Re: [PATCH v1 2/2] ipmi: add StarFive KCS BMC driverAdding Andrew, hopefully he's still available to review.
A few questions inline, but I don't see any big issues in first review.
-corey
Quoted 6 lines · Mason Huo
This driver exposes the Keyboard Controller Style (KCS) interface on StarFive SoCs as a character device. Such SOCs are commonly used as a BaseBoard Management Controller (BMC) on a server board, and KCS interface is commonly used to perform the in-band IPMI communication between the server and its BMC.
Quoted 6 lines
Signed-off-by Mason Huo <[email protected]>--- MAINTAINERS | 6 + drivers/char/ipmi/Kconfig | 15 ++ drivers/char/ipmi/Makefile | 1 + drivers/char/ipmi/kcs_bmc_starfive.c | 311+++++++++++++++++++++++++++
drivers/char/ipmi/Makefile obj-$(CONFIG_IPMI_KCS_BMC_CDEV_IPMI) +=
Quoted 51 lines
4 files changed, 333 insertions(+) create mode 100644 drivers/char/ipmi/kcs_bmc_starfive.cMAINTAINERS +6
-0@@ -26923,6 +26923,12 @@ S: Maintained F: Documentation/devicetree/bindings/pinctrl/starfive,jhb1*.yaml F: drivers/pinctrl/starfive/pinctrl-starfive-jhb1* +STARFIVE KCS-BMC DRIVER +M: Mason Huo <[email protected]> +S: Supported +F: Documentation/devicetree/bindings/ipmi/starfive,kcs-bmc.yaml +F: drivers/char/ipmi/kcs_bmc_starfive.c + STATIC BRANCH/CALL M: Peter Zijlstra <[email protected]> M: Josh Poimboeuf <[email protected]>drivers/char/ipmi/Kconfig +15
-0@@ -149,6 +149,21 @@ config NPCM7XX_KCS_IPMI_BMC This support is also available as a module. If so, the module will be called kcs_bmc_npcm7xx. +config STARFIVE_KCS_IPMI_BMC + depends on ARCH_STARFIVE || COMPILE_TEST + select IPMI_KCS_BMC + select MFD_SYSCON + tristate "StarFive KCS IPMI BMC driver" + help + Provides a driver for the KCS (Keyboard Controller Style) IPMI + interface found on StarFive SoCs. + + The driver implements the BMC side of the KCS controller, it + provides the access of KCS IO space for BMC side. + + This support is also available as a module. If so, the module + will be called kcs_bmc_starfive. + config IPMI_KCS_BMC_CDEV_IPMI depends on IPMI_KCS_BMC tristate "IPMI character device interface for BMC KCS devices"drivers/char/ipmi/Makefile +0
-0@@ -27,5 +27,6 @@ obj-$(CONFIG_IPMI_KCS_BMC_CDEV_IPMI) +=kcs_bmc_cdev_ipmi.o
Review
Quoted 7 lines
drivers/char/ipmi/Makefile +1
-0obj-$(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 +obj-$(CONFIG_STARFIVE_KCS_IPMI_BMC) += kcs_bmc_starfive.o obj-$(CONFIG_IPMB_DEVICE_INTERFACE) += ipmb_dev_int.o obj-$(CONFIG_SSIF_IPMI_BMC) += ssif_bmc.o(quoted diff) +0
-0
b/drivers/char/ipmi/kcs_bmc_starfive.cQuoted 18 lines
new file mode 100644
index 000000000000..bff7bdd5ad1cdrivers/char/ipmi/kcs_bmc_starfive.c new file +13
-0@@ -0,0 +1,311 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2024 StarFive Technology Co., Ltd. +*/ + +#include <linux/bits.h> +#include <linux/errno.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/mfd/syscon.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_address.h> drivers/char/ipmi/kcs_bmc_starfive.c line 23
Quoted 10 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +10
-0+#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/spinlock.h> + +#include "kcs_bmc_device.h" + +#define DEVICE_NAME "starfive-kcs-bmc" + +/* +* Every SIO block of the SoC provides KCS_CHANNELS_PER_SIO KCS channels, each
drivers/char/ipmi/kcs_bmc_starfive.c line 24
Quoted 1 line
drivers/char/ipmi/kcs_bmc_starfive.c new file +1
-0+* occupying a KCS_CHANNEL_STRIDE byte register window, starting at offset
Quoted 11 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +11
-0+* KCS_CHANNEL_BASE of the SIO register space. +*/ +#define KCS_CHANNELS_PER_SIO 4 +#define KCS_CHANNEL_BASE 0x200 +#define KCS_CHANNEL_STRIDE 0x100 +#define KCS_SIO_MAX 2 + +#define KCS_DO 0x0 +#define KCS_DI 0x4 +#define KCS_STS 0x8 +drivers/char/ipmi/kcs_bmc_starfive.c
Quoted 10 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +10
-0+#define KCS_INT 0xc +#define KCS_INT_IBF_EN BIT(0) +#define KCS_INT_IBF_STS BIT(1) + +struct starfive_kcs_bmc { +struct kcs_bmc_device kcs_bmc; +struct regmap *map; +/* Protects ie_en and serialises every write to KCS_INT */ +spinlock_t ie_lock; +/* Shadow of the KCS_INT enable bits, restored after eSPI bus reset */
Quoted 7 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +7
-0+u32 ie_en; +}; + +static inline struct starfive_kcs_bmc * +to_starfive_kcs_bmc (struct kcs_bmc_device *kcs_bmc) +{ + return container_of(kcs_bmc, struct starfive_kcs_bmc, kcs_bmc);drivers/char/ipmi/kcs_bmc_starfive.c line 62
Quoted 10 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +10
-0+} + +static u8 starfive_kcs_inb (struct kcs_bmc_device *kcs_bmc,u32 reg) +{ +struct starfive_kcs_bmc *priv =to_starfive_kcs_bmc (kcs_bmc); +u32 val =0 ; +int rc; + + rc =regmap_read (priv->map, reg, &val); +WARN (rc !=0 ,"regmap_read() failed: %d\n" , rc);The WARNs here seem a little heavy, but there is precedent, so I'm ok with it.
You probably want to print the register, though, on all of these.
drivers/char/ipmi/kcs_bmc_starfive.c
Quoted 5 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +5
-0+ +return rc ==0 ? (u8 )val :0 ; +} + +static void starfive_kcs_outb(struct kcs_bmc_device *kcs_bmc, u32 reg,u8 data)
Quoted 24 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +24
-0+{ +struct starfive_kcs_bmc *priv =to_starfive_kcs_bmc (kcs_bmc); +int rc; + + rc =regmap_write (priv->map, reg, data); +WARN (rc !=0 ,"regmap_write() failed: %d\n" , rc); +} + +static void starfive_kcs_updateb (struct kcs_bmc_device *kcs_bmc, +u32 reg,u8 mask,u8 data) +{ +struct starfive_kcs_bmc *priv =to_starfive_kcs_bmc (kcs_bmc); +int rc; + + rc =regmap_update_bits (priv->map, reg, mask, data); +WARN (rc !=0 ,"regmap_update_bits() failed: %d\n" , rc); +} + +/* +* Write the shadow of the enable bits to KCS_INT. KCS_INT_IBF_STS is a +* read-only mirror of the IBF flag in KCS_STS, which the hardware clears +* once KCS_DI has been read, so only the enable bits are ever written. +*/ +static void starfive_kcs_write_ie (struct starfive_kcs_bmc *priv)drivers/char/ipmi/kcs_bmc_starfive.c
Quoted 10 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +10
-0+{ +int rc; + +lockdep_assert_held (&priv->ie_lock); + + rc =regmap_write (priv->map,KCS_INT , priv->ie_en); +WARN (rc !=0 ,"regmap_write() failed: %d\n" , rc); +} + +static void starfive_kcs_irq_mask_update(struct kcs_bmc_device
*kcs_bmc,Quoted 28 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +28
-0+ u8 mask, u8 state) +{ +struct starfive_kcs_bmc *priv =to_starfive_kcs_bmc (kcs_bmc); +unsigned long flags; + +/* The hardware has no OBE interrupt */ +if (!(mask &KCS_BMC_EVENT_TYPE_IBF )) +return ; + +spin_lock_irqsave (&priv->ie_lock, flags); +if (state &KCS_BMC_EVENT_TYPE_IBF ) + priv->ie_en |=KCS_INT_IBF_EN ; +else + priv->ie_en &= ~KCS_INT_IBF_EN ; +starfive_kcs_write_ie (priv); +spin_unlock_irqrestore (&priv->ie_lock, flags); +} + +static void starfive_kcs_hw_init (struct starfive_kcs_bmc *priv) +{ +unsigned long flags; + +/* Restore the enables, e.g. after an eSPI bus reset */ +spin_lock_irqsave (&priv->ie_lock, flags); +starfive_kcs_write_ie (priv); +spin_unlock_irqrestore (&priv->ie_lock, flags); +} +drivers/char/ipmi/kcs_bmc_starfive.c
Quoted 10 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +10
-0+static irqreturn_t starfive_kcs_irq (int irq,void *arg) +{ +/* The interrupt deasserts once the client has read IDR */ +return kcs_bmc_handle_event (arg); +} + +/* +* "espi_rst" is a dedicated interrupt line which carries a single event: the +* host has de-asserted the eSPI bus reset of the SIO block this channel +* belongs to. The line is requested with IRQF_SHARED only because every
drivers/char/ipmi/kcs_bmc_starfive.c
Quoted 5 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +5
-0+* function of that SIO block (KCS, BT, mailbox, ...) listens to the same +* event and has to reprogram its own registers when it fires. It is not +* shared with unrelated interrupt sources and there is no per-function +* status bit to test, so each occurrence is relevant to all handlers and is +* claimed unconditionally. Rewriting KCS_INT from the shadow is idempotent.
Quoted 10 lines
drivers/char/ipmi/kcs_bmc_starfive.c line 150
Quoted 6 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +6
-0+*/ +static irqreturn_t starfive_espi_rst_deassert_irq (int irq,void *arg) +{ +struct kcs_bmc_device *kcs_bmc = arg; +struct starfive_kcs_bmc *priv =to_starfive_kcs_bmc (kcs_bmc); +I'm not sure what the hardware does, just making sure you don't want to set
ie_ento zero or something here.
It will not, ie_en is to record the current stat, and re-config back to HW when espi bus reset which also resets the kcs controller.
Quoted 116 lines
Quoted 21 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +21
-0+starfive_kcs_hw_init (priv); + +return IRQ_HANDLED ; +} + +static int starfive_kcs_config_irq (struct kcs_bmc_device *kcs_bmc, +struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +int rc, irq; + + irq =platform_get_irq_byname (pdev,"kcs" ); +if (irq <0 ) +return irq; + + rc =devm_request_irq (dev, irq, starfive_kcs_irq,0 , +dev_name (dev), kcs_bmc); +if (rc <0 ) +return dev_err_probe (dev, rc, +"Unable to request kcs IRQ %d\n" , irq); +drivers/char/ipmi/kcs_bmc_starfive.c
Quoted 10 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +10
-0+ irq =platform_get_irq_byname (pdev,"espi_rst" ); +if (irq <0 ) +return irq; + + rc =devm_request_irq (dev, irq, starfive_espi_rst_deassert_irq, +IRQF_SHARED |IRQF_TRIGGER_RISING , +dev_name (dev), kcs_bmc); +if (rc <0 ) + return dev_err_probe(dev, rc, + "Unable to request espi reset IRQ %d\n",irq);
drivers/char/ipmi/kcs_bmc_starfive.c
Quoted 13 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +13
-0+ +return 0 ; +} + +static const struct kcs_bmc_device_ops starfive_kcs_ops = { + .irq_mask_update = starfive_kcs_irq_mask_update, + .io_inputb = starfive_kcs_inb, + .io_outputb = starfive_kcs_outb, + .io_updateb = starfive_kcs_updateb, +}; + +/* +* The channel number is not described in the devicetree, it follows from the
drivers/char/ipmi/kcs_bmc_starfive.c
Quoted 12 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +12
-0+* position of the channel in the SIO block and from the id of that block. +*/ +static int starfive_kcs_of_get_channel (struct device *dev,u32 *chan) +{ +struct device_node *np = dev->of_node; +u32 sio_id, idx; +u64 offset; +int rc; + + struct device_node *sio __free(device_node) = of_get_parent(np); + +/* Don't translate the address, the offset in the SIO block is wanted */
drivers/char/ipmi/kcs_bmc_starfive.c
Quoted 6 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +6
-0+ rc =of_property_read_reg (np,0 , &offset,NULL ); +if (rc) +return rc; + +if (offset <KCS_CHANNEL_BASE || + offset >= KCS_CHANNEL_BASE + KCS_CHANNELS_PER_SIO *
KCS_CHANNEL_STRIDE||Quoted 18 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +18
-0+ offset % KCS_CHANNEL_STRIDE) +return -EINVAL ; + + idx = ((u32 )offset -KCS_CHANNEL_BASE ) /KCS_CHANNEL_STRIDE ; + + rc =of_property_read_u32 (sio,"starfive,sio-id" , &sio_id); +if (rc) +return rc; + +if (sio_id >=KCS_SIO_MAX ) +return -EINVAL ; + + *chan = sio_id *KCS_CHANNELS_PER_SIO + idx; + +return 0 ; +} + +static int starfive_kcs_probe (struct platform_device *pdev)drivers/char/ipmi/kcs_bmc_starfive.c
Quoted 10 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +10
-0+{ +struct device *dev = &pdev->dev; +struct starfive_kcs_bmc *priv; +struct kcs_bmc_device *kcs_bmc; +u32 chan; +int rc; + + rc =starfive_kcs_of_get_channel (dev, &chan); +if (rc) + return dev_err_probe(dev, rc, "Unable to determine thechannel\n");
Quoted 21 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +21
-0+ + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + +spin_lock_init (&priv->ie_lock); + + priv->map =device_node_to_regmap (dev->of_node); +if (IS_ERR (priv->map)) +return dev_err_probe (dev,PTR_ERR (priv->map), +"Couldn't get regmap\n" ); + + kcs_bmc = &priv->kcs_bmc; + kcs_bmc->dev = dev; + kcs_bmc->channel = chan; + kcs_bmc->ioreg.idr =KCS_DI ; + kcs_bmc->ioreg.odr =KCS_DO ; + kcs_bmc->ioreg.str =KCS_STS ; + kcs_bmc->ops = &starfive_kcs_ops; + +platform_set_drvdata (pdev, priv);
Quoted 9 lines
drivers/char/ipmi/kcs_bmc_starfive.c line 266
Quoted 5 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +5
-0+ +starfive_kcs_hw_init (priv); + rc =starfive_kcs_config_irq (kcs_bmc, pdev); +if (rc) +return rc;Can order matter here? Can an interrupt come in between the above and below calls?
hw_init not enable the irq in probe, priv->ie_en default is 0, and will configured after add device.
Quoted 29 lines
drivers/char/ipmi/kcs_bmc_starfive.c
Quoted 4 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +4
-0+ + rc =kcs_bmc_add_device (kcs_bmc); +if (rc) + return dev_err_probe(dev, rc, "Failed to registerchannel %u\n",
Quoted 10 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +4
-0+ kcs_bmc->channel); + + dev_dbg(dev, "Channel=%u idr=0x%x odr=0x%x str=0x%x\n", chan, + kcs_bmc->ioreg.idr, kcs_bmc->ioreg.odr, kcs_bmc-ioreg.str);
drivers/char/ipmi/kcs_bmc_starfive.c new file +5
-0+ +return 0 ; +} + +static void starfive_kcs_remove (struct platform_device *pdev)drivers/char/ipmi/kcs_bmc_starfive.c line 289
Quoted 10 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +10
-0+{ +struct starfive_kcs_bmc *priv =platform_get_drvdata (pdev); +struct kcs_bmc_device *kcs_bmc = &priv->kcs_bmc; + +kcs_bmc_remove_device (kcs_bmc); + +starfive_kcs_irq_mask_update (kcs_bmc, + (KCS_BMC_EVENT_TYPE_IBF | +KCS_BMC_EVENT_TYPE_OBE ), +0 );Would order matter in the above two? Can an interrupt come in after the BMC has been removed?
Quoted 2 lines
Also,
starfive_espi_rst_deassert_irq()?
"revmove_device" will disable kcs interrupt, interrupt should not come in after the BMC has been removed.starfive_espi_rst_deassert_irq() should be no problem, it is to re-config the ie_en back to HW, but it will set to 0 when device remove.
Quoted 15 lines
Quoted 15 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +15
-0+} + +static const struct of_device_id starfive_kcs_bmc_match[] = { + { .compatible ="starfive,jhb100-kcs-bmc" }, + { } +}; +MODULE_DEVICE_TABLE (of, starfive_kcs_bmc_match); + +static struct platform_driver starfive_kcs_bmc_driver = { + .driver = { + .name =DEVICE_NAME , + .of_match_table = starfive_kcs_bmc_match, + .suppress_bind_attrs = true, + }, + .probe = starfive_kcs_probe,
Quoted 11 lines
drivers/char/ipmi/kcs_bmc_starfive.c
Quoted 7 lines
drivers/char/ipmi/kcs_bmc_starfive.c new file +7
-0+ .remove = starfive_kcs_remove, +}; +module_platform_driver (starfive_kcs_bmc_driver); + +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Mason Huo <[email protected]>" ); +MODULE_DESCRIPTION("StarFive device interface to the KCS BMCdevice");
Quoted 3 lines
--
2.50.1
Best Regards
Mason