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.

referencing mapped register in kernel - crash !

Guru 20755 points
Other Parts Discussed in Thread: OMAP3530

Hello,

I try to reference spi status register (0x30 offset  from 0x4809A000) in kernel code, but it results in segmentation fault:

ioaddr = ioremap_nocache(0x4809A000, SZ_4K);
*(( unsigned int*) (ioaddr+0)) = 0x12;
val = *(( unsigned int*) (ioaddr+0x30));
printk("mymem 0x%x\n",val); <<-----------------

I have re-checked the config of kernel, is it related to some device using spi ?

I have removed all spi usage from board file.

[ 24.126739] Unhandled fault: external abort on non-linefetch (0x1028) at 0xfa09a030
[ 24.134948] Internal error: : 1028 [#1] PREEMPT
[ 24.139678] last sysfs file:
[ 24.142791] Modules linked in: rtc(+)
[ 24.146667] CPU: 0 Not tainted (2.6.37 #357)
[ 24.151519] PC is at rtcspi_init+0x20/0x9c [rtc]
[ 24.156372] LR is at rtcspi_init+0x1c/0x9c [rtc]
[ 24.161193] pc : [<bf000498>] lr : [<bf000494>] psr: 80000013
[ 24.161193] sp : cc847e68 ip : 000fffff fp : 00000000
[ 24.173248] r10: 00000000 r9 : bf000478 r8 : c056b300
[ 24.178710] r7 : 00000000 r6 : bf00129c r5 : 00000018 r4 : 00000000
[ 24.185546] r3 : 00000012 r2 : 00000000 r1 : 00001000 r0 : fa09a000
[ 24.192382] Flags: Nzcv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user
[ 24.199859] Control: 10c5387d Table: 8c8c4019 DAC: 00000015
[ 24.205902] Process insmod (pid: 78, stack limit = 0xcc8462f0)
[ 24.212005] Stack: (0xcc847e68 to 0xcc848000)
[ 24.216583] 7e60: 00000093 c02c8a44 00000000 c0034364 bf00129c c008be18
[ 24.225158] 7e80: 00000000 c00d1080 00000000 00000000 00000018 bf00129c 00000000 cc847f64
[ 24.233734] 7ea0: ce0a962c 00000000 00000093 c00a4090 00000000 00000000 c02d0b08 c02d0b08
[ 24.242309] 7ec0: c008621c bf0012a8 c053a88c c02d09f8 ce0a96f4 ce0a96f8 ce0c0eff ce0baf88
[ 24.250885] 7ee0: cc846000 c02d0aa8 ce0a8000 00018f13 ce0baa38 ce0ba8da ce0c0b40 cd33a8c0
[ 24.259460] 7f00: 0000140c 00001a4c 00000000 00000000 00000022 00000023 0000000c 00000009
[ 24.268035] 7f20: 00000007 00000000 6e72656b 00006c65 00000000 00000000 00000000 00000000
[ 24.276611] 7f40: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[ 24.285186] 7f60: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 c039a600
[ 24.293762] 7f80: 60000010 be837b78 00000000 be837ea8 00000080 c003f988 cc846000 00000000
[ 24.302337] 7fa0: 00000000 c003f7c0 be837b78 00000000 0008a040 00018f13 0007be88 00000000
[ 24.310913] 7fc0: be837b78 00000000 be837ea8 00000080 be837ea4 be837ea8 00000001 00000000
[ 24.319488] 7fe0: 00000069 be837b64 000143fc 4018d7d4 60000010 0008a040 8d7fe021 8d7fe421
[ 24.328094] [<bf000498>] (rtcspi_init+0x20/0x9c [rtc]) from [<c0034364>] (do_one_initcall+0x34/0x1b4)
[ 24.337799] [<c0034364>] (do_one_initcall+0x34/0x1b4) from [<c00a4090>] (sys_init_module+0xc0/0x17e0)
[ 24.347473] [<c00a4090>] (sys_init_module+0xc0/0x17e0) from [<c003f7c0>] (ret_fast_syscall+0x0/0x3c)
[ 24.357055] Code: e30a0000 e3440809 eb416d96 e3a03012 (e5901030)
[ 24.363800] ---[ end trace b6cb7a9e5a4e658c ]---
Segmentation fault

Is there any idea what's wrong ?

I am using omap35x

Regards,

Ran

  • Hi Ran Shalit,
    Can you please try like below ?

    void *ioaddr = ioremap_nocache(0x4809A000, SZ_4K);
    printk("Address %p, Value %d\n",ioaddr, *ioaddr);
  • Hi,

    Thank you for the suggestion.
    I tried, and I get compilation error:
    "error: invalid use of void expression"

    Regards,
    Ran
  • Hi,

    I would also like to add more thing:

    It seems that if I read register 0 in mcspi , there is no segmentation faiure, only when reading register 0x30.

    ioaddr = ioremap_nocache(0x4809A000, SZ_4K);
    *(( unsigned int*) (ioaddr+0)) = 0x12;
    //val = *(( unsigned int*) (ioaddr + 0x0)); <------ this makes no failure

    val = *(( unsigned int*) (ioaddr + 0x30)); <------ this results in segment failure

    printk("mymem 0x%x\n",val);

    I think it relates to spi being enabled/disabled:
    e2e.ti.com/.../1079278

    regards,
    Ran
  • We register spi driver in startup (in board file), so
    I think all clocks should have been enabled, so I don't understand why I can't remap and reag the status mcspi register:

    [ 0.000000] Tanya: spi_register_board_info
    [ 0.016113] omap2_mcspi omap2_mcspi.1: registered master spi1
    [ 0.016448] Was called spi_setup
    [ 0.016662] spi spi1.0: setup: speed 750000, sample trailing edge, clk normal
    [ 0.016723] spi spi1.0: setup mode 1, cs_high, 8 bits/w, 1000000 Hz max --> 0
    [ 0.017669] Tanya:SPI: registered child spi1.0 bits_per_word 8
    [ 0.018707] omap2_mcspi omap2_mcspi.2: registered master spi2
    [ 0.019989] omap2_mcspi omap2_mcspi.3: registered master spi3
    [ 0.020935] omap2_mcspi omap2_mcspi.4: registered master spi4
    [ 2.995788] rtc-pcf2123 spi1.0: resetting RTC (0x10 0x58)
    [ 2.996917] rtc-pcf2123 spi1.0: stopping RTC (0x10 0x20)
    [ 2.997161] rtc-pcf2123 spi1.0: checking for presence of RTC (0x90)
    [ 2.997802] rtc-pcf2123 spi1.0: received data from RTC (0xFF 0xFF)
    [ 2.997833] rtc-pcf2123 spi1.0: chip found, driver version 0.6
    [ 3.003906] rtc-pcf2123 spi1.0: spiclk 1000 KHz.
    [ 3.010986] rtc-pcf2123 spi1.0: rtc core: registered rtc-pcf2123 as rtc0
    [ 3.344451] rtc-pcf2123 spi1.0: pcf2123_rtc_read_time: tm is secs=85, mins=85
  • Hi Ran Shalit,
    Can you please try to read the BASE+0x30 register via "devmem2" tool ?
  • Hi Shankari G,

    It fails:

    ~ #
    ~ #
    ~ # ./devmem2 0x4809a030
    /dev/mem opened.[ 261.944976] Unhandled fault: external abort on non-linefetch (0x1018) at 0x40206030

    Memory mapped at address 0x40206000.
    Bus error
    ~ #


    Regards,
    Ran
  • Hi Shankari G,,

    Is there any idea ?

    devmem2 returns the same error.

    Thanks,

    Ran

  • What is your processor ?
    Have you checked the TRM for this register "0x4809a030" ?
  • I using omap3530.
    The TRM says it is Read register, no issues that I can see:
    Table 19-42. MCSPI_CHxSTAT
    page 2922 in OMAP TRM.

    Regards,
    Ran
  • Dear Ran,

    I have checked the OMAP35x TRM and not able to find the register "0x4809a030" but "0x4809a030+(0x14+x)"

    where x,

    x= 0 to 3 for MCSPI1.

    x= 0 to 1 for MCSPI2 and MCSPI3.

    x= 0 for MCSPI4.

    So, you have to read the "0x4809a034" (if x is 0) and not "0x4809a030"

    Can you please try to read the "0x4809a034" ??

    ~ # ./devmem2 0x4809a034

  • Hi,

    Still the same:

    ~ #
    ~ # ./devmem2 0x4809a034
    /dev/mem opened.[ 9867.789031] Unhandled fault: external abort on non-linefetch (0x1018) at 0x402ca034

    Memory mapped at address 0x402ca000.
    Bus error
    ~ #

    Regards,
    Ran
  • I suspect this spi #2 is not enabled (power ?). Not sure How to enable it.
  • I have also found a post which states that this issues are related to power managements:
    e2e.ti.com/.../49197
    Though, in my case I am not using power management... If I could find the exacst registers which enable the clocks maybe it would help.

    Thanks,
    Ran
  • Hi,

    Issue been resolved.
    clks were enabled in u-boot, but not in kernel.

    val = *(volatile U32 *)CM_FCLKEN1_CORE;
    val |=(OMAP35XX_EN_MCSPI1 | OMAP35XX_EN_MCSPI2 | OMAP35XX_EN_MCSPI3 | OMAP35XX_EN_MCSPI4);
    *(volatile U32 *)CM_FCLKEN1_CORE = val;

    val = *(volatile U32 *)CM_ICLKEN1_CORE;
    val |=(OMAP35XX_EN_MCSPI1 | OMAP35XX_EN_MCSPI2 | OMAP35XX_EN_MCSPI3 | OMAP35XX_EN_MCSPI4);
    *(volatile U32 *)CM_ICLKEN1_CORE = val;


    Thank you,
    Ran
  • Sounds good.
    Thanks for the update.