summaryrefslogtreecommitdiffstats
path: root/serprog.c
diff options
context:
space:
mode:
authorDavid Hendricks <dhendrix@google.com>2011-06-14 01:35:36 +0000
committerDavid Hendricks <david.hendricks@gmail.com>2011-06-14 01:35:36 +0000
commit8bb2021d77c8ee213b53d671687b7a1179335522 (patch)
treea77cc4239b59731e98cf6c9681b5a7c665613038 /serprog.c
parent9d9a1042332cd08aa66eee6f37d80c0f09f47d70 (diff)
downloadflashrom-8bb2021d77c8ee213b53d671687b7a1179335522.tar.gz
flashrom-8bb2021d77c8ee213b53d671687b7a1179335522.tar.bz2
flashrom-8bb2021d77c8ee213b53d671687b7a1179335522.zip
Use shutdown callback mechanism to shutdown programmers
This patch attempts to resolve some programmer shutdown ordering issues by having the programmer init functions register shutdown callbacks explicitly wherever it makes most sense. Before, assumptions were made that could lead to the internal programmer's state changing before the external programmer could be shut down properly. Now, each programmer cleans up after itself and (hopefully) performs each operation in the correct order. As a side-effect, this patch gives us a better usage model for reverse operations such as rpci_* and rmmio_*. In the long-run, this should make reversing the initialization process easier to understand, less tedious, and less error-prone. In short, this patch does the following: - Registers a shutdown callback during initialization for each programmer. - Kills the .shutdown function pointer from programmer_entry struct. Also, make most shutdown functions static. - Adds a few minor clean-ups and corrections (e.g. missing physunmap() calls). TODO: Remove forward declaration of serprog_shutdown() (added to simplify diff) Corresponding to flashrom svn r1338. Signed-off-by: David Hendricks <dhendrix@google.com> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Diffstat (limited to 'serprog.c')
-rw-r--r--serprog.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/serprog.c b/serprog.c
index f869b076e..b91e37674 100644
--- a/serprog.c
+++ b/serprog.c
@@ -39,6 +39,13 @@
#define MSGHEADER "serprog:"
+/*
+ * FIXME: This prototype was added to help reduce diffs for the shutdown
+ * registration patch, which shifted many lines of code to place
+ * serprog_shutdown() before serprog_init(). It should be removed soon.
+ */
+static int serprog_shutdown(void *data);
+
#define S_ACK 0x06
#define S_NAK 0x15
#define S_CMD_NOP 0x00 /* No operation */
@@ -373,6 +380,9 @@ int serprog_init(void)
return 1;
}
+ if (register_shutdown(serprog_shutdown, NULL))
+ return 1;
+
msg_pdbg(MSGHEADER "connected - attempting to synchronize\n");
sp_check_avail_automatic = 0;
@@ -555,7 +565,7 @@ static void sp_execute_opbuf(void)
sp_flush_stream();
}
-int serprog_shutdown(void)
+static int serprog_shutdown(void *data)
{
msg_pspew("%s\n", __func__);
if ((sp_opbuf_usage) || (sp_max_write_n && sp_write_n_bytes))