已合并
【b06bae621f9502261aa6e1caf5d1b5e0】feat(lpc_snoop):多芯片HAL层eSP驱动实现 #20
【b06bae621f9502261aa6e1caf5d1b5e0】feat(lpc_snoop):多芯片HAL层eSP驱动实现 #20
已合并
byosoft_zhoujiangkun创建于 5 天前
共 18 个文件变更+678-54
@@ -1,6 +1,11 @@
1# Changelog1# Changelog
2 2 
3All notable changes to this project will be documented in this file.3All notable changes to this project will be documented in this file.
4+ 
5+## [1.0.11] - 2026-11-20
6+ 
7+- 支持 lpc_snoop 驱动接口(Aspeed LPC snoop,POST 码读取)
8+ 
4## [1.0.10] - 2026-11-169## [1.0.10] - 2026-11-16
5 10 
6- 支持i2c驱动接口11- 支持i2c驱动接口
@@ -1,3 +1,13 @@
1+# Copyright (c) 2026 Huawei Technologies Co., Ltd.
2+# openUBMC is licensed under Mulan PSL v2.
3+# You can use this software according to the terms and conditions of the Mulan PSL v2.
4+# You may obtain a copy of Mulan PSL v2 at:
5+# http://license.coscl.org.cn/MulanPSL2
6+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7+# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8+# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9+# See the Mulan PSL v2 for more details.
10+ 
1import os11import os
2from conanbase import ConanBase12from conanbase import ConanBase
3from conan.tools.meson import Meson, MesonToolchain13from conan.tools.meson import Meson, MesonToolchain
@@ -1,11 +1,8 @@
1-/*1+/* Copyright (c) 2026 Huawei Technologies Co., Ltd.
2- * Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved.2+ * openUBMC is licensed under Mulan PSL v2.
3- *
4- * Licensed under Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.3 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:4 * You may obtain a copy of Mulan PSL v2 at:
7- * http://license.coscl.org.cn/MulanPSL25+ * http://license.coscl.org.cn/MulanPSL2
8- *
9 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,6 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
10 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,7 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
11 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.8 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
@@ -1,14 +1,12 @@
1-/*1+/* Copyright (c) 2026 Huawei Technologies Co., Ltd.
2- * Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved.2+ * openUBMC is licensed under Mulan PSL v2.
3- *
4- * Licensed under Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.3 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:4 * You may obtain a copy of Mulan PSL v2 at:
7- * http://license.coscl.org.cn/MulanPSL25+ * http://license.coscl.org.cn/MulanPSL2
8- *
9 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,6 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
10 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,7 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
11 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.8 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9+ * See the Mulan PSL v2 for more details.
12 *10 *
13 * libsoc_adapter_aspeed — 基于 libgpiod C API 的 GPIO 驱动实现11 * libsoc_adapter_aspeed — 基于 libgpiod C API 的 GPIO 驱动实现
14 *12 *
@@ -1,14 +1,12 @@
1-/*1+/* Copyright (c) 2026 Huawei Technologies Co., Ltd.
2- * Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved.2+ * openUBMC is licensed under Mulan PSL v2.
3- *
4- * Licensed under Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.3 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:4 * You may obtain a copy of Mulan PSL v2 at:
7- * http://license.coscl.org.cn/MulanPSL25+ * http://license.coscl.org.cn/MulanPSL2
8- *
9 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,6 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
10 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,7 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
11 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.8 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9+ * See the Mulan PSL v2 for more details.
12 *10 *
13 * bcal_h2b — Host-to-BMC 共享内存驱动实现11 * bcal_h2b — Host-to-BMC 共享内存驱动实现
14 *12 *
@@ -1,11 +1,8 @@
1-/*1+/* Copyright (c) 2026 Huawei Technologies Co., Ltd.
2- * Copyright (c) 2026 Huawei Technologies Co., Ltd. All rights reserved.2+ * openUBMC is licensed under Mulan PSL v2.
3- *
4- * Licensed under Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.3 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:4 * You may obtain a copy of Mulan PSL v2 at:
7- * http://license.coscl.org.cn/MulanPSL25+ * http://license.coscl.org.cn/MulanPSL2
8- *
9 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,6 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
10 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,7 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
11 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.8 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
@@ -1,3 +1,14 @@
1+/* Copyright (c) 2026 Huawei Technologies Co., Ltd.
2+ * openUBMC is licensed under Mulan PSL v2.
3+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
4+ * You may obtain a copy of Mulan PSL v2 at:
5+ * http://license.coscl.org.cn/MulanPSL2
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9+ * See the Mulan PSL v2 for more details.
10+ */
11+ 
1/* SPDX-License-Identifier: GPL-2.0 */12/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (c) 2018 Mellanox Technologies. All rights reserved. */13/* Copyright (c) 2018 Mellanox Technologies. All rights reserved. */
3/* Copyright (c) 2018 Oleksandr Shamray <oleksandrs@mellanox.com> */14/* Copyright (c) 2018 Oleksandr Shamray <oleksandrs@mellanox.com> */
@@ -1,11 +1,8 @@
1-/*1+/* Copyright (c) 2026 Huawei Technologies Co., Ltd.
2- * Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved.2+ * openUBMC is licensed under Mulan PSL v2.
3- *
4- * Licensed under Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.3 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:4 * You may obtain a copy of Mulan PSL v2 at:
7- * http://license.coscl.org.cn/MulanPSL25+ * http://license.coscl.org.cn/MulanPSL2
8- *
9 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,6 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
10 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,7 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
11 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.8 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
@@ -1,7 +1,12 @@
1-/*1+/* Copyright (c) 2026 Huawei Technologies Co., Ltd.
2- * Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved.2+ * openUBMC is licensed under Mulan PSL v2.
3- *3+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
4- * Licensed under Mulan PSL v2.4+ * You may obtain a copy of Mulan PSL v2 at:
5+ * http://license.coscl.org.cn/MulanPSL2
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9+ * See the Mulan PSL v2 for more details.
5 */10 */
6 11 
7#include <bcal/kcs.h>12#include <bcal/kcs.h>
@@ -0,0 +1,590 @@
1+/* Copyright (c) 2026 Huawei Technologies Co., Ltd.
2+ * openUBMC is licensed under Mulan PSL v2.
3+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
4+ * You may obtain a copy of Mulan PSL v2 at:
5+ * http://license.coscl.org.cn/MulanPSL2
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9+ * See the Mulan PSL v2 for more details.
10+ */
11+ 
12+/*
13+ * Aspeed LPC snoop(POST 码监听)驱动实现。
14+ *
15+ * 内核驱动 /dev/aspeed-lpc-snoopN 每通道有 2048 字节 kfifo,只提供 read/poll,
16+ * 没有“读取当前值但不消费 FIFO”的能力。因此 read_current_data() 先把可读数据
17+ * 搬入本层缓存(上限 LPC_SNOOP_MAX_READ_LEN,超出丢弃最旧数据),再返回缓存
18+ * 最后一个字节;后续 read() 仍能读到这些数据。
19+ */
20+ 
21+#include <bcal/lpc_snoop.h>
22+ 
23+#include <algorithm>
24+#include <array>
25+#include <cerrno>
26+#include <chrono>
27+#include <climits>
28+#include <condition_variable>
29+#include <cstdint>
30+#include <cstdio>
31+#include <fcntl.h>
32+#include <mutex>
33+#include <poll.h>
34+#include <stdexcept>
35+#include <string>
36+#include <sys/eventfd.h>
37+#include <system_error>
38+#include <unistd.h>
39+ 
40+namespace BCAL_DRIVER_LPC_SNOOP {
41+using namespace bcal;
42+ 
43+namespace {
44+ 
45+constexpr const char* DRIVER_VERSION = "bcal_lpc_snoop_aspeed v1.0.0 (/dev/aspeed-lpc-snoopN)";
46+constexpr const char* DEV_PREFIX = "/dev/aspeed-lpc-snoop";
47+constexpr int MAX_EINTR_RETRIES = 8;
48+constexpr size_t READ_CHUNK_SIZE = 256;
49+ 
50+/* 实现侧定长数组容量;实际通道数以 get_channel_count() 为准(DTS 未配置的端口不打开)。 */
51+constexpr uint32_t CHANNEL_SLOT_NUM = 2;
52+ 
53+static_assert(CHANNEL_SLOT_NUM <= 32, "channel mask is uint32_t, channel slot number must not exceed 32");
54+ 
55+/* pollfd 固定布局:通道槽 + 数据唤醒 fd + 关停唤醒 fd。
56+ * ::poll 忽略 fd < 0 的条目,未打开通道/本轮不可用的 eventfd 留 -1 即可。 */
57+constexpr size_t POLL_FDS_NUM = CHANNEL_SLOT_NUM + 2;
58+constexpr size_t POLL_WAKEUP_SLOT = CHANNEL_SLOT_NUM;
59+constexpr size_t POLL_SHUTDOWN_SLOT = CHANNEL_SLOT_NUM + 1;
60+ 
61+string_t device_path(uint32_t chan_id)
62+{
63+ return string_t(DEV_PREFIX) + std::to_string(chan_id);
64+}
65+ 
66+/* std::strerror 用共享静态缓冲区,多线程可能串台;message() 每次返回独立 string。 */
67+string_t error_text(int error)
68+{
69+ return std::generic_category().message(error);
70+}
71+ 
72+/* Linux 上 EWOULDBLOCK 与 EAGAIN 同值。 */
73+bool would_block(int error)
74+{
75+ return error == EAGAIN;
76+}
77+ 
78+/* 语义同 ::read;非阻塞 fd 理论不会 EINTR,这里对信号风暴做有限重试。 */
79+ssize_t read_retry(int fd, void* buffer, size_t length)
80+{
81+ for (int retries = 0;; ++retries) {
82+ const ssize_t n = ::read(fd, buffer, length);
83+ if (n >= 0 || errno != EINTR || retries >= MAX_EINTR_RETRIES) {
84+ return n;
85+ }
86+ }
87+}
88+ 
89+} // namespace
90+ 
91+class LpcSnoopImpl : public LpcSnoop {
92+public:
93+ explicit LpcSnoopImpl(int32_t index);
94+ ~LpcSnoopImpl() override;
95+ 
96+ void init(void* args, uint32_t size) override;
97+ void lock(void) override;
98+ void unlock(void) override;
99+ string_t get_version(void) override;
100+ string_t get_driver_name(void) const override;
@@ -0,0 +1,12 @@
1+driver_name = 'lpc_snoop'
2+ 
3+sources = files('lpc_snoop.cpp')
4+ 
5+lpc_snoop_lib = shared_library(driver_name,
6+ sources,
7+ dependencies: [bcal_dep],
8+ # 默认隐藏,create_driver/destroy_driver 靠 visibility("default") 显式导出
9+ cpp_args: ['-fvisibility=hidden', '-fvisibility-inlines-hidden'],
10+ install: true,
11+ install_dir: driver_install_dir
12+)
@@ -7,3 +7,4 @@ subdir('pwm')
7subdir('wdt')7subdir('wdt')
8subdir('jtag')8subdir('jtag')
9subdir('i2c')9subdir('i2c')
10+subdir('lpc_snoop')
@@ -1,3 +1,14 @@
1+/* Copyright (c) 2026 Huawei Technologies Co., Ltd.
2+ * openUBMC is licensed under Mulan PSL v2.
3+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
4+ * You may obtain a copy of Mulan PSL v2 at:
5+ * http://license.coscl.org.cn/MulanPSL2
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9+ * See the Mulan PSL v2 for more details.
10+ */
11+ 
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */12/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/* Copyright (c) 2018-2021 Intel Corporation */13/* Copyright (c) 2018-2021 Intel Corporation */
3 14 
@@ -1,11 +1,8 @@
1-/*1+/* Copyright (c) 2025 Huawei Technologies Co., Ltd.
2- * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.2+ * openUBMC is licensed under Mulan PSL v2.
3- *
4- * Licensed under Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.3 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:4 * You may obtain a copy of Mulan PSL v2 at:
7- * http://license.coscl.org.cn/MulanPSL25+ * http://license.coscl.org.cn/MulanPSL2
8- *
9 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,6 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
10 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,7 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
11 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.8 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
@@ -1,11 +1,8 @@
1-/*1+/* Copyright (c) 2026 Huawei Technologies Co., Ltd.
2- * Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved.2+ * openUBMC is licensed under Mulan PSL v2.
3- *
4- * Licensed under Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.3 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:4 * You may obtain a copy of Mulan PSL v2 at:
7- * http://license.coscl.org.cn/MulanPSL25+ * http://license.coscl.org.cn/MulanPSL2
8- *
9 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,6 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
10 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,7 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
11 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.8 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
@@ -1,11 +1,8 @@
1-/*1+/* Copyright (c) 2026 Huawei Technologies Co., Ltd.
2- * Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved.2+ * openUBMC is licensed under Mulan PSL v2.
3- *
4- * Licensed under Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.3 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:4 * You may obtain a copy of Mulan PSL v2 at:
7- * http://license.coscl.org.cn/MulanPSL25+ * http://license.coscl.org.cn/MulanPSL2
8- *
9 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,6 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
10 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,7 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
11 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.8 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
@@ -2,14 +2,14 @@
2 "name": "libsoc_adapter_aspeed",2 "name": "libsoc_adapter_aspeed",
3 "type": "application",3 "type": "application",
4 "deployConfig": "",4 "deployConfig": "",
5- "version": "1.0.10",5+ "version": "1.0.11",
6 "license": "Mulan PSL v2",6 "license": "Mulan PSL v2",
7 "description": "BMC chip adapter for Aspeed.",7 "description": "BMC chip adapter for Aspeed.",
8 "dependencies": {8 "dependencies": {
9 "test": [],9 "test": [],
10 "build": [10 "build": [
11 {11 {
12- "conan": "bcal/[>=0.0.10]"12+ "conan": "bcal/[>=0.0.12]"
13 }13 }
14 ]14 ]
15 },15 },
@@ -15,3 +15,4 @@ opt/bmc/bcal/libpwm.so f 550 0 0
15opt/bmc/bcal/libwdt.so f 550 0 015opt/bmc/bcal/libwdt.so f 550 0 0
16opt/bmc/bcal/libjtag.so f 550 0 016opt/bmc/bcal/libjtag.so f 550 0 0
17opt/bmc/bcal/libi2c.so f 550 0 017opt/bmc/bcal/libi2c.so f 550 0 0
18+opt/bmc/bcal/liblpc_snoop.so f 550 0 0