[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAAhV-H6smO0RV2pvOb6acD4R_jP3x8zgmu9j+hSWEsNmdLv8Jw@mail.gmail.com>
Date: Sun, 8 Jun 2025 15:43:30 +0800
From: Huacai Chen <chenhuacai@...nel.org>
To: Binbin Zhou <zhoubinbin@...ngson.cn>
Cc: Binbin Zhou <zhoubb.aaron@...il.com>, Huacai Chen <chenhuacai@...ngson.cn>,
Lee Jones <lee@...nel.org>, Corey Minyard <minyard@....org>, Xuerui Wang <kernel@...0n.name>,
loongarch@...ts.linux.dev, linux-kernel@...r.kernel.org,
openipmi-developer@...ts.sourceforge.net, jeffbai@...c.io,
kexybiscuit@...c.io, wangyao@...ote.com, Chong Qiao <qiaochong@...ngson.cn>
Subject: Re: [PATCH v3 1/3] mfd: ls2kbmc: Introduce Loongson-2K BMC core driver
Hi, Binbin,
On Thu, May 29, 2025 at 8:23 PM Binbin Zhou <zhoubinbin@...ngson.cn> wrote:
>
> The Loongson-2K Board Management Controller provides an PCIe interface
> to the host to access the feature implemented in the BMC.
>
> The BMC is assembled on a server similar to the server machine with
> Loongson-3C6000 CPUs. It supports multiple sub-devices like DRM.
Technically the BMC is not bound to Loongson-3C6000, so replace it
with Loongson-3, or a long list
"Loongson-3C5000/Loongson-3D5000/Loongson-3C6000/Loongson-3D6000".
>
> Co-developed-by: Chong Qiao <qiaochong@...ngson.cn>
> Signed-off-by: Chong Qiao <qiaochong@...ngson.cn>
> Signed-off-by: Binbin Zhou <zhoubinbin@...ngson.cn>
> ---
> drivers/mfd/Kconfig | 12 +++
> drivers/mfd/Makefile | 2 +
> drivers/mfd/ls2kbmc-mfd.c | 156 ++++++++++++++++++++++++++++++++++++++
> 3 files changed, 170 insertions(+)
> create mode 100644 drivers/mfd/ls2kbmc-mfd.c
>
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index 22b936310039..4993b0708fe5 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -2422,5 +2422,17 @@ config MFD_UPBOARD_FPGA
> To compile this driver as a module, choose M here: the module will be
> called upboard-fpga.
>
> +config MFD_LS2K_BMC
> + tristate "Loongson-2K Board Management Controller Support"
> + depends on LOONGARCH
> + default y if LOONGARCH
> + select MFD_CORE
> + help
> + Say yes here to add support for the Loongson-2K BMC which is a Board
> + Management Controller connected to the PCIe bus. The device supports
> + multiple sub-devices like DRM. This driver provides common support for
like DRM and IPMI?
> + accessing the devices; additional drivers must be enabled in order to
> + use the functionality of the BMC device.
And moving this block after MFD_INTEL_M10_BMC_PMCI is a little better
(BMC drivers are together).
> +
> endmenu
> endif
> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> index 948cbdf42a18..18960ea13b64 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -290,3 +290,5 @@ obj-$(CONFIG_MFD_RSMU_I2C) += rsmu_i2c.o rsmu_core.o
> obj-$(CONFIG_MFD_RSMU_SPI) += rsmu_spi.o rsmu_core.o
>
> obj-$(CONFIG_MFD_UPBOARD_FPGA) += upboard-fpga.o
> +
> +obj-$(CONFIG_MFD_LS2K_BMC) += ls2kbmc-mfd.o
Also move it after MFD_INTEL_M10_BMC_PMCI.
Huacai
> diff --git a/drivers/mfd/ls2kbmc-mfd.c b/drivers/mfd/ls2kbmc-mfd.c
> new file mode 100644
> index 000000000000..9dbcb5b371f9
> --- /dev/null
> +++ b/drivers/mfd/ls2kbmc-mfd.c
> @@ -0,0 +1,156 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Loongson-2K Board Management Controller (BMC) Core Driver.
> + *
> + * Copyright (C) 2024-2025 Loongson Technology Corporation Limited.
> + *
> + * Authors:
> + * Chong Qiao <qiaochong@...ngson.cn>
> + * Binbin Zhou <zhoubinbin@...ngson.cn>
> + */
> +
> +#include <linux/aperture.h>
> +#include <linux/errno.h>
> +#include <linux/init.h>
> +#include <linux/kernel.h>
> +#include <linux/mfd/core.h>
> +#include <linux/module.h>
> +#include <linux/pci.h>
> +#include <linux/pci_ids.h>
> +#include <linux/platform_data/simplefb.h>
> +#include <linux/platform_device.h>
> +
> +/* LS2K BMC resources */
> +#define LS2K_DISPLAY_RES_START (SZ_16M + SZ_2M)
> +#define LS2K_IPMI_RES_SIZE 0x1C
> +#define LS2K_IPMI0_RES_START (SZ_16M + 0xF00000)
> +#define LS2K_IPMI1_RES_START (LS2K_IPMI0_RES_START + LS2K_IPMI_RES_SIZE)
> +#define LS2K_IPMI2_RES_START (LS2K_IPMI1_RES_START + LS2K_IPMI_RES_SIZE)
> +#define LS2K_IPMI3_RES_START (LS2K_IPMI2_RES_START + LS2K_IPMI_RES_SIZE)
> +#define LS2K_IPMI4_RES_START (LS2K_IPMI3_RES_START + LS2K_IPMI_RES_SIZE)
> +
> +static struct resource ls2k_display_resources[] = {
> + DEFINE_RES_MEM_NAMED(LS2K_DISPLAY_RES_START, SZ_4M, "simpledrm-res"),
> +};
> +
> +static struct resource ls2k_ipmi0_resources[] = {
> + DEFINE_RES_MEM_NAMED(LS2K_IPMI0_RES_START, LS2K_IPMI_RES_SIZE, "ipmi0-res"),
> +};
> +
> +static struct resource ls2k_ipmi1_resources[] = {
> + DEFINE_RES_MEM_NAMED(LS2K_IPMI1_RES_START, LS2K_IPMI_RES_SIZE, "ipmi1-res"),
> +};
> +
> +static struct resource ls2k_ipmi2_resources[] = {
> + DEFINE_RES_MEM_NAMED(LS2K_IPMI2_RES_START, LS2K_IPMI_RES_SIZE, "ipmi2-res"),
> +};
> +
> +static struct resource ls2k_ipmi3_resources[] = {
> + DEFINE_RES_MEM_NAMED(LS2K_IPMI3_RES_START, LS2K_IPMI_RES_SIZE, "ipmi3-res"),
> +};
> +
> +static struct resource ls2k_ipmi4_resources[] = {
> + DEFINE_RES_MEM_NAMED(LS2K_IPMI4_RES_START, LS2K_IPMI_RES_SIZE, "ipmi4-res"),
> +};
> +
> +static struct mfd_cell ls2k_bmc_cells[] = {
> + MFD_CELL_RES("simple-framebuffer", ls2k_display_resources),
> + MFD_CELL_RES("ls2k-ipmi-si", ls2k_ipmi0_resources),
> + MFD_CELL_RES("ls2k-ipmi-si", ls2k_ipmi1_resources),
> + MFD_CELL_RES("ls2k-ipmi-si", ls2k_ipmi2_resources),
> + MFD_CELL_RES("ls2k-ipmi-si", ls2k_ipmi3_resources),
> + MFD_CELL_RES("ls2k-ipmi-si", ls2k_ipmi4_resources),
> +};
> +
> +/*
> + * Currently the Loongson-2K BMC hardware does not have an I2C interface to adapt to the
> + * resolution. We set the resolution by presetting "video=1280x1024-16@2M" to the BMC memory.
> + */
> +static int ls2k_bmc_parse_mode(struct pci_dev *pdev, struct simplefb_platform_data *pd)
> +{
> + char *mode;
> + int depth, ret;
> +
> + /* The last 16M of PCI BAR0 is used to store the resolution string. */
> + mode = devm_ioremap(&pdev->dev, pci_resource_start(pdev, 0) + SZ_16M, SZ_16M);
> + if (!mode)
> + return -ENOMEM;
> +
> + /* The resolution field starts with the flag "video=". */
> + if (!strncmp(mode, "video=", 6))
> + mode = mode + 6;
> +
> + ret = kstrtoint(strsep(&mode, "x"), 10, &pd->width);
> + if (ret)
> + return ret;
> +
> + ret = kstrtoint(strsep(&mode, "-"), 10, &pd->height);
> + if (ret)
> + return ret;
> +
> + ret = kstrtoint(strsep(&mode, "@"), 10, &depth);
> + if (ret)
> + return ret;
> +
> + pd->stride = pd->width * depth / 8;
> + pd->format = depth == 32 ? "a8r8g8b8" : "r5g6b5";
> +
> + return 0;
> +}
> +
> +static int ls2k_bmc_probe(struct pci_dev *dev, const struct pci_device_id *id)
> +{
> + struct simplefb_platform_data pd;
> + resource_size_t base;
> + int ret;
> +
> + ret = pci_enable_device(dev);
> + if (ret)
> + return ret;
> +
> + ret = ls2k_bmc_parse_mode(dev, &pd);
> + if (ret)
> + goto disable_pci;
> +
> + ls2k_bmc_cells[0].platform_data = &pd;
> + ls2k_bmc_cells[0].pdata_size = sizeof(pd);
> + base = dev->resource[0].start + LS2K_DISPLAY_RES_START;
> +
> + /* Remove conflicting efifb device */
> + ret = aperture_remove_conflicting_devices(base, SZ_4M, "simple-framebuffer");
> + if (ret) {
> + dev_err(&dev->dev, "Failed to removed firmware framebuffers: %d\n", ret);
> + goto disable_pci;
> + }
> +
> + return devm_mfd_add_devices(&dev->dev, PLATFORM_DEVID_AUTO,
> + ls2k_bmc_cells, ARRAY_SIZE(ls2k_bmc_cells),
> + &dev->resource[0], 0, NULL);
> +
> +disable_pci:
> + pci_disable_device(dev);
> + return ret;
> +}
> +
> +static void ls2k_bmc_remove(struct pci_dev *dev)
> +{
> + pci_disable_device(dev);
> +}
> +
> +static struct pci_device_id ls2k_bmc_devices[] = {
> + { PCI_DEVICE(PCI_VENDOR_ID_LOONGSON, 0x1a05) },
> + { }
> +};
> +MODULE_DEVICE_TABLE(pci, ls2k_bmc_devices);
> +
> +static struct pci_driver ls2k_bmc_driver = {
> + .name = "ls2k-bmc",
> + .id_table = ls2k_bmc_devices,
> + .probe = ls2k_bmc_probe,
> + .remove = ls2k_bmc_remove,
> +};
> +module_pci_driver(ls2k_bmc_driver);
> +
> +MODULE_DESCRIPTION("Loongson-2K BMC driver");
> +MODULE_AUTHOR("Loongson Technology Corporation Limited");
> +MODULE_LICENSE("GPL");
> --
> 2.47.1
>
>
Powered by blists - more mailing lists