Received: from [140.186.70.92] (port=42778 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OrDoH-0000DR-VR for qemu-devel@nongnu.org; Thu, 02 Sep 2010 13:42:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OrDoG-0000ph-AM for qemu-devel@nongnu.org; Thu, 02 Sep 2010 13:42:49 -0400 Received: from smtp.mailix.net ([66.11.225.183]:29288) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OrDoF-0000pa-SB for qemu-devel@nongnu.org; Thu, 02 Sep 2010 13:42:48 -0400 From: "Adnan Khaleel" Subject: =?iso-8859-1?Q?Re=3A_=5BQemu-devel=5D_Template_for_developing_a_Qe?= =?iso-8859-1?Q?mu_device_with_PCIe=09and_MSI-X?= In-Reply-To: 20100902023831.GA20106@valinux.co.jp Message-ID: <20100902174242.4cb1fb0f@shadowfax.no-ip.com> Date: Thu, 02 Sep 2010 12:42:42 -0500 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="-----------9ff798cb7af029a1bad9e6189ec420e7" Reply-To: adnan@khaleel.us List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Isaku Yamahata Cc: Cam Macdonell , qemu-devel@nongnu.org This is a multi-part message in MIME format. -------------9ff798cb7af029a1bad9e6189ec420e7 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable I've tried everything you mentioned and I still get the same problem. Th= e only thing that seems to avoid that issue is if I reduce the aperture = size from 0x2000000000ull to 0x2000000ull. Here is the relevant section of code: static const unsigned long long BAR=5FRegions[6][2] =3D=20 { // len , type=20 { 0x2000000ull, PCI=5FBASE=5FADDRESS=5FSPACE=5FMEMORY | PCI=5FBASE= =5FADDRESS=5FMEM=5FTYPE=5F64} , //BAR0, =20 { 0, 0} , // BAR1 { 0x2000000ull, PCI=5FBASE=5FADDRESS=5FSPACE=5FIO } , //BAR2, { 0, 0} , // BAR3 for MSI-X { 0, 0} , // BAR4 { 0, 0} , // BAR5 =20 }; static int pcie=5Fmsix=5Finitfn(PCIDevice *pci=5Fdev) { PCIE=5FMSIX=5FDEVState *d =3D DO=5FUPCAST(PCIE=5FMSIX=5FDEVState, de= v, pci=5Fdev); PCIBridge *br =3D DO=5FUPCAST(PCIBridge, dev, pci=5Fdev); PCIEPort *p =3D DO=5FUPCAST(PCIEPort, br, br); int rc, i; PRINT=5FDEBUG("%s: PCIE MSIX Device init...\n", =5F=5FFUNCTION=5F=5F= ); pci=5Fconfig=5Fset=5Fvendor=5Fid(d->dev.config, PCIE=5FMSIX=5FVID); pci=5Fconfig=5Fset=5Fdevice=5Fid(d->dev.config, PCIE=5FMSIX=5FDID); memcpy(d->dev.config, g=5Fcfg=5Finit, sizeof(g=5Fcfg=5Finit[0x20])); d->mmio=5Findex =3D cpu=5Fregister=5Fio=5Fmemory(pcie=5Fmsix=5Fmem= =5Fread=5Ffn, pcie=5Fmsix=5Fmem=5Fwrite=5Ffn, d); int msix=5Fmem=5Fbar =3D 0; // Since its a 64bit BAR, we take up BA= R0 & BAR1 int msix=5Fio=5Fbar =3D 2; int msix=5Fmmio=5Fbar =3D 3; pci=5Fregister=5Fbar(&d->dev, msix=5Fmem=5Fbar, BAR=5FRegions[msix= =5Fmem=5Fbar][0], BAR=5FRegions[msix=5Fmem=5Fbar][1], pcie=5Fmsix=5Fmem= =5Fmap); pci=5Fregister=5Fbar(&d->dev, msix=5Fio=5Fbar, BAR=5FRegions[msix=5F= io=5Fbar][0], BAR=5FRegions[msix=5Fio=5Fbar][1], pcie=5Fmsix=5Fio=5Fmap)= ; rc =3D msix=5Finit(&d->dev, d->vectors, msix=5Fmmio=5Fbar, 0); =20 if (!rc) { PRINT=5FDEBUG("%s: Registering Bar %i as I/O BAR\n", =5F=5FFUNCT= ION=5F=5F, msix=5Fmmio=5Fbar); pci=5Fregister=5Fbar(&d->dev, msix=5Fmmio=5Fbar, msix=5Fbar=5Fsi= ze(&d->dev), PCI=5FBASE=5FADDRESS=5FSPACE=5FMEMORY, msix=5Fmmio=5Fmap); PRINT=5FDEBUG("%s: MSI-X initialized (%d vectors)\n", =5F=5FFUNC= TION=5F=5F, d->vectors); } else { PRINT=5FDEBUG("%s: MSI-X initialization failed!\n", =5F=5FFUNCTI= ON=5F=5F); return rc; } =20 // Activate the vectors for (i =3D 0; i < d->vectors; i++) { msix=5Fvector=5Fuse(&d->dev, i); } rc =3D pci=5Fpcie=5Fcap=5Finit(&d->dev, PCIE=5FMSIX=5FEXP=5FOFFSET, = PCI=5FEXP=5FTYPE=5FENDPOINT, p->port); if (rc < 0) { return rc; } pcie=5Fcap=5Fflr=5Finit(&d->dev, &pcie=5Fmsix=5Fflr); pcie=5Fcap=5Fdeverr=5Finit(&d->dev); pcie=5Fcap=5Fari=5Finit(&d->dev); rc =3D pcie=5Faer=5Finit(&d->dev, PCIE=5FMSIX=5FAER=5FOFFSET); if (rc < 0) { return rc; } PRINT=5FDEBUG("%s: Init done\n", =5F=5FFUNCTION=5F=5F); return 0; } Another question I have is why doesn't the device show up when I try a c= at /proc/interrupts. linux-an84:~/AriesKernelModules/gni/aries/ghal # cat /proc/interrupts CPU0 0: 694 IO-APIC-edge timer 1: 6 IO-APIC-edge i8042 4: 753 IO-APIC-edge serial 8: 1 IO-APIC-edge rtc0 9: 0 IO-APIC-fasteoi acpi 12: 89 IO-APIC-edge i8042 14: 3522 IO-APIC-edge ata=5Fpiix 15: 785 IO-APIC-edge ata=5Fpiix 16: 162 IO-APIC-fasteoi eth0 4344: 0 PCI-MSI-edge aerdrv 4345: 0 PCI-MSI-edge aerdrv 4346: 0 PCI-MSI-edge aerdrv 4347: 0 PCI-MSI-edge aerdrv 4348: 0 PCI-MSI-edge aerdrv 4349: 0 PCI-MSI-edge aerdrv 4350: 0 PCI-MSI-edge aerdrv 4351: 0 PCI-MSI-edge aerdrv NMI: 0 Non-maskable interrupts LOC: 107095 Local timer interrupts RES: 0 Rescheduling interrupts CAL: 0 function call interrupts TLB: 0 TLB shootdowns TRM: 0 Thermal event interrupts THR: 0 Threshold APIC interrupts SPU: 0 Spurious interrupts ERR: 0 Shouldn't there be an entry for the MSI-X device=3F Thanks for all your input. AK =5F=5F=5F=5F=5F =20 Probably what you want is something like =20 { 0x2000000000ull, PCI=5FBASE=5FADDRESS=5FSPACE=5FMEMORY | PCI=5FBASE= =5FADDRESS=5FMEM=5FTYPE=5F64} , //BAR0 { 0, 0} , //BAR1=20 // 64bit BAR occupies 2 BAR entries so that BAR1 can't be used. { 0x2000000ull, PCI=5FBASE=5FADDRESS=5FSPACE=5FIO } , //BAR2 { 0, 0} , //BAR3 // for MSI-X { 0, 0} , //BAR4 { 0, 0} //BAR5 =20 =20 =20 -------------9ff798cb7af029a1bad9e6189ec420e7 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
I've tried everything you mentioned and= I still get the same problem. The only thing that seems to avoid that i= ssue is if I reduce the aperture size from 0x2000000000ull to 0x2000000u= ll.

Here is the relevant section of code:

static const unsigned long long BAR=5FRegions[6][2= ] =3D
{
    // len , type
&nb= sp;   { 0x2000000ull, PCI=5FBASE=5FADDRESS=5FSPACE=5FMEMORY | = PCI=5FBASE=5FADDRESS=5FMEM=5FTYPE=5F64} ,  //BAR0,   = ;    
    { 0, 0} , // BAR1<= /span>
    { 0x2000000ull, PCI=5FBASE=5FADDRESS=5FSPACE= =5FIO    } ,  //BAR2,
    { 0= , 0} , // BAR3 for MSI-X
    { 0, 0} , // BAR4
    { 0, 0} , // BAR5   
};=

static int pcie=5Fmsix=5Fin= itfn(PCIDevice *pci=5Fdev)
{
    PCIE=5FM= SIX=5FDEVState *d =3D DO=5FUPCAST(PCIE=5FMSIX=5FDEVState, dev, pci=5Fdev= );
    PCIBridge *br =3D DO=5FUPCAST(PCIBridge, d= ev, pci=5Fdev);
    PCIEPort *p =3D DO=5FUPCAST(P= CIEPort, br, br);
    int rc, i;

    PRINT=5FDEBUG("%s: PCIE = MSIX Device init...\n", =5F=5FFUNCTION=5F=5F);

    pci=5Fconfig=5Fset=5Fvendor=5Fid(d= ->dev.config, PCIE=5FMSIX=5FVID);
    pci=5Fco= nfig=5Fset=5Fdevice=5Fid(d->dev.config, PCIE=5FMSIX=5FDID);
    memcpy(d->dev.c= onfig, g=5Fcfg=5Finit, sizeof(g=5Fcfg=5Finit[0x20]));
 &nbs= p;  d->mmio=5Findex =3D cpu=5Fregister=5Fio=5Fmemory(pcie=5Fmsix= =5Fmem=5Fread=5Ffn, pcie=5Fmsix=5Fmem=5Fwrite=5Ffn, d);

&nbs= p;   int msix=5Fmem=5Fbar  =3D 0; // Since its a 64bit BA= R, we take up BAR0 & BAR1
=     int msix=5Fio= =5Fbar   =3D 2;
    int msix=5Fmmio=5Fb= ar =3D 3;

   = pci=5Fregister=5Fbar(&d->dev, msix=5Fmem=5Fbar, BAR=5FRegions[ms= ix=5Fmem=5Fbar][0], BAR=5FRegions[msix=5Fmem=5Fbar][1], pcie=5Fmsix=5Fme= m=5Fmap);
    pci=5Fregister=5Fbar(&d->dev= , msix=5Fio=5Fbar, BAR=5FRegions[msix=5Fio=5Fbar][0], BAR=5FRegions[msix= =5Fio=5Fbar][1], pcie=5Fmsix=5Fio=5Fmap);

    rc =3D msix=5Finit(&d->dev, d-&g= t;vectors, msix=5Fmmio=5Fbar, 0);
   
&n= bsp;   if (!rc) {
      =   PRINT=5FDEBUG("%s: Registering Bar %i as I/O BAR\n", =5F=5FFUNCTI= ON=5F=5F, msix=5Fmmio=5Fbar);
=      &nbs= p;  pci=5Fregister=5Fbar(&d->dev, msix=5Fmmio=5Fbar, msix=5F= bar=5Fsize(&d->dev), PCI=5FBASE=5FADDRESS=5FSPACE=5FMEMORY, msix= =5Fmmio=5Fmap);
        PRINT= =5FDEBUG("%s: MSI-X initialized (%d vectors)\n", =5F=5FFUNCTION=5F=5F, d= ->vectors);
    }
    e= lse {
        PRINT=5FDEBUG("= %s: MSI-X initialization failed!\n", =5F=5FFUNCTION=5F=5F);
&nbs= p;       return rc;
  &n= bsp; }
   
    // Activat= e the vectors
    for (i =3D 0; i < d->vect= ors; i++) {
        msix=5Fve= ctor=5Fuse(&d->dev, i);
    }

    rc =3D pci=5Fpcie=5Fc= ap=5Finit(&d->dev, PCIE=5FMSIX=5FEXP=5FOFFSET, PCI=5FEXP=5FTYPE= =5FENDPOINT, p->port);
    if (rc < 0) {

        return rc;
&nbs= p;   }

  = ;  pcie=5Fcap=5Fflr=5Finit(&d->dev, &pcie=5Fmsix=5Fflr);=
    pcie=5Fcap=5Fdeverr=5Finit(&d->dev);<= /span>
    pcie=5Fcap=5Fari=5Finit(&d->dev);

    rc =3D pcie=5Faer=5Finit(&d->dev, PCIE=5FM= SIX=5FAER=5FOFFSET);
    if (rc < 0) {<= br style=3D"font-family: Courier;">        return rc;
 &= nbsp;  }

  &n= bsp; PRINT=5FDEBUG("%s: Init done\n", =5F=5FFUNCTION=5F=5F);
&nb= sp;   return 0;
}

Another question I hav= e is why doesn't the device show up when I try a cat /proc/interrupts.
linux-an84:~/AriesKernelModules/gni/aries/ghal # cat /proc= /interrupts
        &nbs= p;  CPU0
  0:       = ; 694   IO-APIC-edge      timer

  1:          6&nbs= p;  IO-APIC-edge      i8042
 = 4:        753   IO-APIC-ed= ge      serial
  8:  &nb= sp;       1   IO-APIC-edge =      rtc0
=   9:    &= nbsp;     0   IO-APIC-fasteoi   = acpi
 12:         8= 9   IO-APIC-edge      i8042&= nbsp;14:       3522   IO-APIC-ed= ge      ata=5Fpiix
 15:  = ;      785   IO-APIC-edge  =     ata=5Fpiix
=  16:    &= nbsp;   162   IO-APIC-fasteoi   eth0
4344:          0 &n= bsp; PCI-MSI-edge      aerdrv
4345:&n= bsp;         0   PCI-M= SI-edge      aerdrv
4346:  &n= bsp;       0   PCI-MSI-edge = ;     aerdrv
4347:    &n= bsp;     0   PCI-MSI-edge   = ;   aerdrv
4348:      &n= bsp;   0   PCI-MSI-edge     = ; aerdrv
4349:        &n= bsp; 0   PCI-MSI-edge      aerdrv

4350:          0 =   PCI-MSI-edge      aerdrv
4351:&n= bsp;         0   PCI-M= SI-edge      aerdrv
NMI:  &nb= sp;       0   Non-maskable inter= rupts
LOC:     107095   Local time= r interrupts
RES:        = ;  0   Rescheduling interrupts
CAL:  &n= bsp;       0   function call int= errupts
TLB:        &nbs= p; 0   TLB shootdowns
TRM:    &nbs= p;     0   Thermal event interrupts=
<= span style=3D"font-family: Courier;">SPU:     &= nbsp;    0   Spurious interrupts
ERR:&n= bsp;         0

Sho= uldn't there be an entry for the MSI-X device=3F

Thanks for all y= our input.

AK



Probably what you want is something like

{ 0x2000000000ull, PCI=5FBASE=5FADDRESS=5FSPACE=5FMEMORY | PCI=5FBASE=5F= ADDRESS=5FMEM=5FTYPE=5F64} , //BAR0
{ 0, 0} , //BAR1=09
=09// 64bit BAR occupies 2 BAR entries so that BAR1 can't be used.
{ 0x2000000ull, PCI=5FBASE=5FADDRESS=5FSPACE=5FIO } , //BAR2
{ 0, 0} , //BAR3
=09// for MSI-X
{ 0, 0} , //BAR4
{ 0, 0} //BAR5


-------------9ff798cb7af029a1bad9e6189ec420e7--