programmer/physmap: Introduce generic mmio_chip_read/write functions

Export these functions from the `internal` programmer. They can be used
used for other memory-mapping programmers as well. For instance PCI ex-
ansion ROMs that can be programmed through their ROM BAR mapping.

Change-Id: Ibd9b93914e16d586c0144a81fe70b30a2abffd94
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/528
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
diff --git a/include/programmer/physmap.h b/include/programmer/physmap.h
new file mode 100644
index 0000000..5654153
--- /dev/null
+++ b/include/programmer/physmap.h
@@ -0,0 +1,54 @@
+/*
+ * This file is part of the flashprog project.
+ *
+ * Copyright (C) 2026 Nico Huber <nico.h@gmx.de>
+ *
+ * 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 __PROGRAMMER_PHYSMAP_H__
+#define __PROGRAMMER_PHYSMAP_H__
+
+#include <stdint.h>
+
+#include "flash.h"		/* for chipaddr, *sigh* */
+#include "hwaccess_physmap.h"
+
+struct par_master;
+static inline void mmio_chip_writeb(const struct par_master *par, uint8_t val, chipaddr addr)
+{
+	mmio_writeb(val, (void *)addr);
+}
+static inline void mmio_chip_writew(const struct par_master *par, uint16_t val, chipaddr addr)
+{
+	mmio_writew(val, (void *)addr);
+}
+static inline void mmio_chip_writel(const struct par_master *par, uint32_t val, chipaddr addr)
+{
+	mmio_writel(val, (void *)addr);
+}
+static inline uint8_t mmio_chip_readb(const struct par_master *par, const chipaddr addr)
+{
+	return mmio_readb((void *)addr);
+}
+static inline uint16_t mmio_chip_readw(const struct par_master *par, const chipaddr addr)
+{
+	return mmio_readw((void *)addr);
+}
+static inline uint32_t mmio_chip_readl(const struct par_master *par, const chipaddr addr)
+{
+	return mmio_readl((void *)addr);
+}
+static inline void mmio_chip_readn(const struct par_master *par, uint8_t *buf, const chipaddr addr, size_t len)
+{
+	mmio_readn((void *)addr, buf, len);
+}
+
+#endif /* __PROGRAMMER_PHYSMAP_H__ */
diff --git a/internal.c b/internal.c
index 21066e4..7f9713a 100644
--- a/internal.c
+++ b/internal.c
@@ -19,6 +19,7 @@
 #include <stdbool.h>
 #include <stdlib.h>
 #include "programmer.h"
+#include "programmer/physmap.h"
 #include "hwaccess_physmap.h"
 #include "platform/pci.h"
 
@@ -60,21 +61,14 @@
 int is_laptop = 0;
 bool laptop_ok = false;
 
-static void internal_chip_writeb(const struct par_master *, uint8_t val, chipaddr);
-static void internal_chip_writew(const struct par_master *, uint16_t val, chipaddr);
-static void internal_chip_writel(const struct par_master *, uint32_t val, chipaddr);
-static uint8_t internal_chip_readb(const struct par_master *, chipaddr);
-static uint16_t internal_chip_readw(const struct par_master *, chipaddr);
-static uint32_t internal_chip_readl(const struct par_master *, chipaddr);
-static void internal_chip_readn(const struct par_master *, uint8_t *buf, chipaddr, size_t len);
 static const struct par_master par_master_internal = {
-	.chip_readb	= internal_chip_readb,
-	.chip_readw	= internal_chip_readw,
-	.chip_readl	= internal_chip_readl,
-	.chip_readn	= internal_chip_readn,
-	.chip_writeb	= internal_chip_writeb,
-	.chip_writew	= internal_chip_writew,
-	.chip_writel	= internal_chip_writel,
+	.chip_readb	= mmio_chip_readb,
+	.chip_readw	= mmio_chip_readw,
+	.chip_readl	= mmio_chip_readl,
+	.chip_readn	= mmio_chip_readn,
+	.chip_writeb	= mmio_chip_writeb,
+	.chip_writew	= mmio_chip_writew,
+	.chip_writel	= mmio_chip_writel,
 	.chip_writen	= fallback_chip_writen,
 	.map_flash	= physmap,
 	.unmap_flash	= physunmap,
@@ -324,43 +318,6 @@
 	return ret;
 }
 
-static void internal_chip_writeb(const struct par_master *par, uint8_t val, chipaddr addr)
-{
-	mmio_writeb(val, (void *) addr);
-}
-
-static void internal_chip_writew(const struct par_master *par, uint16_t val, chipaddr addr)
-{
-	mmio_writew(val, (void *) addr);
-}
-
-static void internal_chip_writel(const struct par_master *par, uint32_t val, chipaddr addr)
-{
-	mmio_writel(val, (void *) addr);
-}
-
-static uint8_t internal_chip_readb(const struct par_master *par, const chipaddr addr)
-{
-	return mmio_readb((void *) addr);
-}
-
-static uint16_t internal_chip_readw(const struct par_master *par, const chipaddr addr)
-{
-	return mmio_readw((void *) addr);
-}
-
-static uint32_t internal_chip_readl(const struct par_master *par, const chipaddr addr)
-{
-	return mmio_readl((void *) addr);
-}
-
-static void internal_chip_readn(const struct par_master *par, uint8_t *buf,
-				const chipaddr addr, size_t len)
-{
-	mmio_readn((void *)addr, buf, len);
-	return;
-}
-
 const struct programmer_entry programmer_internal = {
 	.name			= "internal",
 	.type			= OTHER,