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.
Tested: builds with both make and meson.
Change-Id: Ie08e2e6c51ccef5281386bf7e3df439b91573974
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/66651
Original-Reviewed-by: Thomas Heijligen <src@posteo.de>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/72349
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/Makefile b/Makefile
index 74bacaa..78b4d43 100644
--- a/Makefile
+++ b/Makefile
@@ -387,7 +387,7 @@
###############################################################################
# Library code.
-LIB_OBJS = libflashrom.o layout.o flashrom.o udelay.o programmer.o programmer_table.o \
+LIB_OBJS = libflashrom.o layout.o flashrom.o udelay.o parallel.o programmer.o programmer_table.o \
helpers.o helpers_fileio.o ich_descriptors.o fmap.o platform/endian_$(ENDIAN).o platform/memaccess.o
diff --git a/flashrom.c b/flashrom.c
index 4a8ab63..c7ad92c 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -223,47 +223,6 @@
msg_gspew("%s: unmapped 0x%0*" PRIxPTR "\n", __func__, PRIxPTR_WIDTH, (uintptr_t)virt_addr);
}
-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);
-}
-
void programmer_delay(unsigned int usecs)
{
if (usecs > 0)
diff --git a/include/flash.h b/include/flash.h
index efc2558..27b3aae 100644
--- a/include/flash.h
+++ b/include/flash.h
@@ -372,6 +372,7 @@
extern const struct flashchip flashchips[];
extern const unsigned int flashchips_size;
+/* parallel.c */
void chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
void chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
void chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
diff --git a/include/programmer.h b/include/programmer.h
index cbbbd26..8821f0e 100644
--- a/include/programmer.h
+++ b/include/programmer.h
@@ -394,15 +394,7 @@
};
int register_opaque_master(const struct opaque_master *mst, void *data);
-/* programmer.c */
-void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len);
-void fallback_unmap(void *virt_addr, size_t len);
-void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
-void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
-void fallback_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
-uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
-uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
-void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
+/* parallel.c */
struct par_master {
void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
@@ -416,6 +408,16 @@
void *data;
};
int register_par_master(const struct par_master *mst, const enum chipbustype buses, void *data);
+
+/* programmer.c */
+void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len);
+void fallback_unmap(void *virt_addr, size_t len);
+void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
+void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
+void fallback_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
+uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
+uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
+void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
struct registered_master {
enum chipbustype buses_supported;
union {
diff --git a/meson.build b/meson.build
index 4acecf6..67c6c01 100644
--- a/meson.build
+++ b/meson.build
@@ -94,6 +94,7 @@
'layout.c',
'libflashrom.c',
'opaque.c',
+ 'parallel.c',
'print.c',
'programmer.c',
'programmer_table.c',
diff --git a/parallel.c b/parallel.c
new file mode 100644
index 0000000..84692fd
--- /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;
+
+ 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.\n"
+ "Please report a bug at flashrom-stable@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);
+}
diff --git a/programmer.c b/programmer.c
index a8218a3..2b960e6 100644
--- a/programmer.c
+++ b/programmer.c
@@ -80,35 +80,6 @@
return;
}
-int register_par_master(const struct par_master *mst,
- const enum chipbustype buses,
- void *data)
-{
- struct registered_master rmst;
-
- 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.\n"
- "Please report a bug at flashrom-stable@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);
-}
-
/* The limit of 4 is totally arbitrary. */
#define MASTERS_MAX 4
struct registered_master registered_masters[MASTERS_MAX];