Anastasia Klimchuk has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/52597 )
Change subject: mec1308.c: Separate shutdown from failed init cleanup
......................................................................
mec1308.c: Separate shutdown from failed init cleanup
Shutdown function was covering two different jobs here:
1) the actual shutdown which is run at the end of the
driver's lifecycle and 2) cleanup in cases when
initialisation failed. Now, shutdown is only doing its
main job (#1), and the driver itself is doing cleanup
when init fails (#2).
The good thing is that now resources are released/closed
immediately in cases when init fails (vs shutdown
function which was run at some point later), and
the driver leaves clean space after itself if init fails.
And very importantly this unlocks API change which plans
to move register_shutdown inside register master API,
see https://review.coreboot.org/c/flashrom/+/51761
TEST=builds and ninja test from 51487
BUG=b:185191942
Change-Id: I6d62d43dd8b6ebc595f9fd747e0f4cd80f3c10da
Signed-off-by: Anastasia Klimchuk <aklm(a)chromium.org>
---
M mec1308.c
1 file changed, 16 insertions(+), 4 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/97/52597/1
diff --git a/mec1308.c b/mec1308.c
index c3b555d..9621c91 100644
--- a/mec1308.c
+++ b/mec1308.c
@@ -496,9 +496,6 @@
goto mec1308_init_exit;
}
- if (register_shutdown(mec1308_shutdown, ctx_data))
- goto mec1308_init_exit;
-
/*
* Enter SPI Pass-Thru Mode after commands which do not require access
* to SPI ROM are complete. We'll start by doing the exit_passthru_mode
@@ -507,15 +504,30 @@
mec1308_exit_passthru_mode(ctx_data);
if (enter_passthru_mode(ctx_data))
- goto mec1308_init_exit;
+ goto failed_init_cleanup;
internal_buses_supported |= BUS_LPC; /* for LPC <--> SPI bridging */
spi_master_mec1308.data = ctx_data;
+
+ if (register_shutdown(mec1308_shutdown, ctx_data))
+ goto failed_init_cleanup;
register_spi_master(&spi_master_mec1308);
msg_pdbg("%s(): successfully initialized mec1308\n", __func__);
return 0;
+failed_init_cleanup:
+ /* Exit passthru mode before performing commands which do not affect
+ the SPI ROM */
+ mec1308_exit_passthru_mode(ctx_data);
+
+ /* Re-enable SMI and ACPI.
+ FIXME: is there an ordering dependency? */
+ if (mbx_write(ctx_data, MEC1308_MBX_CMD, MEC1308_CMD_SMI_ENABLE))
+ msg_pdbg("%s: unable to re-enable SMI\n", __func__);
+ if (mbx_write(ctx_data, MEC1308_MBX_CMD, MEC1308_CMD_ACPI_ENABLE))
+ msg_pdbg("%s: unable to re-enable ACPI\n", __func__);
+
mec1308_init_exit:
free(ctx_data);
return 1;
--
To view, visit https://review.coreboot.org/c/flashrom/+/52597
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I6d62d43dd8b6ebc595f9fd747e0f4cd80f3c10da
Gerrit-Change-Number: 52597
Gerrit-PatchSet: 1
Gerrit-Owner: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-MessageType: newchange
Anastasia Klimchuk has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/52595 )
Change subject: mec1308.c: Extract params check into a function
......................................................................
mec1308.c: Extract params check into a function
This allows char *p to become a local variable in
check_params, and it is allocated and freed within
check_params function. Which means init function
does not need char *p anymore, in particular does not
need to free it - and this makes cleanup after failed
init easier.
As a good side effect, init function becomes easier
to read.
TEST=builds and ninja test from 51487
BUG=b:185191942
Change-Id: If5be7709e93233a2e7ea9133de50382d2524a55f
Signed-off-by: Anastasia Klimchuk <aklm(a)chromium.org>
---
M mec1308.c
1 file changed, 16 insertions(+), 5 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/95/52595/1
diff --git a/mec1308.c b/mec1308.c
index c4b34f5..682e7a9 100644
--- a/mec1308.c
+++ b/mec1308.c
@@ -406,13 +406,27 @@
.write_256 = default_spi_write_256,
};
+static int check_params(void)
+{
+ int ret = 0;
+ char *p = NULL;
+
+ p = extract_programmer_param("type");
+ if (p && strcmp(p, "ec")) {
+ msg_pdbg("mec1308 only supports \"ec\" type devices\n");
+ ret = 1;
+ }
+
+ free(p);
+ return ret;
+}
+
int mec1308_init(void)
{
uint16_t sio_port;
uint8_t device_id;
uint8_t tmp8;
int ret = 0;
- char *p = NULL;
mec1308_data_t *ctx_data = NULL;
msg_pdbg("%s(): entered\n", __func__);
@@ -423,9 +437,7 @@
return 1;
}
- p = extract_programmer_param("type");
- if (p && strcmp(p, "ec")) {
- msg_pdbg("mec1308 only supports \"ec\" type devices\n");
+ if (check_params()) {
ret = 1;
goto mec1308_init_exit;
}
@@ -515,7 +527,6 @@
msg_pdbg("%s(): successfully initialized mec1308\n", __func__);
mec1308_init_exit:
- free(p);
if (ret)
free(ctx_data);
return ret;
--
To view, visit https://review.coreboot.org/c/flashrom/+/52595
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: If5be7709e93233a2e7ea9133de50382d2524a55f
Gerrit-Change-Number: 52595
Gerrit-PatchSet: 1
Gerrit-Owner: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-MessageType: newchange
Attention is currently required from: Nico Huber, Edward O'Callaghan, Angel Pons.
Anastasia Klimchuk has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/51487 )
Change subject: tests: Add unit test to run init/shutdown for mec1308.c
......................................................................
Patch Set 7:
(3 comments)
Commit Message:
https://review.coreboot.org/c/flashrom/+/51487/comment/77061e68_df95ab50
PS6, Line 9: hwaccess_io.h
: because those are needed to test lifecycle of mec1308.c
> I would like to see one other example of ported i/o usage being addressed with the same test code to […]
Do you mean you would like to see more tests that are using mocked i/o, to ensure the approach works for different tests, and not only for one mec1308 test?
If yes, this is not a problem - I was going to write lots of test anyway. I will see which driver is a good another example, and will add another test in this patch. And then maybe we'll split.
File tests/tests.c:
https://review.coreboot.org/c/flashrom/+/51487/comment/9283f8fc_e9c511f1
PS6, Line 88: /*
: * Uncomment LOG_ME below for verbose logging.
: * It is commented by default because of too many calls.
: */
: /* LOG_ME; */
> does cmocka have a mechanism to allow verbosity to be tuned while running a test?
So far I was able to print everything or nothing, but I will look more into this. Those comments were not meant to be final solution.
There are several things to consider: the verbosity is needed most when someone is writing new test or debugging failed test, and less so when just running all existing tests to ensure they pass.
There are lots of i/o calls, maybe I can just count how many times they were called. Or have VERBOSE flag or something.
I plan to think more about this.
Just to be clear: in any case this patch is needed https://review.coreboot.org/c/flashrom/+/52496 , without it nothing is printed.
https://review.coreboot.org/c/flashrom/+/51487/comment/75a27607_7749bc98
PS6, Line 102: return ((port == 0x2e /* MEC1308_SIO_PORT1 */
: || port == 0x4e /* MEC1308_SIO_PORT2 */)
: ? 0x20 /* MEC1308_DEVICE_ID_REG */
: : ((outb_val == 0x84 /* MEC1308_MBX_DATA_START */)
: ? 0xaa /* MEC1308_CMD_PASSTHRU_SUCCESS */
: : 0));
> such values and logic may want to be encoded and stashed away within […]
The tricky thing is: inb needs to know what was the value of the last outb call.
You are right it would be ideal to have this code inside mec1308_init_and_shutdown_test_success() , but it's not obvious how to do it.
This is contained inside tests/ anyway, so it's easy and not risky to change the code.
What do you think?
--
To view, visit https://review.coreboot.org/c/flashrom/+/51487
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I3af612defe1af3850dfc1626a208d873e3a3eddc
Gerrit-Change-Number: 51487
Gerrit-PatchSet: 7
Gerrit-Owner: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Paul Menzel <paulepanter(a)mailbox.org>
Gerrit-Attention: Nico Huber <nico.h(a)gmx.de>
Gerrit-Attention: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Attention: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Comment-Date: Thu, 22 Apr 2021 04:19:30 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-MessageType: comment
Anastasia Klimchuk has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/52560 )
Change subject: jlink_spi.c: Refactor singleton states into reentrant pattern
......................................................................
Patch Set 1:
(1 comment)
Patchset:
PS1:
> I usually let patches sit for review at least 24 hours, so that people from all over the world have […]
Oh yes of course! I just wanted to say there is nothing more from my side. I didn't mean to rush or anything, sorry if my words looked like that!
--
To view, visit https://review.coreboot.org/c/flashrom/+/52560
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: If13ad0c979ccf62ca4ccbd479d471c657895ef59
Gerrit-Change-Number: 52560
Gerrit-PatchSet: 1
Gerrit-Owner: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: Miklós Márton <martonmiklosqdev(a)gmail.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Nico Huber <nico.h(a)gmx.de>
Gerrit-CC: Paul Menzel <paulepanter(a)mailbox.org>
Gerrit-CC: Sam McNally <sammc(a)google.com>
Gerrit-Comment-Date: Wed, 21 Apr 2021 22:32:53 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Angel Pons <th3fanbus(a)gmail.com>
Comment-In-Reply-To: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-MessageType: comment
Attention is currently required from: Anastasia Klimchuk.
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/52560 )
Change subject: jlink_spi.c: Refactor singleton states into reentrant pattern
......................................................................
Patch Set 1:
(1 comment)
Patchset:
PS1:
> Thanks people for reviews, I will address the comment(s) in the next patch. […]
I usually let patches sit for review at least 24 hours, so that people from all over the world have a chance to take a look. I'll revisit this patch tomorrow morning and submit it if no one has any objections. 😊
--
To view, visit https://review.coreboot.org/c/flashrom/+/52560
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: If13ad0c979ccf62ca4ccbd479d471c657895ef59
Gerrit-Change-Number: 52560
Gerrit-PatchSet: 1
Gerrit-Owner: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: Miklós Márton <martonmiklosqdev(a)gmail.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Nico Huber <nico.h(a)gmx.de>
Gerrit-CC: Paul Menzel <paulepanter(a)mailbox.org>
Gerrit-CC: Sam McNally <sammc(a)google.com>
Gerrit-Attention: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Comment-Date: Wed, 21 Apr 2021 21:39:54 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-MessageType: comment
Anastasia Klimchuk has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/52560 )
Change subject: jlink_spi.c: Refactor singleton states into reentrant pattern
......................................................................
Patch Set 1:
(2 comments)
Patchset:
PS1:
Thanks people for reviews, I will address the comment(s) in the next patch.
If anyone can submit this, it would be great!
File jlink_spi.c:
https://review.coreboot.org/c/flashrom/+/52560/comment/e611706b_7adeb0bd
PS1, Line 55: jaylink_c
> I'd move the `jaylink` part to the variable name, maybe shorten it to `jlink`. For example: […]
Sure, I will do the next patch for renaming.
--
To view, visit https://review.coreboot.org/c/flashrom/+/52560
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: If13ad0c979ccf62ca4ccbd479d471c657895ef59
Gerrit-Change-Number: 52560
Gerrit-PatchSet: 1
Gerrit-Owner: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: Miklós Márton <martonmiklosqdev(a)gmail.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Nico Huber <nico.h(a)gmx.de>
Gerrit-CC: Paul Menzel <paulepanter(a)mailbox.org>
Gerrit-CC: Sam McNally <sammc(a)google.com>
Gerrit-Comment-Date: Wed, 21 Apr 2021 21:20:31 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Edward O'Callaghan <quasisec(a)chromium.org>
Comment-In-Reply-To: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-MessageType: comment