Find the answer to your Linux question:
Results 1 to 7 of 7
hi all i am new to in this device driver i have mapped memmory from 0xc8000 to 0xc8007 by using the function request_mem_region it got mapped as i found it ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2010
    Posts
    13

    PROBLEM in ' outb ' and ' inb ' comands


    hi all i am new to in this device driver

    i have mapped memmory from 0xc8000 to 0xc8007
    by using the function request_mem_region

    it got mapped as i found it in cat /proc/iomem in my system

    after that i did
    int ptr=3,value;
    outb(ptr,0xc8000);
    value=inb(oxc8000);
    printk("value=%d",value);

    but in output it is showing value= 255 and not 3

    i googled this problem and many places it is saying that because of io permision to port it may give the problem so i did iopl(3)
    in my application program
    but still this error i am getting plz suggest me something

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,655
    What is the port address? Is it 0xC8000? If so, then you have reversed the arguments for outb().
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Apr 2010
    Posts
    13
    when i did cat /proc/iomem i saw this 0xc8000 space was empty
    so i registered this memory , i thought i can access the memmory address with read write operation
    so i used outb and inb

    0xc8000 is not a port addrss , is that i cant access memmory address of my PC?

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,655
    No, you can't use I/O operations on memory normally. You can map the physical address into your process virtual memory space and read/write it normally, just like setting/reading any address. FYI, on many embedded systems I/O ports are mapped to memory by device drivers to make it easier for normal applications to read and write to them.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  6. #5
    Just Joined!
    Join Date
    Apr 2010
    Posts
    13
    yes sir i got ur point,,i googled about this problem
    and came to know about ioremap function
    but how can i use that function ?

    syntax:
    void* iormeap(unsigned long offset, unsigned long size);

    first argument: if i want to access portb register on my arm board whose address is
    0x4c00000c(from datasheet) ,so unsigned long offset=0x4c00000c

    second argument : here i am confused what should i give is the size means page size
    unkowingly i gave unsigned long size=4096;

    and is the return value is virtual address ?

    plz clear my doubt sir

  7. #6
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,655
    Several issues:

    1. The address has to be on a page boundary, so you would use 0x4c000000
    2. The size should be a page size, which you can get with the function getpagesize()
    3. This does not necessarily map the port address into virtual memory. You should use the i/o helper functions readb/writeb/readw/writew/readl/writel functions to actually read/write the port address, which is derived by adding the offset (0xc in your example) to the address returned by ioremap().
    4. You should REALLY read the kernel man pages (available online) to better understand what is going on here. Kernel driver programming is not for the "newbie" unless you are a very fast learner.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  8. #7
    Just Joined!
    Join Date
    Apr 2010
    Posts
    13

    [solved]

    thanks for ur support
    the function ioremap_nocache allocates the physical memory and gives the virtual address for it
    syntax:
    void* ioremap_nocache(physical address, pagesize);

    example:
    void * virt;
    virt=ioremap_nocache(0x4c00000c,4096);

    to reffer that address use
    *((unsigned long *)virt)=0x2;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •