English 中文(简体)
Zynq PetaHCH PL需要写给PS RAM——我如何向PL提供正确的实物地址?
原标题:Zynq PetaLinux system PL needs to write to PS RAM - how do I provide PL with the correct physical address?

I have a Zynq system where logic in the PL generates a large block of data that needs to be written into PS RAM. In my naive thinking, I would use new or malloc() to get a pointer to allocated memory, then translate that pointer virtual address to a physical address.

有几个问题是错误的。 一种是,在我提出申请之前,记忆可能不存在。 另一个问题是,实际地址可能发生变化。 或许还有其他原因。

人民党希望写到同一地方,希望记忆能够存在,显然!

Here is what I ve tried (C++):

size_t length_in_bytes = 4096*8;
uint8_t * memBlockPtr;
const size_t page_boundary = 4096;
int retval = posix_memalign(reinterpret_cast<void**>(&memBlockPtr), page_boundary, length_in_bytes);
if (retval != 0)
{
    perror("posix_memalign");
    exit(1);
}

uint8_t * physAddr = nullptr;
physAddr = reinterpret_cast<uint8_t *>(mmap(reinterpret_cast<void*>(memBlockPtr),
                length_in_bytes, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, -1, 0));
if (physAddr == MAP_FAILED)
{
    perror("mmap");
    exit(1);
}

This fails with mmap: Bad file descriptor.

在<代码>mmap()方面,我没有什么经验,但我们的运用确实利用这一方法,从PL的记忆空间绘制地图,进入应用记忆空间,而这正是我现在需要的。 此外,我很想知道是否有任何与切身有关的问题,就像PL写到缓冲时一样,从PS看,是否立即看到数据?

另有一件事——我在乌本巴托的PC工作站,而不是PetaHCH上持有上述代码。 尚未做好这项工作的准备。 我不知道我是否因不出现在实际平台上而错了。

问题回答

I did solve this problem, but it was only after I realized I was thinking about this completely wrong. First off, the proposed code above was developed with one of those LLM AIs, which was clearly hallucinating. The correct way to do this can be summarized as:

  1. Define some reserved memory in your Petalinux device tree file. This will let you specify the physical or "bus address" of the base of the memory block and its length. For my case, with the PL writing to PS RAM, this was the address specified in the DMA memory controllers of the PL (using Vivado) and becomes part of the bitstream. Rebuild Petalinux with the updated device tree.
  2. Do the exact same thing with mmap() that you would do if you wanted to access some memory address that exists in the PL. There are multiple links out there that talk about how to do this. This will give you a way to read or write through the physical address.

这是简短的故事。 有许多步骤没有采取,但这是一般的想法。

我看到了几个很好的资源:

装置树:每个人的硬件描述!

https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18842482/Device+Tree+Tips”rel=“nofollow noreferer”>https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18842482/Device+Tree+Tips

亲爱!





相关问题
How portable is mmap?

I ve been considering using mmap for file reading, and was wondering how portable that is. I m developing on a Linux platform, but would like my program to work on Mac OS X and Windows. Can I assume ...

Two C++ apps sharing a read-only region of memory on Linux

I have two processes P1 and P2. I have this large read-only resource, called "R" that I want both P1 and P2 to have access to. R is not just a "flat" group of bytes; it s a bunch of C++ objects that ...

How do I mmap a _particular_ region in memory?

I have a program. I want it to be able to mmap a particular region of memory over different runs. I have the source code of the program. C/C++ I control how the program is compiled. gcc I control how ...

Java, C++, NIO, mmaped buffer, synchronization

Exposition: I am on Linux / Mac. Part of my code is in Java, part of my code is in C++. They both have the same file mmapped for fast communication. I want to synchronize the Java & C++ code. ...

map file in to the ram

Platofrm - Linux, Arch - ARM Programming lang - C/C++ Objective - map a regular (let say text) file to a pre-known location (physical address) in ram and pass that physical address to some other ...

memory mapped files system call - linux

When we map a file to memory, a system call is required. Do subsequent accesses to the file require system calls or is the virtual memory page of the process mapped to the actual page cache in memory? ...

热门标签