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.

OMAPL138 Direct access to shared ram in kernel module or user space

Other Parts Discussed in Thread: DA8XX, OMAP-L138, TCA6416, PMP

Hi,

I am trying to directly access shared ram at address 0x80000000 either from a kernel module or user space and I don't want to use syslink.

My understanding is that I have to open /dev/mem and use mmap to map memory but my attempts were unsuccessful .

Cat /proc/iomem does not show any region for shared ram.

I also noticed this message at boot:

BUG: mapping for 0x80000000 at 0xfffe0000 out of vmalloc space

Any help is greatly appreciated. 

  • Hi Alireza,

    BUG: mapping for 0x80000000 at 0xfffe0000 out of vmalloc space


    What kernel version and SDK details were you used ?

    Did you modify anything on linux kernel source ?

  • Hi Stalin

    My kernel version is 3.3.0 and I use mcsdk 1.01.00.02.

    I have not changed anything in  source but I will reinstall MCSDK and see if that resolve the problem.

    Thank you.

  • Hi Alireza,

    Could you attach your complete bootup log.

    1) Try to pass "vmalloc=1G" in u-boot bootargs.

    2) In linux, shared RAM configured already.

    arch/arm/mach-davinci/include/mach/da8xx.h

    arch/arm/mach-davinci/da850.c

    static struct map_desc da850_io_desc[] = {
    	{
    		.virtual	= IO_VIRT,
    		.pfn		= __phys_to_pfn(IO_PHYS),
    		.length		= IO_SIZE,
    		.type		= MT_DEVICE
    	},
    	{
    		.virtual	= DA8XX_CP_INTC_VIRT,
    		.pfn		= __phys_to_pfn(DA8XX_CP_INTC_BASE),
    		.length		= DA8XX_CP_INTC_SIZE,
    		.type		= MT_DEVICE
    	},
    	{
    		.virtual	= SRAM_VIRT,
    		.pfn		= __phys_to_pfn(DA8XX_SHARED_RAM_BASE),
    		.length		= SZ_8K,
    		.type		= MT_DEVICE
    	},
    };
    

  • Hi Titus,

    I tried vmalloc=1G but the same BUG report happen.

    Here is  boot messages. I have to mention that it belong to a SOC with 64Mb RAM.

    I have another one with 128Mb and boot arguments include 32M and 64M RAM for syslink to work which also render the same BUG report.

    Best Regards,

    Alireza

    I2C: ready
    DRAM: 64 MiB
    MMC: davinci: 0
    SF: Detected M25P64 with page size 256, total 8 MiB
    In: serial
    Out: serial
    Err: serial
    ARM Clock : 300000000 Hz
    DDR Clock : 132000000 Hz
    Net: Ethernet PHY: GENERIC @ 0x00
    DaVinci-EMAC
    Hit any key to stop autoboot: 0
    U-Boot > setenv bootargs 'mem=64M@0xc0000000 vmalloc=1G console=ttyS2,115200n8 root=/dev/nfs nfsroot=192.168.7.4:/opt/ti/mcsdk_1_01_00_02/targe'
    U-Boot > boot
    BOOTP broadcast 1
    *** Unhandled DHCP Option in OFFER/ACK: 44
    *** Unhandled DHCP Option in OFFER/ACK: 44
    DHCP client bound to address 192.168.7.20
    Using DaVinci-EMAC device
    TFTP from server 192.168.7.4; our IP address is 192.168.7.20
    Filename 'uImage-omapl138-lcdk.bin'.
    Load address: 0xc0700000
    Loading: #################################################################
    #################################################################
    #################################################################
    #################################################################
    #################################################################
    #################################################################
    #################################################################
    ##############
    done
    Bytes transferred = 2397856 (2496a0 hex)
    ## Booting kernel from Legacy Image at c0700000 ...
    Image Name: Linux-3.3.0
    Image Type: ARM Linux Kernel Image (uncompressed)
    Data Size: 2397792 Bytes = 2.3 MiB
    Load Address: c0008000
    Entry Point: c0008000
    Verifying Checksum ... OK
    Loading Kernel Image ... OK
    OK

    Starting kernel ...

    Uncompressing Linux... done, booting the kernel.
    Booting Linux on physical CPU 0
    Linux version 3.3.0 (gtbldadm@ubuntu-12) (gcc version 4.5.3 20110311 (prerelease) (GCC) ) #1 PREEMPT Tue Nov 5 20:19:32 EST 2013
    CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00053177
    CPU: VIVT data cache, VIVT instruction cache
    Machine: DaVinci DA850/OMAP-L138/AM18x EVM
    vmalloc area is too big, limiting to 976MB
    Truncating RAM at c0000000-c3ffffff to -c1ffffff (vmalloc region overlap).
    Memory policy: ECC disabled, Data cache writeback
    BUG: mapping for 0x80000000 at 0xfffe0000 out of vmalloc space
    DaVinci da850/omap-l138 variant 0x0
    Built 1 zonelists in Zone order, mobility grouping on. Total pages: 8128
    Kernel command line: mem=64M@0xc0000000 vmalloc=1G console=ttyS2,115200n8 root=/dev/nfs nfsroot=192.168.7.4:/opt/ti/mcsdk_1_01_00_02/targetNFS p
    PID hash table entries: 128 (order: -3, 512 bytes)
    Dentry cache hash table entries: 4096 (order: 2, 16384 bytes)
    Inode-cache hash table entries: 2048 (order: 1, 8192 bytes)
    Memory: 32MB = 32MB total
    Memory: 27396k/27396k available, 5372k reserved, 0K highmem
    Virtual kernel memory layout:
    vector : 0xffff0000 - 0xffff1000 ( 4 kB)
    fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB)
    vmalloc : 0xc2800000 - 0xff000000 ( 968 MB)
    lowmem : 0xc0000000 - 0xc2000000 ( 32 MB)
    modules : 0xbf000000 - 0xc0000000 ( 16 MB)
    .text : 0xc0008000 - 0xc0475000 (4532 kB)
    .init : 0xc0475000 - 0xc049d000 ( 160 kB)
    .data : 0xc049e000 - 0xc04cf760 ( 198 kB)
    .bss : 0xc04cf784 - 0xc04eca6c ( 117 kB)
    SLUB: Genslabs=13, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
    NR_IRQS:245
    Console: colour dummy device 80x30
    Calibrating delay loop... 148.88 BogoMIPS (lpj=744448)
    pid_max: default: 32768 minimum: 301
    Mount-cache hash table entries: 512
    CPU: Testing write buffer coherency: ok
    Setting up static identity map for 0xc03625a0 - 0xc03625f8
    gpiochip_add: registered GPIOs 0 to 31 on device: DaVinci
    gpiochip_add: registered GPIOs 32 to 63 on device: DaVinci
    gpiochip_add: registered GPIOs 64 to 95 on device: DaVinci
    gpiochip_add: registered GPIOs 96 to 127 on device: DaVinci
    gpiochip_add: registered GPIOs 128 to 143 on device: DaVinci
    DaVinci: 144 gpio irqs
    print_constraints: dummy:
    NET: Registered protocol family 16
    bio: create slab <bio-0> at 0
    SCSI subsystem initialized
    usbcore: registered new interface driver usbfs
    usbcore: registered new interface driver hub
    usbcore: registered new device driver usb
    pca953x 1-0020: failed reading register
    pca953x 1-0021: interrupt support not compiled in
    gpiochip_add: registered GPIOs 160 to 175 on device: tca6416
    i2c-gpio i2c-gpio.1: using pins 20 (SDA) and 21 (SCL)
    Advanced Linux Sound Architecture Driver Version 1.0.24.
    Switching to clocksource timer0_1
    musb-hdrc: version 6.0, ?dma?, otg (peripheral+host)
    musb-hdrc musb-hdrc: dma type: dma-cppi41
    MUSB255 controller's USBSS revision = 4ea11003
    Waiting for USB PHY clock good...
    musb-hdrc musb-hdrc: USB OTG mode controller at fee00000 using DMA, IRQ 58
    NET: Registered protocol family 2
    IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
    TCP established hash table entries: 1024 (order: 1, 8192 bytes)
    TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
    TCP: Hash tables configured (established 1024 bind 1024)
    TCP reno registered
    UDP hash table entries: 256 (order: 0, 4096 bytes)
    UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
    NET: Registered protocol family 1
    RPC: Registered named UNIX socket transport module.
    RPC: Registered udp transport module.
    RPC: Registered tcp transport module.
    RPC: Registered tcp NFSv4.1 backchannel transport module.
    EMAC: MII PHY configured, RMII PHY will not be functional
    JFFS2 version 2.2. (NAND) �© 2001-2006 Red Hat, Inc.
    msgmni has been set to 53
    io scheduler noop registered (default)
    da8xx_lcdc da8xx_lcdc.0: GLCD: Found Sharp_LK043T1DG01 panel
    Console: switching to colour frame buffer device 60x34
    Serial: 8250/16550 driver, 3 ports, IRQ sharing disabled
    serial8250.0: ttyS0 at MMIO 0x1c42000 (irq = 25) is a AR7
    serial8250.0: ttyS1 at MMIO 0x1d0c000 (irq = 53) is a AR7
    serial8250.0: ttyS2 at MMIO 0x1d0d000 (irq = 61) is a AR7
    console [ttyS2] enabled
    brd: module loaded
    ahci ahci: forcing PORTS_IMPL to 0x1
    ahci ahci: AHCI 0001.0100 32 slots 1 ports 3 Gbps 0x1 impl platform mode
    ahci ahci: flags: ncq sntf pm led clo only pmp pio slum part ccc
    scsi0 : ahci_platform
    ata1: SATA max UDMA/133 mmio [mem 0x01e18000-0x01e19fff] port 0x100 irq 67
    davinci_mdio davinci_mdio.0: davinci mdio revision 1.5
    davinci_mdio davinci_mdio.0: detected phy mask fffffffe
    davinci_mdio.0: probed
    davinci_mdio davinci_mdio.0: phy[0]: device davinci_mdio-0:00, driver SMSC LAN8710/LAN8720
    ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
    ohci ohci.0: DA8xx OHCI
    ohci ohci.0: new USB bus registered, assigned bus number 1
    Waiting for USB PHY clock good...
    ohci ohci.0: irq 59, io mem 0x01e25000
    hub 1-0:1.0: USB hub found
    hub 1-0:1.0: 1 port detected
    Initializing USB Mass Storage driver...
    usbcore: registered new interface driver usb-storage
    USB Mass Storage support registered.
    input: gpio-keys-polled as /devices/platform/gpio-keys-polled.1/input/input0
    omap_rtc omap_rtc: rtc core: registered omap_rtc as rtc0
    omap_rtc: RTC power up reset detected
    i2c /dev entries driver
    watchdog watchdog: heartbeat 60 sec
    cpuidle: using governor ladder
    cpuidle: using governor menu
    davinci_mmc davinci_mmc.0: Using DMA, 4-bit mode
    usbcore: registered new interface driver usbhid
    usbhid: USB HID core driver
    usbcore: registered new interface driver snd-usb-audio
    soc-audio soc-audio.0: ASoC: Failed to create card debugfs directory
    ALSA device list:
    No soundcards found.
    TCP cubic registered
    NET: Registered protocol family 17
    _regulator_get: deviceless supply cvdd not found, using dummy regulator
    console [netcon0] enabled
    netconsole: network logging started
    davinci_emac davinci_emac.1: using random MAC addr: 76:ec:e5:02:be:d0
    omap_rtc omap_rtc: setting system clock to 2001-01-01 00:01:00 UTC (978307260)
    ata1: SATA link down (SStatus 0 SControl 300)
    mmc0: new SDHC card at address e624
    davinci_mdio davinci_mdio.0: resetting idled controller
    net eth0: attached PHY driver [SMSC LAN8710/LAN8720] (mii_bus:phy_addr=davinci_mdio-0:00, id=7c0f1)
    mmcblk0: mmc0:e624 SD04G 3.69 GiB
    mmcblk0: p1 p2 p3
    PHY: davinci_mdio-0:00 - Link is Up - 100/Full
    Sending DHCP requests .., OK
    IP-Config: Got DHCP answer from 0.0.0.0, my address is 192.168.7.82
    IP-Config: Gateway not on directly connected network.
    VFS: Mounted root (nfs filesystem) on device 0:13.
    Freeing init memory: 160K
    INIT: version 2.88 booting
    Starting udev
    EXT3-fs (mmcblk0p2): warning: maximal mount count reached, running e2fsck is recommended
    kjournald starting. Commit interval 5 seconds
    EXT3-fs (mmcblk0p2): using internal journal
    EXT3-fs (mmcblk0p2): recovery complete
    EXT3-fs (mmcblk0p2): mounted filesystem with writeback data mode
    Starting Bootlog daemon: bootlogd.
    ALSA: Restoring mixer settings...
    /usr/sbin/alsactl: load_state:1686: No soundcards found...
    NOT configuring network interfaces: / is an NFS mount
    Thu Nov 7 15:59:00 UTC 2013
    INIT: Entering runlevel: 5
    Starting system message bus: dbus.
    Starting Dropbear SSH server: NET: Registered protocol family 10
    dropbear.
    Starting telnet daemon.
    Starting syslogd/klogd: done
    Starting thttpd.

  • I am confused about which ram is what in the kernel code. The kernel code appears to be concerned with SRAM (as in Static RAM) that used for saving context in low power mode. There are two blocks of SRAM, ARM Local RAM (8K) and the L3 Shared RAM (128k).

    Code from http://arago-project.org, head of linux-davinci GIT.

    arch/arm/mach-davinci/include/mach/da8xx.h
    #define DA8XX_ARM_RAM_BASE      0xffff0000
    #define DA8XX_SHARED_RAM_BASE   0x80000000

    arch/arm/mach-davinci/include/mach/common.h
    #define SRAM_VIRT       0xfffe0000
    #define SRAM_SIZE       SZ_128K

    arch/arm/mach-davinci/da850.c
    static struct map_desc da850_io_desc[] = {
         {
             .virtual        = SRAM_VIRT,
             .pfn            = __phys_to_pfn(DA8XX_SHARED_RAM_BASE),
             .length         = SZ_8K,
             .type           = MT_DEVICE
         },
    };

    static struct davinci_soc_info davinci_soc_info_da850 = {
            .io_desc                = da850_io_desc,
            .io_desc_num            = ARRAY_SIZE(da850_io_desc),
    ...
            .sram_phys              = DA8XX_ARM_RAM_BASE,
            .sram_len               = SZ_8K,
    };


    I think the "pfn" and "sram_phys" should be point to same memory. I would guess pfn should be
             .pfn            = __phys_to_pfn(DA8XX_ARM_RAM_BASE),
    I suspect that using DA8XX_SHARED_RAM_BASE would reserve the first 8KB of 128KB L3 memory and mmap cannot use it.

    The latest kernel version at www.kernel.org
    - use the field sram_dma instead sram_phys
    - do not specify the map_desc for the SRAM in da850_io_desc
    - implement sram_alloc and sram_free instead.
    - use the larger 128KB L3 SRAM
    - power management code calls sram_alloc and sram_free to save context. The arago version does not save context.

  • Thank you Norman.

    I changed DA8XX_SHARED_RAM_BASE to DA8XX_ARM_RAM_BASE and build kernel but received the same error.

    Regards

  • What is your test code and what is the exact error?

  • By error I mean the kernel Bug report I mentioned earlier.

    But I just want to directly access shared ram area at 0x80000000 either from a kernel module or user space. 

  • I assume the error you see repeated is:

    BUG: mapping for 0x80000000 at 0xfffe0000 out of vmalloc space

    That is odd since DA8XX_SHARED_RAM_BASE appears to be the only reference to DA8XX_SHARED_RAM_BASE or  0x80000000. . Maybe your version of the kernel has others. The 0xfffe0000 matches up to the SRAM_VIRT constant. Not much to suggect. Double check your changes, rebuild and retry. Try without the "vmalloc=1G" bootarg to see if the overlap errors go away.

    What errors do you get with an "mmap" application? Have you tried the devmem command? It uses mmap as well.

  • Hi Alireza,

    As Normal wrote, The shared RAM (only 8K)  was used for power management.

    Earlier we used "ARM LOCAL RAM" for low power mode.

    http://lists.infradead.org/pipermail/linux-arm-kernel/2012-October/124146.html

    So, disable the "da850_register_pm" function in board file and comment out the shared RAM entry in  "map_desc" structure then try to access the shared memory .

    But I just want to directly access shared ram area at 0x80000000 either from a kernel module or user space.

    Did you write any code to accomplish this and getting any error while accessing ?

    Could you share the code either kernel or user space code.

    Have you ever tried to use "kmalloc" to allocate the memory from shared MEM pool?

  • Hi Tutus,

    It seems that my first question was not clear! As I mentioned earlier my primary concern was to access shared ram and I included the "BUG" message since I thought it may be a clue.

    I did not know how to use mmap command and did not find a clear example. 

    But finally I found the correct one by trial and error and it was pretty easy.

    For those who may have little knowledge of this like myself I will write down here a few instructions which do the job!

    fd = open("/dev/mem", O_RDWR | O_SYNC);

    char * shared_ram = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0x80000000);

    Thank you for your time and information.

  • Hi Alireza,

    Thanks for your update.