Commit Graph

22 Commits

Author SHA1 Message Date
Laszlo Ersek 71914406e8 OvmfPkg: Virtio drivers: fix incorrect casts in init functions
The recent patch

  OvmfPkg: Make the VirtIo devices use the new VIRTIO_DEVICE_PROTOCOL

was fixed up at commit time, in order to silence warnings issued by the
Visual Studio compiler. Differences between the posted and committed
patch:

>  diff --git a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c b/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
> -index 17b9f71..96a0d9f 100644
> +index 17b9f71..f09b0d1 100644
>  --- a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
>  +++ b/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
>  @@ -23,7 +23,6 @@
> @@ -994,7 +998,7 @@
>  +  // step 4c -- Report GPFN (guest-physical frame number) of queue.
>  +  //
>  +  Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
> -+      (UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT);
> ++      (UINT32)(UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT);
>  +  if (EFI_ERROR (Status)) {
>  +    goto ReleaseQueue;
>  +  }
> @@ -1495,7 +1499,7 @@
>         goto Exit;
>       }
>  diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/SnpInitialize.c
> -index 6cee014..8dcf9da 100644
> +index 6cee014..4203fbd 100644
>  --- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c
>  +++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c
>  @@ -57,14 +57,15 @@ VirtioNetInitRing (
> @@ -1539,7 +1543,7 @@
>  -  Status = VIRTIO_CFG_WRITE (Dev, Generic.VhdrQueueAddress,
>  -             (UINTN) Ring->Base >> EFI_PAGE_SHIFT);
>  +  Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
> -+      (UINTN) Ring->Base >> EFI_PAGE_SHIFT);
> ++      (UINT32)(UINTN) Ring->Base >> EFI_PAGE_SHIFT);
>     if (EFI_ERROR (Status)) {
>  -    VirtioRingUninit (Ring);
>  +    goto ReleaseQueue;
> @@ -1721,7 +1725,7 @@
>   Exit:
>     gBS->RestoreTPL (OldTpl);
>  diff --git a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c
> -index b836fb3..bcec676 100644
> +index b836fb3..2223c9c 100644
>  --- a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c
>  +++ b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c
>  @@ -38,7 +38,6 @@
> @@ -1908,7 +1912,7 @@
>  +  // step 4c -- Report GPFN (guest-physical frame number) of queue.
>  +  //
>  +  Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
> -+      (UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT);
> ++      (UINT32)(UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT);
>     if (EFI_ERROR (Status)) {
>       goto ReleaseQueue;
>     }

These casts are incorrect -- they throw away address bits >=32 before
shifting, which can break the drivers in guests with more than 4GB RAM.

The bug is clearly an artifact of the edk2 coding style, which requires
cast expressions to be written as

  (type) expression

rather than the usual

  (type)expression

The latter correctly reflects that casts have one of the strongest
bindings in C. The former actively obscures that fact. Cf.

  (type) expr1 >> expr2

vs.

  (type)expr1 >> expr2

Make sure we shift before we truncate.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14970 6f19259b-4bc3-4df7-8a09-765794883524
2013-12-12 17:28:05 +00:00
Olivier Martin ece77e4047 OvmfPkg/Virtio: Removed VirtioReadDevice() / VirtIoWriteDevice() functions
These functions did not provide much more than the new protocol functions
VIRTIO_DEVICE_PROTOCOL.ReadDevice() / VIRTIO_DEVICE_PROTOCOL.WriteDevice().

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14968 6f19259b-4bc3-4df7-8a09-765794883524
2013-12-11 16:58:39 +00:00
Olivier Martin 56f65ed838 OvmfPkg: Make the VirtIo devices use the new VIRTIO_DEVICE_PROTOCOL
This change replaces the accesses to the PCI bus from the Block, Scsi and Net drivers by
the use of the new VIRTIO_DEVICE_PROTOCOL protocol that abstracts the transport layer.
It means these drivers can be used on PCI and MMIO transport layer.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>

v5:
- VirtioFlush(): update comment block in VirtioLib.[hc]; error code is
  propagated from VirtIo->SetQueueNotify().
- VirtioBlkInit(): jump to Failed label if SetPageSize() fails
- VirtioBlkInit(): fixup comment, and add error handling, near
  SetQueueNum() call
- VirtioBlkDriverBindingStart(): remove redundant (always false) check for
  a subsystem device ID different from VIRTIO_SUBSYSTEM_BLOCK_DEVICE;
  VirtioBlkDriverBindingSupported() handles it already
- VirtioNetGetFeatures(): update stale comment block
- VirtioNetGetFeatures(): retrieve MAC address byte for byte (open-coded
  loop)
- VirtioNetDriverBindingStart(): remove redundant (always false) check for
  a subsystem device ID different from VIRTIO_SUBSYSTEM_NETWORK_CARD;
  VirtioNetDriverBindingSupported() handles it already
- VirtioNetInitRing(): call SetQueueNum() and SetQueueAlign() for proper
  MMIO operation
- VirtioNetInitialize(): fix destination error label for when
  SetPageSize() fails
- VirtioScsi.c: fix comment block of VIRTIO_CFG_WRITE()/VIRTIO_CFG_READ()
- VirtioScsiInit(): fix destination error label for when SetPageSize()
  fails
- VirtioScsiInit(): call SetQueueNum() and SetQueueAlign() for proper MMIO
  operation

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14966 6f19259b-4bc3-4df7-8a09-765794883524
2013-12-11 16:58:22 +00:00
Olivier Martin 43e54972af OvmfPkg: Removed magic values for the Virtio Sub-System ID in the PCI device drivers
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>



git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14742 6f19259b-4bc3-4df7-8a09-765794883524
2013-09-30 09:04:22 +00:00
Laszlo Ersek dc9447bd37 OvmfPkg: Virtio: load used ring element strictly after loading used index
Enforce in-order execution of these steps even on not sequentially
consistent architectures, as discussed in [1]. These changes should be
unnecessary on x86 (the only architecture OVMF currently supports), but
they align the OVMF virtio code with the virtio specification and could be
necessary for future OVMF ports.

[1] http://lists.linuxfoundation.org/pipermail/virtualization/2013-June/024547.html

Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14601 6f19259b-4bc3-4df7-8a09-765794883524
2013-08-23 18:46:03 +00:00
Jordan Justen 8258c4e643 OvmfPkg/VirtioNetDxe: Fix build errors on VS2012 (IA32 & X64)
These changes were needed in addition to the silence.patch
that Laszlo posted on May 28.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14420 6f19259b-4bc3-4df7-8a09-765794883524
2013-06-14 07:41:05 +00:00
Laszlo Ersek 9f3acbb5c9 OvmfPkg: VirtioNetDxe: fix some build errors emitted by Visual Studio
These were found with the gcc-4.4 option "-Wconversion" after Jordan
reported the build failure under Visual Studio. The patch was originally
posted to edk2-devel as "silence.patch":

http://thread.gmane.org/gmane.comp.bios.tianocore.devel/2804/focus=2972

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14419 6f19259b-4bc3-4df7-8a09-765794883524
2013-06-14 07:40:59 +00:00
Laszlo Ersek 65575e4f13 OvmfPkg: VirtioNetDxe: complete driver with INF file
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14418 6f19259b-4bc3-4df7-8a09-765794883524
2013-06-14 07:40:53 +00:00
Laszlo Ersek 38f52db9c9 OvmfPkg: VirtioNetDxe: WaitForPacket and EXIT_BOOT_SERVICES event callbacks
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14417 6f19259b-4bc3-4df7-8a09-765794883524
2013-06-14 07:40:47 +00:00
Laszlo Ersek d0e5ff0a0d OvmfPkg: VirtioNetDxe: definitions of unsupported SNP member functions
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14416 6f19259b-4bc3-4df7-8a09-765794883524
2013-06-14 07:40:42 +00:00
Laszlo Ersek 1771d0a1ee OvmfPkg: VirtioNetDxe: emulate Rx filter configuration: SNP.ReceiveFilters
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14415 6f19259b-4bc3-4df7-8a09-765794883524
2013-06-14 07:40:36 +00:00
Laszlo Ersek f8ec2cc52c OvmfPkg: VirtioNetDxe: map multicast IP to MAC: SNP.McastIpToMac
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14414 6f19259b-4bc3-4df7-8a09-765794883524
2013-06-14 07:40:30 +00:00
Laszlo Ersek b6dfc654c8 OvmfPkg: VirtioNetDxe: implement Tx: SNP.Transmit and SNP.GetStatus
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14413 6f19259b-4bc3-4df7-8a09-765794883524
2013-06-14 07:40:24 +00:00
Laszlo Ersek e12fadc3cf OvmfPkg: VirtioNetDxe: SNP.Receive
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14412 6f19259b-4bc3-4df7-8a09-765794883524
2013-06-14 07:40:17 +00:00
Laszlo Ersek 80682e9b2f OvmfPkg: VirtioNetDxe: SNP.Shutdown
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14411 6f19259b-4bc3-4df7-8a09-765794883524
2013-06-14 07:40:11 +00:00
Laszlo Ersek 12384f9b26 OvmfPkg: VirtioNetDxe: add SNP.Initialize and shared dependencies
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14410 6f19259b-4bc3-4df7-8a09-765794883524
2013-06-14 07:40:05 +00:00
Laszlo Ersek 395e912e72 OvmfPkg: VirtioNetDxe: Simple Network Protocol members Start and Stop
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14409 6f19259b-4bc3-4df7-8a09-765794883524
2013-06-14 07:39:58 +00:00
Laszlo Ersek 16e0ece611 OvmfPkg: VirtioNetDxe: driver binding
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14408 6f19259b-4bc3-4df7-8a09-765794883524
2013-06-14 07:39:52 +00:00
Laszlo Ersek bde8a2e0db OvmfPkg: VirtioNetDxe: Component Name Protocol implementation
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14407 6f19259b-4bc3-4df7-8a09-765794883524
2013-06-14 07:39:46 +00:00
Laszlo Ersek 193730d128 OvmfPkg: VirtioNetDxe: add entry point
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14406 6f19259b-4bc3-4df7-8a09-765794883524
2013-06-14 07:39:40 +00:00
Laszlo Ersek 201cac0d5a OvmfPkg: VirtioNetDxe: declarations and macro definitions
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14405 6f19259b-4bc3-4df7-8a09-765794883524
2013-06-14 07:39:32 +00:00
Laszlo Ersek 50d4fa86db OvmfPkg: VirtioNetDxe: add technical notes
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14404 6f19259b-4bc3-4df7-8a09-765794883524
2013-06-14 07:39:25 +00:00