From: Hajime Tazaki <thehajime@gmail.com>
To: linux-um@lists.infradead.org
Cc: Octavian Purdila <tavi.purdila@gmail.com>,
Akira Moroo <retrage01@gmail.com>
Subject: [RFC PATCH 16/47] lkl tools: host lib: memory mapped I/O helpers
Date: Wed, 23 Oct 2019 13:37:50 +0900 [thread overview]
Message-ID: <e96533a0d331dba6dd4a97f11b13d7d4c9f3cead.1571798507.git.thehajime@gmail.com> (raw)
In-Reply-To: <cover.1571798507.git.thehajime@gmail.com>
From: Octavian Purdila <tavi.purdila@gmail.com>
This patch adds helpers for implementing the memory mapped I/O host
operations that can be used by code that implements host
devices. Generic host operations for lkl_ioremap and lkl_iomem_access
are provided that allows multiplexing multiple I/O memory mapped
regions.
The host device code can create a new memory mapped I/O region with
register_iomem(). Read and write access functions need to be provided
by the caller.
Signed-off-by: Octavian Purdila <tavi.purdila@gmail.com>
---
tools/lkl/lib/iomem.c | 88 +++++++++++++++++++++++++++++++++++++++++++
tools/lkl/lib/iomem.h | 15 ++++++++
2 files changed, 103 insertions(+)
create mode 100644 tools/lkl/lib/iomem.c
create mode 100644 tools/lkl/lib/iomem.h
diff --git a/tools/lkl/lib/iomem.c b/tools/lkl/lib/iomem.c
new file mode 100644
index 000000000000..2301fe4e5ad5
--- /dev/null
+++ b/tools/lkl/lib/iomem.c
@@ -0,0 +1,88 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <string.h>
+#include <stdint.h>
+#include <lkl_host.h>
+
+#include "iomem.h"
+
+#define IOMEM_OFFSET_BITS 24
+#define MAX_IOMEM_REGIONS 256
+
+#define IOMEM_ADDR_TO_INDEX(addr) \
+ (((uintptr_t)addr) >> IOMEM_OFFSET_BITS)
+#define IOMEM_ADDR_TO_OFFSET(addr) \
+ (((uintptr_t)addr) & ((1 << IOMEM_OFFSET_BITS) - 1))
+#define IOMEM_INDEX_TO_ADDR(i) \
+ (void *)(uintptr_t)(i << IOMEM_OFFSET_BITS)
+
+static struct iomem_region {
+ void *data;
+ int size;
+ const struct lkl_iomem_ops *ops;
+} iomem_regions[MAX_IOMEM_REGIONS];
+
+void *register_iomem(void *data, int size, const struct lkl_iomem_ops *ops)
+{
+ int i;
+
+ if (size > (1 << IOMEM_OFFSET_BITS) - 1)
+ return NULL;
+
+ for (i = 1; i < MAX_IOMEM_REGIONS; i++)
+ if (!iomem_regions[i].ops)
+ break;
+
+ if (i >= MAX_IOMEM_REGIONS)
+ return NULL;
+
+ iomem_regions[i].data = data;
+ iomem_regions[i].size = size;
+ iomem_regions[i].ops = ops;
+ return IOMEM_INDEX_TO_ADDR(i);
+}
+
+void unregister_iomem(void *base)
+{
+ unsigned int index = IOMEM_ADDR_TO_INDEX(base);
+
+ if (index >= MAX_IOMEM_REGIONS) {
+ lkl_printf("%s: invalid iomem_addr %p\n", __func__, base);
+ return;
+ }
+
+ iomem_regions[index].size = 0;
+ iomem_regions[index].ops = NULL;
+}
+
+void *lkl_ioremap(long addr, int size)
+{
+ int index = IOMEM_ADDR_TO_INDEX(addr);
+ struct iomem_region *iomem = &iomem_regions[index];
+
+ if (index >= MAX_IOMEM_REGIONS)
+ return NULL;
+
+ if (iomem->ops && size <= iomem->size)
+ return IOMEM_INDEX_TO_ADDR(index);
+
+ return NULL;
+}
+
+int lkl_iomem_access(const volatile void *addr, void *res, int size, int write)
+{
+ int index = IOMEM_ADDR_TO_INDEX(addr);
+ struct iomem_region *iomem = &iomem_regions[index];
+ int offset = IOMEM_ADDR_TO_OFFSET(addr);
+ int ret;
+
+ if (index > MAX_IOMEM_REGIONS || !iomem_regions[index].ops ||
+ offset + size > iomem_regions[index].size)
+ return -1;
+
+ if (write)
+ ret = iomem->ops->write(iomem->data, offset, res, size);
+ else
+ ret = iomem->ops->read(iomem->data, offset, res, size);
+
+ return ret;
+}
diff --git a/tools/lkl/lib/iomem.h b/tools/lkl/lib/iomem.h
new file mode 100644
index 000000000000..0ad80ccc2626
--- /dev/null
+++ b/tools/lkl/lib/iomem.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LKL_LIB_IOMEM_H
+#define _LKL_LIB_IOMEM_H
+
+struct lkl_iomem_ops {
+ int (*read)(void *data, int offset, void *res, int size);
+ int (*write)(void *data, int offset, void *value, int size);
+};
+
+void *register_iomem(void *data, int size, const struct lkl_iomem_ops *ops);
+void unregister_iomem(void *iomem_base);
+void *lkl_ioremap(long addr, int size);
+int lkl_iomem_access(const volatile void *addr, void *res, int size, int write);
+
+#endif /* _LKL_LIB_IOMEM_H */
--
2.20.1 (Apple Git-117)
_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um
next prev parent reply other threads:[~2019-10-23 4:39 UTC|newest]
Thread overview: 132+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-23 4:37 [RFC PATCH 00/47] Unifying LKL into UML Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 01/47] asm-generic: atomic64: allow using generic atomic64 on 64bit platforms Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 02/47] kbuild: allow architectures to automatically define kconfig symbols Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 03/47] lkl: architecture skeleton for Linux kernel library Hajime Tazaki
2019-10-25 21:40 ` Richard Weinberger
2019-10-27 2:36 ` Hajime Tazaki
2019-10-29 4:04 ` Lai Jiangshan
2019-10-29 7:13 ` Hajime Tazaki
2019-10-29 7:57 ` Johannes Berg
2019-10-29 8:15 ` Richard Weinberger
2019-10-30 3:19 ` Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 04/47] lkl: host interface Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 05/47] lkl: memory handling Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 06/47] lkl: kernel threads support Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 07/47] lkl: interrupt support Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 08/47] lkl: system call interface and application API Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 09/47] lkl: timers, time and delay support Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 10/47] lkl: memory mapped I/O support Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 11/47] lkl: basic kernel console support Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 12/47] lkl: initialization and cleanup Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 13/47] lkl: plug in the build system Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 14/47] lkl tools: skeleton for host side library, tests and tools Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 15/47] lkl tools: host lib: add utilities functions Hajime Tazaki
2019-10-23 4:37 ` Hajime Tazaki [this message]
2019-10-23 4:37 ` [RFC PATCH 17/47] lkl tools: host lib: virtio devices Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 18/47] lkl tools: host lib: virtio block device Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 19/47] lkl tools: host lib: filesystem helpers Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 20/47] lkl tools: host lib: posix host operations Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 21/47] lkl tools: "boot" test Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 22/47] lkl tools: tool that converts a filesystem image to tar Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 23/47] lkl tools: tool that reads/writes to/from a filesystem image Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 24/47] lkl tools: virtio: add network device support Hajime Tazaki
2019-10-23 4:37 ` [RFC PATCH 25/47] lkl: add support for Windows hosts Hajime Tazaki
2019-10-23 4:38 ` [RFC PATCH 26/47] lkl tools: add support for Windows host Hajime Tazaki
2019-10-23 4:38 ` [RFC PATCH 27/47] lkl: Android ARM (arm/arm64) support Hajime Tazaki
2019-10-23 4:38 ` [RFC PATCH 28/47] lkl tools: add lklfuse Hajime Tazaki
2019-10-23 4:38 ` [RFC PATCH 29/47] lkl: add initial system call hijack support (a.k.a. NUSE of libos) Hajime Tazaki
2019-10-23 4:38 ` [RFC PATCH 30/47] lkl: add documentation Hajime Tazaki
2019-10-23 4:38 ` [RFC PATCH 31/47] cpu: add cpu_yield_to_irqs Hajime Tazaki
2019-10-23 4:38 ` [RFC PATCH 32/47] tools: Add the lkl host library to the common tools Makefile Hajime Tazaki
2019-10-23 4:38 ` [RFC PATCH 33/47] signal: use CONFIG_X86_32 instead of __i386__ Hajime Tazaki
2019-10-23 4:38 ` [RFC PATCH 34/47] arch: add __SYSCALL_DEFINE_ARCH Hajime Tazaki
2019-10-23 4:38 ` [RFC PATCH 35/47] xfs: support for non-mmu architectures Hajime Tazaki
2019-10-23 4:38 ` [RFC PATCH 36/47] checkpatch: avoid showing BIT_ULL warnings for tools/ files Hajime Tazaki
2019-10-23 4:38 ` [RFC PATCH 37/47] Revert "vmlinux.lds.h: remove stale <linux/export.h> include" Hajime Tazaki
2019-10-23 4:38 ` [RFC PATCH 38/47] Revert "export.h: remove code for prefixing symbols with underscore" Hajime Tazaki
2019-10-23 4:38 ` [RFC PATCH 39/47] Revert "linux/linkage.h: replace VMLINUX_SYMBOL_STR() with __stringify()" Hajime Tazaki
2019-10-23 4:38 ` [RFC PATCH 40/47] Revert "vmlinux.lds.h: remove no-op macro VMLINUX_SYMBOL()" Hajime Tazaki
2019-10-23 4:38 ` [RFC PATCH 41/47] Revert "kbuild: remove CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX" Hajime Tazaki
2019-10-23 4:38 ` [RFC PATCH 42/47] Revert "kallsyms: remove symbol prefix support" Hajime Tazaki
2019-10-23 4:38 ` [RFC PATCH 43/47] kallsyms: Add a config option to select section for kallsyms Hajime Tazaki
2019-10-23 4:38 ` [RFC PATCH 44/47] um lkl: use ARCH=um SUBARCH=lkl for tools/lkl Hajime Tazaki
2019-10-23 4:38 ` [RFC PATCH 45/47] um lkl: add CI tests Hajime Tazaki
2019-10-23 4:38 ` [RFC PATCH 46/47] um: use lkl virtio_net_tap device as UML device Hajime Tazaki
2019-10-23 4:38 ` [RFC PATCH 47/47] um: add lkl virtio-blk device Hajime Tazaki
2019-10-25 21:34 ` [RFC PATCH 00/47] Unifying LKL into UML Richard Weinberger
2019-10-27 2:34 ` Hajime Tazaki
2019-10-29 7:57 ` Johannes Berg
2019-10-29 15:45 ` Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 00/37] " Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 01/37] asm-generic: atomic64: allow using generic atomic64 on 64bit platforms Hajime Tazaki
2019-11-25 22:02 ` Richard Weinberger
2019-11-26 14:02 ` Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 02/37] arch: add __SYSCALL_DEFINE_ARCH Hajime Tazaki
2019-11-25 22:02 ` Richard Weinberger
2019-11-27 4:15 ` Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 03/37] lkl: architecture skeleton for Linux kernel library Hajime Tazaki
2019-11-25 22:00 ` Richard Weinberger
2019-11-26 11:42 ` Octavian Purdila
2019-11-26 14:17 ` Hajime Tazaki
2019-11-26 16:02 ` Richard Weinberger
2020-02-05 7:37 ` Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 04/37] lkl: host interface Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 05/37] lkl: memory handling Hajime Tazaki
2019-11-25 22:10 ` Richard Weinberger
2020-02-05 7:38 ` Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 06/37] lkl: kernel threads support Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 07/37] lkl: interrupt support Hajime Tazaki
2019-11-25 22:13 ` Richard Weinberger
2020-02-05 7:38 ` Hajime Tazaki
2020-02-05 10:49 ` Anton Ivanov
2020-02-05 14:24 ` Hajime Tazaki
2020-02-18 8:18 ` Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 08/37] lkl: system call interface and application API Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 09/37] lkl: timers, time and delay support Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 10/37] lkl: memory mapped I/O support Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 11/37] lkl: basic kernel console support Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 12/37] lkl: initialization and cleanup Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 13/37] lkl: plug in the build system Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 14/37] lkl tools: skeleton for host side library, tests and tools Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 15/37] lkl tools: host lib: add utilities functions Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 16/37] lkl tools: host lib: memory mapped I/O helpers Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 17/37] lkl tools: host lib: virtio devices Hajime Tazaki
2019-11-25 22:07 ` Richard Weinberger
2019-11-26 8:43 ` Johannes Berg
2019-11-26 8:50 ` Richard Weinberger
2019-11-26 8:52 ` Johannes Berg
2019-11-26 10:09 ` Richard Weinberger
2019-11-26 10:16 ` Johannes Berg
2019-11-26 10:42 ` Octavian Purdila
2019-11-26 10:49 ` Anton Ivanov
2019-11-27 4:06 ` Hajime Tazaki
2019-11-26 16:04 ` Richard Weinberger
2019-11-27 4:08 ` Hajime Tazaki
2019-11-27 14:28 ` Richard Weinberger
2019-11-28 9:53 ` Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 18/37] lkl tools: host lib: virtio block device Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 19/37] lkl tools: host lib: filesystem helpers Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 20/37] lkl tools: host lib: posix host operations Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 21/37] lkl tools: "boot" test Hajime Tazaki
2020-01-23 19:33 ` Brendan Higgins
2020-01-24 4:32 ` Hajime Tazaki
2020-03-02 19:51 ` Luis Chamberlain
2020-03-02 22:25 ` Brendan Higgins
2019-11-08 5:02 ` [RFC v2 22/37] lkl tools: tool that reads/writes to/from a filesystem image Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 23/37] lkl tools: tool that converts a filesystem image to tar Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 24/37] lkl tools: virtio: add network device support Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 25/37] checkpatch: avoid showing BIT_ULL warnings for tools/ files Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 26/37] tools: Add the lkl host library to the common tools Makefile Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 27/37] lkl tools: add lklfuse Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 28/37] lkl: add system call hijack support Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 29/37] lkl: add documentation Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 30/37] scripts: revert CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX patches Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 31/37] lkl: add support for Windows hosts Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 32/37] lkl tools: add support for Windows host Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 33/37] kallsyms: Add a config option to select section for kallsyms Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 34/37] lkl: Android ARM (arm/arm64) support Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 35/37] um lkl: add CI tests Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 36/37] um: use lkl virtio_net_tap device as UML device Hajime Tazaki
2019-11-08 5:02 ` [RFC v2 37/37] um: add lkl virtio-blk device Hajime Tazaki
2019-11-08 9:13 ` [RFC v2 00/37] Unifying LKL into UML Anton Ivanov
2019-11-08 11:17 ` Octavian Purdila
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e96533a0d331dba6dd4a97f11b13d7d4c9f3cead.1571798507.git.thehajime@gmail.com \
--to=thehajime@gmail.com \
--cc=linux-um@lists.infradead.org \
--cc=retrage01@gmail.com \
--cc=tavi.purdila@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).