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.

userspace read problem

Other Parts Discussed in Thread: AM3894, AM3892

Hi guys, i'm using the dm816x board as my learning board. i had ioremap a memory region,then i iowrite32() a string into that region and ioread32() from that region and everything is work prefectly.

However, when i read from user space using mmap().it cannot show me the string.Can anyone help me?Thank you.

  • I think mmap() only supports mapping on page aligned addresses. Maybe you are trying to mmap() a physical address that is not page aligned.

  • i thought ioremap is remap the physical -> virtual address...then how can i know the region is page aligned or not?Thank you.

  • the weird thing is when i write a number using iowrite32(), i can read from userspace by mmaping.When i try to write a string, then it is not work.

  • Hi,

    Address should be 4K bytes aligned. Can you check what physical address are you doing IO remap to.

    Regards,

    Hardik Shah

  • I believe ioremap() handles unaligned requests. I remember mmap() would change addresses to page aligned addresses. Use getpagesize() to get the actual value. I vaguely remember it is 4k or 0x1000. So if you requested physical address 0x12345678, mmap() would round that 0x12345000 and return a page aligned virtual address. You would have to add 0x678 to the virtual address to access the original physical address of 0x12345678.

    If you can share memory using a number, you should be able to to do the same with strings. You should post an example of your kernel code and your user space code. Maybe others can comment better than me.

  • Hi HardikShah, i refer to the AM3894,AM3892 Sitara ARM Microprocessors (MPUs) (Rev.A).My physical address is 0xC000 0000, DDR EMIF0/1 SDRAM,  the size is 0x4000000.Does it correct?Thank you.

  • hi, this is my code.

    kernel:

    #define PHYS_ADDR_BUFFER  0xC0000000ULL  // AM3894,AM3892 Sitara ARM Microprocessors (MPUs) (Rev.A).My physical address is 0xC000 0000, DDR EMIF0/1                                                                                                          // SDRAM,  the size is 0x4000000

    #define IMAGE_BUFFER_NUM   2

    #define IMAGE_BUFFER_SIZE  0x2000000

    #define MAPPED_SIZE_BUFFER (IMAGE_BUFFER_NUM * IMAGE_BUFFER_SIZE)

    u64 buffer_phys  = PHYS_ADDR_BUFFER;

    typedef struct memorydriverconfig{

         u32 mem_virt;

    }memorydriverconfig;

    memory->mem_virt     = (u32 )ioremap( buffer_phys,  MAPPED_SIZE_BUFFER );

    iowrite32("12ss",memory->mem_virt);

    user space:

    int *map=NULL;

    #define MAPPED_SIZE_BUFFER (IMAGE_BUFFER_NUM*IMAGE_BUFFER_SIZE)

    #define PHYS_ADDR_BUFFER  0xC0000000ULL

    const char imagingDevice[] = "/dev/mem"; 

    _fdmem = open( imagingDevice, O_RDWR | O_SYNC );

    map= (mmap(0,MAPPED_SIZE_BUFFER,PROT_READ|PROT_WRITE,MAP_SHARED,_fdmem,PHYS_ADDR_BUFFER));

    printf("the address is %s\n",*map);

    After i compile and load it to my dm816x, the userspace  cannot show the string...Can anyone guide me?Thank you.

  • I think you are saving the address of the constant literal string "12ss". Not an 32 bit value with an ASCII value of "12ss". All ignores the null terminator. You probably need to write the string to memory one character at a time using iowrite8().