mmap in kernel module

Jun 09, 2006 3 Replies

Hi, i'm newby in kernel programming.



I need to directly address a device in the memory, but i can't use open, mmap and munmap.


What i actually need to do is the following (from application point of view): """ mem = open("/dev/mem", O_RDWR | O_SYNC); base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, mem, EBI_BASE & ~MAP_MASK); munmap(base, MAP_SIZE); cs_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, mem, CS_BASE & ~MAP_MASK); """ MAP_SIZE, MAP_SHARED, CS_BASE, EBI_BASE and MAP_MASK are predifinied consts which define addresses, masks and offsets.


How can i do this in the device_open method?


Please help.


thanks in advance



I still have problems.

If i do the following: // mem = open("/dev/mem", O_RDWR | O_SYNC); //base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, mem, EBI_BASE & ~MAP_MASK); base = ioremap(EBI_BASE & ~MAP_MASK, MAP_SIZE); // === DO SOMETHIN' DIRECTLY ON IT

*((unsigned long *) (base + (O_SMC_CSR3 & MAP_MASK))) = 0x4494; //munmap(base, MAP_SIZE); iounmap(base); //cs_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, mem, CS_BASE & ~MAP_MASK); cs_base = ioremap(CS_BASE & ~MAP_MASK, MAP_SIZE); // === DO SOMETHIN' DIRECTLY ON IT *((unsigned char *) (cs_base) +3) = 0x0001;

It does actually nothin. If i print the address it is also funny: "c4854000" as the CS_BASE is "0x40000000UL".

Please help ... urgent.

Depending on the arch, you may not be able to do this. You may need readb() and writeb() instead.

Hey, hang on a minute. Why don't you read "Linux Device Drivers" ? It tells you all this stuff.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required