Attention is currently required from: Julius Werner, Philipp Hug, ron minnich.

Alper Nebi Yasak has uploaded this change for review.

View Change

arch/io.h: Add stubs for x86 I/O port functions to other arches

The QEMU Bochs display driver and the QEMU Firmware Configuration
interface code (in the qemu-i440fx mainboard dir) were written for x86.
These devices are available in QEMU VMs of other architectures as well,
so we want to port them to be independent from x86.

The Bochs display driver already has an interesting pattern of using a
resource struct to choose whether to use I/O port instructions or MMIO.
We could simply continue with the MMIO code path on non-x86 arches, but
the x86-specific instructions cause a compile error on the other branch.

We could cover every port function call with #if CONFIG(ARCH_X86), but
that gets very cluttery. And it looks like it might be possible to
somehow access to I/O ports over MMIO, as far as I can tell from U-Boot
and Linux code.

For now, add unimplemented stubs for these functions for all other
architectures where they are missing, so that we can compile code using
that attempt to use them. Print error messages for visibility if they
are accidentally used as is.

Change-Id: If7d9177283e8c692088ba8e30d6dfe52623c8cb9
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
---
A src/arch/arm/include/armv4/arch/io.h
A src/arch/arm/include/armv7/arch/io.h
A src/arch/arm64/include/armv8/arch/io.h
A src/arch/riscv/include/arch/io.h
4 files changed, 312 insertions(+), 0 deletions(-)

git pull ssh://review.coreboot.org:29418/coreboot refs/changes/72/80372/1
diff --git a/src/arch/arm/include/armv4/arch/io.h b/src/arch/arm/include/armv4/arch/io.h
new file mode 100644
index 0000000..8bebd87
--- /dev/null
+++ b/src/arch/arm/include/armv4/arch/io.h
@@ -0,0 +1,78 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __ARCH_IO_H__
+#define __ARCH_IO_H__
+
+#include <stdint.h>
+#include <arch/mmio.h>
+#include <console/console.h>
+
+/*
+ * This file contains unimplemented stubs for the x86 IO instructions
+ * so we can compile code that can choose between these and MMIO access
+ * without having to use #if CONFIG(ARCH_X86) everywhere.
+ */
+static inline void outb(uint8_t value, uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void outw(uint16_t value, uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void outl(uint32_t value, uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline uint8_t inb(uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+ return 0;
+}
+
+static inline uint16_t inw(uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+ return 0;
+}
+
+static inline uint32_t inl(uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+ return 0;
+}
+
+static inline void outsb(uint16_t port, const void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void outsw(uint16_t port, const void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void outsl(uint16_t port, const void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void insb(uint16_t port, void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void insw(uint16_t port, void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void insl(uint16_t port, void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+#endif
diff --git a/src/arch/arm/include/armv7/arch/io.h b/src/arch/arm/include/armv7/arch/io.h
new file mode 100644
index 0000000..8bebd87
--- /dev/null
+++ b/src/arch/arm/include/armv7/arch/io.h
@@ -0,0 +1,78 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __ARCH_IO_H__
+#define __ARCH_IO_H__
+
+#include <stdint.h>
+#include <arch/mmio.h>
+#include <console/console.h>
+
+/*
+ * This file contains unimplemented stubs for the x86 IO instructions
+ * so we can compile code that can choose between these and MMIO access
+ * without having to use #if CONFIG(ARCH_X86) everywhere.
+ */
+static inline void outb(uint8_t value, uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void outw(uint16_t value, uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void outl(uint32_t value, uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline uint8_t inb(uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+ return 0;
+}
+
+static inline uint16_t inw(uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+ return 0;
+}
+
+static inline uint32_t inl(uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+ return 0;
+}
+
+static inline void outsb(uint16_t port, const void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void outsw(uint16_t port, const void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void outsl(uint16_t port, const void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void insb(uint16_t port, void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void insw(uint16_t port, void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void insl(uint16_t port, void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+#endif
diff --git a/src/arch/arm64/include/armv8/arch/io.h b/src/arch/arm64/include/armv8/arch/io.h
new file mode 100644
index 0000000..8bebd87
--- /dev/null
+++ b/src/arch/arm64/include/armv8/arch/io.h
@@ -0,0 +1,78 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __ARCH_IO_H__
+#define __ARCH_IO_H__
+
+#include <stdint.h>
+#include <arch/mmio.h>
+#include <console/console.h>
+
+/*
+ * This file contains unimplemented stubs for the x86 IO instructions
+ * so we can compile code that can choose between these and MMIO access
+ * without having to use #if CONFIG(ARCH_X86) everywhere.
+ */
+static inline void outb(uint8_t value, uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void outw(uint16_t value, uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void outl(uint32_t value, uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline uint8_t inb(uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+ return 0;
+}
+
+static inline uint16_t inw(uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+ return 0;
+}
+
+static inline uint32_t inl(uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+ return 0;
+}
+
+static inline void outsb(uint16_t port, const void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void outsw(uint16_t port, const void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void outsl(uint16_t port, const void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void insb(uint16_t port, void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void insw(uint16_t port, void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void insl(uint16_t port, void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+#endif
diff --git a/src/arch/riscv/include/arch/io.h b/src/arch/riscv/include/arch/io.h
new file mode 100644
index 0000000..8bebd87
--- /dev/null
+++ b/src/arch/riscv/include/arch/io.h
@@ -0,0 +1,78 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __ARCH_IO_H__
+#define __ARCH_IO_H__
+
+#include <stdint.h>
+#include <arch/mmio.h>
+#include <console/console.h>
+
+/*
+ * This file contains unimplemented stubs for the x86 IO instructions
+ * so we can compile code that can choose between these and MMIO access
+ * without having to use #if CONFIG(ARCH_X86) everywhere.
+ */
+static inline void outb(uint8_t value, uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void outw(uint16_t value, uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void outl(uint32_t value, uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline uint8_t inb(uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+ return 0;
+}
+
+static inline uint16_t inw(uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+ return 0;
+}
+
+static inline uint32_t inl(uint16_t port)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+ return 0;
+}
+
+static inline void outsb(uint16_t port, const void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void outsw(uint16_t port, const void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void outsl(uint16_t port, const void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void insb(uint16_t port, void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void insw(uint16_t port, void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+static inline void insl(uint16_t port, void *addr, unsigned long count)
+{
+ printk(BIOS_ERR, "arch/io.h: %s() not implemented\n", __func__);
+}
+
+#endif

To view, visit change 80372. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: main
Gerrit-Change-Id: If7d9177283e8c692088ba8e30d6dfe52623c8cb9
Gerrit-Change-Number: 80372
Gerrit-PatchSet: 1
Gerrit-Owner: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Gerrit-Reviewer: Julius Werner <jwerner@chromium.org>
Gerrit-Reviewer: Philipp Hug <philipp@hug.cx>
Gerrit-Reviewer: ron minnich <rminnich@gmail.com>
Gerrit-Attention: Philipp Hug <philipp@hug.cx>
Gerrit-Attention: Julius Werner <jwerner@chromium.org>
Gerrit-Attention: ron minnich <rminnich@gmail.com>
Gerrit-MessageType: newchange