Hello sel4 developers,
I am using seL4 for in our arm64 based hardware platform.
I need to write a simple driver where i need to read/write some memory
mapped registers
The device physical address is "0x40520000"
When i print the bootinfo using the below code:
/*-- filter TaskContent("untyped-start", TaskContentType.ALL,
subtask='init') -*/
printf(" CSlot \tPaddr \tSize\tType\n");
for (seL4_CPtr slot = info->untyped.start; slot != info->untyped.end;
slot++) {
seL4_UntypedDesc *desc = &info->untypedList[slot -
info->untyped.start];
printf("%8p\t%16p\t2^%d\t%s\n", (void *) slot,
(void *) desc->paddr, desc->sizeBits, desc->isDevice ? "device untyped" :
"untyped");
I get the following output:
CSlot Paddr Size Type
0x1ac 0 2^30 device untyped
0x1ad 0x40000000 2^28 device untyped
0x1ae 0x50000000 2^23 device untyped
0x1af 0x50810000 2^16 device untyped
0x1b0 0x50820000 2^17 device untyped
I am mappint the physical address to virtual and trying to access it as:
va = ps_io_map(&ops.io_mapper, (uintptr_t) 0x40520000,0x3000,
PS_MEM_NORMAL);
ZF_LOGE("Physical address 0x%x mapped to virtual address %p
\n",DEV_REG_PADDR,va);
for(int j=0;j<DEV_REG_SIZE;j+=sizeof(unsigned int))
{
ZF_LOGE("Loc %d --> 0x%x ",j,*(unsigned int*)(va+j));
}
I am able to access some registers, but then it gives a fault (after
printing 5-6 register values)
Similar is the behaviour with any reg between the range 0x40000000 -
0x50000000
Attaching the sample code and output:
I am able to access first two address location, after that it gives halt.
Regards,
Misbah
#include <stdio.h>
#include <stdio.h>
#include <sel4/sel4.h>
#include <sel4platsupport/bootinfo.h>
#include <utils/util.h>
#include <sel4runtime.h>
#include <utils/arith.h>
#include <utils/attribute.h>
#include <platsupport/io.h>
#include <platsupport/irq.h>
#include <vka/vka.h>
#include <vspace/vspace.h>
#include <sel4runtime.h>
#include <allocman/bootstrap.h>
#include <allocman/vka.h>
#include <cpio/cpio.h>
#include <sel4debug/register_dump.h>
#include <sel4platsupport/device.h>
#include <sel4platsupport/platsupport.h>
#include <sel4utils/vspace.h>
#include <sel4utils/stack.h>
#include <sel4utils/process.h>
#include <simple/simple.h>
#include <simple-default/simple-default.h>
#include <utils/util.h>
#include <vka/object.h>
#include <vka/capops.h>
#include <vspace/vspace.h>
#include <sel4platsupport/io.h>
//#define DEV_REG_PADDR 0x4011c000
//#define DEV_REG_PADDR 0x40000000
#define DEV_REG_PADDR 0x40520000 //0x40000000
#define DEV_REG_SIZE 0x3000
//#define DEV_REG_SIZE 0x200000
/* ammount of untyped memory to reserve for the driver (32mb) */
#define DRIVER_UNTYPED_MEMORY (1 << 25)
/* Number of untypeds to try and use to allocate the driver memory.
* if we cannot get 32mb with 16 untypeds then something is probably wrong */
#define DRIVER_NUM_UNTYPEDS 16
/* dimensions of virtual memory for the allocator to use */
#define ALLOCATOR_VIRTUAL_POOL_SIZE ((1 << seL4_PageBits) * 100)
/* static memory for the allocator to bootstrap with */
#define ALLOCATOR_STATIC_POOL_SIZE ((1 << seL4_PageBits) * 20)
static char allocator_mem_pool[ALLOCATOR_STATIC_POOL_SIZE];
/* static memory for virtual memory bootstrapping */
static sel4utils_alloc_data_t data;
/* When the root task exists, it should simply suspend itself */
static void sel4test_exit(int code)
{
seL4_TCB_Suspend(seL4_CapInitThreadTCB);
}
/* initialise our runtime environment */
static int init_env(void)
{
/* An initialised vka that may be used by the test. */
vka_t vka;
/* virtual memory management interface */
vspace_t vspace;
/* abtracts over kernel version and boot environment */
simple_t simple;
/* IO ops for devices */
ps_io_ops_t ops;
allocman_t *allocman;
reservation_t virtual_reservation;
int error;
void *vaddr=NULL;
void *va=NULL;
ZF_LOGE("Enter::init_env()");
sel4runtime_set_exit(sel4test_exit);
seL4_BootInfo *info = platsupport_get_bootinfo(); /* get boot info */
simple_default_init_bootinfo(&simple, info); /* initialize simple object */
simple_print(&simple); /* print boot info and other info about image */
seL4_Word untyped_size_bits = seL4_TCBBits + 1;
seL4_CPtr parent_untyped = 0;
seL4_CPtr child_untyped = info->empty.start;
seL4_CPtr child_tcb = child_untyped + 1;
seL4_CPtr child_ep = child_tcb + 1;
/*-- filter TaskContent("untyped-start", TaskContentType.ALL,
subtask='init') -*/
printf(" CSlot \tPaddr \tSize\tType\n");
for (seL4_CPtr slot = info->untyped.start; slot != info->untyped.end;
slot++) {
seL4_UntypedDesc *desc = &info->untypedList[slot - info->untyped.start];
#if 0
if(desc->paddr == 0x40000000)
{
printf("Got address for the physical device ...\n");
parent_untyped = info->untyped.start;
child_untyped = info->empty.start;
untyped_size_bits = desc->sizeBits;
error = seL4_Untyped_Retype(parent_untyped, // the untyped
capability to retype
seL4_UntypedObject, // type
untyped_size_bits, //size
seL4_CapInitThreadCNode, // root
0, // node_index
0, // node_depth
child_untyped, // node_offset
1 // num_caps
);
ZF_LOGF_IF(error != seL4_NoError, "Failed to create
endpoints.");
}
#endif
printf("%8p\t%16p\t2^%d\t%s\n", (void *) slot, (void *) desc->paddr,
desc->sizeBits, desc->isDevice ? "device untyped" : "untyped");
}
/*-- endfilter -*/
//seL4_Word num_eps = BIT(untyped_size_bits - seL4_EndpointBits);
//error = seL4_Untyped_Retype(child_untyped, seL4_EndpointObject, 0,
seL4_CapInitThreadCNode, 0, 0, child_tcb, num_eps);
printf("Success\n");
ZF_LOGE("Calling bootstrap_use_current_simple() ...");
/* create an allocator */
allocman = bootstrap_use_current_simple(&simple,
ALLOCATOR_STATIC_POOL_SIZE, allocator_mem_pool);
if (allocman == NULL) {
ZF_LOGF("Failed to create allocman");
return -1;
}
ZF_LOGE("bootstrap_use_current_simple() done");
/* create a vka (interface for interacting with the underlying allocator) */
allocman_make_vka(&vka, allocman);
/* create a vspace (virtual memory management interface). We pass
* boot info not because it will use capabilities from it, but so
* it knows the address and will add it as a reserved region */
error = sel4utils_bootstrap_vspace_with_bootinfo_leaky(&vspace,
&data,
simple_get_pd(&simple),
&vka,
platsupport_get_bootinfo());
if (error) {
ZF_LOGF("Failed to bootstrap vspace");
return -1;
}
ZF_LOGE("sel4utils_bootstrap_vspace_with_bootinfo_leaky() done");
/* fill the allocator with virtual memory */
virtual_reservation = vspace_reserve_range(&vspace,
ALLOCATOR_VIRTUAL_POOL_SIZE,
seL4_AllRights, 1, &vaddr);
if (virtual_reservation.res == 0) {
ZF_LOGF("Failed to provide virtual memory for allocator");
return -1;
}
ZF_LOGE("vspace_reserve_range() done");
bootstrap_configure_virtual_pool(allocman, vaddr,
ALLOCATOR_VIRTUAL_POOL_SIZE,
simple_get_pd(&simple));
ZF_LOGE("bootstrap_configure_virtual_pool() done");
error = sel4platsupport_new_io_ops(&vspace, &vka, &simple, &ops);
ZF_LOGF_IF(error, "Failed to initialise IO ops");
ZF_LOGE("Page size = 0x%x ",(1 << seL4_PageBits));
va = ps_io_map(&ops.io_mapper, (uintptr_t) DEV_REG_PADDR, DEV_REG_SIZE, 0,
PS_MEM_NORMAL);
if (va == NULL) {
ZF_LOGE("ps_io_map() failed to map frame");
return -1;
}
ZF_LOGE("Physical address 0x%x mapped to virtual address %p
\n",DEV_REG_PADDR,va);
for(int j=0;j<DEV_REG_SIZE;j+=sizeof(unsigned int))
{
ZF_LOGE("Loc %d --> 0x%x ",j,*(unsigned int*)(va+j));
}
//ZF_LOGE("1 Data read before write = 0x%x \n",*(unsigned int*)va);
//*(unsigned int*)(va+i) = 1;
//ZF_LOGE("2. Data read after write = 0x%x \n",*(unsigned int *)va);
ZF_LOGE("Exit::init_env()");
return 0;
}
int main(void)
{
printf("\n $$$ Hello World! $$$ \n\n");
init_env();
#ifdef CONFIG_DEBUG_BUILD
seL4_DebugNameThread(seL4_CapInitThreadTCB, "hello-world");
#endif
return 0;
}
=> boot
2482408 bytes read in 19 ms (124.6 MiB/s)
## Starting application at 0x807cf000 ...
Enter::platform_init
Exit::platform_init
ELF-loader started on CPU: ARM Ltd. Cortex-A53 r0p4
paddr=[807cf000..80a011af]
No DTB passed in from boot loader.
Looking for DTB in CPIO archive...found at 808f98e0.
Loaded DTB from 808f98e0.
paddr=[80245000..80253fff]
ELF-loading image 'kernel' to 80000000
paddr=[80000000..80244fff]
vaddr=[ffffff8080000000..ffffff8080244fff]
virt_entry=ffffff8080000000
ELF-loading image 'hello' to 80254000
paddr=[80254000..803ddfff]
vaddr=[400000..589fff]
virt_entry=428ac8
Enabling MMU and paging
Jumping to kernel-image entry point...
Bootstrapping kernel
available phys memory regions: 3
[80000000..83200000]
[835e0000..84000000]
[84400000..a0000000]
reserved virt address space regions: 3
[ffffff8080000000..ffffff8080245000]
[ffffff8080245000..ffffff8080253b44]
[ffffff8080254000..ffffff80803de000]
@@@ paddr = 0x0 sizeBits = 30
@@@ paddr = 0x40000000 sizeBits = 28
#### paddr is matched
@@@ paddr = 0x50000000 sizeBits = 23
@@@ paddr = 0x50810000 sizeBits = 16
@@@ paddr = 0x50820000 sizeBits = 17
@@@ paddr = 0x50840000 sizeBits = 18
@@@ paddr = 0x50880000 sizeBits = 19
@@@ paddr = 0x50a00000 sizeBits = 21
@@@ paddr = 0x50c00000 sizeBits = 22
@@@ paddr = 0x51000000 sizeBits = 24
@@@ paddr = 0x52000000 sizeBits = 25
@@@ paddr = 0x54000000 sizeBits = 26
@@@ paddr = 0x58000000 sizeBits = 27
@@@ paddr = 0x60000000 sizeBits = 29
@@@ paddr = 0x83200000 sizeBits = 21
@@@ paddr = 0x83400000 sizeBits = 20
@@@ paddr = 0x83500000 sizeBits = 19
@@@ paddr = 0x83580000 sizeBits = 18
@@@ paddr = 0x835c0000 sizeBits = 17
@@@ paddr = 0x84000000 sizeBits = 22
@@@ paddr = 0xa0000000 sizeBits = 29
@@@ paddr = 0xc0000000 sizeBits = 30
@@@ paddr = 0x100000000 sizeBits = 32
@@@ paddr = 0x200000000 sizeBits = 33
@@@ paddr = 0x400000000 sizeBits = 34
@@@ paddr = 0x800000000 sizeBits = 35
@@@ paddr = 0x1000000000 sizeBits = 36
@@@ paddr = 0x2000000000 sizeBits = 37
@@@ paddr = 0x4000000000 sizeBits = 38
@@@ paddr = 0x8000000000 sizeBits = 39
@@@ paddr = 0x80000000 sizeBits = 16
@@@ paddr = 0x80253b50 sizeBits = 4
@@@ paddr = 0x80253b60 sizeBits = 5
@@@ paddr = 0x80253b80 sizeBits = 7
@@@ paddr = 0x80253c00 sizeBits = 10
@@@ paddr = 0x803de000 sizeBits = 13
@@@ paddr = 0x803e0000 sizeBits = 17
@@@ paddr = 0x80400000 sizeBits = 22
@@@ paddr = 0x80800000 sizeBits = 23
@@@ paddr = 0x81000000 sizeBits = 24
@@@ paddr = 0x82000000 sizeBits = 24
@@@ paddr = 0x83000000 sizeBits = 21
@@@ paddr = 0x835e0000 sizeBits = 17
@@@ paddr = 0x83600000 sizeBits = 21
@@@ paddr = 0x83800000 sizeBits = 23
@@@ paddr = 0x84400000 sizeBits = 22
@@@ paddr = 0x84800000 sizeBits = 23
@@@ paddr = 0x85000000 sizeBits = 24
@@@ paddr = 0x86000000 sizeBits = 25
@@@ paddr = 0x88000000 sizeBits = 27
@@@ paddr = 0x90000000 sizeBits = 27
@@@ paddr = 0x98000000 sizeBits = 26
@@@ paddr = 0x9c000000 sizeBits = 25
@@@ paddr = 0x9e000000 sizeBits = 24
@@@ paddr = 0x9f000000 sizeBits = 23
@@@ paddr = 0x9f800000 sizeBits = 22
@@@ paddr = 0x9fc00000 sizeBits = 21
@@@ paddr = 0x9fe00000 sizeBits = 20
@@@ paddr = 0x9ff00000 sizeBits = 19
@@@ paddr = 0x9ff80000 sizeBits = 18
@@@ paddr = 0x9fff7800 sizeBits = 11
@@@ paddr = 0x9fff8000 sizeBits = 15
Booting all finished, dropped to user space
Warning: using printf before serial is set up. This only works as your
printf is backed by seL4_Debug_PutChar()
$$$ Hello World! $$$
[email protected]:82 Enter::init_env()
Node 0 of 1
IOPT levels: 0
IPC buffer: 0x58a000
Empty slots: [490 --> 4096)
sharedFrames: [0 --> 0)
userImageFrames: [34 --> 428)
userImagePaging: [16 --> 19)
untypeds: [428 --> 490)
Initial thread domain: 0
Initial thread cnode size: 12
List of untypeds
------------------
Paddr | Size | Device
0 | 30 | 1
0x40000000 | 28 | 1
0x50000000 | 23 | 1
0x50810000 | 16 | 1
0x50820000 | 17 | 1
0x50840000 | 18 | 1
0x50880000 | 19 | 1
0x50a00000 | 21 | 1
0x50c00000 | 22 | 1
0x51000000 | 24 | 1
0x52000000 | 25 | 1
0x54000000 | 26 | 1
0x58000000 | 27 | 1
0x60000000 | 29 | 1
0x83200000 | 21 | 1
0x83400000 | 20 | 1
0x83500000 | 19 | 1
0x83580000 | 18 | 1
0x835c0000 | 17 | 1
0x84000000 | 22 | 1
0xa0000000 | 29 | 1
0xc0000000 | 30 | 1
0x100000000 | 32 | 1
0x200000000 | 33 | 1
0x400000000 | 34 | 1
0x800000000 | 35 | 1
0x1000000000 | 36 | 1
0x2000000000 | 37 | 1
0x4000000000 | 38 | 1
0x8000000000 | 39 | 1
0x80000000 | 16 | 0
0x80253b50 | 4 | 0
0x80253b60 | 5 | 0
0x80253b80 | 7 | 0
0x80253c00 | 10 | 0
0x803de000 | 13 | 0
0x803e0000 | 17 | 0
0x80400000 | 22 | 0
0x80800000 | 23 | 0
0x81000000 | 24 | 0
0x82000000 | 24 | 0
0x83000000 | 21 | 0
0x835e0000 | 17 | 0
0x83600000 | 21 | 0
0x83800000 | 23 | 0
0x84400000 | 22 | 0
0x84800000 | 23 | 0
0x85000000 | 24 | 0
0x86000000 | 25 | 0
0x88000000 | 27 | 0
0x90000000 | 27 | 0
0x98000000 | 26 | 0
0x9c000000 | 25 | 0
0x9e000000 | 24 | 0
0x9f000000 | 23 | 0
0x9f800000 | 22 | 0
0x9fc00000 | 21 | 0
0x9fe00000 | 20 | 0
0x9ff00000 | 19 | 0
0x9ff80000 | 18 | 0
0x9fff7800 | 11 | 0
0x9fff8000 | 15 | 0
Untyped summary
1 untypeds of size 4
1 untypeds of size 5
1 untypeds of size 7
1 untypeds of size 10
1 untypeds of size 11
1 untypeds of size 13
1 untypeds of size 15
2 untypeds of size 16
4 untypeds of size 17
3 untypeds of size 18
3 untypeds of size 19
2 untypeds of size 20
5 untypeds of size 21
5 untypeds of size 22
5 untypeds of size 23
5 untypeds of size 24
3 untypeds of size 25
2 untypeds of size 26
3 untypeds of size 27
1 untypeds of size 28
2 untypeds of size 29
2 untypeds of size 30
1 untypeds of size 32
1 untypeds of size 33
1 untypeds of size 34
1 untypeds of size 35
1 untypeds of size 36
1 untypeds of size 37
1 untypeds of size 38
1 untypeds of size 39
CSlot Paddr Size Type
0x1ac 0 2^30 device untyped
0x1ad 0x40000000 2^28 device untyped
0x1ae 0x50000000 2^23 device untyped
0x1af 0x50810000 2^16 device untyped
0x1b0 0x50820000 2^17 device untyped
0x1b1 0x50840000 2^18 device untyped
0x1b2 0x50880000 2^19 device untyped
0x1b3 0x50a00000 2^21 device untyped
0x1b4 0x50c00000 2^22 device untyped
0x1b5 0x51000000 2^24 device untyped
0x1b6 0x52000000 2^25 device untyped
0x1b7 0x54000000 2^26 device untyped
0x1b8 0x58000000 2^27 device untyped
0x1b9 0x60000000 2^29 device untyped
0x1ba 0x83200000 2^21 device untyped
0x1bb 0x83400000 2^20 device untyped
0x1bc 0x83500000 2^19 device untyped
0x1bd 0x83580000 2^18 device untyped
0x1be 0x835c0000 2^17 device untyped
0x1bf 0x84000000 2^22 device untyped
0x1c0 0xa0000000 2^29 device untyped
0x1c1 0xc0000000 2^30 device untyped
0x1c2 0x100000000 2^32 device untyped
0x1c3 0x200000000 2^33 device untyped
0x1c4 0x400000000 2^34 device untyped
0x1c5 0x800000000 2^35 device untyped
0x1c6 0x1000000000 2^36 device untyped
0x1c7 0x2000000000 2^37 device untyped
0x1c8 0x4000000000 2^38 device untyped
0x1c9 0x8000000000 2^39 device untyped
0x1ca 0x80000000 2^16 untyped
0x1cb 0x80253b50 2^4 untyped
0x1cc 0x80253b60 2^5 untyped
0x1cd 0x80253b80 2^7 untyped
0x1ce 0x80253c00 2^10 untyped
0x1cf 0x803de000 2^13 untyped
0x1d0 0x803e0000 2^17 untyped
0x1d1 0x80400000 2^22 untyped
0x1d2 0x80800000 2^23 untyped
0x1d3 0x81000000 2^24 untyped
0x1d4 0x82000000 2^24 untyped
0x1d5 0x83000000 2^21 untyped
0x1d6 0x835e0000 2^17 untyped
0x1d7 0x83600000 2^21 untyped
0x1d8 0x83800000 2^23 untyped
0x1d9 0x84400000 2^22 untyped
0x1da 0x84800000 2^23 untyped
0x1db 0x85000000 2^24 untyped
0x1dc 0x86000000 2^25 untyped
0x1dd 0x88000000 2^27 untyped
0x1de 0x90000000 2^27 untyped
0x1df 0x98000000 2^26 untyped
0x1e0 0x9c000000 2^25 untyped
0x1e1 0x9e000000 2^24 untyped
0x1e2 0x9f000000 2^23 untyped
0x1e3 0x9f800000 2^22 untyped
0x1e4 0x9fc00000 2^21 untyped
0x1e5 0x9fe00000 2^20 untyped
0x1e6 0x9ff00000 2^19 untyped
0x1e7 0x9ff80000 2^18 untyped
0x1e8 0x9fff7800 2^11 untyped
0x1e9 0x9fff8000 2^15 untyped
Success
[email protected]:129 Calling bootstrap_use_current_simple() ...
[email protected]:137 bootstrap_use_current_simple() done
[email protected]:151 sel4utils_bootstrap_vspace_with_bootinfo_leaky() done
[email protected]:160 vspace_reserve_range() done
[email protected]:165 bootstrap_configure_virtual_pool() done
[email protected]:169 Page size = 0x1000
[email protected]:175 Physical address 0x40520000 mapped to virtual address
0x10064000
[email protected]:179 Loc 0 --> 0x0
[email protected]:179 Loc 4 --> 0x0
Caught cap fault in send phase at address 0
while trying to handle:
vm fault on data at address 0x10064008 with status 0x92000210
in thread 0xffffff809fff7400 "rootserver" at address 0x4011c4
With stack:
0x483b80: 0x483ea0
0x483b88: 0x40127c
0x483b90: 0x484000
0x483b98: 0x1
0x483ba0: 0x483bd0
0x483ba8: 0x10000000
0x483bb0: 0x489020
0x483bb8: 0x489060
0x483bc0: 0x423e7c
0x483bc8: 0x424008
0x483bd0: 0x0
0x483bd8: 0x0
0x483be0: 0x0
0x483be8: 0x0
0x483bf0: 0x0
0x483bf8: 0x0
_______________________________________________
Devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]