mmap large physical memory space

This is probably a silly question but I just want to verify that I’m
correct in my assumption.

We’ve written a resmgr to control the hardware bus on our box. It works
great. I’m using a mmap_device_memory() to map the physical memory into
virtual, and in8() and out8() to set values. No worries there.

One really weird thing about our bus is that when you want to write a 16
bit value to the bus you write the least significant byte (LSB) to a
specific address, and the most significant byte (MSB) to that same
address, plus 0x40000 (yes, that’s forty thousand hex :slight_smile:).

Now, the real physical size of the memory map we need for just the low
bytes is nowhere near 0x40000, so that means that there is a very
sizeable gap between the end of the LSB addresses and the beginning
of the MSB addresses which is unused.


Right now what my code does, rather than doing two distinct mmap()
invocations returning two different areas of memory, necessitating two
different calculations, etc. I’m simply mapping the whole entire space
from the lowest address in the LSB space to the highest address in the
MSB memory space in one mmap.

My assumption here is that since I’m really just creating a virtual
“pass-through” capability to write from my program into hardware, I’m
not really allocating all that memory for my program. The mmap above
doesn’t actually allocate any real memory at all (except maybe some
bookkeeping), right?

It’s much simpler for me to code if I map the whole thing into one
memory block, but I sure don’t want to be wasting all that memory if I’m
wrong about how this works :slight_smile:.


Comments anyone?

Thanks…

Paul D. Smith <pausmith@nortelnetworks.com> HASMAT–HA Software Mthds & Tools
“Please remain calm…I may be mad, but I am a professional.” --Mad Scientist

These are my opinions—Nortel Networks takes no responsibility for them.

“Paul D. Smith” <pausmith@nortelnetworks.com> wrote in
news:p5r8l8joux.fsf@lemming.engeast.baynetworks.com:

My assumption here is that since I’m really just creating a virtual
“pass-through” capability to write from my program into hardware, I’m
not really allocating all that memory for my program. The mmap above
doesn’t actually allocate any real memory at all (except maybe some
bookkeeping), right?

If your hardware sits at a certain address range, and you mmap that address
range into your process, you are not allocating memory(RAM). It’s just a
mapping so that your linear addresses correspond to physical ones.


\

Cheers,
Adam

QNX Software Systems Ltd.
[ amallory@qnx.com ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <pschon@baste.magibox.net>

Adam Mallory <amallory@qnx.com> wrote:

“Paul D. Smith” <> pausmith@nortelnetworks.com> > wrote in
news:> p5r8l8joux.fsf@lemming.engeast.baynetworks.com> :

My assumption here is that since I’m really just creating a virtual
“pass-through” capability to write from my program into hardware, I’m
not really allocating all that memory for my program. The mmap above
doesn’t actually allocate any real memory at all (except maybe some
bookkeeping), right?

If your hardware sits at a certain address range, and you mmap that address
range into your process, you are not allocating memory(RAM). It’s just a
mapping so that your linear addresses correspond to physical ones.

Yup, though you do have the overhead of the page table entries – the
book-keeping that you mention. The exact cost of that overhead will
vary from hw to hw, but on x86 I think it is about 1000:1. That is, a
4K page cost 4 bytes of overhead. Your 0x40000 is gonna cost you
about 263 bytes of overhead.

Probably won’t kill you for the convenience. :slight_smile:

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

“David Gibbs” <dagibbs@qnx.com> wrote in message
news:aa4nbe$2ao$1@nntp.qnx.com

Adam Mallory <> amallory@qnx.com> > wrote:
“Paul D. Smith” <> pausmith@nortelnetworks.com> > wrote in
news:> p5r8l8joux.fsf@lemming.engeast.baynetworks.com> :

My assumption here is that since I’m really just creating a virtual
“pass-through” capability to write from my program into hardware, I’m
not really allocating all that memory for my program. The mmap above
doesn’t actually allocate any real memory at all (except maybe some
bookkeeping), right?

If your hardware sits at a certain address range, and you mmap that
address
range into your process, you are not allocating memory(RAM). It’s just
a
mapping so that your linear addresses correspond to physical ones.

Yup, though you do have the overhead of the page table entries – the
book-keeping that you mention. The exact cost of that overhead will
vary from hw to hw, but on x86 I think it is about 1000:1. That is, a
4K page cost 4 bytes of overhead. Your 0x40000 is gonna cost you
about 263 bytes of overhead.

Probably won’t kill you for the convenience. > :slight_smile:

I think there is a limit on virtual memory as well. On x86 I don’t think
you can have 10000 processes that have mmap 1G of memory each.
That would mean 10T of virtual memory. I don’t know what the limit
is and if it applies to powerpc. I could be confusing thing with QNX4.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Mario Charest <goto@nothingness.com> wrote:

I think there is a limit on virtual memory as well. On x86 I don’t think
you can have 10000 processes that have mmap 1G of memory each.
That would mean 10T of virtual memory. I don’t know what the limit
is and if it applies to powerpc. I could be confusing thing with QNX4.

QNX4 had this sort of limitation, and it hit at relatively low values
(for high-end systems). I don’t think QNX6 has the same sort of
limitations.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

“Paul D. Smith” <pausmith@nortelnetworks.com> wrote in message
news:p5r8l8joux.fsf@lemming.engeast.baynetworks.com

This is probably a silly question but I just want to verify that I’m
correct in my assumption.

We’ve written a resmgr to control the hardware bus on our box. It works
great. I’m using a mmap_device_memory() to map the physical memory into
virtual, and in8() and out8() to set values. No worries there.

I don’t quite follow, in8() and out8() addresses should be obtain via
mmap_device_io
not mmap_device_memory(). Or you saying the board has both
physical memory and io address space?


One really weird thing about our bus is that when you want to write a 16
bit value to the bus you write the least significant byte (LSB) to a
specific address, and the most significant byte (MSB) to that same
address, plus 0x40000 (yes, that’s forty thousand hex > :slight_smile:> ).

Now, the real physical size of the memory map we need for just the low
bytes is nowhere near 0x40000, so that means that there is a very
sizeable gap between the end of the LSB addresses and the beginning
of the MSB addresses which is unused.


Right now what my code does, rather than doing two distinct mmap()
invocations returning two different areas of memory, necessitating two
different calculations, etc. I’m simply mapping the whole entire space
from the lowest address in the LSB space to the highest address in the
MSB memory space in one mmap.

My assumption here is that since I’m really just creating a virtual
“pass-through” capability to write from my program into hardware, I’m
not really allocating all that memory for my program. The mmap above
doesn’t actually allocate any real memory at all (except maybe some
bookkeeping), right?

It’s much simpler for me to code if I map the whole thing into one
memory block, but I sure don’t want to be wasting all that memory if I’m
wrong about how this works > :slight_smile:> .


Comments anyone?

Thanks…


Paul D. Smith <> pausmith@nortelnetworks.com> > HASMAT–HA Software Mthds &
Tools
“Please remain calm…I may be mad, but I am a professional.” --Mad
Scientist


These are my opinions—Nortel Networks takes no responsibility for
them.

%% “Mario Charest” postmaster@127.0.0.1 writes:

mc> “Paul D. Smith” <pausmith@nortelnetworks.com> wrote in message
mc> news:p5r8l8joux.fsf@lemming.engeast.baynetworks.com

We’ve written a resmgr to control the hardware bus on our box. It works
great. I’m using a mmap_device_memory() to map the physical memory into
virtual, and in8() and out8() to set values. No worries there.

mc> I don’t quite follow, in8() and out8() addresses should be obtain
mc> via mmap_device_io not mmap_device_memory(). Or you saying the
mc> board has both physical memory and io address space?

Not sure what you mean, but since we’ve been using it successfully for
about 6 months now I’m pretty sure mmap_device_memory() is what I want.
I thought mmap_device_io() would be for I/O controllers, etc.?

Or, do you mean that in*() and out*() aren’t appropriate for use outside
of memory returned by mmap_device_io()? The docs do seem to suggest
that, but on PPC these macros simply do memory assignment, but then they
also do EIEIO, which I definitely need.

Paul D. Smith <pausmith@nortelnetworks.com> HASMAT–HA Software Mthds & Tools
“Please remain calm…I may be mad, but I am a professional.” --Mad Scientist

These are my opinions—Nortel Networks takes no responsibility for them.

“Paul D. Smith” <pausmith@nortelnetworks.com> wrote in message
news:p5bs8p8412.fsf@lemming.engeast.baynetworks.com

Or, do you mean that in*() and out*() aren’t appropriate for use outside
of memory returned by mmap_device_io()? The docs do seem to suggest
that, but on PPC these macros simply do memory assignment, but then they
also do EIEIO, which I definitely need.

Didn’t Old McDonald have that problem?

%% “Bill Caroselli (Q-TPS)” <QTPS@EarthLink.net> writes:

bc> “Paul D. Smith” <pausmith@nortelnetworks.com> wrote in message
bc> news:p5bs8p8412.fsf@lemming.engeast.baynetworks.com

Or, do you mean that in*() and out*() aren’t appropriate for use outside
of memory returned by mmap_device_io()? The docs do seem to suggest
that, but on PPC these macros simply do memory assignment, but then they
also do EIEIO, which I definitely need.

bc> Didn’t Old McDonald have that problem?

No, he had a farm.

Paul D. Smith <pausmith@nortelnetworks.com> HASMAT–HA Software Mthds & Tools
“Please remain calm…I may be mad, but I am a professional.” --Mad Scientist

These are my opinions—Nortel Networks takes no responsibility for them.

Paul D. Smith <pausmith@nortelnetworks.com> wrote:

%% “Bill Caroselli (Q-TPS)” <> QTPS@EarthLink.net> > writes:

bc> “Paul D. Smith” <> pausmith@nortelnetworks.com> > wrote in message
bc> news:> p5bs8p8412.fsf@lemming.engeast.baynetworks.com> …

Or, do you mean that in*() and out*() aren’t appropriate for use outside
of memory returned by mmap_device_io()? The docs do seem to suggest
that, but on PPC these macros simply do memory assignment, but then they
also do EIEIO, which I definitely need.

bc> Didn’t Old McDonald have that problem?

No, he had a farm.

And on that farm he had a bus,
EIEIO

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.