Received: from [140.186.70.92] (port=37950 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OrIiG-0003TB-V8 for qemu-devel@nongnu.org; Thu, 02 Sep 2010 18:56:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OrIiE-0005Mx-Jm for qemu-devel@nongnu.org; Thu, 02 Sep 2010 18:56:56 -0400 Received: from smtp.mailix.net ([66.11.225.183]:56846) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OrIiE-0005Md-3h for qemu-devel@nongnu.org; Thu, 02 Sep 2010 18:56:54 -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: <20100902225648.c36436e0@shadowfax.no-ip.com> Date: Thu, 02 Sep 2010 17:56:48 -0500 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="-----------b7433c2fe550da2c0f6e0df25183cf8f" 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: qemu-devel@nongnu.org This is a multi-part message in MIME format. -------------b7433c2fe550da2c0f6e0df25183cf8f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable During bootup, I also see the following error message: pci 0000:40:00.0: BAR 0 bad alignment 2000000000: 0x00000000000000-0x000= 01fffffffff Any idea whats causing this=3F AK =5F=5F=5F=5F=5F =20 From: Isaku Yamahata [mailto:yamahata@valinux.co.jp] To: Adnan Khaleel [mailto:adnan@khaleel.us] Cc: Cam Macdonell [mailto:cam@cs.ualberta.ca], qemu-devel@nongnu.org Sent: Wed, 01 Sep 2010 21:38:31 -0500 Subject: Re: [Qemu-devel] Template for developing a Qemu device with PCI= e and MSI-X On Wed, Sep 01, 2010 at 02:07:33PM -0500, Adnan Khaleel wrote: > Yamahata, Cam, >=20 > Thank you both very much for pointers about Qemu coding for PCIe and= MSI-X. >=20 > I'm at a point where I can see my device when I do an lspci -t -v as= shown > below. >=20 > linux-an84:~ # lspci -t -v > -[0000:00]-+-00.0 Intel Corporation 82G33/G31/P35/P31 Express DRAM = Controller > +-01.0 Cirrus Logic GD 5446 > +-04.0-[0000:20]-- > +-18.0-[0000:21]-- > +-18.1-[0000:22]-- > +-18.2-[0000:23]-- > +-18.3-[0000:24]-- > +-18.4-[0000:25]-- > +-18.5-[0000:26]-- > +-19.0-[0000:36-bf]--+-00.0-[0000:37-47]--+-00.0-[0000:38= ]-- > | | +-01.0-[0000:39= ]-- > | | +-02.0-[0000:3a= ]-- > | | +-03.0-[0000:3b= ]-- > | | +-04.0-[0000:3c= ]-- > | | +-05.0-[0000:3d= ]-- > | | +-06.0-[0000:3e= ]-- > | | +-07.0-[0000:3f= ]-- > | | +-08.0-[0000:40= ]----00.0=20 > Cray Inc Device 0301 <- The device that I've included >=20 > However, I'm having a bit of an issue with the MSI-X. >=20 > I'm following the code examples in virtio-pci.c and ivshmem.c that C= am pointed > out to. I've got bar 0&1 already occupied so I assign the msix=5Fmmi= o=5Fmap to bar > 2. However, when I do that, Qemu fails to boot and fails with the fo= llowing > assertion fail: >=20 > unused outb: port=3D0x00f1 data=3D0x00 > qemu: fatal: Trying to execute code outside RAM or ROM at 0x00000000= 00100000 >=20 > Couple of thins I'm unsure about: > 1. Am I registering the 64bit bar addresses correctly=3F > pci=5Fregister=5Fbar(&d->dev, i, BAR=5FRegions[i][0], PCI=5FBASE=5FA= DDRESS=5FSPACE=5FIO | > PCI=5FBASE=5FADDRESS=5FMEM=5FTYPE=5F64, pcie=5Fmsix=5Fio=5Fmap); =20 No. PCI=5FBASE=5FADDRESS=5FSPACE=5FIO | PCI=5FBASE=5FADDRESS=5FMEM=5FT= YPE=5F64 is invalid. PCI doesn't support 64bit io space, but 32bit. And x86 supports 64k io sparce. =20 =20 > 2. In the function int msix=5Finit(PCIDevice *pdev, unsigned short n= entries, > unsigned bar=5Fnr, unsigned bar=5Fsize); > I'm not sure what bar=5Fnr is, however setting it to 1 (as in code e= xamples > above) or to 2 (bar that I want to register the msix=5Fmmio=5Fmap to= ) both fail > with the same error. =20 It should be 2. I'm not sure why it failed. =20 =20 > rc =3D msix=5Finit(&d->dev, d->vectors, 2, 0); > : > : > pci=5Fregister=5Fbar(&d->dev, 2, msix=5Fbar=5Fsize(&d->dev), > PCI=5FBASE=5FADDRESS=5FSPACE=5FMEMORY | PCI=5FBASE=5FADDRESS=5FMEM= =5FTYPE=5F64, msix=5Fmmio=5Fmap); >=20 >=20 > Here is my init function code in its entirety: >=20 > static const unsigned long long BAR=5FRegions[6][2] =3D > { > // len , type > { 0x2000000000ull, PCI=5FBASE=5FADDRESS=5FSPACE=5FMEMORY} , //B= AR0 > { 0x2000000ull, PCI=5FBASE=5FADDRESS=5FSPACE=5FIO } , //B= AR1 > { 0, 0} , //BAR2 > { 0, 0} , //BAR3 > { 0, 0} , //BAR4 > { 0, 0} //BAR5 > }; =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 > static int pcie=5Fmsix=5Finitfn(PCIDevice *pci=5Fdev) > { > PCIE=5FMSIX=5FDEVState *d =3D DO=5FUPCAST(PCIE=5FMSIX=5FDEVState= , dev, pci=5Fdev); > PCIBridge *br =3D DO=5FUPCAST(PCIBridge, dev, pci=5Fdev); > PCIEPort *p =3D DO=5FUPCAST(PCIEPort, br, br); > int rc, i; >=20 > PRINT=5FDEBUG("%s: PCIE MSIX Device init...\n", =5F=5FFUNCTION= =5F=5F); >=20 > pci=5Fconfig=5Fset=5Fvendor=5Fid(d->dev.config, PCIE=5FMSIX=5FVI= D); > pci=5Fconfig=5Fset=5Fdevice=5Fid(d->dev.config, PCIE=5FMSIX=5FDI= D); > d->dev.config[PCI=5FREVISION=5FID] =3D PCIE=5FMSIX=5FVERSION; > d->dev.config[PCI=5FSUBSYSTEM=5FVENDOR=5FID] =3D PCIE=5FMSIX= =5FVID & 0xff; > d->dev.config[PCI=5FSUBSYSTEM=5FVENDOR=5FID+1] =3D (PCIE=5FMSIX= =5FVID >> 8) & 0xff; > d->dev.config[PCI=5FSUBSYSTEM=5FID] =3D PCIE=5FMSIX=5FSS=5FDID= & 0xff; > d->dev.config[PCI=5FSUBSYSTEM=5FID+1] =3D (PCIE=5FMSIX=5FSS=5FDI= D >> 8) & 0xff; =20 Use pci=5Fset=5Fword(). =20 > d->mmio=5Findex =3D cpu=5Fregister=5Fio=5Fmemory(pcie=5Fmsix=5Fm= em=5Fread=5Ffn, > pcie=5Fmsix=5Fmem=5Fwrite=5Ffn, d); > =20 > for(i=3D0; i < PCI=5FNUM=5FREGIONS -1; i++) { //-1 for the Exp R= OM BAR > if(BAR=5FRegions[i][0] !=3D 0) > { > if(BAR=5FRegions[i][1] =3D=3D PCI=5FBASE=5FADDRESS=5FSPA= CE=5FIO) > { > //io region > PRINT=5FDEBUG("%s: Registering Bar %i as I/O BAR\n", > =5F=5FFUNCTION=5F=5F, i); > pci=5Fregister=5Fbar(&d->dev, i, BAR=5FRegions[i][0]= , > PCI=5FBASE=5FADDRESS=5FSPACE=5FIO | PCI=5FBASE=5FADDRESS=5FMEM=5FTYP= E=5F64, pcie=5Fmsix=5Fio=5Fmap); > } else { > //mem region > PRINT=5FDEBUG("%s: Registering Bar %i as MEM BAR\n", > =5F=5FFUNCTION=5F=5F, i); > pci=5Fregister=5Fbar(&d->dev, i, BAR=5FRegions[i][0]= , > PCI=5FBASE=5FADDRESS=5FSPACE=5FMEMORY | PCI=5FBASE=5FADDRESS=5FMEM= =5FTYPE=5F64, > pcie=5Fmsix=5Fmem=5Fmap); > } > } > } > d->dev.config[PCI=5FINTERRUPT=5FPIN] =3D 1; >=20 > rc =3D msix=5Finit(&d->dev, d->vectors, 2, 0); > =20 > if (!rc) { > PRINT=5FDEBUG("%s: Registering Bar %i as I/O BAR\n", =5F=5FF= UNCTION=5F=5F, i); > pci=5Fregister=5Fbar(&d->dev, 2, msix=5Fbar=5Fsize(&d->dev), > PCI=5FBASE=5FADDRESS=5FSPACE=5FMEMORY | PCI=5FBASE=5FADDRESS=5FMEM= =5FTYPE=5F64, msix=5Fmmio=5Fmap); > PRINT=5FDEBUG("%s: MSI-X initialized (%d vectors)\n", =5F=5F= FUNCTION=5F=5F, d-> > vectors); > } > else { > PRINT=5FDEBUG("%s: MSI-X initialization failed!\n", =5F=5FFU= NCTION=5F=5F); > exit(1); > } > =20 > // Activate the vectors > for (i =3D 0; i < d->vectors; i++) { > msix=5Fvector=5Fuse(&d->dev, i); > } >=20 > rc =3D pci=5Fpcie=5Fcap=5Finit(&d->dev, PCIE=5FMSIX=5FEXP=5FOFFS= ET, > PCI=5FEXP=5FTYPE=5FENDPOINT, p->port); > if (rc < 0) { > return rc; > } >=20 > 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; > } >=20 > PRINT=5FDEBUG("%s: Init done\n", =5F=5FFUNCTION=5F=5F); > return 0; > } >=20 >=20 > Thanks >=20 > AK >=20 >=20 >=20 >=20 > =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81= =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81= =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81= =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81= =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81 > From: Cam Macdonell [mailto:cam@cs.ualberta.ca] > To: adnan@khaleel.us > Cc: Isaku Yamahata [mailto:yamahata@valinux.co.jp], qemu-devel@n= ongnu.org > Sent: Fri, 27 Aug 2010 10:48:48 -0500 > Subject: Re: [Qemu-devel] Template for developing a Qemu device = with PCIe > and MSI-X >=20 > On Wed, Aug 25, 2010 at 4:39 PM, Adnan Khaleel wrote: > > Hi Isaku, > > > > I've made some progress in coding the device template but its = no where > near > > complete. > > > > I've created some files and am attaching it to this note. Base= d on what I > > could gather from the pcie source files I've made a stab at cr= eating a > > simple model. I've also attached a file for a simple pci devic= e that > works > > under regular Qemu. I would like to duplicate its functionalit= y in your > pcie > > environment for starters. > > > > Could you please take a look at the files I've created and tel= l me if > I've > > understood your pcie model correctly. Any help will be truly a= ppreciated. > > > > Adnan >=20 > Hi Adnan, >=20 > There is a fairly simple device I've created called "ivshmem" th= at is > in the qemu git tree. It is a regular PCI device that exports a > shared memory object via a BAR and supports a few registers and > optional MSI-X interrupts (I had to pick through the virtio code= to > get MSI-X working, so looking at ivshmem might save you some eff= ort). > My device is somewhat similar to a graphics card actually which = I > recall is your goal. The purpose of ivshmem is to support sharin= g > memory between multiple guests running on the same host. It foll= ows > the qdev model which you will need to do. >=20 > Cam >=20 > > > > The five files I've modified from your git repository are as f= ollows > > > > hw/pci=5Fids.h // Added vendor id defines > > hw/pc=5Fq35.c // Device instantiation > > hw/pcie=5Fmsix=5Ftemplate.h // Device header file > > hw/pcie=5Fmsix=5Ftemplate.c // Device file > > Makefile.objs // Added pcie=5Fmsix=5Ftemplat= e.o to list of > > objects being built > > > > Everything should compile without any warnings or errors. > > > > The last file: > > sc=5Flink=5Fpci.c > > Is the original PCI device that I'm trying to convert into bei= ng PCIe and > > MSI-X and is included merely for reference to help you underst= and what > I'd > > like to achieve in your environment. > > > > > > =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F= =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F > > From: Isaku Yamahata [mailto:yamahata@valinux.co.jp] > > To: Adnan Khaleel [mailto:adnan@khaleel.us] > > Cc: qemu-devel@nongnu.org > > Sent: Wed, 18 Aug 2010 22:19:04 -0500 > > Subject: Re: [Qemu-devel] Template for developing a Qemu devic= e with PCIe > > and MSI-X > > > > On Wed, Aug 18, 2010 at 02:10:10PM -0500, Adnan Khaleel wrote: > >> Hello Qemu developers, > >> > >> I'm interested in developing a device model that plugs into Q= emu that is > >> based > >> on a PCIe interface and uses MSI-X. My goal is to ultimately = attach a > GPU > >> simulator to this PCIe interface and use the entire platfom (= Qemu + GPU > >> simulator) for studying cpu, gpu interactions. > >> > >> I'm not terribly familiar with the Qemu device model and I'm = looking for > >> some > >> assistance, perhaps a starting template for pcie and msi-x th= at would > >> offer the > >> basic functionality that I could then build upon. > >> > >> I have looked at the various devices that already modelled th= at are > >> included > >> with Qemu (v0.12.5 at least) and I've noticed several a few p= ci devices, > >> eg; > >> ne2k and cirrus-pci etc, however only one device truly seems = to utilize > >> both > >> the technologies that I'm interested in and that is the virti= o-pci.c > >> > >> I'm not sure what virtio-pci does so I'm not sure if that is = a suitable > >> starting point for me. > >> > >> Any help, suggestions etc would be extremely helpful and much > appreciated. > > > > Qemu doesn't support pcie at the moment. > > Only partial patches have been merged, still more patches have= to > > be merged for pcie to fully work. The following repo is availa= ble. > > > > git clone http://people.valinux.co.jp/~yamahata/qemu/q35/qemu > > git clone http://people.valinux.co.jp/~yamahata/qemu/q35/seabi= os > > git clone http://people.valinux.co.jp/~yamahata/qemu/q35/vgabi= os > > > > Note: patched seabios and vgabios are needed, you have to pass= ACPI DSDT > > for q35. > > example: > > qemu-system-x86=5F64 -M pc=5Fq35 -acpitable > > load=5Fheader,data=3Droms/seabios/src/q35-acpi-dsdt.aml > > > > This repo is for those who want to try/develop pcie support, > > not for upstream merge. So they include patches unsuitable for= upstream. > > The repo includes pcie port switch emulator which utilize pcie= and > > MSI(not MSI-X). > > > > The difference between PCI device and PCIe device is configura= tion > > space size. > > By setting PCIDeviceInfo::is=5Fexpress =3D 1, you'll get 4K co= nfiguration > > space. Helper functions for pcie are found in qemu/hw/pcie.c > > For msi-x, see qemu/hw/msix.c. > > > > Thanks, > > -- > > yamahata > > >=20 =20 --=20 yamahata =20 -------------b7433c2fe550da2c0f6e0df25183cf8f Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable
During bootup, I also see the following= error message:

pci 0000:40= :00.0: BAR 0 bad alignment 2000000000: 0x00000000000000-0x00001fffffffff=

Any idea whats causing this=3F

AK


From: Isaku Yamahat= a [mailto:yamahata@valinux.co.jp]
To: Adnan Khaleel [mailto:ad= nan@khaleel.us]
Cc: Cam Macdonell [mailto:cam@cs.ualberta.ca],= qemu-devel@nongnu.org
Sent: Wed, 01 Sep 2010 21:38:31 -0500Subject: Re: [Qemu-devel] Template for developing a Qemu device= with PCIe=09and MSI-X

On Wed, Sep 01, 2010 at 02:07:33PM -0500, = Adnan Khaleel wrote:
> Yamahata, Cam,
>
> Thank you both very much for pointers about Qemu coding for PCIe an= d MSI-X.
>
> I'm at a point where I can see my device when I do an lspci -t -v a= s shown
> below.
>
> linux-an84:~ # lspci -t -v
> -[0000:00]-+-00.0 Intel Corporation 82G33/G31/P35/P31 Express DRAM= Controller
> +-01.0 Cirrus Logic GD 5446
> +-04.0-[0000:20]--
> +-18.0-[0000:21]--
> +-18.1-[0000:22]--
> +-18.2-[0000:23]--
> +-18.3-[0000:24]--
> +-18.4-[0000:25]--
> +-18.5-[0000:26]--
> +-19.0-[0000:36-bf]--+-00.0-[0000:37-47]--+-00.0-[0000:3= 8]--
> | | +-01.0-[0000:3= 9]--
> | | +-02.0-[0000:3= a]--
> | | +-03.0-[0000:3= b]--
> | | +-04.0-[0000:3= c]--
> | | +-05.0-[0000:3= d]--
> | | +-06.0-[0000:3= e]--
> | | +-07.0-[0000:3= f]--
> | | +-08.0-[0000:4= 0]----00.0
> Cray Inc Device 0301 <- The device that I've included
>
> However, I'm having a bit of an issue with the MSI-X.
>
> I'm following the code examples in virtio-pci.c and ivshmem.c that = Cam pointed
> out to. I've got bar 0&1 already occupied so I assign the msix= =5Fmmio=5Fmap to bar
> 2. However, when I do that, Qemu fails to boot and fails with the f= ollowing
> assertion fail:
>
> unused outb: port=3D0x00f1 data=3D0x00
> qemu: fatal: Trying to execute code outside RAM or ROM at 0x0000000= 000100000
>
> Couple of thins I'm unsure about:
> 1. Am I registering the 64bit bar addresses correctly=3F
> pci=5Fregister=5Fbar(&d->dev, i, BAR=5FRegions[i][0], PCI=5F= BASE=5FADDRESS=5FSPACE=5FIO |
> PCI=5FBASE=5FADDRESS=5FMEM=5FTYPE=5F64, pcie=5Fmsix=5Fio=5Fmap);
No. PCI=5FBASE=5FADDRESS=5FSPACE=5FIO | PCI=5FBASE=5FADDRESS=5FMEM=5FTYP= E=5F64 is invalid.
PCI doesn't support 64bit io space, but 32bit. And x86 supports 64k
io sparce.


> 2. In the function int msix=5Finit(PCIDevice *pdev, unsigned short = nentries,
> unsigned bar=5Fnr, unsigned bar=5Fsize);
> I'm not sure what bar=5Fnr is, however setting it to 1 (as in code = examples
> above) or to 2 (bar that I want to register the msix=5Fmmio=5Fmap t= o) both fail
> with the same error.

It should be 2. I'm not sure why it failed.


> rc =3D msix=5Finit(&d->dev, d->vectors, 2, 0);
> :
> :
> pci=5Fregister=5Fbar(&d->dev, 2, msix=5Fbar=5Fsize(&d-&g= t;dev),
> PCI=5FBASE=5FADDRESS=5FSPACE=5FMEMORY | PCI=5FBASE=5FADDRESS=5FMEM= =5FTYPE=5F64, msix=5Fmmio=5Fmap);
>
>
> Here is my init function code in its entirety:
>
> static const unsigned long long BAR=5FRegions[6][2] =3D
> {
> // len , type
> { 0x2000000000ull, PCI=5FBASE=5FADDRESS=5FSPACE=5FMEMORY} , //= BAR0
> { 0x2000000ull, PCI=5FBASE=5FADDRESS=5FSPACE=5FIO } , //= BAR1
> { 0, 0} , //BAR2
> { 0, 0} , //BAR3
> { 0, 0} , //BAR4
> { 0, 0} //BAR5
> };

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

>
> static int pcie=5Fmsix=5Finitfn(PCIDevice *pci=5Fdev)
> {
> PCIE=5FMSIX=5FDEVState *d =3D DO=5FUPCAST(PCIE=5FMSIX=5FDEVStat= e, dev, 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);
> d->dev.config[PCI=5FREVISION=5FID] =3D PCIE=5FMSIX=5FVERSION= ;
> d->dev.config[PCI=5FSUBSYSTEM=5FVENDOR=5FID] =3D PCIE=5FMS= IX=5FVID & 0xff;
> d->dev.config[PCI=5FSUBSYSTEM=5FVENDOR=5FID+1] =3D (PCIE=5FM= SIX=5FVID >> 8) & 0xff;
> d->dev.config[PCI=5FSUBSYSTEM=5FID] =3D PCIE=5FMSIX=5FSS= =5FDID & 0xff;
> d->dev.config[PCI=5FSUBSYSTEM=5FID+1] =3D (PCIE=5FMSIX=5FSS= =5FDID >> 8) & 0xff;

Use pci=5Fset=5Fword().

> d->mmio=5Findex =3D cpu=5Fregister=5Fio=5Fmemory(pcie=5Fmsix= =5Fmem=5Fread=5Ffn,
> pcie=5Fmsix=5Fmem=5Fwrite=5Ffn, d);
>
> for(i=3D0; i < PCI=5FNUM=5FREGIONS -1; i++) { //-1 for the E= xp ROM BAR
> if(BAR=5FRegions[i][0] !=3D 0)
> {
> if(BAR=5FRegions[i][1] =3D=3D PCI=5FBASE=5FADDRESS=5FSP= ACE=5FIO)
> {
> //io region
> PRINT=5FDEBUG("%s: Registering Bar %i as I/O BAR\n"= ,
> =5F=5FFUNCTION=5F=5F, i);
> pci=5Fregister=5Fbar(&d->dev, i, BAR=5FRegio= ns[i][0],
> PCI=5FBASE=5FADDRESS=5FSPACE=5FIO | PCI=5FBASE=5FADDRESS=5FMEM=5FTY= PE=5F64, pcie=5Fmsix=5Fio=5Fmap);
> } else {
> //mem region
> PRINT=5FDEBUG("%s: Registering Bar %i as MEM BAR\n"= ,
> =5F=5FFUNCTION=5F=5F, i);
> pci=5Fregister=5Fbar(&d->dev, i, BAR=5FRegio= ns[i][0],
> PCI=5FBASE=5FADDRESS=5FSPACE=5FMEMORY | PCI=5FBASE=5FADDRESS=5FMEM= =5FTYPE=5F64,
> pcie=5Fmsix=5Fmem=5Fmap);
> }
> }
> }
> d->dev.config[PCI=5FINTERRUPT=5FPIN] =3D 1;
>
> rc =3D msix=5Finit(&d->dev, d->vectors, 2, 0);
>
> if (!rc) {
> PRINT=5FDEBUG("%s: Registering Bar %i as I/O BAR\n", =5F=5F= FUNCTION=5F=5F, i);
> pci=5Fregister=5Fbar(&d->dev, 2, msix=5Fbar=5Fsize(&= amp;d->dev),
> PCI=5FBASE=5FADDRESS=5FSPACE=5FMEMORY | PCI=5FBASE=5FADDRESS=5FMEM= =5FTYPE=5F64, msix=5Fmmio=5Fmap);
> PRINT=5FDEBUG("%s: MSI-X initialized (%d vectors)\n", =5F= =5FFUNCTION=5F=5F, d->
> vectors);
> }
> else {
> PRINT=5FDEBUG("%s: MSI-X initialization failed!\n", =5F=5FF= UNCTION=5F=5F);
> exit(1);
> }
>
> // 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=5FEX= P=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=5FOF= FSET);
> if (rc < 0) {
> return rc;
> }
>
> PRINT=5FDEBUG("%s: Init done\n", =5F=5FFUNCTION=5F=5F);
> return 0;
> }
>
>
> Thanks
>
> AK
>
>
>
>
> =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81= =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81= =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81= =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81= =E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81=E2=94=81
> From: Cam Macdonell [mailto:cam@cs.ualberta.ca]
> To: adnan@khaleel.us > Cc: Isaku Yamahata [mailto:yamahata@valinux.co.jp], qemu-devel@nongnu.org
> Sent: Fri, 27 Aug 2010 10:48:48 -0500
> Subject: Re: [Qemu-devel] Template for developing a Qemu device= with PCIe
> and MSI-X
>
> On Wed, Aug 25, 2010 at 4:39 PM, Adnan Khaleel <adnan@khaleel.us> wrote:
> > Hi Isaku,
> >
> > I've made some progress in coding the device template but = its no where
> near
> > complete.
> >
> > I've created some files and am attaching it to this note. = Based on what I
> > could gather from the pcie source files I've made a stab a= t creating a
> > simple model. I've also attached a file for a simple pci d= evice that
> works
> > under regular Qemu. I would like to duplicate its function= ality in your
> pcie
> > environment for starters.
> >
> > Could you please take a look at the files I've created and= tell me if
> I've
> > understood your pcie model correctly. Any help will be tru= ly appreciated.
> >
> > Adnan
>
> Hi Adnan,
>
> There is a fairly simple device I've created called "ivshmem" t= hat is
> in the qemu git tree. It is a regular PCI device that exports a=
> shared memory object via a BAR and supports a few registers and=
> optional MSI-X interrupts (I had to pick through the virtio cod= e to
> get MSI-X working, so looking at ivshmem might save you some ef= fort).
> My device is somewhat similar to a graphics card actually which= I
> recall is your goal. The purpose of ivshmem is to support shari= ng
> memory between multiple guests running on the same host. It fol= lows
> the qdev model which you will need to do.
>
> Cam
>
> >
> > The five files I've modified from your git repository are = as follows
> >
> > hw/pci=5Fids.h // Added vendor id defin= es
> > hw/pc=5Fq35.c // Device instantiation > > hw/pcie=5Fmsix=5Ftemplate.h // Device header file
> > hw/pcie=5Fmsix=5Ftemplate.c // Device file
> > Makefile.objs // Added pcie=5Fmsix=5Ftem= plate.o to list of
> > objects being built
> >
> > Everything should compile without any warnings or errors.<= br> > >
> > The last file:
> > sc=5Flink=5Fpci.c
> > Is the original PCI device that I'm trying to convert into= being PCIe and
> > MSI-X and is included merely for reference to help you und= erstand what
> I'd
> > like to achieve in your environment.
> >
> >
> > =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F= =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F
> > From: Isaku Yamahata [mailto:yamahata@valinux.co.jp]
> > To: Adnan Khaleel [mailto:adnan@khaleel.us]
> > Cc: qemu-devel@no= ngnu.org
> > Sent: Wed, 18 Aug 2010 22:19:04 -0500
> > Subject: Re: [Qemu-devel] Template for developing a Qemu d= evice with PCIe
> > and MSI-X
> >
> > On Wed, Aug 18, 2010 at 02:10:10PM -0500, Adnan Khaleel wr= ote:
> >> Hello Qemu developers,
> >>
> >> I'm interested in developing a device model that plugs= into Qemu that is
> >> based
> >> on a PCIe interface and uses MSI-X. My goal is to ulti= mately attach a
> GPU
> >> simulator to this PCIe interface and use the entire pl= atfom (Qemu + GPU
> >> simulator) for studying cpu, gpu interactions.
> >>
> >> I'm not terribly familiar with the Qemu device model a= nd I'm looking for
> >> some
> >> assistance, perhaps a starting template for pcie and m= si-x that would
> >> offer the
> >> basic functionality that I could then build upon.
> >>
> >> I have looked at the various devices that already mode= lled that are
> >> included
> >> with Qemu (v0.12.5 at least) and I've noticed several = a few pci devices,
> >> eg;
> >> ne2k and cirrus-pci etc, however only one device truly= seems to utilize
> >> both
> >> the technologies that I'm interested in and that is th= e virtio-pci.c
> >>
> >> I'm not sure what virtio-pci does so I'm not sure if t= hat is a suitable
> >> starting point for me.
> >>
> >> Any help, suggestions etc would be extremely helpful a= nd much
> appreciated.
> >
> > Qemu doesn't support pcie at the moment.
> > Only partial patches have been merged, still more patches = have to
> > be merged for pcie to fully work. The following repo is av= ailable.
> >
> > git clone http://people.valinux.co.jp/~yamah= ata/qemu/q35/qemu
> > git clone http://people.valinux.co.jp/~ya= mahata/qemu/q35/seabios
> > git clone http://people.valinux.co.jp/~ya= mahata/qemu/q35/vgabios
> >
> > Note: patched seabios and vgabios are needed, you have to = pass ACPI DSDT
> > for q35.
> > example:
> > qemu-system-x86=5F64 -M pc=5Fq35 -acpitable
> > load=5Fheader,data=3Droms/seabios/src/q35-acpi-dsdt.aml > >
> > This repo is for those who want to try/develop pcie suppor= t,
> > not for upstream merge. So they include patches unsuitable= for upstream.
> > The repo includes pcie port switch emulator which utilize = pcie and
> > MSI(not MSI-X).
> >
> > The difference between PCI device and PCIe device is confi= guration
> > space size.
> > By setting PCIDeviceInfo::is=5Fexpress =3D 1, you'll get 4= K configuration
> > space. Helper functions for pcie are found in qemu/hw/pcie= .c
> > For msi-x, see qemu/hw/msix.c.
> >
> > Thanks,
> > --
> > yamahata
> >
>

--
yamahata
-------------b7433c2fe550da2c0f6e0df25183cf8f--