Johnny Lin has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/34857 )
Change subject: mb/ocp/monolake: Add IPMI CMOS clear support ......................................................................
mb/ocp/monolake: Add IPMI CMOS clear support
coreboot would clear CMOS by request via IPMI command, for example BMC can issue "bios-util server --boot_order enable --clear_CMOS" to set the request and reboot the system, then coreboot would clear CMOS on the next boot.
Tested on Mono Lake
Change-Id: I21d44557896680cfac3c3b6d83e07b755b242cad --- M src/mainboard/ocp/monolake/Kconfig M src/mainboard/ocp/monolake/Makefile.inc A src/mainboard/ocp/monolake/ipmi.c A src/mainboard/ocp/monolake/ipmi.h M src/mainboard/ocp/monolake/mainboard.c 5 files changed, 147 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/57/34857/1
diff --git a/src/mainboard/ocp/monolake/Kconfig b/src/mainboard/ocp/monolake/Kconfig index 13d7876..c55c84e 100644 --- a/src/mainboard/ocp/monolake/Kconfig +++ b/src/mainboard/ocp/monolake/Kconfig @@ -12,6 +12,7 @@ select MAINBOARD_USES_IFD_GBE_REGION select MAINBOARD_HAS_LPC_TPM select MAINBOARD_HAS_TPM1 + select IPMI_KCS
config INTEGRATED_UART def_bool n diff --git a/src/mainboard/ocp/monolake/Makefile.inc b/src/mainboard/ocp/monolake/Makefile.inc index 1606476..b6a26b0 100644 --- a/src/mainboard/ocp/monolake/Makefile.inc +++ b/src/mainboard/ocp/monolake/Makefile.inc @@ -14,3 +14,4 @@ ##
ramstage-y += irqroute.c +ramstage-y += ipmi.c diff --git a/src/mainboard/ocp/monolake/ipmi.c b/src/mainboard/ocp/monolake/ipmi.c new file mode 100755 index 0000000..84530e1 --- /dev/null +++ b/src/mainboard/ocp/monolake/ipmi.c @@ -0,0 +1,79 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2019 Wiwynn Corp. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ +#include <stdint.h> +#include <drivers/ipmi/ipmi_kcs.h> +#include <console/console.h> +#include "ipmi.h" + +#define BMC_KCS_BASE 0xca2 + +int is_ipmi_clear_cmos_set(ipmi_oem_rsp_t *rsp) +{ + int ret; + ipmi_oem_req_t req; + + if (rsp == NULL) { + printk(BIOS_ERR, "%s failed, null pointer parameter\n", + __func__); + return 0; + } + ret = ipmi_kcs_message(BMC_KCS_BASE, IPMI_NETFN_OEM, 0x0, + IPMI_OEM_GET_BIOS_BOOT_ORDER, + (const unsigned char *) &req, sizeof(ipmi_oem_req_t), + (unsigned char *) rsp, sizeof(ipmi_oem_rsp_t)); + + if (ret < sizeof(struct ipmi_rsp) || rsp->CompletionCode) { + printk(BIOS_ERR, "IPMI: %s command failed (ret=%d resp=0x%x)\n", + __func__, ret, rsp->CompletionCode); + return 0; + } + + if (rsp->Data.Valid && rsp->Data.CmosClear) { + printk(BIOS_INFO, "IPMI CMOS clear requested\n"); + return 1; + } + + printk(BIOS_DEBUG, "IPMI CMOS clear is not set\n"); + return 0; +} + +void clear_ipmi_flags(ipmi_oem_rsp_t *rsp_get) +{ + int ret; + ipmi_oem_req_t req; + struct ipmi_rsp rsp; + + if (rsp_get == NULL) { + printk(BIOS_ERR, "%s failed, null pointer parameter\n", + __func__); + return; + } + + req = rsp_get->Data; + req.CmosClear = 0; + req.Valid = 0; + ret = ipmi_kcs_message(BMC_KCS_BASE, IPMI_NETFN_OEM, 0x0, + IPMI_OEM_SET_BIOS_BOOT_ORDER, + (const unsigned char *) &req, sizeof(ipmi_oem_req_t), + (unsigned char *) &rsp, sizeof(rsp)); + + if (ret < sizeof(struct ipmi_rsp) || rsp.completion_code) { + printk(BIOS_ERR, "IPMI: %s command failed (ret=%d resp=0x%x)\n", + __func__, ret, rsp.completion_code); + return; + } + + printk(BIOS_INFO, "clear IPMI flags done\n"); +} diff --git a/src/mainboard/ocp/monolake/ipmi.h b/src/mainboard/ocp/monolake/ipmi.h new file mode 100644 index 0000000..ef4fbd3 --- /dev/null +++ b/src/mainboard/ocp/monolake/ipmi.h @@ -0,0 +1,54 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2019 Wiwynn Corp. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef MONOLAKE_IPMI_H +#define MONOLAKE_IPMI_H + +#define IPMI_NETFN_OEM 0x30 +#define IPMI_OEM_SET_BIOS_BOOT_ORDER 0x52 +#define IPMI_OEM_GET_BIOS_BOOT_ORDER 0x53 + +typedef struct { + u8 BiosType:1; + u8 CmosClear:1; + u8 ForceBiosSetup:1; + u8 Reserved:4; + u8 Valid:1; + u8 Boot0000; + u8 Boot0001; + u8 Boot0002; + u8 Boot0003; + u8 Boot0004; +} __packed ipmi_oem_req_t; + +typedef struct { + u16 KcsRsp; + u8 CompletionCode; + ipmi_oem_req_t Data; +} __packed ipmi_oem_rsp_t; + +/* + * IPMI get response to check if Valid and CMOS clear bit + * are both set and store the IPMI response data to the parameter. + */ +int is_ipmi_clear_cmos_set(ipmi_oem_rsp_t *rsp); +/* + * Clear Valid bit and CMOS clear bit from the parameter + * and set it back via IPMI. + */ +void clear_ipmi_flags(ipmi_oem_rsp_t *rsp); + +#endif + diff --git a/src/mainboard/ocp/monolake/mainboard.c b/src/mainboard/ocp/monolake/mainboard.c index bbfeeaf..56aef6b 100644 --- a/src/mainboard/ocp/monolake/mainboard.c +++ b/src/mainboard/ocp/monolake/mainboard.c @@ -19,6 +19,9 @@ #if CONFIG(VGA_ROM_RUN) #include <x86emu/x86emu.h> #endif +#include <pc80/mc146818rtc.h> +#include <cf9_reset.h> +#include "ipmi.h"
#define BMC_KCS_BASE 0xca2 #define INTERFACE_IS_IO 0x1 @@ -57,9 +60,18 @@ /* Enable access to the BMC IPMI via KCS */ struct device *lpc_sio_dev = dev_find_slot_pnp(BMC_KCS_BASE, 0); struct resource *res = new_resource(lpc_sio_dev, BMC_KCS_BASE); + ipmi_oem_rsp_t rsp; res->base = BMC_KCS_BASE; res->size = 1; res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; + + if (is_ipmi_clear_cmos_set(&rsp)) { + /* TODO: Should also try to restore CMOS to cmos.default + * if USE_OPTION_TABLE is set */ + cmos_init(1); + clear_ipmi_flags(&rsp); + system_reset(); + } }
struct chip_operations mainboard_ops = {
Hello Patrick Rudolph, Philipp Deppenwiese, build bot (Jenkins), Patrick Georgi, Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/34857
to look at the new patch set (#2).
Change subject: mb/ocp/monolake: Add IPMI CMOS clear support ......................................................................
mb/ocp/monolake: Add IPMI CMOS clear support
coreboot would clear CMOS by request via IPMI command, for example BMC can issue "bios-util server --boot_order enable --clear_CMOS" to set the request and reboot the system, then coreboot would clear CMOS on the next boot.
Tested on Mono Lake
Change-Id: I21d44557896680cfac3c3b6d83e07b755b242cad Signed-off-by: Johnny Lin johnny_lin@wiwynn.com --- M src/mainboard/ocp/monolake/Kconfig M src/mainboard/ocp/monolake/Makefile.inc A src/mainboard/ocp/monolake/ipmi.c A src/mainboard/ocp/monolake/ipmi.h M src/mainboard/ocp/monolake/mainboard.c 5 files changed, 147 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/57/34857/2
Hello David Hendricks, Łukasz Siudut, Patrick Rudolph, Jonathan Zhang, Philipp Deppenwiese, build bot (Jenkins), Patrick Georgi, Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/34857
to look at the new patch set (#3).
Change subject: mb/ocp/monolake: Add IPMI CMOS clear support ......................................................................
mb/ocp/monolake: Add IPMI CMOS clear support
coreboot would clear CMOS by request via IPMI command, for example BMC can issue "bios-util server --boot_order enable --clear_CMOS" to set the request and reboot the system, then coreboot would clear CMOS on the next boot.
Tested on Mono Lake
Change-Id: I21d44557896680cfac3c3b6d83e07b755b242cad Signed-off-by: Johnny Lin johnny_lin@wiwynn.com --- M src/mainboard/ocp/monolake/Kconfig M src/mainboard/ocp/monolake/Makefile.inc A src/mainboard/ocp/monolake/ipmi.c A src/mainboard/ocp/monolake/ipmi.h M src/mainboard/ocp/monolake/mainboard.c 5 files changed, 146 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/57/34857/3
Patrick Rudolph has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/34857 )
Change subject: mb/ocp/monolake: Add IPMI CMOS clear support ......................................................................
Patch Set 3:
I don't see why that should be board specific.
Johnny Lin has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/34857 )
Change subject: mb/ocp/monolake: Add IPMI CMOS clear support ......................................................................
Patch Set 3:
Patch Set 3:
I don't see why that should be board specific.
This is implemented according to Mono Lake specific OEM command spec but not standard IPMI spec, therefore I think it's board specific.
Patrick Rudolph has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/34857 )
Change subject: mb/ocp/monolake: Add IPMI CMOS clear support ......................................................................
Patch Set 3:
Patch Set 3:
Patch Set 3:
I don't see why that should be board specific.
This is implemented according to Mono Lake specific OEM command spec but not standard IPMI spec, therefore I think it's board specific.
On the first sight it looked like "Set System Boot Options" and "Get System Boot Options" from the Chassis Netfn. Can you reference the OEM spec you are using to implement that functionality?
Johnny Lin has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/34857 )
Change subject: mb/ocp/monolake: Add IPMI CMOS clear support ......................................................................
Patch Set 3:
Patch Set 3:
Patch Set 3:
Patch Set 3:
I don't see why that should be board specific.
This is implemented according to Mono Lake specific OEM command spec but not standard IPMI spec, therefore I think it's board specific.
On the first sight it looked like "Set System Boot Options" and "Get System Boot Options" from the Chassis Netfn. Can you reference the OEM spec you are using to implement that functionality?
The OEM spec is confidential and cannot be found in the public, so I am afraid that I'm not able to reference it.
Hello David Hendricks, Łukasz Siudut, Patrick Rudolph, Jonathan Zhang, Philipp Deppenwiese, build bot (Jenkins), Patrick Georgi, Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/34857
to look at the new patch set (#4).
Change subject: mb/ocp/monolake: Add IPMI CMOS clear support ......................................................................
mb/ocp/monolake: Add IPMI CMOS clear support
coreboot would clear CMOS by request via IPMI command, for example BMC can issue "bios-util server --boot_order enable --clear_CMOS" to set the request and reboot the system, then coreboot would clear CMOS on the next boot.
Tested on Mono Lake
Change-Id: I21d44557896680cfac3c3b6d83e07b755b242cad Signed-off-by: Johnny Lin johnny_lin@wiwynn.com --- M src/mainboard/ocp/monolake/Kconfig M src/mainboard/ocp/monolake/Makefile.inc A src/mainboard/ocp/monolake/ipmi.c A src/mainboard/ocp/monolake/ipmi.h M src/mainboard/ocp/monolake/mainboard.c 5 files changed, 149 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/57/34857/4
Andrey Petrov has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/34857 )
Change subject: mb/ocp/monolake: Add IPMI CMOS clear support ......................................................................
Patch Set 4:
(2 comments)
https://review.coreboot.org/c/coreboot/+/34857/4/src/mainboard/ocp/monolake/... File src/mainboard/ocp/monolake/ipmi.h:
https://review.coreboot.org/c/coreboot/+/34857/4/src/mainboard/ocp/monolake/... PS4, Line 18: please add #include so this file could be sourced independently. I think you just need "types.h"
https://review.coreboot.org/c/coreboot/+/34857/4/src/mainboard/ocp/monolake/... File src/mainboard/ocp/monolake/ipmi.c:
https://review.coreboot.org/c/coreboot/+/34857/4/src/mainboard/ocp/monolake/... PS4, Line 32: ret = ipmi_kcs_message(BMC_KCS_BASE, IPMI_NETFN_OEM, 0x0, this is confusing. We are asking for bios boot order and use it to tell if clear request is pending. This looks like a bit of overloaded message to me. Could you perhaps add a comment and explain what is happening?
Andrey Petrov has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/34857 )
Change subject: mb/ocp/monolake: Add IPMI CMOS clear support ......................................................................
Patch Set 4:
(1 comment)
https://review.coreboot.org/c/coreboot/+/34857/4/src/mainboard/ocp/monolake/... File src/mainboard/ocp/monolake/ipmi.h:
https://review.coreboot.org/c/coreboot/+/34857/4/src/mainboard/ocp/monolake/... PS4, Line 34: } __packed ipmi_oem_req_t; using packed struct and bitfields is discouraged due to portability concerns. Please add code to serialize/serialize the data.
Hello David Hendricks, Łukasz Siudut, Patrick Rudolph, Jonathan Zhang, Philipp Deppenwiese, build bot (Jenkins), Patrick Georgi, Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/34857
to look at the new patch set (#5).
Change subject: mb/ocp/monolake: Add IPMI CMOS clear support ......................................................................
mb/ocp/monolake: Add IPMI CMOS clear support
coreboot would clear CMOS by request via IPMI command, for example BMC can issue "bios-util server --boot_order enable --clear_CMOS" to set the request and reboot the system, then coreboot would clear CMOS on the next boot.
Tested on Mono Lake
Change-Id: I21d44557896680cfac3c3b6d83e07b755b242cad Signed-off-by: Johnny Lin johnny_lin@wiwynn.com --- M src/mainboard/ocp/monolake/Kconfig M src/mainboard/ocp/monolake/Makefile.inc A src/mainboard/ocp/monolake/ipmi.c A src/mainboard/ocp/monolake/ipmi.h M src/mainboard/ocp/monolake/mainboard.c 5 files changed, 150 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/57/34857/5
Johnny Lin has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/34857 )
Change subject: mb/ocp/monolake: Add IPMI CMOS clear support ......................................................................
Patch Set 5: Code-Review+1
(3 comments)
Patch Set 4:
(2 comments)
https://review.coreboot.org/c/coreboot/+/34857/4/src/mainboard/ocp/monolake/... File src/mainboard/ocp/monolake/ipmi.h:
https://review.coreboot.org/c/coreboot/+/34857/4/src/mainboard/ocp/monolake/... PS4, Line 18:
please add #include so this file could be sourced independently. I think you just need "types. […]
Done
https://review.coreboot.org/c/coreboot/+/34857/4/src/mainboard/ocp/monolake/... PS4, Line 34: } __packed ipmi_oem_req_t;
using packed struct and bitfields is discouraged due to portability concerns. […]
Done
https://review.coreboot.org/c/coreboot/+/34857/4/src/mainboard/ocp/monolake/... File src/mainboard/ocp/monolake/ipmi.c:
https://review.coreboot.org/c/coreboot/+/34857/4/src/mainboard/ocp/monolake/... PS4, Line 32: ret = ipmi_kcs_message(BMC_KCS_BASE, IPMI_NETFN_OEM, 0x0,
this is confusing. We are asking for bios boot order and use it to tell if clear request is pending. […]
Comment added in new patch set, this is an OEM defined IPMI spec.
Johnny Lin has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/34857 )
Change subject: mb/ocp/monolake: Add IPMI CMOS clear support ......................................................................
Patch Set 5:
Patch Set 5: Code-Review+1
(3 comments)
Patch Set 4:
(2 comments)
Andrey Petrov has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/34857 )
Change subject: mb/ocp/monolake: Add IPMI CMOS clear support ......................................................................
Patch Set 5: Code-Review+2
Andrey Petrov has submitted this change and it was merged. ( https://review.coreboot.org/c/coreboot/+/34857 )
Change subject: mb/ocp/monolake: Add IPMI CMOS clear support ......................................................................
mb/ocp/monolake: Add IPMI CMOS clear support
coreboot would clear CMOS by request via IPMI command, for example BMC can issue "bios-util server --boot_order enable --clear_CMOS" to set the request and reboot the system, then coreboot would clear CMOS on the next boot.
Tested on Mono Lake
Change-Id: I21d44557896680cfac3c3b6d83e07b755b242cad Signed-off-by: Johnny Lin johnny_lin@wiwynn.com Reviewed-on: https://review.coreboot.org/c/coreboot/+/34857 Reviewed-by: Johnny Lin Reviewed-by: Andrey Petrov andrey.petrov@gmail.com Tested-by: build bot (Jenkins) no-reply@coreboot.org --- M src/mainboard/ocp/monolake/Kconfig M src/mainboard/ocp/monolake/Makefile.inc A src/mainboard/ocp/monolake/ipmi.c A src/mainboard/ocp/monolake/ipmi.h M src/mainboard/ocp/monolake/mainboard.c 5 files changed, 150 insertions(+), 0 deletions(-)
Approvals: build bot (Jenkins): Verified Andrey Petrov: Looks good to me, approved Johnny Lin: Looks good to me, but someone else must approve
diff --git a/src/mainboard/ocp/monolake/Kconfig b/src/mainboard/ocp/monolake/Kconfig index 13d7876..9536c30 100644 --- a/src/mainboard/ocp/monolake/Kconfig +++ b/src/mainboard/ocp/monolake/Kconfig @@ -12,6 +12,7 @@ select MAINBOARD_USES_IFD_GBE_REGION select MAINBOARD_HAS_LPC_TPM select MAINBOARD_HAS_TPM1 + select IPMI_KCS
config INTEGRATED_UART def_bool n @@ -47,4 +48,7 @@ string default "src/mainboard/$(CONFIG_MAINBOARD_DIR)/board.fmd"
+config IPMI_KCS_REGISTER_SPACING + default 4 + endif # BOARD_OCP_MONOLAKE diff --git a/src/mainboard/ocp/monolake/Makefile.inc b/src/mainboard/ocp/monolake/Makefile.inc index 1606476..b6a26b0 100644 --- a/src/mainboard/ocp/monolake/Makefile.inc +++ b/src/mainboard/ocp/monolake/Makefile.inc @@ -14,3 +14,4 @@ ##
ramstage-y += irqroute.c +ramstage-y += ipmi.c diff --git a/src/mainboard/ocp/monolake/ipmi.c b/src/mainboard/ocp/monolake/ipmi.c new file mode 100644 index 0000000..37aacc8 --- /dev/null +++ b/src/mainboard/ocp/monolake/ipmi.c @@ -0,0 +1,80 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2019 Wiwynn Corp. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ +#include <stdint.h> +#include <drivers/ipmi/ipmi_kcs.h> +#include <console/console.h> +#include "ipmi.h" + +#define BMC_KCS_BASE 0xca2 + +int is_ipmi_clear_cmos_set(ipmi_oem_rsp_t *rsp) +{ + int ret; + ipmi_oem_req_t req; + + if (rsp == NULL) { + printk(BIOS_ERR, "%s failed, null pointer parameter\n", + __func__); + return 0; + } + /* IPMI OEM get bios boot order command to check if the valid bit and + the CMOS clear bit are both set from the response BootMode byte. */ + ret = ipmi_kcs_message(BMC_KCS_BASE, IPMI_NETFN_OEM, 0x0, + IPMI_OEM_GET_BIOS_BOOT_ORDER, + (const unsigned char *) &req, sizeof(ipmi_oem_req_t), + (unsigned char *) rsp, sizeof(ipmi_oem_rsp_t)); + + if (ret < sizeof(struct ipmi_rsp) || rsp->CompletionCode) { + printk(BIOS_ERR, "IPMI: %s command failed (ret=%d resp=0x%x)\n", + __func__, ret, rsp->CompletionCode); + return 0; + } + + if (GET_VALID_BIT(rsp->Data.BootMode) && GET_CMOS_BIT(rsp->Data.BootMode)) { + printk(BIOS_INFO, "IPMI CMOS clear requested\n"); + return 1; + } + + printk(BIOS_DEBUG, "IPMI CMOS clear is not set\n"); + return 0; +} + +void clear_ipmi_flags(ipmi_oem_rsp_t *rsp_get) +{ + int ret; + ipmi_oem_req_t req; + struct ipmi_rsp rsp; + + if (rsp_get == NULL) { + printk(BIOS_ERR, "%s failed, null pointer parameter\n", + __func__); + return; + } + + req = rsp_get->Data; + CLEAR_CMOS_AND_VALID_BIT(req.BootMode); + ret = ipmi_kcs_message(BMC_KCS_BASE, IPMI_NETFN_OEM, 0x0, + IPMI_OEM_SET_BIOS_BOOT_ORDER, + (const unsigned char *) &req, sizeof(ipmi_oem_req_t), + (unsigned char *) &rsp, sizeof(rsp)); + + if (ret < sizeof(struct ipmi_rsp) || rsp.completion_code) { + printk(BIOS_ERR, "IPMI: %s command failed (ret=%d resp=0x%x)\n", + __func__, ret, rsp.completion_code); + return; + } + + printk(BIOS_INFO, "clear IPMI flags done\n"); +} diff --git a/src/mainboard/ocp/monolake/ipmi.h b/src/mainboard/ocp/monolake/ipmi.h new file mode 100644 index 0000000..5863eb5 --- /dev/null +++ b/src/mainboard/ocp/monolake/ipmi.h @@ -0,0 +1,53 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2019 Wiwynn Corp. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef MONOLAKE_IPMI_H +#define MONOLAKE_IPMI_H +#include <types.h> + +#define IPMI_NETFN_OEM 0x30 +#define IPMI_OEM_SET_BIOS_BOOT_ORDER 0x52 +#define IPMI_OEM_GET_BIOS_BOOT_ORDER 0x53 +#define GET_CMOS_BIT(x) ((x) & (1 << 1)) +#define GET_VALID_BIT(x) ((x) & (1 << 7)) +#define CLEAR_CMOS_AND_VALID_BIT(x) ((x) &= 0x7d) + +typedef struct { + u8 BootMode; /* Bit 1:CMOS clear, bit 7:valid bit. */ + u8 Boot0000; + u8 Boot0001; + u8 Boot0002; + u8 Boot0003; + u8 Boot0004; +} __packed ipmi_oem_req_t; + +typedef struct { + u16 KcsRsp; + u8 CompletionCode; + ipmi_oem_req_t Data; +} __packed ipmi_oem_rsp_t; + +/* + * IPMI get response to check if valid and CMOS clear bit + * are both set and store the IPMI response data to the parameter. + */ +int is_ipmi_clear_cmos_set(ipmi_oem_rsp_t *rsp); +/* + * Clear valid bit and CMOS clear bit from the parameter + * and set it back via IPMI. + */ +void clear_ipmi_flags(ipmi_oem_rsp_t *rsp); + +#endif diff --git a/src/mainboard/ocp/monolake/mainboard.c b/src/mainboard/ocp/monolake/mainboard.c index bbfeeaf..56aef6b 100644 --- a/src/mainboard/ocp/monolake/mainboard.c +++ b/src/mainboard/ocp/monolake/mainboard.c @@ -19,6 +19,9 @@ #if CONFIG(VGA_ROM_RUN) #include <x86emu/x86emu.h> #endif +#include <pc80/mc146818rtc.h> +#include <cf9_reset.h> +#include "ipmi.h"
#define BMC_KCS_BASE 0xca2 #define INTERFACE_IS_IO 0x1 @@ -57,9 +60,18 @@ /* Enable access to the BMC IPMI via KCS */ struct device *lpc_sio_dev = dev_find_slot_pnp(BMC_KCS_BASE, 0); struct resource *res = new_resource(lpc_sio_dev, BMC_KCS_BASE); + ipmi_oem_rsp_t rsp; res->base = BMC_KCS_BASE; res->size = 1; res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; + + if (is_ipmi_clear_cmos_set(&rsp)) { + /* TODO: Should also try to restore CMOS to cmos.default + * if USE_OPTION_TABLE is set */ + cmos_init(1); + clear_ipmi_flags(&rsp); + system_reset(); + } }
struct chip_operations mainboard_ops = {