2022-01-14 16:25:49 +01:00
|
|
|
/****************************************************************************
|
2022-02-16 08:23:49 +01:00
|
|
|
* drivers/rptun/rptun_dump.c
|
2022-01-14 16:25:49 +01:00
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/rptun/openamp.h>
|
|
|
|
#include <nuttx/rptun/rptun.h>
|
|
|
|
#include <metal/utilities.h>
|
|
|
|
|
|
|
|
#include <rpmsg/rpmsg_internal.h>
|
|
|
|
|
2022-02-16 08:23:49 +01:00
|
|
|
#include "rptun.h"
|
|
|
|
|
2022-01-14 16:25:49 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-02-16 08:23:49 +01:00
|
|
|
static void rptun_dump_addr(FAR struct rpmsg_device *rdev,
|
2022-01-14 16:25:49 +01:00
|
|
|
FAR void *addr, bool rx)
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_hdr *hdr = addr;
|
|
|
|
FAR struct rpmsg_endpoint *ept;
|
|
|
|
|
|
|
|
ept = rpmsg_get_ept_from_addr(rdev, rx ? hdr->dst : hdr->src);
|
|
|
|
if (ept)
|
|
|
|
{
|
2022-04-25 12:39:15 +02:00
|
|
|
metal_log(METAL_LOG_EMERGENCY,
|
2022-01-14 16:25:49 +01:00
|
|
|
" %s buffer %p hold by %s\n",
|
|
|
|
rx ? "RX" : "TX", hdr, ept->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-16 08:23:49 +01:00
|
|
|
static void rptun_dump_buffer(FAR struct rpmsg_virtio_device *rvdev,
|
2022-01-14 16:25:49 +01:00
|
|
|
bool rx)
|
|
|
|
{
|
|
|
|
FAR struct virtqueue *vq = rx ? rvdev->rvq : rvdev->svq;
|
|
|
|
FAR void *addr;
|
|
|
|
int desc_idx;
|
|
|
|
int num;
|
|
|
|
int i;
|
|
|
|
|
2022-02-16 08:23:49 +01:00
|
|
|
num = rptun_buffer_nused(rvdev, rx);
|
2022-04-25 12:39:15 +02:00
|
|
|
metal_log(METAL_LOG_EMERGENCY,
|
2022-01-14 16:25:49 +01:00
|
|
|
" %s buffer, total %d, pending %d\n",
|
|
|
|
rx ? "RX" : "TX", vq->vq_nentries, num);
|
|
|
|
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
2022-07-21 16:26:51 +02:00
|
|
|
if ((rpmsg_virtio_get_role(rvdev) == RPMSG_HOST) ^ rx)
|
2022-01-14 16:25:49 +01:00
|
|
|
{
|
|
|
|
desc_idx = (vq->vq_ring.used->idx + i) & (vq->vq_nentries - 1);
|
|
|
|
desc_idx = vq->vq_ring.avail->ring[desc_idx];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
desc_idx = (vq->vq_ring.avail->idx + i) & (vq->vq_nentries - 1);
|
|
|
|
desc_idx = vq->vq_ring.used->ring[desc_idx].id;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr = metal_io_phys_to_virt(vq->shm_io,
|
|
|
|
vq->vq_ring.desc[desc_idx].addr);
|
|
|
|
if (addr)
|
|
|
|
{
|
2022-02-16 08:23:49 +01:00
|
|
|
rptun_dump_addr(&rvdev->rdev, addr, rx);
|
2022-01-14 16:25:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-02-16 08:23:49 +01:00
|
|
|
void rptun_dump(FAR struct rpmsg_virtio_device *rvdev)
|
2022-01-14 16:25:49 +01:00
|
|
|
{
|
|
|
|
FAR struct rpmsg_device *rdev = &rvdev->rdev;
|
|
|
|
FAR struct rpmsg_endpoint *ept;
|
|
|
|
FAR struct metal_list *node;
|
2023-06-16 03:35:14 +02:00
|
|
|
bool needlock = true;
|
2022-01-14 16:25:49 +01:00
|
|
|
|
|
|
|
if (!rvdev->vdev)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-16 03:35:14 +02:00
|
|
|
if (up_interrupt_context() || sched_idletask() ||
|
|
|
|
nxmutex_is_hold(&rdev->lock))
|
|
|
|
{
|
|
|
|
needlock = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needlock)
|
2022-04-24 09:25:13 +02:00
|
|
|
{
|
|
|
|
metal_mutex_acquire(&rdev->lock);
|
|
|
|
}
|
2022-01-14 16:25:49 +01:00
|
|
|
|
2022-04-25 12:39:15 +02:00
|
|
|
metal_log(METAL_LOG_EMERGENCY,
|
2022-05-11 16:17:02 +02:00
|
|
|
"Dump rpmsg info between cpu (master: %s)%s <==> %s:\n",
|
2022-07-21 16:26:51 +02:00
|
|
|
rpmsg_virtio_get_role(rvdev) == RPMSG_HOST ? "yes" : "no",
|
2024-02-04 08:04:16 +01:00
|
|
|
CONFIG_RPMSG_LOCAL_CPUNAME, rpmsg_get_cpuname(rdev));
|
2022-01-14 16:25:49 +01:00
|
|
|
|
2022-05-11 16:17:02 +02:00
|
|
|
metal_log(METAL_LOG_EMERGENCY, "rpmsg vq RX:\n");
|
|
|
|
virtqueue_dump(rvdev->rvq);
|
|
|
|
metal_log(METAL_LOG_EMERGENCY, "rpmsg vq TX:\n");
|
|
|
|
virtqueue_dump(rvdev->svq);
|
|
|
|
|
2022-04-25 12:39:15 +02:00
|
|
|
metal_log(METAL_LOG_EMERGENCY, " rpmsg ept list:\n");
|
2022-01-14 16:25:49 +01:00
|
|
|
|
|
|
|
metal_list_for_each(&rdev->endpoints, node)
|
|
|
|
{
|
|
|
|
ept = metal_container_of(node, struct rpmsg_endpoint, node);
|
2022-04-25 12:39:15 +02:00
|
|
|
metal_log(METAL_LOG_EMERGENCY, " ept %s\n", ept->name);
|
2022-01-14 16:25:49 +01:00
|
|
|
}
|
|
|
|
|
2022-04-25 12:39:15 +02:00
|
|
|
metal_log(METAL_LOG_EMERGENCY, " rpmsg buffer list:\n");
|
2022-01-14 16:25:49 +01:00
|
|
|
|
2022-02-16 08:23:49 +01:00
|
|
|
rptun_dump_buffer(rvdev, true);
|
|
|
|
rptun_dump_buffer(rvdev, false);
|
2022-01-14 16:25:49 +01:00
|
|
|
|
2023-06-16 03:35:14 +02:00
|
|
|
if (needlock)
|
2022-04-24 09:25:13 +02:00
|
|
|
{
|
|
|
|
metal_mutex_release(&rdev->lock);
|
|
|
|
}
|
2022-01-14 16:25:49 +01:00
|
|
|
}
|