Skip to content

Commit f11eaf2

Browse files
chombourgerjan-kiszka
authored andcommitted
drivers: ipcbx21a: custom driver for the SIMATIC IPC BX-21A
The BX-21A was unfortunately not designed to either use iTCO or WDAT as we (Linux folks) are now recommending for SIMATIC IPCs. Their custom Linux driver was consequently ported over to support this somewhat recent SIMATIC IPC. Signed-off-by: Cedric Hombourger <[email protected]> Signed-off-by: Jan Kiszka <[email protected]>
1 parent b72e402 commit f11eaf2

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,15 @@ if BOOTLOADER
163163

164164
if ARCH_IS_X86
165165
# NOTE: wdat.c is placed first so it is tried before any other drivers
166+
# NOTE: ipcbx21a.c must be *before* itco.c
166167
# NOTE: ipc4x7e_wdt.c must be *before* itco.c
167168
# NOTE: ipmi_wdt.c must be *before* itco.c
168169
efi_sources_watchdogs = \
169170
drivers/watchdog/wdat.c \
170171
drivers/watchdog/amdfch_wdt.c \
171172
drivers/watchdog/i6300esb.c \
172173
drivers/watchdog/atom-quark.c \
174+
drivers/watchdog/ipcbx21a.c \
173175
drivers/watchdog/ipc4x7e_wdt.c \
174176
drivers/watchdog/w83627hf_wdt.c \
175177
drivers/watchdog/ipmi_wdt.c \

drivers/watchdog/ipcbx21a.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* EFI Boot Guard
3+
*
4+
* Copyright (c) Siemens AG, 2024
5+
*
6+
* Ported by Cedric Hombourger <[email protected]>
7+
* From unpublished code created by XingTong Wu <[email protected]>
8+
*
9+
* This work is licensed under the terms of the GNU GPL, version 2. See
10+
* the COPYING file in the top-level directory.
11+
*
12+
* SPDX-License-Identifier: GPL-2.0
13+
*/
14+
15+
#include <efi.h>
16+
#include <efilib.h>
17+
#include <pci/header.h>
18+
#include <sys/io.h>
19+
#include "simatic.h"
20+
#include "utils.h"
21+
22+
#define WDT_CTRL_REG_BX_21A 0x1854
23+
#define TIMEOUT_MIN_BX_21A (1)
24+
#define TIMEOUT_DEF_BX_21A (60)
25+
#define TIMEOUT_MAX_BX_21A (1024)
26+
/* Over-Clocking WDT Timeout Value */
27+
#define WDT_CTRL_REG_TOV_MASK_BX_21A (0x3FF)
28+
/* Over-Clocking WDT ICC Survivability Impact */
29+
#define WDT_CTRL_REG_ICCSURV_BIT_BX_21A BIT(13)
30+
/* Over-Clocking WDT Enable */
31+
#define WDT_CTRL_REG_EN_BIT_BX_21A BIT(14)
32+
/* Over-Clocking WDT Force All */
33+
#define WDT_CTRL_REG_FORCE_ALL_BIT_BX_21A BIT(15)
34+
/* Over-Clocking WDT Non-ICC Survivability Mode Timeout Status */
35+
#define WDT_CTRL_REG_NO_ICCSURV_STS_BIT_BX_21A BIT(24)
36+
/* Over-Clocking WDT ICC Survivability Mode Timeout Status */
37+
#define WDT_CTRL_REG_ICCSURV_STS_BIT_BX_21A BIT(25)
38+
39+
static EFI_STATUS init(EFI_PCI_IO __attribute__((unused)) * pci_io,
40+
UINT16 __attribute__((unused)) pci_vendor_id,
41+
UINT16 __attribute__((unused)) pci_device_id,
42+
UINTN timeout)
43+
{
44+
UINT32 regval;
45+
46+
if (simatic_station_id() != SIMATIC_IPCBX_21A)
47+
return EFI_UNSUPPORTED;
48+
49+
INFO(L"Detected SIMATIC BX-21A watchdog\n");
50+
51+
if (timeout < TIMEOUT_MIN_BX_21A || timeout > TIMEOUT_MAX_BX_21A) {
52+
WARNING(L"Invalid timeout value (%d), default (%ds) is used.\n",
53+
timeout, TIMEOUT_DEF_BX_21A);
54+
timeout = TIMEOUT_DEF_BX_21A;
55+
}
56+
57+
regval = inl(WDT_CTRL_REG_BX_21A);
58+
/* setup timeout value */
59+
regval &= (~WDT_CTRL_REG_TOV_MASK_BX_21A);
60+
regval |= (timeout - 1);
61+
/* get and clear status */
62+
regval |= WDT_CTRL_REG_NO_ICCSURV_STS_BIT_BX_21A;
63+
regval |= WDT_CTRL_REG_ICCSURV_STS_BIT_BX_21A;
64+
outl(regval, WDT_CTRL_REG_BX_21A);
65+
66+
/* start watchdog */
67+
regval = inl(WDT_CTRL_REG_BX_21A);
68+
regval |= (WDT_CTRL_REG_EN_BIT_BX_21A |
69+
WDT_CTRL_REG_ICCSURV_BIT_BX_21A |
70+
WDT_CTRL_REG_FORCE_ALL_BIT_BX_21A);
71+
outl(regval, WDT_CTRL_REG_BX_21A);
72+
73+
return EFI_SUCCESS;
74+
}
75+
76+
WATCHDOG_REGISTER(init);

include/simatic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#define SIMATIC_IPC427E 0x0a01
2727
#define SIMATIC_IPC477E 0x0a02
28+
#define SIMATIC_IPCBX_21A 0x1101
2829
#define SIMATIC_IPCBX_56A 0x1201
2930
#define SIMATIC_IPCBX_59A 0x1202
3031

0 commit comments

Comments
 (0)