This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

GPMC module driver is crashing when it is re-inserted. We are using ti8148 based board the Linux version 04.01.00.07.

Other Parts Discussed in Thread: SYSCONFIG, CCSTUDIO


Hi,

                I am using the GPMC driver using chip select 0, It is working fine but when I am removing the module and then inserting the module once again it is failing at requesting GPMC memory for CS0.

I think there is some issue with de-initialization code.

Code for initialization and de initialization is given at bottom.

Error log:

root@(none):~# insmod uu_gpmc_drv_read_interrupt_mode9.ko
UURMI gpmc drver with IQ samples
board_fpga_init  ........................
FPGA initialization
GPMC_CS_CONFIG1: 28001010
GPMC_CS_CONFIG2: 30380
GPMC_CS_CONFIG3: 20201
GPMC_CS_CONFIG4: f031003
GPMC_CS_CONFIG5: 50607
GPMC_CS_CONFIG6: 2000080
GPMC_CS_CONFIG7: c48

uu_cs0_mem_base:8000000
uu_gpmc_cs0_base:
root@(none):~# rmmod uu_gpmc_drv_read_interrupt_mode.ko
FPGA De-initialization

 Module removed Successfully
root@(none):~# insmod uu_gpmc_drv_read_interrupt_mode9.ko
UURMI gpmc drver with IQ samples
board_fpga_init  ........................
FPGA initialization
GPMC_CS_CONFIG1: 28001010
GPMC_CS_CONFIG2: 30380
GPMC_CS_CONFIG3: 20201
GPMC_CS_CONFIG4: f031003
GPMC_CS_CONFIG5: 50607
GPMC_CS_CONFIG6: 2000080
GPMC_CS_CONFIG7: c48

Unable to handle kernel NULL pointer dereference at virtual address 00000000
pgd = cf074000
[00000000] *pgd=8f04b031, *pte=00000000, *ppte=00000000
Internal error: Oops: 17 [#1]
last sysfs file:
Modules linked in: uu_gpmc_drv_read_interrupt_mode(+) [last unloaded: uu_gpmc_drv_read_interrupt_mode]
CPU: 0    Not tainted  (2.6.37+ #5)
PC is at adjust_resource+0x14/0xc4
LR is at gpmc_cs_request+0x140/0x154
pc : [<c007cbe8>]    lr : [<c0059c3c>]    psr: 00000013
sp : cf025e94  ip : cf025ea8  fp : cf025ea4
r10: 00000078  r9 : 00000001  r8 : c05e762c
r7 : 00000000  r6 : 01000000  r5 : c05e7604  r4 : bf019938
r3 : c05e762c  r2 : 01000000  r1 : 08000000  r0 : 00000000
Flags: nzcv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
Control: 10c5387d  Table: 8f074019  DAC: 00000015
Process insmod (pid: 132, stack limit = 0xcf0242e8)
Stack: (0xcf025e94 to 0xcf026000)
5e80:                                              bf019938 cf025eec cf025ea8
5ea0: c0059c3c c007cbe0 00000000 c004a288 cf024000 00000000 cf025edc c05e762c
5ec0: c046e834 bf011430 bf019410 00000000 00000000 c004a288 cf024000 00000000
5ee0: cf025f14 cf025ef0 bf0109f4 c0059b08 c0068048 c00533fc c05e7340 c05e7340
5f00: bf011430 bf010c34 cf025f3c cf025f18 bf010c90 bf0108e4 00000000 0000001d
5f20: 0000001e c05e7340 bf01130c bf010c34 cf025f7c cf025f40 c003d52c bf010c40
5f40: 00000000 00012018 bf01130c 00000000 0001a433 00012018 bf01130c 00000000
5f60: 0001a433 c004a288 cf024000 00000000 cf025fa4 cf025f80 c00a8800 c003d3e0
5f80: cf025fa4 cf025f90 00000000 00020000 00000003 00000080 00000000 cf025fa8
5fa0: c004a0c0 c00a8754 00000000 00020000 00012018 0001a433 00012008 00000001
5fc0: 00000000 00020000 00000003 00000080 00012008 00000000 00012018 00000000
5fe0: beb46ee3 beb46c7c 00008da0 401a97d4 60000010 00012018 aaaaaaaa aaaaaaaa
Backtrace:
[<c007cbd4>] (adjust_resource+0x0/0xc4) from [<c0059c3c>] (gpmc_cs_request+0x140/0x154)
 r4:bf019938
[<c0059afc>] (gpmc_cs_request+0x0/0x154) from [<bf0109f4>] (uu_init_gpmc_fpga_hw_init+0x11c/0x35c [uu_gpmc_drv_read_interrupt_mode])
[<bf0108d8>] (uu_init_gpmc_fpga_hw_init+0x0/0x35c [uu_gpmc_drv_read_interrupt_mode]) from [<bf010c90>] (init_module+0x5c/0x154 [uu_gpmc_drv_read_interrupt_mode])
 r6:bf010c34 r5:bf011430 r4:c05e7340
[<bf010c34>] (init_module+0x0/0x154 [uu_gpmc_drv_read_interrupt_mode]) from [<c003d52c>] (do_one_initcall+0x158/0x1b0)
 r6:bf010c34 r5:bf01130c r4:c05e7340
[<c003d3d4>] (do_one_initcall+0x0/0x1b0) from [<c00a8800>] (sys_init_module+0xb8/0x1c8)
[<c00a8748>] (sys_init_module+0x0/0x1c8) from [<c004a0c0>] (ret_fast_syscall+0x0/0x30)
 r7:00000080 r6:00000003 r5:00020000 r4:00000000
Code: e92dd810 e24cb004 e1a03000 e5900010 (e590c000)
---[ end trace 10b924f980820d34 ]---
Segmentation fault
root@(none):~#

Initialization and UN-initialization of the GPMC driver.

 
int  uu_init_gpmc_fpga_hw_init(void )
{
    unsigned int ret=-1,read_val=-1;//tx_irq=0,rx_irq=0;
 
    gpmc_write_reg(GPMC_SYSCONFIG, 0x0);
    gpmc_write_reg(GPMC_CONFIG, 0x0);
    //sychronous,16bit,NOR,no multiplexed,GPMC_CLK==GPMC_FCLK
 
    gpmc_cs_write_reg(0, GPMC_CS_CONFIG1,0x28001010);    // 0x28001010
    read_val= gpmc_cs_read_reg(0, GPMC_CS_CONFIG1);
    printk("GPMC_CS_CONFIG1: %x\n\r",read_val);
    read_val=0;
 
    gpmc_cs_write_reg(0, GPMC_CS_CONFIG2,0x00030380);      // 0x00101080  *
    read_val= gpmc_cs_read_reg(0, GPMC_CS_CONFIG2);
    printk("GPMC_CS_CONFIG2: %x\n\r",read_val);
    read_val=0;
 
    gpmc_cs_write_reg(0, GPMC_CS_CONFIG3,0x00020201);    // 0x00020201
    read_val= gpmc_cs_read_reg(0, GPMC_CS_CONFIG3);
    printk("GPMC_CS_CONFIG3: %x\n\r",read_val);
    read_val=0;
 
    gpmc_cs_write_reg(0, GPMC_CS_CONFIG4,0x0f031003);    // 0x0f031003
    read_val= gpmc_cs_read_reg(0, GPMC_CS_CONFIG4);
    printk("GPMC_CS_CONFIG4: %x\n\r",read_val);
    read_val=0;
    gpmc_cs_write_reg(0, GPMC_CS_CONFIG5,0x00050607);        // 0x000F1011
    read_val= gpmc_cs_read_reg(0, GPMC_CS_CONFIG5);
    printk("GPMC_CS_CONFIG5: %x\n\r",read_val);
    read_val=0;
 
    gpmc_cs_write_reg(0, GPMC_CS_CONFIG6,0x02000080);    // 0x0F000080
    read_val= gpmc_cs_read_reg(0, GPMC_CS_CONFIG6);
    printk("GPMC_CS_CONFIG6: %x\n\r",read_val);
    read_val=0;
 
    gpmc_cs_write_reg(0, GPMC_CS_CONFIG7,0x00000C48);    // 0x00000C48
    read_val= gpmc_cs_read_reg(0, GPMC_CS_CONFIG7);
    printk("GPMC_CS_CONFIG7: %x\n\r",read_val);
    read_val=0;
 
    if (gpmc_cs_request(0, SZ_16M, &uu_cs0_mem_base) < 0)
    {
        printk("<1>Failed to request GPMC mem for cs0\n");
        return -1;
    }
    printk("<1>uu_cs0_mem_base:%x\n",uu_cs0_mem_base);
    uu_gpmc_cs0_base=ioremap(uu_cs0_mem_base,SZ_16M);
    if(uu_gpmc_cs0_base!=0)
    {
        printk("<1>uu_gpmc_cs0_base:");
    }
 
out:
    return ret;
}
 
int init_gpmc_fpga_device(void)
{
    unsigned int  l=0;

    printk(KERN_INFO"board_fpga_init  ........................\n\r");
    printk("FPGA initialization\n");
    l = TI8148_GPMC_BASE;
    uu_gpmc_base = ioremap(l, SZ_4K);
    if (uu_gpmc_base == NULL)
    {
        printk("gpmc-fpga: Memory allocation failed\n");
        goto out;
    }
    uu_init_gpmc_fpga_hw_init();
    uu_init_device_node();
 
 
out:
    return 0;
}
void exit_gpmc_fpga_device(void)
{
    printk("FPGA De-initialization\n");
    gpmc_cs_free(0);
    iounmap(uu_gpmc_base);
    device_destroy(uu_fpga_class, MKDEV(UU_FPGA_MAJOR, 0));
    class_destroy(uu_fpga_class);
    unregister_chrdev(UU_FPGA_MAJOR, UU_FPGADEVNAME);
    if(tx_irq > 0)
        free_irq(tx_irq, NULL);
    if(rx_irq > 0)
        free_irq(rx_irq, NULL);
    printk("\n Module removed Successfully\n");
}
 
module_init(init_gpmc_fpga_device);
module_exit(exit_gpmc_fpga_device);

Please help to resolve

Thanks,

Sudheer.

  • Sudheer,

    Can you attach this GPMC module (uu_gpmc_drv_read_interrupt_mode9.ko) to test it on my side.

    Can you also check the gpmc_cs_free(0), with printk and/or CCStudio, to see if this function frees the CS successfully.

    BR
    Pavel

  • Hi Pavel,

                             In exit code if I am not using gpmc_cs_free(0) and  when I am reinserting the module it is giving the print message

    "Failed to request GPMC mem for cs0".

    It means gpmc_cs_free(0) is freeing the cs0 right?


    I am unable to locate the option to attach the .ko file in this link, so I could not attach the module as requested.

    Thanks,

    Sudheer.

  • Hi Sudheer,

    sudheer singh1 said:
    It means gpmc_cs_free(0) is freeing the cs0 right?

    I suspect there is something wrong in it, as the kernel crash at this point.

    sudheer singh1 said:
    I am unable to locate the option to attach the .ko file in this link, so I could not attach the module as requested.

    You should click on the "Use rich formatting" button in the right down corner (see screen shot) then you should drag and drop the file you want to attach.

    Regards,
    Pavel

  • Hi pavel,

                              I have attached the .ko file now.

    Thanks,

    Sudheer.

  • Sudheer,

    sudheer singh1 said:
    I have attached the .ko file now.

    There is no file attached. Can you try again? Or can you send it to me at p-botev@ti.com

    BR
    Pavel

  • Sudheer,

    I received your mail and the file attached. But I can not load it in my kernel, I assume I have different kernel from yours, that is the reason I can not use your .ko file.

    Could you please share your steps to create the .ko file, I want to review.

    BR
    Pavel

  • Hi,
    Below are the command used and make file content.

    command used is :
    make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-

    Make file content is:
    obj-m += uu_gpmc_drv_read_interrupt_mode.o
    ARCH=arm
    CROSS_COMPILE=/home/uurmi/arm-2010q1/bin/arm-none-linux-gnueabi-
    CFLAGS_MODULES = -Wall
    EXTRA_CFLAGS += -g -Wall -I$(PWD)/../inc/.
    def:
    make -C /ravr/SDR/linux-04.01.00.07 M=$(PWD) modules
    clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean


    Thanks,
    Sudheer.
  • Sudheer,

    Can you share which header files you are using in the uu_gpmc_drv_read_interrupt_mode.c file?

    BR
    Pavel
  • Hi,
    Header files used in the file are as follows,

    #include <linux/kernel.h>
    #include <linux/module.h>
    #include <linux/fs.h>
    #include <asm/uaccess.h>
    #include <asm/io.h>
    #include <linux/slab.h>
    #include <linux/init.h>
    #include <linux/sched.h>
    #include <linux/signal.h>
    #include <linux/delay.h>
    #include <linux/time.h>
    #include<linux/cdev.h>
    #include <linux/device.h>
    #include <linux/version.h>
    #include <linux/irq.h>
    #include <linux/clk.h>
    #include <linux/module.h>
    #include <linux/kernel.h>
    #include <linux/moduleparam.h>
    #include <linux/init.h>
    #include <linux/pm.h>
    #include <linux/platform_device.h>
    #include <linux/spi/spi.h>
    #include <linux/fs.h>
    #include <linux/cdev.h>
    #include <linux/uaccess.h>
    #include <linux/interrupt.h>
    #include <linux/preempt.h>
    #include <mach/gpio.h>
    #include "/ravr/SDR/linux-04.01.00.07/arch/arm/mach-omap2/mux.h"
    #include <asm/ioctl.h>
    #include "uu_gpmc.h"
    #include <linux/vmalloc.h>
    #include <linux/fs.h>
    #include <asm/segment.h>
    #include <asm/uaccess.h>
    #include <linux/buffer_head.h>
    #include <linux/semaphore.h>

    Thanks,
    Sudheer.
  • sudheer singh1 said:
    #include "uu_gpmc.h"

    This one is your own file (not part of the linux kernel), is that correct?
    Can you provide it to me? Also the uu_gpmc_drv_read_interrupt_mode.c file.

    BR
    Pavel

  • Sudheer,

    I was able to reproduce this issue on the TI EVM with latest kernel version.

    When you load the gpmc module for second time, the kernel crash at:

    linux-kernel/kernel/resources.c

    int adjust_resource(struct resource *res, resource_size_t start, resource_size_t size)
    {
    struct resource *tmp, *parent = res->parent;
    resource_size_t end = start + size - 1;

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

    if ((start < parent->start) || (end > parent->end))

    In the second load of gpmc module, parent->start is NULL, also parent->end is NULL.

    I suspect your module is not handling properly the memory for struct resource. I would recommend you to check this in our Linux forum, as this seems to be related more to the Linux, not specific to the DM814x device.

    Regards,
    Pavel

  • Sudheer,

    I have found that the problem is in the void gpmc_cs_free(int cs) function from the linux-kernel/arch/arm/mach-omap2/gpmc.c file. As you know, DM814x PSP linux kernel is 2.6.37. When I update this void gpmc_cs_free(int cs) to align its code with the mainline/upstream linux kernel (3.18 as of now), I do not have this issue any more. So please update your void gpmc_cs_free(int cs) function as below:

    void gpmc_cs_free(int cs)
    {
        struct resource *res = &gpmc_cs_mem[cs];    
        
        spin_lock(&gpmc_mem_lock);
        if (cs >= GPMC_CS_NUM || cs < 0 || !gpmc_cs_reserved(cs)) {
            printk(KERN_ERR "Trying to free non-reserved GPMC CS%d\n", cs);
            BUG();
            spin_unlock(&gpmc_mem_lock);
            return;
        }
        gpmc_cs_disable_mem(cs);
        if (res->flags)
            //release_resource(&gpmc_cs_mem[cs]);
            release_resource(res);
        gpmc_cs_set_reserved(cs, 0);
        spin_unlock(&gpmc_mem_lock);
    }


    BR
    Pavel