We should have I/O memory map API for user as
the memory should already be mapped when the I/O region
is ready to use.
However, as I/O memory mapping is still required on RTOS
and baremetal systems, we keep the I/O memory mapping
for library internal usage.
lib/device.c | 2 +-
lib/device.h | 4 +++
lib/io.c | 2 +-
lib/io.h | 31 -----------------
lib/system/freertos/CMakeLists.txt | 2 +-
lib/system/freertos/device.c | 64 +++++++++++++++++++++++++++++++++++
lib/system/freertos/io.c | 48 ---------------------------
lib/system/freertos/sys.h | 6 ++++
lib/system/freertos/zynq7/sys.c | 52 ++++-------------------------
lib/system/freertos/zynqmp_r5/sys.c | 27 +++------------
lib/system/generic/CMakeLists.txt | 2 +-
lib/system/generic/device.c | 66 +++++++++++++++++++++++++++++++++++++
lib/system/generic/io.c | 48 ---------------------------
lib/system/generic/sys.h | 6 ++++
lib/system/generic/zynq7/sys.c | 53 ++++-------------------------
lib/system/generic/zynqmp_r5/sys.c | 27 +++------------
lib/system/linux/CMakeLists.txt | 1 -
lib/system/linux/device.c | 10 ++++--
lib/system/linux/io.c | 44 -------------------------
19 files changed, 180 insertions(+), 315 deletions(-)
create mode 100644 lib/system/freertos/device.c
delete mode 100644 lib/system/freertos/io.c
create mode 100644 lib/system/generic/device.c
delete mode 100644 lib/system/generic/io.c
delete mode 100644 lib/system/linux/io.c
diff --git a/lib/device.c b/lib/device.c
index 79c1df2..063bf5d 100644
--- a/lib/device.c
+++ b/lib/device.c
@@ -145,7 +145,7 @@ static int metal_generic_dev_open(struct metal_bus *bus, const char *dev_name,
if (strcmp(dev->name, dev_name) != 0)
continue;
*device = dev;
- return 0;
+ return metal_generic_dev_sys_open(dev);
}
return -ENODEV;
diff --git a/lib/device.h b/lib/device.h
index 863b95c..3ba1d5e 100644
--- a/lib/device.h
+++ b/lib/device.h
@@ -171,6 +171,10 @@ metal_device_io_region(struct metal_device *device, unsigned index)
/** @} */
+#ifdef METAL_INTERNAL
+extern int metal_generic_dev_sys_open(struct metal_device *dev);
+#endif /* METAL_INTERNAL */
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/io.c b/lib/io.c
index 850f47b..5d08d7a 100644
--- a/lib/io.c
+++ b/lib/io.c
@@ -115,7 +115,7 @@ int metal_io_block_set(struct metal_io_region *io, unsigned long offset,
len = io->size - offset;
retlen = len;
if (io->ops.block_set) {
- retlen = (*io->ops.block_set)(
+ (*io->ops.block_set)(
io, offset, value, memory_order_seq_cst, len);
} else {
unsigned int cint = value;
diff --git a/lib/io.h b/lib/io.h
index 24905e9..e439beb 100644
--- a/lib/io.h
+++ b/lib/io.h
@@ -50,23 +50,6 @@ extern "C" {
/** \defgroup io IO Interfaces
* @{ */
-/** I/O memory flags macros for caching scheme */
-
-/** Cache bits */
-#define METAL_CACHE_UNKNOWN 0x0 /** Use cache, unknown cache type */
-#define METAL_UNCACHED 0x1 /** No cache */
-#define METAL_CACHE_WB 0x2 /** Write back */
-#define METAL_CACHE_WT 0x4 /** Write through */
-
-/** Memory types */
-#define METAL_MEM_MAPPED 0x10 /** Memory mapped */
-#define METAL_IO_MAPPED 0x20 /** I/O mapped */
-#define METAL_SHARED_MEM 0x40 /** Shared memory */
-
-/** DMA cache bits */
-#define METAL_DMA_NO_CACHE_OPS 0x0 /** No cache ops in DMA transaction */
-#define METAL_DMA_CACHE_OPS 0x1 /** Require cache ops in DMA transaction */
-
struct metal_io_region;
/** Generic I/O operations. */
@@ -378,20 +361,6 @@ int metal_io_block_write(struct metal_io_region *io, unsigned long offset,
int metal_io_block_set(struct metal_io_region *io, unsigned long offset,
unsigned char value, int len);
-/**
- * @brief libmetal memory map
- *
- * This function is to enable memory mapping to the specified I/O memory.
- *
- * @param[in] pa physical memory start address
- * @param[in] io memory region
- * @param[in] size size of the memory range
- * @return logical address if suceeded, or 0 if failed.
- */
-void *metal_io_mem_map(metal_phys_addr_t pa,
- struct metal_io_region *io,
- size_t size);
-
#ifdef __cplusplus
}
#endif
diff --git a/lib/system/freertos/CMakeLists.txt b/lib/system/freertos/CMakeLists.txt
index c21d676..b941dcd 100644
--- a/lib/system/freertos/CMakeLists.txt
+++ b/lib/system/freertos/CMakeLists.txt
@@ -6,8 +6,8 @@ collect (PROJECT_LIB_HEADERS condition.h)
collect (PROJECT_LIB_SOURCES init.c)
collect (PROJECT_LIB_SOURCES irq.c)
+collect (PROJECT_LIB_SOURCES device.c)
collect (PROJECT_LIB_SOURCES cache.c)
-collect (PROJECT_LIB_SOURCES io.c)
collect (PROJECT_LIB_SOURCES shmem.c)
collect (PROJECT_LIB_SOURCES condition.c)
collect (PROJECT_LIB_SOURCES time.c)
diff --git a/lib/system/freertos/device.c b/lib/system/freertos/device.c
new file mode 100644
index 0000000..1198b0d
--- /dev/null
+++ b/lib/system/freertos/device.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2017, Xilinx Inc. and Contributors. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of Xilinx nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * @file linux/bus.c
+ * @brief Linux libmetal bus definitions.
+ */
+
+#include "metal/device.h"
+#include "metal/sys.h"
+#include "metal/utilities.h"
+
+int metal_generic_dev_sys_open(struct metal_device *dev)
+{
+ struct metal_io_region *io;
+ unsigned long p;
+ size_t size;
+ void *va;
+ unsigned i;
+
+ /* map I/O memory regions */
+ for (i = 0; i < dev->num_regions; i++) {
+ io = &dev->regions[i];
+ va = io->virt;
+ size = io->size;
+ if (size >> io->page_shift)
+ size = (size_t)1 << io->page_shift;
+ for (p = 0; p <= (io->size >> io->page_shift); p++) {
+ metal_machine_io_mem_map(va, io->physmap[p],
+ size, io->mem_flags);
+ va += size;
+ }
+ }
+
+ return 0;
+}
+
diff --git a/lib/system/freertos/io.c b/lib/system/freertos/io.c
deleted file mode 100644
index e238ffc..0000000
--- a/lib/system/freertos/io.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2016, Xilinx Inc. and Contributors. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * 3. Neither the name of Xilinx nor the names of its contributors may be used
- * to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * @file freertos/io.c
- * @brief FreeRTOS libmetal I/O handling.
- */
-
-#include "metal/io.h"
-
-extern void metal_machine_io_mem_map(metal_phys_addr_t pa,
- size_t size, unsigned int flags);
-
-void *metal_io_mem_map(metal_phys_addr_t pa,
- struct metal_io_region *io, size_t size)
-{
- unsigned int flags = io->mem_flags;
- metal_machine_io_mem_map(pa, size, flags);
- return metal_io_phys_to_virt(io, pa);
-}
-
diff --git a/lib/system/freertos/sys.h b/lib/system/freertos/sys.h
index 3034ca4..7fef30a 100644
--- a/lib/system/freertos/sys.h
+++ b/lib/system/freertos/sys.h
@@ -69,6 +69,12 @@ void sys_irq_restore_enable(void);
*/
void sys_irq_save_disable(void);
+/**
+ * @brief memory mapping
+ */
+void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
+ size_t size, unsigned int flags);
+
#endif /* METAL_INTERNAL */
#ifdef __cplusplus
diff --git a/lib/system/freertos/zynq7/sys.c b/lib/system/freertos/zynq7/sys.c
index 7e60e79..735415d 100644
--- a/lib/system/freertos/zynq7/sys.c
+++ b/lib/system/freertos/zynq7/sys.c
@@ -51,28 +51,6 @@
/* Mask off lower bits of addr */
#define ARM_AR_MEM_TTB_SECT_SIZE_MASK (~(ARM_AR_MEM_TTB_SECT_SIZE-1UL))
-/* Define shift to convert memory address to index of translation table entry (descriptor).
- Shift 20 bits (for a 1MB section) - 2 bits (for a 4 byte TTB descriptor) */
-#define ARM_AR_MEM_TTB_SECT_TO_DESC_SHIFT (20-2)
-
-/* Macro used to make a 32-bit value with the specified bit set */
-#define ESAL_GE_MEM_32BIT_SET(bit_num) (1UL<<(bit_num))
-
-#define ARM_AR_MEM_TTB_DESC_BACKWARDS ESAL_GE_MEM_32BIT_SET(4)
-#define ARM_AR_MEM_TTB_DESC_AP_MANAGER (ESAL_GE_MEM_32BIT_SET(10) | \
- ESAL_GE_MEM_32BIT_SET(11))
-#define ARM_AR_MEM_TTB_DESC_SECT ESAL_GE_MEM_32BIT_SET(1)
-
-/* Define translation table descriptor bits */
-#define ARM_AR_MEM_TTB_DESC_B ESAL_GE_MEM_32BIT_SET(2)
-#define ARM_AR_MEM_TTB_DESC_C ESAL_GE_MEM_32BIT_SET(3)
-#define ARM_AR_MEM_TTB_DESC_TEX ESAL_GE_MEM_32BIT_SET(12)
-#define ARM_AR_MEM_TTB_DESC_S ESAL_GE_MEM_32BIT_SET(16)
-
-/* Define all access (manager access permission / not cachable / not bufferd) */
-#define ARM_AR_MEM_TTB_DESC_ALL_ACCESS (ARM_AR_MEM_TTB_DESC_AP_MANAGER | \
- ARM_AR_MEM_TTB_DESC_SECT)
-
static unsigned int int_old_val = XIL_EXCEPTION_ALL;
void sys_irq_restore_enable(void)
@@ -116,17 +94,17 @@ void __attribute__((weak)) metal_generic_default_poll(void)
asm volatile("wfi");
}
-void metal_machine_io_mem_map(metal_phys_addr_t pa,
+void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
size_t size, unsigned int flags)
{
unsigned int section_offset;
unsigned int ttb_addr;
- unsigned int ttb_value;
+ if (!flags)
+ return va;
/* Ensure the virtual and physical addresses are aligned on a
section boundary */
pa &= ARM_AR_MEM_TTB_SECT_SIZE_MASK;
- ttb_value = ARM_AR_MEM_TTB_DESC_ALL_ACCESS;
/* Loop through entire region of memory (one MMU section at a time).
Each section requires a TTB entry. */
@@ -136,27 +114,9 @@ void metal_machine_io_mem_map(metal_phys_addr_t pa,
/* Calculate translation table entry for this memory section */
ttb_addr = (pa + section_offset);
- /* Build translation table entry value */
-
- /* Set cache related bits in translation table entry.
- NOTE: Default is uncached instruction and data. */
- if ((flags & METAL_CACHE_WB)) {
- /* Update translation table entry value */
- ttb_value |=
- (ARM_AR_MEM_TTB_DESC_B |
- ARM_AR_MEM_TTB_DESC_C);
- } else if ((flags & METAL_CACHE_WT)) {
- /* Update translation table entry value */
- ttb_value |= ARM_AR_MEM_TTB_DESC_C;
- }
- /* In case of un-cached memory, set TEX 0 bit to set memory
- attribute to normal. */
- else if ((flags & METAL_UNCACHED)) {
- ttb_value |= ARM_AR_MEM_TTB_DESC_TEX;
- }
-
/* Write translation table entry value to entry address */
- Xil_SetTlbAttributes(ttb_addr, ttb_value);
-
+ Xil_SetTlbAttributes(ttb_addr, flags);
}
+
+ return va;
}
diff --git a/lib/system/freertos/zynqmp_r5/sys.c b/lib/system/freertos/zynqmp_r5/sys.c
index 1bcd186..6593102 100644
--- a/lib/system/freertos/zynqmp_r5/sys.c
+++ b/lib/system/freertos/zynqmp_r5/sys.c
@@ -89,31 +89,14 @@ void __attribute__((weak)) metal_generic_default_poll(void)
asm volatile("wfi");
}
-void metal_machine_io_mem_map(metal_phys_addr_t pa,
+void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
size_t size, unsigned int flags)
{
- unsigned int r5_flags;
size_t rsize = MPU_REGION_SIZE_MIN;
metal_phys_addr_t base_pa;
- /* Assume DEVICE_SHARED if nothing indicates this is memory. */
- r5_flags = DEVICE_SHARED;
- if ((flags & METAL_SHARED_MEM)) {
- r5_flags = NORM_SHARED_NCACHE;
- if ((flags & METAL_CACHE_WB)) {
- r5_flags = NORM_SHARED_WB_WA;
- } else if ((flags & METAL_CACHE_WT)) {
- r5_flags = NORM_SHARED_WT_NWA;
- }
- } else {
- r5_flags = NORM_NSHARED_NCACHE;
- if ((flags & METAL_CACHE_WB)) {
- r5_flags = NORM_NSHARED_WB_WA;
- } else if ((flags & METAL_CACHE_WT)) {
- r5_flags = NORM_NSHARED_WT_NWA;
- }
- }
-
+ if (!flags)
+ return va;
while(1) {
if (rsize < size) {
rsize <<= 1;
@@ -127,6 +110,6 @@ void metal_machine_io_mem_map(metal_phys_addr_t pa,
break;
}
}
- Xil_SetMPURegion(base_pa, rsize, r5_flags | PRIV_RW_USER_RW);
- return;
+ Xil_SetMPURegion(base_pa, rsize, flags);
+ return va;
}
diff --git a/lib/system/generic/CMakeLists.txt b/lib/system/generic/CMakeLists.txt
index 5e33671..03341b2 100644
--- a/lib/system/generic/CMakeLists.txt
+++ b/lib/system/generic/CMakeLists.txt
@@ -6,9 +6,9 @@ collect (PROJECT_LIB_HEADERS irq.h)
collect (PROJECT_LIB_SOURCES init.c)
collect (PROJECT_LIB_SOURCES shmem.c)
+collect (PROJECT_LIB_SOURCES device.c)
collect (PROJECT_LIB_SOURCES condition.c)
collect (PROJECT_LIB_SOURCES cache.c)
-collect (PROJECT_LIB_SOURCES io.c)
collect (PROJECT_LIB_SOURCES irq.c)
collect (PROJECT_LIB_SOURCES time.c)
collect (PROJECT_LIB_SOURCES sleep.c)
diff --git a/lib/system/generic/device.c b/lib/system/generic/device.c
new file mode 100644
index 0000000..f83153b
--- /dev/null
+++ b/lib/system/generic/device.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2017, Xilinx Inc. and Contributors. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of Xilinx nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * @file linux/bus.c
+ * @brief Linux libmetal bus definitions.
+ */
+
+#include "metal/device.h"
+#include "metal/sys.h"
+#include "metal/utilities.h"
+
+int metal_generic_dev_sys_open(struct metal_device *dev)
+{
+ struct metal_io_region *io;
+ unsigned long p;
+ size_t size;
+ void *va;
+ unsigned i;
+
+ /* map I/O memory regions */
+ for (i = 0; i < dev->num_regions; i++) {
+ io = &dev->regions[i];
+ va = io->virt;
+ size = io->size;
+ if (!size)
+ break;
+ if (size >> io->page_shift)
+ size = (size_t)1 << io->page_shift;
+ for (p = 0; p <= (io->size >> io->page_shift); p++) {
+ metal_machine_io_mem_map(va, io->physmap[p],
+ size, io->mem_flags);
+ va += size;
+ }
+ }
+
+ return 0;
+}
+
diff --git a/lib/system/generic/io.c b/lib/system/generic/io.c
deleted file mode 100644
index 5bff6bf..0000000
--- a/lib/system/generic/io.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2016, Xilinx Inc. and Contributors. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * 3. Neither the name of Xilinx nor the names of its contributors may be used
- * to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * @file generic/io.c
- * @brief Generic libmetal I/O handling.
- */
-
-#include "metal/io.h"
-
-extern void metal_machine_io_mem_map(metal_phys_addr_t pa,
- size_t size, unsigned int flags);
-
-void *metal_io_mem_map(metal_phys_addr_t pa,
- struct metal_io_region *io, size_t size)
-{
- unsigned int flags = io->mem_flags;
- metal_machine_io_mem_map(pa, size, flags);
- return metal_io_phys_to_virt(io, pa);
-}
-
diff --git a/lib/system/generic/sys.h b/lib/system/generic/sys.h
index c3607f7..56415eb 100644
--- a/lib/system/generic/sys.h
+++ b/lib/system/generic/sys.h
@@ -78,6 +78,12 @@ void sys_irq_restore_enable(void);
*/
void sys_irq_save_disable(void);
+/**
+ * @brief memory mapping
+ */
+void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
+ size_t size, unsigned int flags);
+
#endif /* METAL_INTERNAL */
#ifdef __cplusplus
diff --git a/lib/system/generic/zynq7/sys.c b/lib/system/generic/zynq7/sys.c
index 39d8259..212918e 100644
--- a/lib/system/generic/zynq7/sys.c
+++ b/lib/system/generic/zynq7/sys.c
@@ -51,29 +51,6 @@
/* Mask off lower bits of addr */
#define ARM_AR_MEM_TTB_SECT_SIZE_MASK (~(ARM_AR_MEM_TTB_SECT_SIZE-1UL))
-/* Define shift to convert memory address to index of translation table entry (descriptor).
- Shift 20 bits (for a 1MB section) - 2 bits (for a 4 byte TTB descriptor) */
-#define ARM_AR_MEM_TTB_SECT_TO_DESC_SHIFT (20-2)
-
-/* Macro used to make a 32-bit value with the specified bit set */
-#define ESAL_GE_MEM_32BIT_SET(bit_num) (1UL<<(bit_num))
-
-#define ARM_AR_MEM_TTB_DESC_BACKWARDS ESAL_GE_MEM_32BIT_SET(4)
-#define ARM_AR_MEM_TTB_DESC_AP_MANAGER (ESAL_GE_MEM_32BIT_SET(10) | \
- ESAL_GE_MEM_32BIT_SET(11))
-#define ARM_AR_MEM_TTB_DESC_SECT ESAL_GE_MEM_32BIT_SET(1)
-
-/* Define translation table descriptor bits */
-#define ARM_AR_MEM_TTB_DESC_B ESAL_GE_MEM_32BIT_SET(2)
-#define ARM_AR_MEM_TTB_DESC_C ESAL_GE_MEM_32BIT_SET(3)
-#define ARM_AR_MEM_TTB_DESC_TEX ESAL_GE_MEM_32BIT_SET(12)
-#define ARM_AR_MEM_TTB_DESC_S ESAL_GE_MEM_32BIT_SET(16)
-
-/* Define all access (manager access permission / not cachable / not bufferd) */
-#define ARM_AR_MEM_TTB_DESC_ALL_ACCESS (ARM_AR_MEM_TTB_DESC_AP_MANAGER | \
- ARM_AR_MEM_TTB_DESC_SECT)
-
-
static unsigned int int_old_val = XIL_EXCEPTION_ALL;
void sys_irq_restore_enable(void)
@@ -117,17 +94,17 @@ void __attribute__((weak)) metal_generic_default_poll(void)
asm volatile("wfi");
}
-void metal_machine_io_mem_map(metal_phys_addr_t pa,
+void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
size_t size, unsigned int flags)
{
unsigned int section_offset;
unsigned int ttb_addr;
- unsigned int ttb_value;
+ if (!flags)
+ return va;
/* Ensure the virtual and physical addresses are aligned on a
section boundary */
pa &= ARM_AR_MEM_TTB_SECT_SIZE_MASK;
- ttb_value = ARM_AR_MEM_TTB_DESC_ALL_ACCESS;
/* Loop through entire region of memory (one MMU section at a time).
Each section requires a TTB entry. */
@@ -137,27 +114,9 @@ void metal_machine_io_mem_map(metal_phys_addr_t pa,
/* Calculate translation table entry for this memory section */
ttb_addr = (pa + section_offset);
- /* Build translation table entry value */
-
- /* Set cache related bits in translation table entry.
- NOTE: Default is uncached instruction and data. */
- if ((flags & METAL_CACHE_WB)) {
- /* Update translation table entry value */
- ttb_value |=
- (ARM_AR_MEM_TTB_DESC_B |
- ARM_AR_MEM_TTB_DESC_C);
- } else if ((flags & METAL_CACHE_WT)) {
- /* Update translation table entry value */
- ttb_value |= ARM_AR_MEM_TTB_DESC_C;
- }
- /* In case of un-cached memory, set TEX 0 bit to set memory
- attribute to normal. */
- else if ((flags & METAL_UNCACHED)) {
- ttb_value |= ARM_AR_MEM_TTB_DESC_TEX;
- }
-
/* Write translation table entry value to entry address */
- Xil_SetTlbAttributes(ttb_addr, ttb_value);
-
+ Xil_SetTlbAttributes(ttb_addr, flags);
}
+
+ return va;
}
diff --git a/lib/system/generic/zynqmp_r5/sys.c b/lib/system/generic/zynqmp_r5/sys.c
index 74c305f..9891fdf 100644
--- a/lib/system/generic/zynqmp_r5/sys.c
+++ b/lib/system/generic/zynqmp_r5/sys.c
@@ -89,31 +89,14 @@ void __attribute__((weak)) metal_generic_default_poll(void)
asm volatile("wfi");
}
-void metal_machine_io_mem_map(metal_phys_addr_t pa,
+void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
size_t size, unsigned int flags)
{
- unsigned int r5_flags;
size_t rsize = MPU_REGION_SIZE_MIN;
metal_phys_addr_t base_pa;
- /* Assume DEVICE_SHARED if nothing indicates this is memory. */
- r5_flags = DEVICE_SHARED;
- if ((flags & METAL_SHARED_MEM)) {
- r5_flags = NORM_SHARED_NCACHE;
- if ((flags & METAL_CACHE_WB)) {
- r5_flags = NORM_SHARED_WB_WA;
- } else if ((flags & METAL_CACHE_WT)) {
- r5_flags = NORM_SHARED_WT_NWA;
- }
- } else {
- r5_flags = NORM_NSHARED_NCACHE;
- if ((flags & METAL_CACHE_WB)) {
- r5_flags = NORM_NSHARED_WB_WA;
- } else if ((flags & METAL_CACHE_WT)) {
- r5_flags = NORM_NSHARED_WT_NWA;
- }
- }
-
+ if (!flags)
+ return va;
while(1) {
if (rsize < size) {
rsize <<= 1;
@@ -127,6 +110,6 @@ void metal_machine_io_mem_map(metal_phys_addr_t pa,
break;
}
}
- Xil_SetMPURegion(base_pa, rsize, r5_flags | PRIV_RW_USER_RW);
- return;
+ Xil_SetMPURegion(base_pa, rsize, flags);
+ return va;
}
diff --git a/lib/system/linux/CMakeLists.txt b/lib/system/linux/CMakeLists.txt
index 86aa72d..4049c51 100644
--- a/lib/system/linux/CMakeLists.txt
+++ b/lib/system/linux/CMakeLists.txt
@@ -11,7 +11,6 @@ collect (PROJECT_LIB_SOURCES utilities.c)
collect (PROJECT_LIB_SOURCES condition.c)
collect (PROJECT_LIB_SOURCES irq.c)
collect (PROJECT_LIB_SOURCES cache.c)
-collect (PROJECT_LIB_SOURCES io.c)
collect (PROJECT_LIB_SOURCES time.c)
collect (PROJECT_LIB_SOURCES sleep.c)
diff --git a/lib/system/linux/device.c b/lib/system/linux/device.c
index 6966e25..2e858b8 100644
--- a/lib/system/linux/device.c
+++ b/lib/system/linux/device.c
@@ -249,8 +249,7 @@ static int metal_uio_dev_open(struct linux_bus *lbus, struct linux_device *ldev)
metal_map(ldev->fd, offset, size, 0, 0, &virt));
if (!result) {
io = &ldev->device.regions[ldev->device.num_regions];
- metal_io_init(io, virt, phys, size, -1,
- METAL_UNCACHED | METAL_IO_MAPPED, NULL);
+ metal_io_init(io, virt, phys, size, -1, 0, NULL);
ldev->device.num_regions++;
}
}
@@ -619,3 +618,10 @@ void metal_linux_bus_finish(void)
metal_bus_unregister(bus);
}
}
+
+int metal_generic_dev_sys_open(struct metal_device *dev)
+{
+ (void)dev;
+ return 0;
+}
+
diff --git a/lib/system/linux/io.c b/lib/system/linux/io.c
deleted file mode 100644
index 31c82b6..0000000
--- a/lib/system/linux/io.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2016, Xilinx Inc. and Contributors. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * 3. Neither the name of Xilinx nor the names of its contributors may be used
- * to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * @file linux/io.c
- * @brief Linux libmetal I/O handling.
- */
-
-#include "metal/io.h"
-
-void *metal_io_mem_map(metal_phys_addr_t pa,
- struct metal_io_region *io, size_t size)
-{
- (void)size;
- return metal_io_phys_to_virt(io, pa);
-}
-
--
2.7.4