[okl4-developer] Request virt to phys mapping in Iguana application
Nelson Tam
nelson at ok-labs.com
Tue Feb 5 17:25:03 EST 2008
Hi Kashin,
OK, I've taken a good look at your problem now.
On 28/01/2008, at 5:18 PM, kashin Lin wrote:
> i have tried "memsection_virt_to_phys" as following:
>
> uintptr_t virt, mem_sect;
> uintptr_t scm_phys;
> size_t size;
>
> mem_sect = memsection_create_user(0x1000, &virt);
> result = hardware_back_memsection(mem_sect,0x01c40000, L4_IOMemory);
>
> scm_phys = memsection_virt_to_phys(virt, &size);
>
> but i always got "scm:0xfffffffe, size:0x0" not "scm:0x01c40000,
> size:0x1000".
> is the way i used wrong or there are something i should take care?
First I'd like to point out that the "preferred" method of granting
physical memory mappings to programs, is using the OKL4 object
environment.
The OKL4 object environment is configured using an XML file in build/
images/weaver.xml. This file is read during link time by the
Elfweaver tool. During system startup, the specified mappings will be
processed before any program starts execution.
The advantages are numerous, but here are two good ones: i) you avoid
taking the pagefault for mappings that you know will happen anyway;
and more importantly ii) programs are only given physical mappings for
those specified by the XML file.
In any case, here is how to configure the physical mapping:
a) next to other <physical_memory> tags, add:
<physical_memory name="kashin_mem">
<region base="0x01c40000" size="0x1000" />
</physical_memory>
b) next to other <physical_pool> tags, add:
<physical_pool name="kashin_pool" direct="true">
<memory src="kashin_mem" />
</physical_pool>
c) inside the <program> tag that you are running your test on, add:
<memsection name="kashin_memsect" size="0x1000"
physpool="kashin_pool" />
Now, in your program, you can do the following:
#include <l4/misc.h>
#include <l4/kdebug.h>
#include <iguana/env.h>
#include <iguana/memsection.h>
void
mapping_test()
{
memsection_ref_t ms;
int result;
uint32_t * ptr;
uintptr_t ms_base, ms_size;
size_t size;
ms = env_memsection(iguana_getenv("KASHIN_MEMSECT"));
ms_base = (uintptr_t)memsection_base(ms);
ms_size = memsection_size(ms);
result = memsection_virt_to_phys(ms_base, &size);
printf("base: 0x%lx, size: 0x%lx\n", (unsigned long)result,
(unsigned long)size);
printf("ms_base: 0x%lx, ms_size: 0x%lx\n", ms_base, ms_size);
ptr = (uint32_t *)ms_base;
*ptr = 0xdeadbeef;
printf("ptr: 0x%lx, *ptr: 0x%lx\n", (unsigned long)ptr, *ptr);
L4_KDB_Enter("Success!");
}
Now compile. But before you run it, you need to relink using the new
XML file.
$ rm -rf build/images/image.*
$ vim build/images/weaver.xml (apply the changes now)
$ ./tools/build.py <your_args> simulate
If you get an assertion like so:
Assertion failed: item, function env_memsection, file libs/iguana/src/
env.c, line 170.
then you haven't configured your XML properly.
You should see something like:
base: 0xfffffffe, size: 0x0
ms_base: 0x80090000, ms_size: 0x1000
ptr: 0x80090000, *ptr: 0xdeadbeef
--- KD# User: Success! ---
These are the same results as you have before. But now you're in KDB,
do the following:
> ptab (you should just press 'p')
Space [current]: current (you should just press 'return')
80000000 [f010b70c]: tree=f010b70c
80000000 [a0116c01]: tree=f4116c00
80040000 [00000000]: tree=f4116d00
8004c000 [a00d5ffe]: phys=a00d5000 pg=f4116d30 4KB rwx (RWX)
user WB domain = 9
8004d000 [a00d6ffe]: phys=a00d6000 pg=f4116d34 4KB rwx (RWX)
user WB domain = 9
8004e000 [a00d7ffe]: phys=a00d7000 pg=f4116d38 4KB rwx (RWX)
user WB domain = 9
80090000 [01c40ffe]: tree=f4116e40
80090000 [01c40ffe]: phys=01c40000 pg=f4116e40 4KB rwx (RWX)
user WB domain = 9
800a0000 [a0500ffd]: phys=a0500000 pg=f4116e80 64KB rwx (RWX)
user WB domain = 9
80600000 [a0118001]: tree=f4118000
80600000 [a0090aae]: tree=f4118000
80600000 [a0090aae]: phys=a0090000 pg=f4118000 4KB r~x (RWX)
user WB domain = 9
80601000 [a0091aae]: phys=a0091000 pg=f4118004 4KB r~x (RWX)
user WB domain = 9
80602000 [a0092aae]: phys=a0092000 pg=f4118008 4KB r~x (RWX)
user WB domain = 9
80603000 [a0093aae]: phys=a0093000 pg=f411800c 4KB r~x (RWX)
user WB domain = 9
80604000 [a0094aae]: phys=a0094000 pg=f4118010 4KB r~x (RWX)
user WB domain = 9
80605000 [a0095aae]: phys=a0095000 pg=f4118014 4KB r~x (RWX)
user WB domain = 9
80606000 [a0096aae]: phys=a0096000 pg=f4118018 4KB r~x (RWX)
user WB domain = 9
80607000 [a0097aae]: phys=a0097000 pg=f411801c 4KB r~x (RWX)
user WB domain = 9
80608000 [a0098aae]: phys=a0098000 pg=f4118020 4KB r~x (RWX)
user WB domain = 9
80610000 [a0072ffe]: tree=f4118040
80610000 [a0072ffe]: phys=a0072000 pg=f4118040 4KB rwx (RWX)
user WB domain = 9
What you're seeing is the page table. Notice how the entry for
80090000 actually maps to 01c40000 now.
Moreover, I can confirm that on our latest internal build, we're
seeing correct results like so:
base: 0x1c40000, size: 0x1000
ms_base: 0x80090000, ms_size: 0x1000
ptr: 0x80090000, *ptr: 0xdeadbeef
--- KD# User: Success! ---
What this means is that we have already fixed this bug recently, and
in the next public release you will be able to call
memsection_virt_to_phys() and get correct results.
I hope this helps! Keep the questions coming.
--
(nt)
Nelson Tam
nelson at ok-labs.com
More information about the Developer
mailing list