Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit 8bb4763

Browse files
xinanluxbuildslave
authored andcommitted
WDT: add iTCO watchdog driver in efiwrapper
Add a simple driver for iTCO watchdog, to implement TCO watchdog enable and disable. These interfaces could be called in kernelflinger for enable/disable wdt. Change-Id: I31b972da09c77db59c3f1232d5c5ec691f060b76 Tracked-On: https://jira01.devtools.intel.com/browse/OAM-69751 Signed-off-by: xinanlux <[email protected]> Signed-off-by: btian1 <[email protected]> Reviewed-on: https://android.intel.com:443/647421
1 parent 09ee75e commit 8bb4763

File tree

7 files changed

+270
-0
lines changed

7 files changed

+270
-0
lines changed

drivers/tco_wdt/tco_protocol.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2015, Intel Corporation
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* * Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer
13+
* in the documentation and/or other materials provided with the
14+
* distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27+
* OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*
29+
*/
30+
31+
#ifndef _TCO_PROTOCOL_H_
32+
#define _TCO_PROTOCOL_H_
33+
34+
#include <efi.h>
35+
36+
#define EFI_TCO_RESET_PROTOCOL_GUID \
37+
{0xa6a79162, 0xe325, 0x4c30,{0xbc, 0xc3, 0x59, 0x37, 0x30, 0x64, 0xef, 0xb3}}
38+
39+
typedef struct _EFI_TCO_RESET_PROTOCOL EFI_TCO_RESET_PROTOCOL;
40+
41+
typedef
42+
EFI_STATUS
43+
(EFIAPI *EFI_TCO_RESET_PROTOCOL_ENABLE_WATCHDOG) (
44+
IN OUT UINT32 *RcrbGcsValue
45+
);
46+
47+
typedef
48+
EFI_STATUS
49+
(EFIAPI *EFI_TCO_RESET_PROTOCOL_DISABLE_WATCHDOG) (
50+
IN UINT32 RcrbGcsValue
51+
);
52+
53+
struct _EFI_TCO_RESET_PROTOCOL {
54+
EFI_TCO_RESET_PROTOCOL_ENABLE_WATCHDOG EnableTcoReset;
55+
EFI_TCO_RESET_PROTOCOL_DISABLE_WATCHDOG DisableTcoReset;
56+
};
57+
58+
#endif /* _TCO_PROTOCOL_H_ */

drivers/tco_wdt/tco_wdt.c

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/*
2+
* Copyright (c) 2016, Intel Corporation
3+
* All rights reserved.
4+
*
5+
* Author: Baofeng, Tian <[email protected]>
6+
* Author: Xinanx, Luo <[email protected]>
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions
10+
* are met:
11+
*
12+
* * Redistributions of source code must retain the above copyright
13+
* notice, this list of conditions and the following disclaimer.
14+
* * Redistributions in binary form must reproduce the above copyright
15+
* notice, this list of conditions and the following disclaimer
16+
* in the documentation and/or other materials provided with the
17+
* distribution.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30+
* OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
33+
#include <hwconfig.h>
34+
#include <interface.h>
35+
#include <kconfig.h>
36+
#include <libpayload-config.h>
37+
#include <libpayload.h>
38+
39+
#include "tco_wdt/tco_protocol.h"
40+
#include "tco_wdt/tco_wdt.h"
41+
42+
#ifndef BIT
43+
#define BIT(x) (1 << (x))
44+
#endif
45+
46+
/* TCO Registers */
47+
#define TCO_RLD (TCOBASE + 0x00) /* TCO Timer Reload/Curr. Value */
48+
#define TCO1_STS (TCOBASE + 0x04) /* TCO1 Status Register */
49+
#define TCO2_STS (TCOBASE + 0x06) /* TCO2 Status Register */
50+
#define TCO1_CNT (TCOBASE + 0x08) /* TCO1 Control Register */
51+
#define TCO2_CNT (TCOBASE + 0x0a) /* TCO1 Control Register */
52+
#define TCOv2_TMR (TCOBASE + 0x12) /* TCOv2 Timer Initial Value*/
53+
54+
#define PMC_GCR_PMC_CFG_REG (0xfe043008) /*NO_REBOOT bit config reg*/
55+
56+
/* TCO Registers' bits */
57+
#define TCO_HALT_BIT BIT(11)
58+
#define TCO_TIMEOUT1_BIT BIT(3)
59+
#define TCO_TIMEOUT2_BIT BIT(2)
60+
#define NO_REBOOT_BIT BIT(4)
61+
62+
#define TCO_MIN_TIMEOUT 4
63+
64+
static EFI_GUID tco_wdt_guid = EFI_TCO_RESET_PROTOCOL_GUID;
65+
static EFI_HANDLE handle;
66+
67+
static EFIAPI EFI_STATUS tco_wdt_enable (UINT32 *timeout)
68+
{
69+
UINT16 val = 0;
70+
UINT32 tmp = 0;
71+
72+
if (NULL == timeout)
73+
return EFI_INVALID_PARAMETER;
74+
if (*timeout < TCO_MIN_TIMEOUT)
75+
*timeout = TCO_MIN_TIMEOUT;
76+
77+
/* Halt TCO */
78+
val = inw(TCO1_CNT);
79+
val |= TCO_HALT_BIT;
80+
outw(val, TCO1_CNT);
81+
val = inw(TCO1_CNT);
82+
83+
/* Clear STS */
84+
outw(TCO_TIMEOUT1_BIT, TCO1_STS);
85+
outw(TCO_TIMEOUT2_BIT, TCO2_STS);
86+
87+
/* Set timeout */
88+
val = inw(TCOv2_TMR);
89+
val = (val & 0xfc00) | (((*timeout * 10) / 6) & 0x3ff);
90+
outw((val & 0x3ff), TCOv2_TMR);
91+
val = inw(TCOv2_TMR);
92+
93+
/* Clear NO_REBOOT bit */
94+
tmp = read32((void *)(UINTN)PMC_GCR_PMC_CFG_REG);
95+
tmp &= ~ NO_REBOOT_BIT;
96+
write32((void *)(UINTN)PMC_GCR_PMC_CFG_REG, tmp);
97+
/*Read back and check */
98+
tmp = read32((void *)(UINTN)PMC_GCR_PMC_CFG_REG);
99+
if (tmp & NO_REBOOT_BIT)
100+
return EFI_DEVICE_ERROR;
101+
102+
/* Reload */
103+
outw(0x1, TCO_RLD);
104+
105+
/* Start TCO */
106+
val = inw(TCO1_CNT);
107+
val &= ~ TCO_HALT_BIT;
108+
outw(val, TCO1_CNT);
109+
val = inw(TCO1_CNT);
110+
if (val & TCO_HALT_BIT)
111+
return EFI_DEVICE_ERROR;
112+
113+
return EFI_SUCCESS;
114+
}
115+
116+
static EFIAPI EFI_STATUS tco_wdt_disable (UINT32 timeout)
117+
{
118+
UINT16 val = 0;
119+
UINT32 tmp = timeout;
120+
121+
/* Halt TCO */
122+
val = inw(TCO1_CNT);
123+
val |= TCO_HALT_BIT;
124+
outw(val, TCO1_CNT);
125+
val = inw(TCO1_CNT);
126+
if (!(val & TCO_HALT_BIT))
127+
return EFI_DEVICE_ERROR;
128+
129+
/* Set NO_REBOOT bit */
130+
tmp = read32((void *)(UINTN)PMC_GCR_PMC_CFG_REG);
131+
tmp |= NO_REBOOT_BIT;
132+
write32((void *)(UINTN)PMC_GCR_PMC_CFG_REG, tmp);
133+
/*Read back and check */
134+
tmp = read32((void *)(UINTN)PMC_GCR_PMC_CFG_REG);
135+
if (!(tmp & NO_REBOOT_BIT))
136+
return EFI_DEVICE_ERROR;
137+
138+
return EFI_SUCCESS;
139+
}
140+
static EFI_STATUS tco_wdt_init(EFI_SYSTEM_TABLE *st)
141+
{
142+
static EFI_TCO_RESET_PROTOCOL tco_wdt_default = {
143+
.EnableTcoReset = tco_wdt_enable,
144+
.DisableTcoReset = tco_wdt_disable
145+
};
146+
EFI_TCO_RESET_PROTOCOL *tco_wdt;
147+
148+
return interface_init(st, &tco_wdt_guid, &handle,
149+
&tco_wdt_default, sizeof(tco_wdt_default),
150+
(void **)&tco_wdt);
151+
}
152+
153+
static EFI_STATUS tco_wdt_exit(EFI_SYSTEM_TABLE *st)
154+
{
155+
return interface_free(st, &tco_wdt_guid, handle);
156+
}
157+
158+
ewdrv_t tco_wdt_drv = {
159+
.name = "tco_wdt",
160+
.description = "TCO watchdog Protocol",
161+
.init = tco_wdt_init,
162+
.exit = tco_wdt_exit
163+
};

drivers/tco_wdt/tco_wdt.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2016, Intel Corporation
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* * Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer
13+
* in the documentation and/or other materials provided with the
14+
* distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27+
* OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
#ifndef _TCO_WDT_H_
31+
#define _TCO_WDT_H_
32+
33+
#include <ewdrv.h>
34+
35+
extern ewdrv_t tco_wdt_drv;
36+
37+
#endif

include/hardware/hw_broxton.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,8 @@
5555

5656
#define SERIAL_IOC_PCI_DID 0x5abe
5757

58+
/* TCO base address for Gordon peak */
59+
#define TCOBASE (0x00000460)
60+
5861
#endif /* __HW_BROXTON__ */
5962

include/hardware/hw_icelake.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,8 @@
6767

6868
#define SERIAL_IOC_PCI_DID 0x34a9
6969

70+
/* TCO base address, to be determined */
71+
#define TCOBASE (0xffffffff)
72+
7073
#endif /* __HW_ICELAKE__ */
7174

include/hardware/hw_kabylake.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,8 @@
5050
#define NVME_PCI_DID 0xF1A5
5151
#define NVME_DISKBUS 0x1D00
5252

53+
/* TCO base address, to be determined */
54+
#define TCOBASE (0xffffffff)
55+
5356
#endif /* __HW_KABYLAKE__ */
5457

include/hardware/hw_tigerlake.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,8 @@
5858

5959
#endif /* EFIWRAPPER_USE_EC_UART */
6060

61+
/* TCO base address, to be determined */
62+
#define TCOBASE (0xffffffff)
63+
6164
#endif /* __HW_TIGERLAKE__ */
6265

0 commit comments

Comments
 (0)