- 论坛徽章:
- 0
|
代码如下
static int vdriver_get_cardinfo(VD_PCI_CARD_INFO *vd_card_info)
{
unsigned int i, j, result;
unsigned int bus, devfn;
unsigned short cont = 0;
struct pci_dev *pci_dev = NULL;
unsigned int configspcce[6];
unsigned int configspace[6];
u64 membase, iobase;
unsigned int io_size, mem_size;
void __iomem *virmembase;
int irqnum, err;
bus = vd_card_info->pciSlot.dwBus;
devfn = (vd_card_info->pciSlot.dwSlot << 3) | (vd_card_info->pciSlot.dwFunction);
pci_dev = pci_get_domain_bus_and_slot(0, bus, devfn);
vdriver_debug("Vendor Id is %x,Device Id is %x, pci_dev is %x\n",pci_dev->vendor,pci_dev->device,pci_dev);
if(pci_enable_device(pci_dev))
{
vdriver_error("can't enble pci device!\n");
return -EIO;
}
pci_set_master(pci_dev);
pci_set_dma_mask(pci_dev, DMA_BIT_MASK(32));
for(i = 0x10, j = 0; i < 0x24; i += 4, j++)
{
result = pci_read_config_dword(pci_dev, i , &configspcce[j]);
vdriver_debug("bar: %d, data: %x.................\n" ,j, configspcce[j]);
if(((configspcce[j] & 0x1) == 1) && (configspcce[j] != 0xffffffff))
{
iobase = pci_resource_start(pci_dev,j);
io_size = pci_resource_len(pci_dev, j);
vd_card_info->Card.Item[j].item = ITEM_IO;
vd_card_info->Card.Item[j].I.IO.dwBar = j;
vd_card_info->Card.Item[j].I.IO.dwAddr = iobase;
vd_card_info->Card.Item[j].I.IO.dwBytes = io_size;
vdriver_debug("IO bar is %d,baseaddr is %x,size is %x\n",j,vd_card_info->Card.Item[j].I.IO.dwAddr,io_size);
cont++;
}
else if(((configspcce[j] & 0x1) == 0) && (configspcce[j] != 0xfffffffe))
{
membase = pci_resource_start(pci_dev, j);
printk("membase: %llx.....................................................\n",membase);
mem_size = pci_resource_len(pci_dev, j);
if((membase != 0) && (mem_size != 0))
{
vd_card_info->Card.Item[j].item = ITEM_MEMORY;
vd_card_info->Card.Item[j].I.Mem.dwBar = j;
vd_card_info->Card.Item[j].I.Mem.dwPhysicalAddr = membase;
vd_card_info->Card.Item[j].I.Mem.dwBytes = mem_size;
vdriver_debug("MEM bar is %d,baseaddr is %x,size is %x\n",j,(unsigned int)vd_card_info->Card.Item[j].I.Mem.dwPhysicalAddr,mem_size);
cont++;
}
}
}
irqnum = pci_dev->irq;
if(irqnum != -1)
{
vd_card_info->Card.Item[j].item = ITEM_INTERRUPT;
vd_card_info->Card.Item[j].I.Int.dwInterrupt = irqnum;
vd_card_info->Card.Item[j].I.Int.dwOptions = INTERRUPT_LEVEL_SENSITIVE;
vd_card_info->Card.Item[j].I.Int.hInterrupt = 0;
vdriver_debug("INT number is %x\n",irqnum);
j++;
}
vd_card_info->Card.dwItems = j;
vdriver_debug("the cardinfo resource items number: %d\n",(int)vd_card_info->Card.dwItems);
return 0;
}
代码执行到pci_set_dma_mask函数时,段错误,dmesg 信息如下
[ 1657.296000] CPU 0 Unable to handle kernel paging request at virtual address 0000000100000000, epc == ffffffffc0268cd0, ra == ffffffffc0268cc0
[ 1657.304000] Oops[#1]:
[ 1657.304000] Cpu 0
[ 1657.304000] $ 0 : 0000000000000000 000000007000cce0 0000000100000000 0000000000000000
[ 1657.304000] $ 4 : 98000000fc561088 0000000000000000 0000000000000000 000000000000000a
[ 1657.304000] $ 8 : 000000000000ef41 0000000000000005 0000000000000001 0000000000000000
[ 1657.304000] $12 : 0000000000000005 ffffffff80305d5c ffffffff804450d0 000000007fb3d168
[ 1657.304000] $16 : 98000000fc561000 00000000ffffffff ffffffff80323ffc 98000000f8bdc800
[ 1657.304000] $20 : 000000007fb3cfac ffffffff80320000 000000007fb3e9b4 000000007fb3e9c0
[ 1657.304000] $24 : 0000000000000000 ffffffff8033e538
[ 1657.304000] $28 : 98000000f8d10000 98000000f8d13d40 000000007fb3cf68 ffffffffc0268cc0
[ 1657.304000] Hi : 0000000000000000
[ 1657.304000] Lo : 0000000000000000
[ 1657.304000] epc : ffffffffc0268cd0 $L134+0x20/0x24 [vdriver]
[ 1657.304000] Not tainted
[ 1657.304000] ra : ffffffffc0268cc0 $L134+0x10/0x24 [vdriver]
[ 1657.304000] Status: 7000cce3 KX SX UX KERNEL EXL IE
[ 1657.304000] Cause : 1000000c
[ 1657.304000] BadVA : 0000000100000000
[ 1657.304000] PrId : 00006305 (ICT Loongson-3A5)
[ 1657.304000] Modules linked in: vdriver fuse sunrpc ipv6 snd_hda_intel snd_hda_codec snd_hwdep snd_seq snd_seq_device snd_pcm snd_page_alloc snd_timer snd soundcore [last unloaded: vdriver]
[ 1657.304000] Process runPlugins (pid: 10625, threadinfo=98000000f8d10000, task=98000000f86f5828, tls=000000002b4e3150)
[ 1657.304000] Stack : 000000007fb3e9b4 000000007fb3e9c0 000000007fb3cf68 ffffffff80324030
[ 1657.304000] 98000000f8d13d88 0000000000000000 000000007fb3cfac 98000000f8bdc800
[ 1657.304000] ffffffff80323ffc 000000007fb3dfac 000000007fb3cfac 000000007fb3e9b0
[ 1657.304000] 000000007fb3e9b4 000000007fb3e9c0 000000007fb3cf68 ffffffffc0269df0
[ 1657.304000] 0000000000000000 0000000000000000 98000000f8d4e400 0000000000000000
[ 1657.304000] 98000000f8d4e400 0000000000000009 000000007fb3d980 ffffffffc0045605
[ 1657.304000] 000000007fb3cfac 000000007fb3e9b0 000000007fb3e9b4 000000007fb3e9c0
[ 1657.304000] 000000007fb3cf68 ffffffff80445208 0000000000000000 ffffffff81c40000
[ 1657.304000] 9800000000000000 ffffffff803a2df8 0000000000000000 0000000031b1b4f8
[ 1657.304000] ffffffff804450d0 000000002ca0924c 000000007fb3e1d8 000000002ca0924c
[ 1657.304000] ...
[ 1657.304000] Call Trace:
[ 1657.304000] [<ffffffffc0268cd0>] $L134+0x20/0x24 [vdriver]
[ 1657.304000] [<ffffffffc0268cc0>] $L134+0x10/0x24 [vdriver]
[ 1657.304000]
[ 1657.304000]
[ 1657.304000] Code: 3c158032 de0201e8 6631ffff <fc510000> 3c04c027 66b53ffc
这个驱动程序在x86系统是没问题的,但目前是往mips架构的龙芯上移植。我的理解是pci_set_dma_mask(pci_dev, DMA_BIT_MASK(32))这个函数的DMA_BIT_MASK(32)参数有问题,网上说这个函数是表示该设备的DMA的寻址能力,我的理解就是我的pci设备的寻址范围,把这个32的参数改成别的DMA功能出现问题,但不会出现段错误。弄了2天没有找到原因,不知道该怎么调了,求大神给解决下!!!!!!!!!!!!!! |
|