c - 将虚拟地址映射回物理地址

标签 c linux virtual-memory beagleboard texas-instruments

免责声明:我在 Texas Instruments Forum 上交叉发布了这个问题。 ,但我已经五天没有收到任何回复了。我对嵌入式编程还很陌生,所以请指出您是否需要更多信息或者我的方法是否无意义。

动机

我有一个带有 DM3730 processor from Texas Instruments 的嵌入式设备(与 Beagleboard -xm 上的相同)处理器通过其显示子系统 (DSS) 连接到 LCD 显示器。显示屏看起来很暗,必须进行 Gamma 校正。幸运的是,DSS 有一个调色板/ Gamma 查找表。不幸的是,我无法让它工作。

我发现了什么

我找到了similar question在德州仪器 (TI) 论坛上针对类似处理器,一名 TI 员工给出了以下解释(强调我的解释):

I don't think there is any support in the current Linux kernel for color indexed graphics, but it is fairly easy to enable from the application level through direct register configuration.

[...]

Next, declare an array of 256 unsigned integers and populate it with the RGB values you want for each color index entry.

Set DISPC_GFX_TABLE_BA to the physical address of the previously configured array (Note 1, this needs the physical address and not the virtual address so you will likely need to map it back. Note 2, this needs to be a 32 bit aligned address so depending on how the array is created it may be necessary to create an array of char slightly larger and populate the array such that the start is on a 32 bit boundary)

[...]

他后来提到了 mem_util转换地址,我能够使用它从应用程序级别(用户空间)直接写入寄存器,但我不知道如何将虚拟地址“映射回”物理地址。

系统信息

~# uname -a
Linux dm37x-evm 2.6.32.1 #1 Fri Dec 2 11:19:53 EST 2011 armv7l unknown

我的问题

  • 如何将虚拟地址映射回物理地址?
  • 这可以在用户空间中完成吗? (我设想提供一个用户可以调整 Gamma 曲线的界面)
  • 总的来说,这是正确的方法吗?我是否应该将其移至内核空间(我不愿意这样做,因为我对 Linux 内核没有太多经验)
  • 任何好的资源或示例!

最佳答案

对您的问题的一个非常具体的答案是使用 CMEM,其目的是从启动时保留的内存中分配连续的内存块。

在下面的示例代码中,我通过编解码器引擎使用 cmem。 ptr 是您在应用程序中用于访问缓冲区的内容,而 physptr 是您在寄存器中写入的内容。

    ptr = Memory_contigAlloc(len, Memory_DEFAULTALIGNMENT);
    if(ptr == NULL) {
        debug_printf("Buffer allocation failed : buf size = %d\n", len);
        return -1;
    }
    physptr = (void *)Memory_getBufferPhysicalAddress(ptr, len, 0);

“正确”的方法实际上是不使用 memutil 并在内核中完成所有操作。

关于c - 将虚拟地址映射回物理地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10210515/

相关文章:

c - 如何在 while 循环中找到最大值和最小值 - c

c - 我会滥用 fwrite 功能吗?

python - 使用 PPID 创建文件

java - 当我从一台 PC 有双头或三头时,如何知道分辨率屏幕宽度和高度?

Linux:在特定日期对日志文件中的多个字符串进行grep

c++ - 消除发布代码 C++ 中的调试代码

c# - AVR32 UC3 USB 在 cdc 设备模式下数据丢失

c++ - 递归页面错误处理程序

c - 增加 ARM i.MX287 上的 Linux DMA_ZONE 内存

linux - 什么时候使用虚拟内存是个坏主意?