* Newbie question about accessing memory in kernel space
@ 2005-05-24 19:19 Niklaus Giger
2005-05-24 20:17 ` Wolfgang Grandegger
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Niklaus Giger @ 2005-05-24 19:19 UTC (permalink / raw)
To: linuxppc-embedded, rtai
Hi
I am working on a custom PPC405 board where I have a 2.6.10 kernel with RTAI
patches (fusion) running.
I am trying to access some custom CPLD chip hanging at 0x7D000000. In my
intial board (hcu3_map_io) I added a corresponding io_block_mapping.
I can see the CPLD when I access the address via my Abatron BDI debugger.
In a user space test program I did a
map_base = mmap((void *)target, nSize, PROT_READ | PROT_WRITE, MAP_SHARED,
fd, target);
and was able to access the CPLD, too.
In user and kernel space the procedure looks like this:
void sys_set_tick_control_register_value(uint16 value)
{
static uint16 *tickControlRegister = (uint16*)
HCU_TICK_CONTROL_REGISTER_ADDRESS;
*tickControlRegister = value;
}
Now I compiled a module which tries to access the CPLD during the insmod phase
and I get the following output.
Oops: kernel access of bad area, sig: 11 [#1]
NIP: C302B0C4 LR: C302B350 SP: C1DABED0 REGS: c1dabe20 TRAP: 0300 Not
tainted
MSR: 00029030 EE: 1 PR: 0 FP: 0 ME: 1 IR/DR: 11
DAR: 7D000000, DSISR: 00800000
TASK = c1d827b0[27] 'insmod' THREAD: c1daa000
Last syscall: 128
PLB0: bear= 0x04000004 acr= 0x00000000 besr= 0x00000000
PLB0 to OPB: bear= 0xef6007ff besr0= 0x00000000 besr1= 0x00000000
GPR00: C302B348 C1DABED0 C1D827B0 0000002B 00000CAC FFFFFFFF C01C0000 00029030
GPR08: C01CBB30 C3030000 00000000 7D000000 00000000 10075308 01FFBC00 007FFF77
GPR16: 00000000 00000001 10050000 00000002 7FFFFF68 10070000 00000001 C3030000
GPR24: C3030000 C3030000 FFFFFFFF 00000000 C3030000 C3030000 C0189318 C302BEC0
NIP [c302b0c4] sys_set_tick_control_register_value+0x8/0x10 [kTickTest]
LR [c302b350] init_module+0xd0/0x10c [kTickTest]
Call trace:
[c0030954] sys_init_module+0x218/0x328
[c0002900] syscall_dotrace_cont+0x24/0x38
Segmentation fault
What is wrong with my code?
Any hints would be appreciated.
Thanks in advance.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Newbie question about accessing memory in kernel space
2005-05-24 19:19 Niklaus Giger
@ 2005-05-24 20:17 ` Wolfgang Grandegger
2005-05-24 20:31 ` Matt Porter
2005-05-24 23:58 ` Roger Larsson
2 siblings, 0 replies; 7+ messages in thread
From: Wolfgang Grandegger @ 2005-05-24 20:17 UTC (permalink / raw)
To: niklaus.giger; +Cc: rtai, linuxppc-embedded
On 05/24/2005 09:19 PM Niklaus Giger wrote:
> Hi
>
> I am working on a custom PPC405 board where I have a 2.6.10 kernel with RTAI
> patches (fusion) running.
>
> I am trying to access some custom CPLD chip hanging at 0x7D000000. In my
> intial board (hcu3_map_io) I added a corresponding io_block_mapping.
>
> I can see the CPLD when I access the address via my Abatron BDI debugger.
>
> In a user space test program I did a
> map_base = mmap((void *)target, nSize, PROT_READ | PROT_WRITE, MAP_SHARED,
> fd, target);
> and was able to access the CPLD, too.
>
> In user and kernel space the procedure looks like this:
> void sys_set_tick_control_register_value(uint16 value)
> {
> static uint16 *tickControlRegister = (uint16*)
> HCU_TICK_CONTROL_REGISTER_ADDRESS;
> *tickControlRegister = value;
> }
>
> Now I compiled a module which tries to access the CPLD during the insmod phase
> and I get the following output.
>
> Oops: kernel access of bad area, sig: 11 [#1]
> NIP: C302B0C4 LR: C302B350 SP: C1DABED0 REGS: c1dabe20 TRAP: 0300 Not
> tainted
> MSR: 00029030 EE: 1 PR: 0 FP: 0 ME: 1 IR/DR: 11
> DAR: 7D000000, DSISR: 00800000
> TASK = c1d827b0[27] 'insmod' THREAD: c1daa000
> Last syscall: 128
> PLB0: bear= 0x04000004 acr= 0x00000000 besr= 0x00000000
> PLB0 to OPB: bear= 0xef6007ff besr0= 0x00000000 besr1= 0x00000000
>
> GPR00: C302B348 C1DABED0 C1D827B0 0000002B 00000CAC FFFFFFFF C01C0000 00029030
> GPR08: C01CBB30 C3030000 00000000 7D000000 00000000 10075308 01FFBC00 007FFF77
> GPR16: 00000000 00000001 10050000 00000002 7FFFFF68 10070000 00000001 C3030000
> GPR24: C3030000 C3030000 FFFFFFFF 00000000 C3030000 C3030000 C0189318 C302BEC0
> NIP [c302b0c4] sys_set_tick_control_register_value+0x8/0x10 [kTickTest]
> LR [c302b350] init_module+0xd0/0x10c [kTickTest]
> Call trace:
> [c0030954] sys_init_module+0x218/0x328
> [c0002900] syscall_dotrace_cont+0x24/0x38
> Segmentation fault
>
> What is wrong with my code?
If the physical address is not already mapped an ioremap() is required
in kernel space.
> Any hints would be appreciated.
>
> Thanks in advance.
>
> _______________________________________________
> RTAI mailing list
> RTAI@rtai.org
> https://mail.rtai.org/cgi-bin/mailman/listinfo/rtai
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Newbie question about accessing memory in kernel space
2005-05-24 19:19 Niklaus Giger
2005-05-24 20:17 ` Wolfgang Grandegger
@ 2005-05-24 20:31 ` Matt Porter
2005-05-25 11:31 ` Niklaus Giger
2005-05-24 23:58 ` Roger Larsson
2 siblings, 1 reply; 7+ messages in thread
From: Matt Porter @ 2005-05-24 20:31 UTC (permalink / raw)
To: Niklaus Giger; +Cc: rtai, linuxppc-embedded
On Tue, May 24, 2005 at 09:19:28PM +0200, Niklaus Giger wrote:
> Hi
>
> I am working on a custom PPC405 board where I have a 2.6.10 kernel with RTAI
> patches (fusion) running.
>
> I am trying to access some custom CPLD chip hanging at 0x7D000000. In my
> intial board (hcu3_map_io) I added a corresponding io_block_mapping.
Is a "corresponding" mapping a 1:1 mapping? Don't do that. You cannot
map stuff that way since it is below TASK_SIZE i.e. it's in user address
space, not kernel address space.
> Now I compiled a module which tries to access the CPLD during the insmod phase
> and I get the following output.
>
> Oops: kernel access of bad area, sig: 11 [#1]
<snip>
> What is wrong with my code?
You mapped the device into user virtual address space. The TLB
replacement code is unable to load a TLB entry for a page outside
of kernel space...so you crash.
Don't use io_block_map()...it allows you to shoot yourself in the
foot very easily (as you just witnessed). Use ioremap() to map
your device.
-Matt
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Newbie question about accessing memory in kernel space
2005-05-24 19:19 Niklaus Giger
2005-05-24 20:17 ` Wolfgang Grandegger
2005-05-24 20:31 ` Matt Porter
@ 2005-05-24 23:58 ` Roger Larsson
2005-05-25 11:35 ` Niklaus Giger
2 siblings, 1 reply; 7+ messages in thread
From: Roger Larsson @ 2005-05-24 23:58 UTC (permalink / raw)
To: linuxppc-embedded
On Tuesday 24 May 2005 21.19, Niklaus Giger wrote:
> Hi
>
> I am working on a custom PPC405 board where I have a 2.6.10 kernel with
> RTAI patches (fusion) running.
>
> I am trying to access some custom CPLD chip hanging at 0x7D000000. In my
> intial board (hcu3_map_io) I added a corresponding io_block_mapping.
>
> I can see the CPLD when I access the address via my Abatron BDI debugger.
>
> In a user space test program I did a
> map_base = mmap((void *)target, nSize, PROT_READ | PROT_WRITE,
> MAP_SHARED, fd, target);
> and was able to access the CPLD, too.
Via 'map_base' I guess?
For kernel try
virt_base=ioremap(target, nSize)
>
> In user and kernel space the procedure looks like this:
> void sys_set_tick_control_register_value(uint16 value)
> {
> static uint16 *tickControlRegister = (uint16*)
> HCU_TICK_CONTROL_REGISTER_ADDRESS;
This indicates that you tries to read directly from an adress (no virt_base?)
You might want to use __raw_readl instead (depending on bus endianess).
/RogerL
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Newbie question about accessing memory in kernel space
2005-05-24 20:31 ` Matt Porter
@ 2005-05-25 11:31 ` Niklaus Giger
0 siblings, 0 replies; 7+ messages in thread
From: Niklaus Giger @ 2005-05-25 11:31 UTC (permalink / raw)
To: Matt Porter; +Cc: rtai, linuxppc-embedded
Am Dienstag, 24. Mai 2005 22.31 schrieb Matt Porter:
> On Tue, May 24, 2005 at 09:19:28PM +0200, Niklaus Giger wrote:
> > Hi
> > Oops: kernel access of bad area, sig: 11 [#1]
>
> <snip>
>
> > What is wrong with my code?
>
> You mapped the device into user virtual address space. The TLB
> replacement code is unable to load a TLB entry for a page outside
> of kernel space...so you crash.
>
> Don't use io_block_map()...it allows you to shoot yourself in the
> foot very easily (as you just witnessed). Use ioremap() to map
> your device.
ioremap() fixed my problem.
Thanks a lot for your help.
Best regards
Niklaus
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Newbie question about accessing memory in kernel space
2005-05-24 23:58 ` Roger Larsson
@ 2005-05-25 11:35 ` Niklaus Giger
0 siblings, 0 replies; 7+ messages in thread
From: Niklaus Giger @ 2005-05-25 11:35 UTC (permalink / raw)
To: linuxppc-embedded
Am Mittwoch, 25. Mai 2005 01.58 schrieb Roger Larsson:
> On Tuesday 24 May 2005 21.19, Niklaus Giger wrote:
> > Hi
> >
> > I am working on a custom PPC405 board where I have a 2.6.10 kernel with
> > RTAI patches (fusion) running.
> >
> > I am trying to access some custom CPLD chip hanging at 0x7D000000. In my
> > intial board (hcu3_map_io) I added a corresponding io_block_mapping.
> >
> > I can see the CPLD when I access the address via my Abatron BDI debugger.
> >
> > In a user space test program I did a
> > map_base = mmap((void *)target, nSize, PROT_READ | PROT_WRITE,
> > MAP_SHARED, fd, target);
> > and was able to access the CPLD, too.
>
> Via 'map_base' I guess?
>
> For kernel try
> virt_base=ioremap(target, nSize)
Thanks this fixed my problem.
> > In user and kernel space the procedure looks like this:
> > void sys_set_tick_control_register_value(uint16 value)
> > {
> > static uint16 *tickControlRegister = (uint16*)
> > HCU_TICK_CONTROL_REGISTER_ADDRESS;
>
> This indicates that you tries to read directly from an adress (no
> virt_base?) You might want to use __raw_readl instead (depending on bus
> endianess).
__raw_readl was not necessary.
Thanks for your help.
Best regards
Niklaus
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Newbie question about accessing memory in kernel space
[not found] <20050525020004.CCA3A67A3F@ozlabs.org>
@ 2005-05-25 13:17 ` David Bruce
0 siblings, 0 replies; 7+ messages in thread
From: David Bruce @ 2005-05-25 13:17 UTC (permalink / raw)
To: linuxppc-embedded
I was going down the same path as you are a year ago and had similar
issues. This book covers up to 2.4 but will probably answer future
issues you encounter:
http://www.xml.com/ldd/chapter/book/
The code in book:
http://examples.oreilly.com/linuxdrive2/
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2005-05-25 13:49 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20050525020004.CCA3A67A3F@ozlabs.org>
2005-05-25 13:17 ` Newbie question about accessing memory in kernel space David Bruce
2005-05-24 19:19 Niklaus Giger
2005-05-24 20:17 ` Wolfgang Grandegger
2005-05-24 20:31 ` Matt Porter
2005-05-25 11:31 ` Niklaus Giger
2005-05-24 23:58 ` Roger Larsson
2005-05-25 11:35 ` Niklaus Giger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).