Skip to contentSkip to conversation

"Kernel access of bad area" in kernel module

DISCUSSION Jack 2 participants 5 messages Oct 1, 2013 – Oct 10, 2013

lore
Share & tools
lore

Jack

author
#0 lore raw

Hi,
I want to set/reset GPIO registers in freescale p1022 processor. I saw a hello-mod kernel module in yocto and I added it to my image and it worked. According to hello-mod kernel module, I created GPIO module like hello-mod. But it GPIO module failed when I run it in kernel level. I checked several times addresses of registers and it seems accurate.
My code is here :

#include <linux/module.h>

int init_module(void)

{
	volatile uint32_t * Guts_Pmuxcr;
	volatile uint32_t * Gpio3_Gpdir;
	volatile uint32_t * Gpio3_Gpdat;
	
	// e500 Core View To Power Architecture CCSR: 0x0_FF70_0000

       // GUTS_PMUXCR:Alternate Function Signal Multiplex Control Register
	Guts_Pmuxcr = (volatile uint32_t *)(0xFF7E0060);
      
        // GPIO3_GPDIR: GPIO3 direction register
	Gpio3_Gpdir = (volatile uint32_t *)(0xFF70F200);

        // GPIO3_GPDAT: GPIO3 data register
	Gpio3_Gpdat = (volatile uint32_t *)(0xFF70F208); 
	 

	// Enable GPIO3[10]: IRQ_DEBUG1_GPIO FIELD [BIT 26] set to "1"
	*(Guts_Pmuxcr) = 0x00000010;
	 

	// Set Direction for GPIO3[10] to Output: FIELD DR10 [BIT 10] set to '1'
	*(Gpio3_Gpdir) = 0x00200000;
	
	 
	// Set GPIO3[10] to '0': FIELD D10 [BIT 10] set to '0'
	*(Gpio3_Gpdat) = 0x00000000;
	
	printk("Hello World!\n");
	return 0;
}

void cleanup_module(void)

{
	printk("Goodbye Cruel World!\n");
}

MODULE_LICENSE("GPL");

When I write insmod GPIO.ko in the terminal I get error these errors:

Unable to handle kernel paging request for data at address 0xff7e0060
faulting instruction address: 0xf107e05c
Oops: Kernel access of bad area, sig: 11 [#1]

..........
.........

How can I solve this problem?

#1 lore raw
Quoted 23 lines · Jack

Hi,
I want to set/reset GPIO registers in freescale p1022 processor. I saw a
hello-mod kernel module in yocto and I added it to my image and it worked.
According to hello-mod kernel module, I created GPIO module like hello-mod.
But it GPIO module failed when I run it in kernel level. I checked several
times addresses of registers and it seems accurate.
My code is here :

#include <linux/module.h>

int init_module(void)

{
	volatile uint32_t * Guts_Pmuxcr;
	volatile uint32_t * Gpio3_Gpdir;
	volatile uint32_t * Gpio3_Gpdat;
	
	// e500 Core View To Power Architecture CCSR: 0x0_FF70_0000
Quoted 8 lines
   // GUTS_PMUXCR:Alternate Function Signal Multiplex Control Register
	Guts_Pmuxcr = (volatile uint32_t *)(0xFF7E0060);
     
       // GPIO3_GPDIR: GPIO3 direction register
	Gpio3_Gpdir = (volatile uint32_t *)(0xFF70F200);

       // GPIO3_GPDAT: GPIO3 data register
	Gpio3_Gpdat = (volatile uint32_t *)(0xFF70F208); 

You should generally a of trying to dereference physical addresses, or you should explicitly declare them as such.

If suggest looking for some info on using GPIO on your CPU. Unfortunately, I've not used the p1022, so I can't really help you.

http://linuxppc.10917.n7.nabble.com/Re-GPIO-IRQ-on-P1022-td59356.html discusses some IRQ issues, though you should be able to use the codes as an example of the GPIO framework and how to use it.

Cheers,
Anders

Quoted 43 lines
	// Enable GPIO3[10]: IRQ_DEBUG1_GPIO FIELD [BIT 26] set to "1"
	*(Guts_Pmuxcr) = 0x00000010;




	// Set Direction for GPIO3[10] to Output: FIELD DR10 [BIT 10] set to
'1'
	*(Gpio3_Gpdir) = 0x00200000;
	
	 
	// Set GPIO3[10] to '0': FIELD D10 [BIT 10] set to '0'
	*(Gpio3_Gpdat) = 0x00000000;
	
	printk("Hello World!\n");
	return 0;
}

void cleanup_module(void)

{
	printk("Goodbye Cruel World!\n");
}

MODULE_LICENSE("GPL");

When I write insmod GPIO.ko in the terminal I get error these errors:

Unable to handle kernel paging request for data at address 0xff7e0060
faulting instruction address: 0xf107e05c
Oops: Kernel access of bad area, sig: 11 [#1]

..........
.........

How can I solve this problem?

_______________________________________________
yocto mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/yocto

Signature · 6 lines
Anders Darander
ChargeStorm AB          Tel: +46 702 44 84 36
Laxholmstorget 3        Email: [email protected]
602 21 Norrköping       Web: www.chargestorm.se

Sent from my Android phone with K-9 Mail. Please excuse my brevity.
author
#2 lore raw

(No subject)

Quoted 29 lines · Anders Darander
Quoted 26 lines · Jack <jackrubby2010 <at> gmail.com> wrote:

Hi,
I want to set/reset GPIO registers in freescale p1022 processor. I saw a
hello-mod kernel module in yocto and I added it to my image and it worked.
According to hello-mod kernel module, I created GPIO module like hello-mod.
But it GPIO module failed when I run it in kernel level. I checked several
times addresses of registers and it seems accurate.
My code is here :

#include <linux/module.h>

int init_module(void)

{
	volatile uint32_t * Guts_Pmuxcr;
	volatile uint32_t * Gpio3_Gpdir;
	volatile uint32_t * Gpio3_Gpdat;
	
	// e500 Core View To Power Architecture CCSR: 0x0_FF70_0000
   // GUTS_PMUXCR:Alternate Function Signal Multiplex Control Register
	Guts_Pmuxcr = (volatile uint32_t *)(0xFF7E0060);
Quoted 7 lines
Quoted 5 lines
       // GPIO3_GPDIR: GPIO3 direction register
	Gpio3_Gpdir = (volatile uint32_t *)(0xFF70F200);

       // GPIO3_GPDAT: GPIO3 data register
	Gpio3_Gpdat = (volatile uint32_t *)(0xFF70F208); 

You should generally a of trying to dereference physical addresses, or you

should explicitly declare them

Quoted 3 lines

as such.

If suggest looking for some info on using GPIO on your CPU. Unfortunately,

I've not used the p1022, so I can't

Quoted 3 lines

really help you.

http://linuxppc.10917.n7.nabble.com/Re-GPIO-IRQ-on-P1022-td59356.html

discusses some IRQ

Quoted 1 line

issues, though you should be able to use the codes as an example of the

GPIO framework and how to use it.

Quoted 47 lines

Cheers,
Anders

Quoted 42 lines
	// Enable GPIO3[10]: IRQ_DEBUG1_GPIO FIELD [BIT 26] set to "1"
	*(Guts_Pmuxcr) = 0x00000010;



	// Set Direction for GPIO3[10] to Output: FIELD DR10 [BIT 10] set to
'1'
	*(Gpio3_Gpdir) = 0x00200000;
	
	 
	// Set GPIO3[10] to '0': FIELD D10 [BIT 10] set to '0'
	*(Gpio3_Gpdat) = 0x00000000;
	
	printk("Hello World!\n");
	return 0;
}

void cleanup_module(void)

{
	printk("Goodbye Cruel World!\n");
}

MODULE_LICENSE("GPL");

When I write insmod GPIO.ko in the terminal I get error these errors:

Unable to handle kernel paging request for data at address 0xff7e0060
faulting instruction address: 0xf107e05c
Oops: Kernel access of bad area, sig: 11 [#1]

..........
.........

How can I solve this problem?

_______________________________________________
yocto mailing list
yocto <at> yoctoproject.org
https://lists.yoctoproject.org/listinfo/yocto

Thanks Anders,

But I have this problem not only for GPIOs, but also for other registers. For example, I tried to change DTW bits of PROCTL register in eSDH but I get "Kernel access of bad area" again. My simple code is here :

#include <linux/module.h>

int init_module(void)

{
	
	// e500 Core View To Power Architecture CCSR: 0x0_FF70_0000
	
	volatile uint32_t * eSDH_PROCTL = (volatile uint32_t *)(0xFF72E028);

	*(eSDH_PROCTL) = 0x00000002;

	return 0;
}

void cleanup_module(void)

{
	printk("Goodbye Cruel World!\n");
}

MODULE_LICENSE("GPL");

What should I do? Can you help me?

#3 lore raw

(No subject)

Quoted 6 lines · Jack

Anders Darander <anders@...> writes:

Thanks Anders,

But I have this problem not only for GPIOs, but also for other registers.

Well, my comment about dereferencing physical addresses using *-only, wasn't restricted to GPIO's only. It was regarding physical addresses in general...

Once again, I've not used this platform, this I'm not able to be too specific.

Quoted 4 lines

For example, I tried to change DTW bits of PROCTL register in eSDH but I get
"Kernel access of bad area" again. My simple code is here :

Quoted 8 lines

int init_module(void)

{
	
	// e500 Core View To Power Architecture CCSR: 0x0_FF70_0000
	
	volatile uint32_t * eSDH_PROCTL = (volatile uint32_t *)(0xFF72E028);

	*(eSDH_PROCTL) = 0x00000002;

I think that you should try to look at some code from the kernel that accesses registers on your platform. For instance http://lxr.free-electrons.com/source/sound/soc/fsl/p1022_ds.c?v=3.4 (this is just a randomly chosen file that relates to P1022.

Have a look at how guts_phys is declared, as well as how guts later on is both declared and initialized from guts_phys.
When the registers are actually read / written, this driver uses the clrsetbits_XX. These functions then implements the actual reading and writing of the registers.

(Note again, I've just looked at this file and p1022 for a couple of minutes).

Cheers,
Anders

Signature · 1 line
ChargeStorm AB / eStorm 
author
#4 lore raw

(No subject)

Quoted 11 lines · Anders Darander
Quoted 6 lines · Jack

Anders Darander <anders <at> ...> writes:

Thanks Anders,

But I have this problem not only for GPIOs, but also for other registers.

Well, my comment about dereferencing physical addresses using *-only,

wasn't restricted to GPIO's only.

Quoted 3 lines

It was regarding physical addresses in general...

Once again, I've not used this platform, this I'm not able to be too

specific.

Quoted 8 lines
Quoted 8 lines

For example, I tried to change DTW bits of PROCTL register in eSDH but I get
"Kernel access of bad area" again. My simple code is here :

int init_module(void)
{

Quoted 7 lines
Quoted 5 lines
	// e500 Core View To Power Architecture CCSR: 0x0_FF70_0000
	
	volatile uint32_t * eSDH_PROCTL = (volatile uint32_t *)(0xFF72E028);

	*(eSDH_PROCTL) = 0x00000002;

I think that you should try to look at some code from the kernel that

accesses registers on your platform. For

Quoted 1 line

instance

http://lxr.free-electrons.com/source/sound/soc/fsl/p1022_ds.c?v=3.4 (this is just a

Quoted 3 lines

randomly chosen file that relates to P1022.

Have a look at how guts_phys is declared, as well as how guts later on is

both declared and initialized from

Quoted 2 lines

guts_phys.
When the registers are actually read / written, this driver uses the

clrsetbits_XX. These functions then

Quoted 3 lines

implements the actual reading and writing of the registers.

(Note again, I've just looked at this file and p1022 for a couple of

minutes).

Quoted 4 lines

Cheers,
Anders

Thank you very much Anders for useful comments and replies,

I saw the link that you mentioned and I could write in pmuxcr register. So writing to register problem almost has solved. But I have some problems yet.

I read fsl_guts.h in powerpc architecture and saw Global Utility Registers like gpiocr as GPIO Control Register, gpindr as General-Purpose Input Data Register and gpoutdr as General-Purpose Output Data Register. But in GPIO registers in p1022 reference manual we have GPDIR register to set specify GPIO direction and GPDAT register for GPIO data register. We have only one register for data but fsl_guts.h defines two register for input an output data.

Does gpiocr work as GPDIR?

For GPDAT, which of the two registers I should use? gpindr or gpoutdr?

Thanks,

Best regards.