Thread: How to Map a Memory Space

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    22

    How to Map a Memory Space

    So, I have the address of the memory address and I want to map it into my kernels memory space, so that I can access the memory for both reading and writing. I am not very good at doing this. I have been reading up a C pointers but for some reason I don't think that is all I need. I have been working with another member here with bitwise shifts and masking, so that I understand; however, my trouble is that I don't fully understand how to map the memory for usage. Any help?

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Address of the memory address? You mean the address of a pointer which contains a memory address?
    What OS are you using? Linux I suppose?
    If you want to allocate memory for the kernel you can use kmalloc() for example in linux.
    If you want to allocate a specific memory location then... dunno. I can't think of a reason you would want to to this either.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    22
    No, I mean the address of a space of memory belonging to a device on the PCI bus. From the PCI controller I was given the IO and Memory space addresses of a device I am coding for and I now need to map the memory space address so that I can read/write to and from it. Any ideas? I was thinking to kmalloc a struct but not sure how that actually maps the memory space for access.
    Last edited by jacob12; 10-04-2008 at 07:34 AM.

  4. #4
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Dunno exactly. You could use copy_from(to)_user maybe and use that data, but I guess you don't want that because of efficiency.
    Other functions that I found with a google search:
    iorempa(), mmap(), kmap()

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981

  6. #6
    Registered User
    Join Date
    Sep 2008
    Posts
    22
    See the Linux Reference says that I could access the device three ways:

    01. Memory Locations
    02. I/O Ports
    03. Config Registers

    I was trying the Config Registers method but I kept returning garbage. I would write 003F0000 to Offset 0x90 of the Base 5 Memory Space Address and my return would be 00700000. I made sure the IO Enabled bits were set to 00000011 which enables IO and Memory Access, but I never checked it after, I'll try that to see if it got set; however assuming it had I am still returning garbage. I might try the I/O Ports as I have the data sheet for my card and I know the address and data ports for it. I think the traditional approach is to use method 01 above, but I am hoping to get around it using 02, or 03.

    I'll keep trying using methods 2 and 3 and I'll keep you posted. Thanks

  7. #7
    Registered User
    Join Date
    Sep 2008
    Posts
    22
    What does the following actually suggest:

    The BAR is written to by software to map the device regis-
    ters into a window of processor address space. Once this mapping is
    done, the device registers can be accessed relative to the base address.
    What is the "processor address space" is that RAM? What does "relative to the base address" mean, is that Address+Offset?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. tools for finding memory leaks
    By stanlvw in forum C++ Programming
    Replies: 4
    Last Post: 04-03-2009, 11:41 AM
  2. Sharing a Memory Space between two Processes
    By akm3 in forum C Programming
    Replies: 1
    Last Post: 04-02-2009, 02:06 AM
  3. Memory usage and memory leaks
    By vsanandan in forum C Programming
    Replies: 1
    Last Post: 05-03-2008, 05:45 AM
  4. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  5. New editor updates
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-05-2005, 03:26 PM