Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring in Xilinx-AMD commits #64

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/legacy_apps/examples/echo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ link_directories (${_list} ${_app_list})
get_property (_linker_opt GLOBAL PROPERTY APP_LINKER_OPT)
collector_list (_deps PROJECT_LIB_DEPS)

# Enable user to pass in extra linker flags
if (DEFINED DEMO_LINK_FLAGS)
set (_deps "${_deps} ${DEMO_LINK_FLAGS}")
endif(DEFINED DEMO_LINK_FLAGS)

set (OPENAMP_LIB open_amp)

foreach (_app rpmsg-echo-ping rpmsg-echo)
Expand Down
53 changes: 32 additions & 21 deletions examples/legacy_apps/examples/echo/rpmsg-echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

#define SHUTDOWN_MSG 0xEF56A55A

#define LPRINTF(format, ...) printf(format, ##__VA_ARGS__)
#define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__)
#define LPRINTF(format, ...) metal_info("INFO: " format, ##__VA_ARGS__)
#define LPERROR(format, ...) metal_err("ERROR: " format, ##__VA_ARGS__)

static struct rpmsg_endpoint lept;
static int shutdown_req = 0;
Expand Down Expand Up @@ -78,16 +78,7 @@ int app(struct rpmsg_device *rdev, void *priv)
LPRINTF("RPMsg device TX buffer size: %#x\r\n", rpmsg_get_tx_buffer_size(&lept));
LPRINTF("RPMsg device RX buffer size: %#x\r\n", rpmsg_get_rx_buffer_size(&lept));

while(1) {
platform_poll(priv);
/* we got a shutdown request, exit */
if (shutdown_req) {
break;
}
}
rpmsg_destroy_ept(&lept);

return 0;
return platform_poll_on_vdev_reset(rdev, priv);
}

/*-----------------------------------------------------------------------------*
Expand Down Expand Up @@ -115,23 +106,43 @@ int main(int argc, char *argv[])
ret = platform_init(argc, argv, &platform);
if (ret) {
LPERROR("Failed to initialize platform.\r\n");
ret = -1;
} else {
LPERROR("Server reboot is required to recover\r\n");
platform_cleanup(platform);
/*
* If main function is returned in baremetal firmware,
* Server behavior is undefined. It's better to wait in
* an infinite loop instead
*/
while (1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you will break the CI that should migrate on these examples. This should be addressed in your test environment

Copy link
Contributor Author

@bentheredonethat bentheredonethat Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see tanmay's comment

}

/*
* If host detach from remoteproc device, then destroy current rpmsg
* device and create new one.
*/
while (1) {
rpdev = platform_create_rpmsg_vdev(platform, 0,
VIRTIO_DEV_DEVICE,
NULL, NULL);
if (!rpdev) {
LPERROR("Failed to create rpmsg virtio device.\r\n");
ret = -1;
} else {
app(rpdev, platform);
platform_release_rpmsg_vdev(rpdev, platform);
ret = 0;
LPERROR("Server reboot is required to recover\r\n");
platform_cleanup(platform);

/*
* If main function is returned in baremetal firmware,
* Server behavior is undefined. It's better to wait in
* an infinite loop instead
*/
while (1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same issue here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arnopo is that okay, if we can define return of main based on PROJECT_SYSTEM variable ?

#ifdef PROJECT_SYSTEM == LINUX
return ;
#else
while (1);
#endif

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems to me not enough generic.
Behavior is platform dependent so I would be treated in platform_info.c , what about implementing in cleanup_system or a system_shutdown that would be empty by default?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's a good idea. It will be re-factored accordingly.

}

app(rpdev, platform);
platform_release_rpmsg_vdev(rpdev, platform);
}

LPRINTF("Stopping application...\r\n");
platform_cleanup(platform);

return ret;
/* Never reach here. */
return -EINVAL;
}
5 changes: 5 additions & 0 deletions examples/legacy_apps/examples/matrix_multiply/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ link_directories (${_list} ${_app_list})
get_property (_linker_opt GLOBAL PROPERTY APP_LINKER_OPT)
collector_list (_deps PROJECT_LIB_DEPS)

# Enable user to pass in extra linker flags
if (DEFINED DEMO_LINK_FLAGS)
set (_deps "${_deps} ${DEMO_LINK_FLAGS}")
endif(DEFINED DEMO_LINK_FLAGS)

set (OPENAMP_LIB open_amp)
foreach (_app matrix_multiply matrix_multiplyd)
collector_list (_sources APP_COMMON_SOURCES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@

#define SHUTDOWN_MSG 0xEF56A55A

#define LPRINTF(format, ...) printf(format, ##__VA_ARGS__)
//#define LPRINTF(format, ...)
#define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__)
#define LPRINTF(format, ...) metal_info("INFO: " format, ##__VA_ARGS__)
#define LPERROR(format, ...) metal_err("ERROR: " format, ##__VA_ARGS__)

typedef struct _matrix {
unsigned int size;
Expand Down
5 changes: 5 additions & 0 deletions examples/legacy_apps/examples/rpc_demo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ if (NOT _linker_opt)
endif (NOT _linker_opt)
collector_list (_deps PROJECT_LIB_DEPS)

# Enable user to pass in extra linker flags
if (DEFINED DEMO_LINK_FLAGS)
set (_deps "${_deps} ${DEMO_LINK_FLAGS}")
endif(DEFINED DEMO_LINK_FLAGS)

set (OPENAMP_LIB open_amp)

if (${PROJECT_SYSTEM} STREQUAL "linux")
Expand Down
5 changes: 2 additions & 3 deletions examples/legacy_apps/examples/rpc_demo/rpc_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
#define REDEF_O_APPEND 0002000
#define REDEF_O_ACCMODE 0000003

#define LPRINTF(format, ...) xil_printf(format, ##__VA_ARGS__)
//#define LPRINTF(format, ...)
#define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__)
#define LPRINTF(format, ...) metal_info("INFO: " format, ##__VA_ARGS__)
#define LPERROR(format, ...) metal_err("ERROR: " format, ##__VA_ARGS__)

static void rpmsg_rpc_shutdown(struct rpmsg_rpc_data *rpc)
{
Expand Down
2 changes: 2 additions & 0 deletions examples/legacy_apps/include/platform_info_common.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2024 Texas Instruments, Inc.
* Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
Expand Down Expand Up @@ -57,6 +58,7 @@ platform_create_rpmsg_vdev(void *platform, unsigned int vdev_index,
* return negative value for errors, otherwise 0.
*/
int platform_poll(void *platform);
int platform_poll_on_vdev_reset(struct rpmsg_device *rpdev, void *priv);

/**
* platform_release_rpmsg_vdev - release rpmsg virtio device
Expand Down
39 changes: 39 additions & 0 deletions examples/legacy_apps/machine/zynqmp/platform_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,45 @@ int platform_poll(void *priv)
return 0;
}

int platform_poll_on_vdev_reset(struct rpmsg_device *rpdev, void *priv)
{
struct rpmsg_virtio_device *rvdev;
struct remoteproc *rproc = priv;
struct remoteproc_priv *prproc;
unsigned int flags;

if (!priv || !rpdev)
return -EINVAL;

prproc = rproc->priv;
if (!prproc)
return -EINVAL;

rvdev = metal_container_of(rpdev, struct rpmsg_virtio_device, rdev);

/**
* Check virtio status after every interrupt. In case of stop or
* detach, virtio device status will be reset by remote
* processor. In that case, break loop and destroy rvdev
*/
while (rpmsg_virtio_get_status(rvdev)) {
#ifdef RPMSG_NO_IPI
(void)flags;
if (metal_io_read32(prproc->kick_io, 0))
remoteproc_get_notification(rproc, RSC_NOTIFY_ID_ANY);
#else /* !RPMSG_NO_IPI */
flags = metal_irq_save_disable();
if (!(atomic_flag_test_and_set(&prproc->ipi_nokick))) {
metal_irq_restore_enable(flags);
remoteproc_get_notification(rproc, RSC_NOTIFY_ID_ANY);
}
_rproc_wait();
metal_irq_restore_enable(flags);
#endif /* RPMSG_NO_IPI */
}
return 0;
}

void platform_release_rpmsg_vdev(struct rpmsg_device *rpdev, void *platform)
{
struct rpmsg_virtio_device *rpvdev;
Expand Down
65 changes: 41 additions & 24 deletions examples/legacy_apps/machine/zynqmp_r5/platform_info.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
* Copyright (c) 2014, Mentor Graphics Corporation
* All rights reserved.
* Copyright (c) 2017 Xilinx, Inc.
* Copyright (c) 2017 - 2021 Xilinx, Inc.
* Copyright (c) 2022 - 2025 Advanced Micro Devices, Inc. All Rights Reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
Expand Down Expand Up @@ -31,29 +32,6 @@
#define KICK_DEV_NAME "poll_dev"
#define KICK_BUS_NAME "generic"

/* Cortex R5 memory attributes */
#define DEVICE_SHARED 0x00000001U /* device, shareable */
#define DEVICE_NONSHARED 0x00000010U /* device, non shareable */
#define NORM_NSHARED_NCACHE 0x00000008U /* Non cacheable non shareable */
#define NORM_SHARED_NCACHE 0x0000000CU /* Non cacheable shareable */
#define PRIV_RW_USER_RW (0x00000003U<<8U) /* Full Access */

#ifndef SHARED_MEM_PA
#if XPAR_CPU_ID == 0
#define SHARED_MEM_PA 0x3ED40000UL
#else
#define SHARED_MEM_PA 0x3EF40000UL
#endif /* XPAR_CPU_ID */
#endif /* !SHARED_MEM_PA */

#ifndef SHARED_MEM_SIZE
#define SHARED_MEM_SIZE 0x100000UL
#endif /* !SHARED_MEM_SIZE */

#ifndef SHARED_BUF_OFFSET
#define SHARED_BUF_OFFSET 0x8000UL
#endif /* !SHARED_BUF_OFFSET */

#ifndef RPMSG_NO_IPI
#define _rproc_wait() asm volatile("wfi")
#endif /* !RPMSG_NO_IPI */
Expand Down Expand Up @@ -237,6 +215,45 @@ platform_create_rpmsg_vdev(void *platform, unsigned int vdev_index,
return NULL;
}

int platform_poll_on_vdev_reset(struct rpmsg_device *rpdev, void *priv)
{
struct rpmsg_virtio_device *rvdev;
struct remoteproc *rproc = priv;
struct remoteproc_priv *prproc;
unsigned int flags;

if (!priv || !rpdev)
return -EINVAL;

prproc = rproc->priv;
if (!prproc)
return -EINVAL;

rvdev = metal_container_of(rpdev, struct rpmsg_virtio_device, rdev);

/**
* Check virtio status after every interrupt. In case of stop or
* detach, virtio device status will be reset by remote
* processor. In that case, break loop and destroy rvdev
*/
while (rpmsg_virtio_get_status(rvdev)) {
#ifdef RPMSG_NO_IPI
(void)flags;
if (metal_io_read32(prproc->kick_io, 0))
remoteproc_get_notification(rproc, RSC_NOTIFY_ID_ANY);
#else /* !RPMSG_NO_IPI */
flags = metal_irq_save_disable();
if (!(atomic_flag_test_and_set(&prproc->ipi_nokick))) {
metal_irq_restore_enable(flags);
remoteproc_get_notification(rproc, RSC_NOTIFY_ID_ANY);
}
_rproc_wait();
metal_irq_restore_enable(flags);
#endif /* RPMSG_NO_IPI */
}
return 0;
}

int platform_poll(void *priv)
{
struct remoteproc *rproc = priv;
Expand Down
Loading