Skip to contentSkip to conversation

mmap not working?

DISCUSSION Rogier Wolff 2 participants 2 messages Nov 16, 2001

lore
Share & tools
lore
#0 lore raw

Hi,

I want to mmap a device in an application, so I do:

	base = mmap(NULL ,  DEV_LENGTH,  myprot , flags, kmem, dev_base); 

Turns out that some BIOSs put my device at an address like

	0xdffffc00

whereas others put it at 0xfa000000 . In the latter case, mmap works as expected. However in the first case I get EINVAL: The base is not page-aligned.

However, in the latter case I get my requested 1k of memory, and the following 3k for free. In the first case I'd want "3k for free, followed by the 1k I requested".

effectively, provided "start" equals NULL, the kernel IMHO should:

	offset = dev_base & PAGE_MASK; 
	return mmap (NULL, length+offset, prot, flags, base - offset) + offset; 

Comments?

The "failure" was observed on 2.4.14 and/or 2.4.9.

Roger.

P.S. I end up not being able to closely follow linux-kernel lately. CCs to me appreciated.

Signature · 4 lines
** [email protected] ** http://www.BitWizard.nl/ ** +31-15-2137555 **
*-- BitWizard writes Linux device drivers for any device you may have! --*
* There are old pilots, and there are bold pilots. 
* There are also old, bald pilots. 
#1 lore raw
Followup to:  <[email protected]>
By author:    [email protected] (Rogier Wolff)
In newsgroup: linux.dev.kernel
Quoted 26 lines

Hi,

I want to mmap a device in an application, so I do:

	base = mmap(NULL ,  DEV_LENGTH,  myprot , flags, kmem, dev_base); 

Turns out that some BIOSs put my device at an address like

	0xdffffc00

whereas others put it at 0xfa000000 . In the latter case, mmap works as expected. However in the first case I get EINVAL: The base is not page-aligned.

However, in the latter case I get my requested 1k of memory, and the following 3k for free. In the first case I'd want "3k for free, followed by the 1k I requested".

effectively, provided "start" equals NULL, the kernel IMHO should:

	offset = dev_base & PAGE_MASK; 
	return mmap (NULL, length+offset, prot, flags, base - offset) + offset; 

Comments?

Quoted 8 lines

The "failure" was observed on 2.4.14 and/or 2.4.9.

Roger.

P.S. I end up not being able to closely follow linux-kernel lately. CCs to me appreciated.

Sorry, what you're asking for the TLB to do something it simply cannot do -- there is no way for the TLB to remap the bottom 12 bits since it doesn't control them.

What you'd have to do is to make your device driver move the device to a different address.

-hpa

Signature · 3 lines
<[email protected]> at work, <[email protected]> in private!
"Unix gives you enough rope to shoot yourself in the foot."
http://www.zytor.com/~hpa/puzzle.txt	<[email protected]>