Help on request_mem_region across different driver modules - Regarding

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

I am facing a problem currently and I am kind of running out of
ideas. I would really appreciate if someone could give me some pointers
on what I am doing wrong and advise me on how I might go about
fixing this problem.

I am guessing it has to do with calling the
check_mem_region
request_mem_region
release_mem_region

on the same memory region across two driver modules(not loaded at the same time).

Thanks for your time
Vijay

Scenario:

Device driver1 -
This is a reset/download device driver implemented as a kernel module,
which resets a board on the PCI bus from the host and downloads the
linux kernel to the board.

Device driver2 -
This is a two way communication channel implemented as
device driver kernel modules on the host (and board), which sets up a two way
communication channel between the board and the host.

Both drivers are loaded on the host.

Driver2 is loaded after the driver1 is loaded and unloaded to reproduce the error.

Loading and unloading Driver1 many times seems to work fine.


*********************
Driver1 Code Segments:
*********************

 #define PEER_DRAM_RESOURCE 3

 int Initialization (struct pci_dev *dev)
  {
  u32 barBase = pci_resource_start (dev, PEER_DRAM_RESOURCE);

  int size = pci_resource_len(dev,PEER_DRAM_RESOURCE)

  int result = check_mem_region
      (
      barBase,
      size
      );

  if (result < 0)
   {
   return -1;
   }

  result = request_mem_region
      (
      barBase,
      size,
      "PCI ResetAndDownload Device"
      );

  if (!result)
   {
   return -1;
   }

  char* remappedAddress = NULL;

  remappedAddress = (char*) ioremap (barBase, size);

  // ... Do some readls and writels
  // ... All seems good
  readl (remappedAddress);
  readl (remappedAddress+0x04);
  readl (remappedAddress+0x08);

  // ... Download the linux kernel image to the board
  // ... by writing to the remapped address
  // ... Works fine
  }

 Cleanup (struct pci_dev *dev, void* remappedAddress)
  {
  u32 barBase = pci_resource_start (dev, PEER_DRAM_RESOURCE);

  int size = pci_resource_len(dev,PEER_DRAM_RESOURCE)

  // ... Does the order of release_mem_region and iounmap matter?

  release_mem_region
   (
   barBase,
   size
   );
  iounmap (remappedAddress);
  }

Load the Driver1,
Driver1 seems happy,
does its job,
cleansup correctly,
Unload the Driver1 module.


*********************
Driver2 Code segments:
*********************

 #define PEER_DRAM_RESOURCE 3

 int Initialization (struct pci_dev *dev, void* remappedAddress)
  {
  u32 barBase = pci_resource_start (dev, PEER_DRAM_RESOURCE);

  int size = pci_resource_len(dev,PEER_DRAM_RESOURCE)

  int result = check_mem_region
      (
      barBase,
      size
      );

  if (result < 0)
   {
   return -1;
   }

  result = request_mem_region
      (
      barBase,
      size,
      "PCI Communication Device"
      );
  if (!result)
   {
   return -1;
   }

  char* remappedAddress = NULL;

  remappedAddress = (char*) ioremap (barBase, size));

  // ... I have verified that the remapped address is within the
  // ... window size allocated

  // ... I have also tried to read from different address within the
  // ... window, and all of them fail

  // ... Test for reading from the remapped address
  // ... This bombs big time and I can't read anything from this
  // ... remapped address window (starting point to the size allocated)
  // ... It also crashes the host which makes it even more
  // ... harder to test with the host reset and all

  readl (remappedAddress);
  }




--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux