Commit Graph
380 Commits
Author SHA1 Message Date
Iuliana Prodan 961d0171a6 io: fix buffer overflow in metal_sys_io_mem_map()
In metal_sys_io_mem_map() if the I/O region size
is a multiple of (1<<page_shift) will result in a
buffer overflow in the for loop.

Therefore, adjust loop termination condition to
prevent accessing an out-of-bounds page.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2025-02-14 16:40:24 +01:00
Bowen Wang 465fcf018c lib: system: nuttx: change MUTEX_INITIALIZER to NXMUTEX_INITIALIZER
Now nuttx uses NXMUTEX_INITIALIZER to initialize the mutex, so updated.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-11-26 13:54:36 +01:00
Arnaud Pouliquen 289e4de876 lib: processor: hosted: Fix compilation warning in metal_cpu_yield
Fix cross inclusion between metal/sys.h and /processor/hosted/cpu.h

The fix consists in creating a cpu.c file to avoid inline declaration.

Issue reported by Zephyr twister CI test:

libmetal/lib/include/metal/processor/hosted/cpu.h:19:9:
error: implicit declaration of function ‘metal_wait_usec’
   19 |         metal_wait_usec(10);
      |         ^~~~~~~~~~~~~~~
libmetal/lib/include/metal/system/zephyr/sys.h:46:20:
error: conflicting types for ‘metal_wait_usec’; have ‘void(uint32_t)’
   46 | static inline void metal_wait_usec(uint32_t usec_to_wait)
      |                    ^~~~~~~~~~~~~~~
libmetal/lib/include/metal/processor/hosted/cpu.h:19:9:
note: previous implicit declaration of ‘metal_wait_usec’ with
type ‘void(uint32_t)’ {aka ‘void(unsigned int)’}
   19 |         metal_wait_usec(10);
      |         ^~~~~~~~~~~~~~~

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2024-10-25 23:23:01 +02:00
Yongrong Wang 7f351a5158 lib: fix compile error
lib/errno.h: defined(__ARMCC_VERSION) for use GCC compile
lib/autmoic:fix compiler error:
nuttx/include/metal/compiler/gcc/atomic.h:19:13: error: conflicting type
qualifiers for 'atomic_flag'
19 | typedef int atomic_flag;
| ^~~~~~~~~~~
In file included from nuttx/include/nuttx/net/netdev_lowerhalf.h:38,
from virtio/virtio-net.c:33:
prebuilts/gcc/linux/arm/lib/gcc/arm-none-eabi/13.2.1/include/
stdatomic.h:233:3: note: previous declaration of 'atomic_flag' with
type 'atomic_flag'
233 | } atomic_flag;
| ^~~~~~~~~~~
nuttx/include/metal/compiler/gcc/atomic.h:20:14: error: conflicting
type qualifiers for 'atomic_char'
20 | typedef char atomic_char;
^~~~~~~~~~~

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
2024-10-21 13:57:15 +02:00
Arnaud Pouliquen 1ed90fd967 lib: system: fix missing metal_yield API for generic systems.
The metal_yield API needs also to be declared for the baremetal systems.
This fix build issue in Open-amp for generic system:

/github/workspace/open-amp/lib/rpmsg/rpmsg_virtio.c:275:17:
error: implicit declaration of function 'metal_yield'
275 |                 metal_yield();
    |                 ^~~~~~~~~~~

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2024-10-21 10:50:58 +02:00
Yongrong Wang 142c40321e lib: system: create a new libmetal API metal_yield
Define metal_yield in sys.h files is more flexible to manage this
in libmetal, metal_yield would be managed at the OS level and
dispatched to metal_cpu_yield, metal_sleep_usec, or others.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
2024-10-21 09:17:06 +02:00
Yongrong Wang e2c504f219 lib: system: nuttx: fix undeclared parameter compile error
Fix compile error:
/nuttx/openamp/libmetal/lib/system/nuttx/device.c:16:22: error:
'io' undeclared (first use in this function)
   16 |         metal_unused(io);
/nuttx/openamp/libmetal/lib/system/nuttx/device.c:14:53: error:
unused parameter 'dev' [-Werror=unused-parameter]
   14 | int metal_generic_dev_sys_open(struct metal_device *dev)
...

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
2024-10-18 10:22:17 +02:00
Andrew Davis 0f0393503e lib: system: linux: Remove unneeded forward declaration
The declaration metal_linux_bus_close() is not needed, it is already
defined at this point.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-10-18 09:12:43 +02:00
Andrew Davis 6b0b1cbb1d lib: system: linux: Remove unused sysfs_path from metal_state
This is not used, remove to prevent failures related to getting a
path that is not needed.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-10-18 09:12:43 +02:00
Andrew Davis 13428794f1 lib: system: linux: Inline metal_mlock() function
This is a one-line one user internal function, just use mlock directly.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-10-18 09:12:43 +02:00
Andrew Davis 4202dd3563 lib: system: linux: Move metal_virt2phys() into shmem
This function is only used by shmem. Move it to where it is used to
reduce internal-only "API" functions.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-10-18 09:12:43 +02:00
Andrew Davis af3a028338 lib: system: linux: Remove use of ENOSYS error code
This return code is for system calls only, and checkpatch warns about the
same. Remove the use of this return code.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-10-18 09:12:43 +02:00
Andrew Davis efb8ade752 lib: system: linux: Remove unused internal functions
These functions are labeled METAL_INTERNAL so should have no external
users, but they are not used internally either. Remove these functions.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-10-18 09:12:43 +02:00
Bowen Wang 7969bed068 lib: system nuttx: include <stddef.h> in nuttx/io.c
Because nuttx/io.c use NULL and NULL is defined in <stddef.h>.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-10-18 09:03:16 +02:00
Ben Levinsky eb82854950 lib: xlnx: Update logic to pull in vendor-specific logic based on PROJECT_VENDOR
Simplify logic that coordinates when to pull in Xilinx-AMD BSP and setup code
basedd on new CMake variable 'PROJECT_VENDOR'.

Add PROJECT_VENDOR check in cmake/options.cmake for case where PROJECT_VENDOR
is not defined.

Signed-off-by: Ben Levinsky <ben.levinsky@amd.com>
2024-08-15 06:55:16 -04:00
Andrew Davis e1a78ed150 lib: Fix available error message in softirq
This message should state that there are no more available Soft IRQs.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-05-23 09:42:48 +02:00
Arnaud Pouliquen 1de0f27d7d lib: fix doxygen warning in log.h
fix following warning:

lib/log.h:91: warning: argument 'args...' of command @param is not found
in the argumentlist of metal_log(level, fmt, args...)
lib/log.h:98: warning: The following parameter of
metal_log(level, fmt, args...) is not documented:
  parameter 'args...'

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2024-05-20 09:33:08 +02:00
Andrew Davis d52e69bb79 lib: Do not label function declarations in headers with extern
This is not needed for function declarations, they already have
implicit external linkage.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-05-20 09:27:36 +02:00
Rajiv Mohan 5bab7225ca lib: system: MPU flag check fix for xilinx platform
Check if valid MPU flag is set or not. Current condition checks
if flag is 0 or not, which is not intended use of flags

Signed-off-by: Rajiv Mohan <rajiv.mohan@amd.com>
2024-02-23 10:19:23 +01:00
Bowen Wang f21fea6c32 libmetal/nuttx/io.c: width matched access when read/write size = 1,2,4,8
Follow the virtio spec v1.2:
The driver MUST only use 32 bit wide and aligned reads and writes to access
the control registers described in table 4.1. For the device-specific
configuration space, the driver MUST use 8 bit wide accesses for 8 bit
wide fields, 16 bit wide and aligned accesses for 16 bit wide fields
and 32 bit wide and aligned accesses for 32 and 64 bit wide fields.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2024-02-23 09:48:42 +01:00
Rajiv Mohan 5d93a3c193 FreeRTOS Avoid mem mapping in MPU for region mapped
FreeRTOS patch for Avoiding memory mapping in MPU config table for region
that are already mapped by bsp and no change in attribute property

Signed-off-by: Rajiv Mohan <rajiv.mohan@amd.com>
2024-02-19 14:11:14 +01:00
Rajiv Mohan 3517a07836 lib: xlnx: Avoid mapping in MPU for region mapped by bsp
Avoiding memory mapping in MPU config table for region that are already
mapped by bsp and no change in attribute property.

Signed-off-by: Rajiv Mohan <rajiv.mohan@amd.com>
Signed-off-by: Tanmay Shah <tanmay.shah@amd.com>
2024-02-19 09:28:46 +01:00
Ben Levinsky 224cdea188 lib: generic: xlnx: Enable CMake handling for System Device Tree Flow
For AMD-Xilinx tooling, there is a new System Device Tree  (SDT) BSP
with different symbols for GIC than the classic BSP. This causes issues
when linking Libmetal against the SDT Flow BSP. Note that there is a
planned deprecation of the classic BSP.

For AMD-Xilinx System Device Tree (SDT) Flow, one of the files provided
by BSP is bspconfig.h. This file provides reference to the symbols that
describe GIC Device ID and GIC distributor Base Address. AMD-Xilinx
tools that use the SDT Flow BSP will provide symbol 'SDT' to signal that
the SDT Flow BSP is present. If SDT symbol is present then the Libmetal
build will include the new header "lib/system/generic/xlnx/sdt.h" to
preserve library build.

Signed-off-by: Ben Levinsky <ben.levinsky@amd.com>
2023-12-20 14:10:05 +01:00
Johan Hedberg f55c02a7b5 Zephyr integration: Use K_HEAP_MEM_POOL_SIZE
This define should be used instead of the Kconfig option to determine if
the k_malloc family of functions are available.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2023-12-15 09:41:58 +01:00
Daniel Leung f3f365d3f4 zephyr: use k_cpu_idle instead of arch_cpu_idle
arch_cpu_idle() is an internal API that should not be used
outside of the main Zephyr. Use k_cpu_idle() instead, which
is the same thing (at least for now).

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-11-20 11:38:28 +01:00
Alberto Escolar Piedras 85fb13958d Refactor equal processor headers into new generic ones
Refactor all processor headers which had the same content
into a generic set, to reduce the number of duplicates.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-11-10 14:04:39 +01:00
Alberto Escolar Piedras dabb14f677 Add support for hosted test environments
Add a new hosted test environment "processor".

This is meant as a build target used when the
code is not built for a real target
but as part of a test in a hosted environment
(for ex. as a test environment like Zephyr's
native_sim target).

When building for this target PROJECT_PROCESSOR
should be set as "hosted".

In this, the "metal_sleep_usec()" call
is expected to be provided by the system folder
headers.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-11-10 14:04:39 +01:00
Alberto Escolar Piedras 0a67afa94e Zephyr integration: Add support for hosted test environment
Provide the metal_sleep_usec() required for hosted
environments.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-11-10 14:04:39 +01:00
Ledion Daja 8041e1c276 lib: add guards for errno values for ARMCC compiler
The new guards prevent redefinition of errno values which have already
been defined in the standard libraries.

Signed-off-by: Ledion Daja <ledion.daja@arm.com>
2023-11-06 14:28:26 +01:00
Arnaud Pouliquen 9855f84ae9 lib: compiler support of arm compiler v6
The predefined macro __CC_ARM available on 5.x is migrated to the
macro __arm__ for the version 6.x. Add defines to support both versions.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2023-11-06 14:27:22 +01:00
Guiding Li 694620ff25 libmetal: set ept address loop++ in bitmap
CPU0                                CPU1
create_ept1:addr1                   create_ept1
OK                       <======    msg1
OK                       <======    msg2
OK                       <======    msg3
                           msg4
                         <======    msg4 on the virtioqueue
close_ept1                          close_ept1

create_ept2:addr1                   create_ept1
(same addr with ept1)
                           msg4
ept2 recv ept1 msg ERROR <======

The msg4 which belong to ep1, error received by ept2.

For the issue, I give a resolve method,
for the rpmsg_get_address(), always return a new increased num.

Signed-off-by: Guiding Li <liguiding1@xiaomi.com>
2023-10-31 18:50:02 +01:00
Guiding Li e087ea5d38 libmetal: add metal_list_for_each_safe() support
Add a more secure way to traverse linked lists

Signed-off-by: Guiding Li <liguiding1@xiaomi.com>
2023-10-31 18:44:47 +01:00
Ben Levinsky f6a87a8cdb lib: freertos: consolidate common Xilinx code
Move common code in Xilinx area to consolidated location to remove
redundant code.

Enable A72 and A78 build in BSP for FreeRTOS OS.

Signed-off-by: Ben Levinsky <ben.levinsky@amd.com>
2023-10-17 19:08:08 +02:00
Ben Levinsky 45a8edaddd lib: generic: consolidate common Xilinx code
Move common code in Xilinx area to consolidated location to remove
redundant code.

Enable A72 and A78 build in Standalone BSP.

lib: generic: Add support for a78 with System Device Tree flow

System Device Tree workflow is AMD-Xilinx workflow whereby the BSP,
libraries and applications in software are derived from a
hardware-design. The hardware-design is used to generate a system
device tree (SDT) that describes information for Linux and other
processing environments.

The xreg/xcpu files are not generated for SDT workflow. Because of
this do not include if SDT symbol is present in BSP.

Signed-off-by: Ben Levinsky <ben.levinsky@amd.com>
2023-10-17 19:08:08 +02:00
Ben Levinsky 9dd72ddbfd lib: a53: remove redundant MB and GB macros
lib/utilities.h provided MB and GB macros so include from there
instead of providing the definition again for a53 platforms.

Signed-off-by: Ben Levinsky <ben.levinsky@amd.com>
2023-10-17 19:08:08 +02:00
Arnaud Pouliquen 9fe00e0582 Remove vim editor configuration in files
Remove all remaining instances of "# vim: ..." in files.
This vim settings were part of the initial commit. But no reason
to keep them.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2023-10-17 09:02:59 +02:00
Sergei Korneichuk 37f1660b20 log: add function name, line number prefix
Add convenience macros metal_err, metal_warn, metal_info, metal_dbg
to avoid using excessively long and redundant metal_log(METAL_LOG_*).
Add "function-name:line-number" prefix to all messages if the option
WITH_FUNC_LINE_LOG is set ON during the configuration phase.

Signed-off-by: Sergei Korneichuk <sergei.korneichuk@amd.com>
2023-10-13 18:26:14 +02:00
Tanmay Shah 0ad1183a82 lib: utilities: add MB and GB defines
If MB and GB definition is not available then define new ones

Signed-off-by: Tanmay Shah <tanmay.shah@amd.com>
2023-09-11 09:48:39 +02:00
Ben Levinsky 6d571fd068 lib: system: freertos: Add metal/errno.h to match standalone
As lib/system/generic/sys.h has metal/errno.h add this to the freertos
equivalent.

This fixes some compilation issues when linking against certain FreeRTOS port
BSPs.

Signed-off-by: Ben Levinsky <ben.levinsky@amd.com>
2023-09-11 09:47:18 +02:00
Sergei Korneichuk 548f642855 Export each of the memory_order enumerators
The lib/atomic.h exports memory_order enum into the global namespace,
but none of its enumerators. According to Section 7.3.3 "The using
declaration" of the C++ standard: "specifying an enumeration name
in a using-declaration does not declare its enumerators in
the using-declaration's declarative region." See also:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0943r1.html

Signed-off-by: Sergei Korneichuk <sergei.korneichuk@amd.com>
2023-08-21 18:46:33 +02:00
Andrew Davis f2144b12ae lib: refactor alloc.h to not need forward declaration
This should have no functional change, but makes this header consistent
with how the other headers are organized.

Signed-off-by: Andrew Davis <afd@ti.com>
2023-08-16 17:17:14 +02:00
Xiang Xiao 6fb9f4565f Add reference count to metal_common_state
to allow to invoke metal_init and metal_finish multiple times

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-07-19 09:17:59 +02:00
Ben Levinsky 7ec5b636e7 lib: add support for A78 Baremetal
Enable cache, IPI, exception and shared-memory operations on Versal A78
for Libmetal.

Signed-off-by: Ben Levinsky <ben.levinsky@amd.com>
2023-06-29 09:36:00 +02:00
Ben Levinsky 6e4b016151 lib: add support for A72 Baremetal
Enable cache, IPI, exception and shared-memory operations on Versal A72
for Libmetal.

Additionally, as the code for A72 and A53 is almost identical, move
the common code to generic/xlnx_common/zynqmp_aarch64 and differentiate
the slight differences with macro checks.

Signed-off-by: Ben Levinsky <ben.levinsky@xilinx.com>

Acked-by: tanmay.shah@xilinx.com
2023-06-29 09:36:00 +02:00
Arnaud Pouliquen a136ce83b3 lib: system: freertos: remove deprecated METAL_MUTEX_INIT
The METAL_MUTEX_INIT macro has been deprecated in release 2021.04.0
Remove it after it has been in a deprecated state for 2 years.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2023-04-20 13:26:28 +02:00
Gustavo Henrique Nihei 5a87db2f0c nuttx: Add missing include header in IRQ implementation
Missing header became evident after a code refactor in another NuttX
component, which resulted in build warnings.

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2023-03-23 09:56:59 +01:00
Carlo Caione ea2b894138 zephyr: cache: Use new cache API
Use the new cache API for the cache hooks.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-11-18 10:29:30 +01:00
Tammy Leino c1c4e55992 New routine to find a node on a list
metal_list_find_node is used to ensure a node is not on a list before adding it
Signed-off-by: Tammy Leino <tammy_leino@mentor.com>
2022-10-04 09:31:23 +02:00
Sergei Korneichuk d077e286a4 cmake: set PROJECT_EC_FLAGS to be GLOBAL property
Declare PROJECT_EC_FLAGS to be a global property
to simplify code for target_compile_options.

Signed-off-by: Sergei Korneichuk <sergei.korneichuk@amd.com>
2022-10-03 16:55:01 +02:00
Sergei Korneichuk 9a814dac13 zynqmp_r5: replace Xil_SetMPURegion with Xil_MemMap
The metal_machine_io_mem_map() used to call Xil_SetMPURegion directly
and could get into an infinite loop. Replace the faulty code in
metal_machine_io_mem_map() with Xil_MemMap() call and assert it succeeds.

Signed-off-by: Sergei Korneichuk <sergei.korneichuk@amd.com>
2022-09-21 17:23:24 +02:00