interrupt: Change signature of pre_eoi

pre_eoi return 'true' when the interrupt is for the device, 'false'
otherwise. This is the preparation for interrupt sharing support.

Signed-off-by: Asias He <asias@cloudius-systems.com>
interrupt: Support interrupt sharing

This patch makes multiple devices which share the same interrupt line
works, e.g. on GCE, it shares virito-net and virtio-scsi interrupts.

Signed-off-by: Asias He <asias@cloudius-systems.com>
interrupt: Introduce set_ack_and_handler

Add set_ack_and_handler helper to setup ack and handler function of gsi
level interrupt.

Signed-off-by: Asias He <asias@cloudius-systems.com>
rcu: Optimize rcu_dispose and rcu_dispose_array

Only call rcu_defer if the pointer is not nullptr.

Signed-off-by: Asias He <asias@cloudius-systems.com>
interrupt: call rcu_dispose unconditionally

nullptr check is done in rcu_dispose.

Signed-off-by: Asias He <asias@cloudius-systems.com>
interrupt: Rename gsi version of overloaded register_interrupt_handler

The overloaded version of register_interrupt_handler with a gsi
parameter is only used by register_level_triggered_handler. Fold it into
register_level_triggered_handler.

Signed-off-by: Asias He <asias@cloudius-systems.com>
interrupt: Handle unregister of shared vector properly

Introduce unregister_level_triggered_handler to handle unregister of
shared vector.

Signed-off-by: Asias He <asias@cloudius-systems.com>
virtio-blk: Enable gsi interrupt support

msi interrupt is not always implemented. Fallback to gsi interrupt when
msi interrupt is not available.

Signed-off-by: Asias He <asias@cloudius-systems.com>
virtio-net: Enable gsi interrupt support

msi interrupt is not always implemented. Fallback to gsi interrupt when
msi interrupt is not available.

Signed-off-by: Asias He <asias@cloudius-systems.com>
virtio-scsi: Enable gsi interrupt support

msi interrupt is not always implemented. Fallback to gsi interrupt when
msi interrupt is not available.

Signed-off-by: Asias He <asias@cloudius-systems.com>
virtio: Simplify device reset operation

No need to reset VIRTIO_PCI_QUEUE_PFN to 0 when reset the device. This
is not required by the virtio spec. Set device status to zero is enough
to reset the device.

Signed-off-by: Asias He <asias@cloudius-systems.com>
bio: Copy bio_private in multiplex_strategy

bio->bio_private is uesed by low-level device driver, e.g. virtio-scsi.
In multiplex_strategy, when one bio is splitted into multiple smaller
bios, we should copy bio_private into the newly created bios.

Signed-off-by: Asias He <asias@cloudius-systems.com>
scsi: Fix cdb_report_luns command format

Fix the REPORT LUNS CDB format according to the scsi spec.

Signed-off-by: Asias He <asias@cloudius-systems.com>
scsi: Fix typo in scsi-common.hh

resreved -> reserved

Signed-off-by: Asias He <asias@cloudius-systems.com>
virtio-scsi: Set up tag in scsi cmd

tag is a unique identifier of a scsi cmd. tag is required when more than
one concurrent requests are in-flight. Set tag to the address of bio.
Using bio for tag should be fine, since we can not have two same bio
in-flight at the same time. When one bio is reused, the previous one
should be finished already.

Signed-off-by: Asias He <asias@cloudius-systems.com>
virtio-scsi: Limit size of a request

virtio-scsi device can not handle a request of an infinite size. It
reports max_sectors in the config space. Respect it by using
multiplex_strategy and dev->max_io_size to limit max request size.
multiplex_strategy works by splitting large bios into multiple smaller
bios.

Signed-off-by: Asias He <asias@cloudius-systems.com>
virtio-scsi: Fallback to TEST_UNIT_READY to scan luns

GCE does not support REPORT LUNS, fallback to TEST_UNIT_READY to scan
luns.

Signed-off-by: Asias He <asias@cloudius-systems.com>
virtio-scsi: Use response instead of req->resp.cmd.response

We already copied req->resp.cmd.response into response. Use the shorter
one.

Signed-off-by: Asias He <asias@cloudius-systems.com>
virtio-scsi: Scan target 1 by default.

Currently we only support scan one target. We scan target 0 by
default.  On GCE, the default target is 1. Let's scan scan target 1.

Signed-off-by: Asias He <asias@cloudius-systems.com>
pci: Fix pci enumeration

In GCE, the pci bus looks like:

   $ lspci -x
   00:01.0 ISA bridge: Intel Corporation 82371AB/EB/MB PIIX4 ISA (rev 03)
   00: 86 80 10 71 03 01 00 00 03 00 01 06 00 00 80 00
   10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
   20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
   30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

   00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
   00: 86 80 13 71 03 01 00 00 03 00 80 06 00 00 00 00
   10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
   20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
   30: 00 00 00 00 00 00 00 00 00 00 00 00 09 01 00 00

   00:03.0 SCSI storage controller: Red Hat, Inc Virtio SCSI
   00: f4 1a 04 10 03 01 00 00 00 00 00 01 00 00 00 00
   10: 01 c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00
   20: 00 00 00 00 00 00 00 00 00 00 00 00 f4 1a 08 00
   30: 00 00 00 00 00 00 00 00 00 00 00 00 0b 01 00 00

   00:04.0 Ethernet controller: Red Hat, Inc Virtio network device
   00: f4 1a 00 10 03 01 00 00 00 00 00 02 00 00 00 00
   10: 41 c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00
   20: 00 00 00 00 00 00 00 00 00 00 00 00 f4 1a 01 00
   30: 00 00 00 00 00 00 00 00 00 00 00 00 0b 01 00 00

This makes the code goes to !single_bus branch. However, device 00:00:0
is not present. So, No device is scanned! Obviously, this is not what
we want.

To fix, the following is almost correct except bus 0 might not be there.

   void pci_device_enumeration(void)
   {
          check_bus(0);
   }

To address it, we scan starting from bus 0 and exit the scan when the
first non-empty bus is found. The first non-empty bus should find the
entire hierarchy.

Signed-off-by: Asias He <asias@cloudius-systems.com>