linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: mmap, PCI, segmentation fault, Dell Dimension 4550
@ 2003-08-07 14:46 Scott Jacobsen
  0 siblings, 0 replies; 2+ messages in thread
From: Scott Jacobsen @ 2003-08-07 14:46 UTC (permalink / raw)
  To: linux-kernel



Oops.  Private variable for the Software_Radio class.

unsigned long * bar0, *bar1, *bar2, *bar3, *bar4

Thx.

David B. Stevens wrote:

> Scott,
>
> Maybe I'm blind but where is bar0[x] ... defined.
>
> Cheers,
>   Dave
>
>
> Scott Jacobsen wrote:
>
>> Hi.  Sorry for the intrusion but I've searched the archives and can't 
>> seem to find the answer for my problem.
>>
>> After using mmap() map a peripheral card's PCI base address registers 
>> to user space on my Dell Dimension 4550 (Dell BIOS), I cause a 
>> segmentation fault by accessing the mapped memory.
>>
>> My OS is Redhat 9 and the underlying kernel is 2.4.20-8.  The code 
>> works fine on a generic computer (Award BIOS) running exactly the 
>> same kernel.
>>
>> My driver for the card also maps the PCI base address registers in 
>> kernel space for the driver's usage, but like I mentioned, the code 
>> works fine on the other computer.
>>
>> Here's my code and command line output (please pardon my non-gdb 
>> testing procedure):
>>
>> ////////////////////// code /////////////////////////
>>
>> int Software_Radio::get_bars()
>> {
>>   printf("get_bars\n");        // TEST LINE
>>   uchar config_data[256];
>>   off_t physical_bars[5];
>>
>>   if(ioctl(filep, CONFIG_READ, config_data) == -1)
>>     perror("\nSoftware_Radio::get_bars() ioctl() CONFIG_READ failed");
>>
>>   physical_bars[0]=((off_t)config_data[PCI_BASE_ADDRESS_0] |
>>            ((off_t)config_data[PCI_BASE_ADDRESS_0 + 1] << 8) |
>>            ((off_t)config_data[PCI_BASE_ADDRESS_0 + 2] << 16) |
>>            ((off_t)config_data[PCI_BASE_ADDRESS_0 + 3] << 24) );
>>   physical_bars[1]=((off_t)config_data[PCI_BASE_ADDRESS_1] |
>>            ((off_t)config_data[PCI_BASE_ADDRESS_1 + 1] << 8) |
>>            ((off_t)config_data[PCI_BASE_ADDRESS_1 + 2] << 16) |
>>            ((off_t)config_data[PCI_BASE_ADDRESS_1 + 3] << 24) );
>>   physical_bars[2]=((off_t)config_data[PCI_BASE_ADDRESS_2] |
>>            ((off_t)config_data[PCI_BASE_ADDRESS_2 + 1] << 8) |
>>            ((off_t)config_data[PCI_BASE_ADDRESS_2 + 2] << 16) |
>>            ((off_t)config_data[PCI_BASE_ADDRESS_2 + 3] << 24) );
>>   physical_bars[3]=((off_t)config_data[PCI_BASE_ADDRESS_3] |
>>            ((off_t)config_data[PCI_BASE_ADDRESS_3 + 1] << 8) |
>>            ((off_t)config_data[PCI_BASE_ADDRESS_3 + 2] << 16) |
>>            ((off_t)config_data[PCI_BASE_ADDRESS_3 + 3] << 24) );
>>   physical_bars[4]=((off_t)config_data[PCI_BASE_ADDRESS_4] |
>>            ((off_t)config_data[PCI_BASE_ADDRESS_4 + 1] << 8) |
>>            ((off_t)config_data[PCI_BASE_ADDRESS_4 + 2] << 16) |
>>            ((off_t)config_data[PCI_BASE_ADDRESS_4 + 3] << 24) );
>>
>>   int fd;
>>   if((fd=open("/dev/mem",O_RDWR)) < 0) {
>>     perror("opening /dev/mem");
>>     return -1;
>>   }
>>   unsigned long * remapped_bars[5];
>>   void * temp;
>>   for (int i = 0; i < 5; i++) {
>>     if((temp = mmap(0,bar_sizes[i],PROT_WRITE | PROT_READ,
>>             MAP_SHARED | MAP_FILE, fd, physical_bars[i])) < 0) {
>>       printf("MMAP failed.  Reason: %s\n",strerror(errno));
>>       return -1;
>>     }
>>     remapped_bars[i] = (unsigned long *)temp;
>>   }
>>   bar0 = remapped_bars[0];
>>   printf("bar0 = 0x%x\n",&bar0);    // TEST LINE
>>   printf("bar0[15] = 0x%x\n",bar0[0]);  // THIS LINE, OR ANY bar0[0] 
>> CAUSES A SEGMENTATION FAULT
>>   bar1 = remapped_bars[1];
>>   bar2 = remapped_bars[2];
>>   bar3 = remapped_bars[3];
>>   bar4 = remapped_bars[4];
>>   close(fd);
>> }
>>
>> /////////////////// command line //////////////////
>>
>> [root@jacobsen swr]# ./test
>> main:line 1           opening device /dev/sidrv0
>> get_bars
>> bar0 = 0xbfffe0b0
>> Segmentation fault
>> [root@jacobsen swr]#
>>
>>
>> //////////////////////////////////////////////////
>>
>> Any suggestions?
>>
>> Thanks,
>>
>> Scott Jacobsen
>> MSc(Eng) Student
>> University of Calgary
>>
>> -
>> To unsubscribe from this list: send the line "unsubscribe 
>> linux-kernel" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at  http://www.tux.org/lkml/
>>
>
>
>

-- 
TRLabs
#280, 3553 - 31 Street NW
Calgary, Alberta T2L 2K7
Canada

Phone: 403-210-3530
Fax: 403-282-5870

Email: jacobsen@cal.trlabs.ca

 





-- 
TRLabs
#280, 3553 - 31 Street NW
Calgary, Alberta T2L 2K7
Canada

Phone: 403-210-3530
Fax: 403-282-5870

Email: jacobsen@cal.trlabs.ca

 



^ permalink raw reply	[flat|nested] 2+ messages in thread

* mmap, PCI, segmentation fault, Dell Dimension 4550
@ 2003-08-06 22:24 Scott Jacobsen
  0 siblings, 0 replies; 2+ messages in thread
From: Scott Jacobsen @ 2003-08-06 22:24 UTC (permalink / raw)
  To: linux-kernel

Hi.  Sorry for the intrusion but I've searched the archives and can't 
seem to find the answer for my problem.

After using mmap() map a peripheral card's PCI base address registers to 
user space on my Dell Dimension 4550 (Dell BIOS), I cause a segmentation 
fault by accessing the mapped memory.

My OS is Redhat 9 and the underlying kernel is 2.4.20-8.  The code works 
fine on a generic computer (Award BIOS) running exactly the same kernel.

My driver for the card also maps the PCI base address registers in 
kernel space for the driver's usage, but like I mentioned, the code 
works fine on the other computer.

Here's my code and command line output (please pardon my non-gdb testing 
procedure):

////////////////////// code /////////////////////////

int Software_Radio::get_bars()
{
   printf("get_bars\n");		// TEST LINE
   uchar config_data[256];
   off_t physical_bars[5];

   if(ioctl(filep, CONFIG_READ, config_data) == -1)
     perror("\nSoftware_Radio::get_bars() ioctl() CONFIG_READ failed");

   physical_bars[0]=((off_t)config_data[PCI_BASE_ADDRESS_0] |
		   ((off_t)config_data[PCI_BASE_ADDRESS_0 + 1] << 8) |
		   ((off_t)config_data[PCI_BASE_ADDRESS_0 + 2] << 16) |
		   ((off_t)config_data[PCI_BASE_ADDRESS_0 + 3] << 24) );
   physical_bars[1]=((off_t)config_data[PCI_BASE_ADDRESS_1] |
		   ((off_t)config_data[PCI_BASE_ADDRESS_1 + 1] << 8) |
		   ((off_t)config_data[PCI_BASE_ADDRESS_1 + 2] << 16) |
		   ((off_t)config_data[PCI_BASE_ADDRESS_1 + 3] << 24) );
   physical_bars[2]=((off_t)config_data[PCI_BASE_ADDRESS_2] |
		   ((off_t)config_data[PCI_BASE_ADDRESS_2 + 1] << 8) |
		   ((off_t)config_data[PCI_BASE_ADDRESS_2 + 2] << 16) |
		   ((off_t)config_data[PCI_BASE_ADDRESS_2 + 3] << 24) );
   physical_bars[3]=((off_t)config_data[PCI_BASE_ADDRESS_3] |
		   ((off_t)config_data[PCI_BASE_ADDRESS_3 + 1] << 8) |
		   ((off_t)config_data[PCI_BASE_ADDRESS_3 + 2] << 16) |
		   ((off_t)config_data[PCI_BASE_ADDRESS_3 + 3] << 24) );
   physical_bars[4]=((off_t)config_data[PCI_BASE_ADDRESS_4] |
		   ((off_t)config_data[PCI_BASE_ADDRESS_4 + 1] << 8) |
		   ((off_t)config_data[PCI_BASE_ADDRESS_4 + 2] << 16) |
		   ((off_t)config_data[PCI_BASE_ADDRESS_4 + 3] << 24) );

   int fd;
   if((fd=open("/dev/mem",O_RDWR)) < 0) {
     perror("opening /dev/mem");
     return -1;
   }
   unsigned long * remapped_bars[5];
   void * temp;
   for (int i = 0; i < 5; i++) {
     if((temp = mmap(0,bar_sizes[i],PROT_WRITE | PROT_READ,
		    MAP_SHARED | MAP_FILE, fd, physical_bars[i])) < 0) {
       printf("MMAP failed.  Reason: %s\n",strerror(errno));
       return -1;
     }
     remapped_bars[i] = (unsigned long *)temp;
   }
   bar0 = remapped_bars[0];
   printf("bar0 = 0x%x\n",&bar0);	// TEST LINE
   printf("bar0[15] = 0x%x\n",bar0[0]);  // THIS LINE, OR ANY bar0[0] 
CAUSES A SEGMENTATION FAULT
   bar1 = remapped_bars[1];
   bar2 = remapped_bars[2];
   bar3 = remapped_bars[3];
   bar4 = remapped_bars[4];
   close(fd);
}

/////////////////// command line //////////////////

[root@jacobsen swr]# ./test
main:line 1			
opening device /dev/sidrv0
get_bars
bar0 = 0xbfffe0b0
Segmentation fault
[root@jacobsen swr]#


//////////////////////////////////////////////////

Any suggestions?

Thanks,

Scott Jacobsen
MSc(Eng) Student
University of Calgary


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-08-07 14:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-07 14:46 mmap, PCI, segmentation fault, Dell Dimension 4550 Scott Jacobsen
  -- strict thread matches above, loose matches on Subject: below --
2003-08-06 22:24 Scott Jacobsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).