如何使用memcpy_toio/fromio? [英] How do I use memcpy_toio/fromio?

查看:183
本文介绍了如何使用memcpy_toio/fromio?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C语言的内核模块与PCIe卡进行通信,我已经使用pci_iomap分配了一些io内存,并使用ioread/write32在那里进行了读写.

I am working on a kernel module in C to talk to a PCIe card and I have allocated some io memory using pci_iomap, and I write/read there using ioread/write32.

这可行,但性能很差,我读到我可以通过 memcpy_toio/fromio 使用块传输,而不是一次只执行 32b.

This works but the performance is quite poor, and I read I could use block transfer through memcpy_toio/fromio instead of just doing 32b at a time.

要编写,我正在使用 iowrite32(buffer [i],privdata->寄存器+ i);

要阅读,我要做 buffer [i] = ioread32(& privdata->寄存器[i]);

我尝试用以下命令替换这些for循环:

I tried to replace the for loops these are in with:

memcpy_toio(privdata->registers, buffer, 2048);
memcpy_fromio(buffer, privdata->registers, 2048);

如果仅用memcpy_toio代替写循环,并使用ioread32进行读取,则程序不会崩溃,但指令似乎没有做任何事情(寄存器不变);

If I only replace the write loop with memcpy_toio and I do the reading using ioread32, the program doesn't crash but the instruction doesn't seem to be doing anything (registers don't change);

此外,当我用memcpy_fromio指令替换读取循环时,它也会崩溃.

Also, when I replace the read loop as well with the memcpy_fromio instruction, it crashes.

我当时想这可能是因为读取尝试访问仍在写入的mem位置.有没有办法在 iowrite32 或 memcpy_toio 之后刷新写入队列?

I was thinking it might be because the reads try to access the mem location while it is still being written to. Is there a way to flush the writes queue after either iowrite32 or memcpy_toio?

我在这里做错了什么?

推荐答案

memcpy_from/toio()仅在I/O内存的行为类似于内存时(即,如果可以读取值)才可以使用推测性的,并且被多次写入或乱序写入.

memcpy_from/toio() can be used only if the I/O memory behaves like memory, i.e., if values can be read speculatively, and be written multiple times or out of order.

标记为不可预取的I/O范围不支持此操作.

An I/O range marked as non-prefetchable does not support this.

这篇关于如何使用memcpy_toio/fromio?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆