aboutsummaryrefslogtreecommitdiffstats
path: root/parallel.c
diff options
context:
space:
mode:
authorEdward O'Callaghan <quasisec@google.com>2022-08-12 12:56:43 +1000
committerEdward O'Callaghan <quasisec@chromium.org>2022-08-25 00:29:00 +0000
commit8f9e910eb342799c582ee2c9569ffb4be6296719 (patch)
treead485edfa2df067c0eae7fbe7c4f6901eee86cd9 /parallel.c
parent16744f9e96d0f1e203d4a67ad2bfd0c50e3c437a (diff)
downloadflashrom-8f9e910eb342799c582ee2c9569ffb4be6296719.tar.gz
flashrom-8f9e910eb342799c582ee2c9569ffb4be6296719.tar.bz2
flashrom-8f9e910eb342799c582ee2c9569ffb4be6296719.zip
parallel.c: Consoldiate parallel master registration logic
This is analogous to spi.c and opaque.c however parallel logic was previously never consoldiated. This free's up flashrom.c from namespace pollution. BUG=b:242246291 TEST=builds with both make and meson. Change-Id: Ie08e2e6c51ccef5281386bf7e3df439b91573974 Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/66651 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Thomas Heijligen <src@posteo.de>
Diffstat (limited to 'parallel.c')
-rw-r--r--parallel.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/parallel.c b/parallel.c
new file mode 100644
index 00000000..9001fe80
--- /dev/null
+++ b/parallel.c
@@ -0,0 +1,93 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright (C) 2000 Silicon Integrated System Corporation
+ * Copyright (C) 2004 Tyan Corp <yhlu@tyan.com>
+ * Copyright (C) 2005-2008 coresystems GmbH
+ * Copyright (C) 2008,2009 Carl-Daniel Hailfinger
+ * Copyright (C) 2016 secunet Security Networks AG
+ * (Written by Nico Huber <nico.huber@secunet.com> for secunet)
+ * Copyright (C) 2009,2010,2011 Carl-Daniel Hailfinger
+ *
+ * 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 "flash.h"
+#include "programmer.h"
+
+void chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
+{
+ flash->mst->par.chip_writeb(flash, val, addr);
+}
+
+void chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr)
+{
+ flash->mst->par.chip_writew(flash, val, addr);
+}
+
+void chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr)
+{
+ flash->mst->par.chip_writel(flash, val, addr);
+}
+
+void chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len)
+{
+ flash->mst->par.chip_writen(flash, buf, addr, len);
+}
+
+uint8_t chip_readb(const struct flashctx *flash, const chipaddr addr)
+{
+ return flash->mst->par.chip_readb(flash, addr);
+}
+
+uint16_t chip_readw(const struct flashctx *flash, const chipaddr addr)
+{
+ return flash->mst->par.chip_readw(flash, addr);
+}
+
+uint32_t chip_readl(const struct flashctx *flash, const chipaddr addr)
+{
+ return flash->mst->par.chip_readl(flash, addr);
+}
+
+void chip_readn(const struct flashctx *flash, uint8_t *buf, chipaddr addr,
+ size_t len)
+{
+ flash->mst->par.chip_readn(flash, buf, addr, len);
+}
+
+int register_par_master(const struct par_master *mst,
+ const enum chipbustype buses,
+ void *data)
+{
+ struct registered_master rmst = {0};
+
+ if (mst->shutdown) {
+ if (register_shutdown(mst->shutdown, data)) {
+ mst->shutdown(data); /* cleanup */
+ return 1;
+ }
+ }
+
+ if (!mst->chip_writeb || !mst->chip_writew || !mst->chip_writel ||
+ !mst->chip_writen || !mst->chip_readb || !mst->chip_readw ||
+ !mst->chip_readl || !mst->chip_readn) {
+ msg_perr("%s called with incomplete master definition. "
+ "Please report a bug at flashrom@flashrom.org\n",
+ __func__);
+ return ERROR_FLASHROM_BUG;
+ }
+
+ rmst.buses_supported = buses;
+ rmst.par = *mst;
+ if (data)
+ rmst.par.data = data;
+ return register_master(&rmst);
+}