与内存进行通信在Linux映射设备 [英] communicating with a memory mapped device in linux

查看:132
本文介绍了与内存进行通信在Linux映射设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个内存映射设备,我需要与之通信。我的老板告诉我,这是不可能将其通过的/ dev / MEM 。我在网上看了看,并没有发现与之相关的任何事情。是否有可能做到这一点还是我的老板是错的?

I have a memory mapped device and I need to communicate with it. My boss told me that it is possible to it through /dev/mem. I looked online and didn't find anything related to it. Is it possible to do it or my boss was wrong?

假设你有超级用户的权限。

Assume that you have superuser permissions.

任何帮助是AP preciated。

Any help is appreciated.

推荐答案

您有地址 MMIO_ADDR 占用内存映射设备 MMIO_LEN 字节。您需要在切换设备的地址空间中的第123个字节。这可能是这样的:

You got a memory mapped device at address MMIO_ADDR which occupies MMIO_LEN of bytes. You need to toggle the 123rd byte in the device's address space. This could look like this:

#define MMIO_ADDR 0xDEAD0000
#define MMIO_LEN  0x400

// open a handle into physical memory, requires root
int memfd = open("/dev/mem", O_RDWR);
// map the range [MMIO_ADDR, MMIO_ADDR+MMIO_LEN] into your virtual address space
unsigned char* shmem = mmap(0, MMIO_LEN, PROT_WRITE | PROT_READ, MAP_SHARED, memfd, MMIO_ADDR);

// do your deed
unsigned char *magic_toggle_byte = &shmem[123];
*magic_toggle_byte = !*magic_toggle_byte;

这篇关于与内存进行通信在Linux映射设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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