[dev][virtio] add a partition scan once a block device is found

Move the irq registration of the virtio drivers into their init hooks so
the driver is fully working at partition scan time.

TODO: think of a more integrated solution for this. Triggering from the
bio layer, for example.
This commit is contained in:
Travis Geiselbrecht
2022-09-05 00:22:21 -07:00
parent 213cc90857
commit 0ae7244eff
7 changed files with 20 additions and 14 deletions

View File

@@ -7,7 +7,7 @@ MODULE_SRCS += \
MODULE_DEPS += \
dev/virtio \
lib/bio
lib/bio \
lib/partition
include make/module.mk

View File

@@ -18,7 +18,9 @@
#include <kernel/event.h>
#include <kernel/mutex.h>
#include <lib/bio.h>
#include <lib/partition.h>
#include <inttypes.h>
#include <platform/interrupts.h>
#if WITH_KERNEL_VM
#include <kernel/vm.h>
@@ -187,6 +189,7 @@ status_t virtio_block_init(struct virtio_device *dev, uint32_t host_features) {
/* set our irq handler */
dev->irq_driver_callback = &virtio_block_irq_driver_callback;
unmask_interrupt(dev->irq);
/* set DRIVER_OK */
virtio_status_driver_ok(dev);
@@ -229,6 +232,9 @@ status_t virtio_block_init(struct virtio_device *dev, uint32_t host_features) {
printf("\twrite zeroes: max sectors %u max sequence %u may unmap %u\n", config->max_write_zeroes_sectors, config->max_write_zeroes_seq, config->write_zeros_may_unmap);
}
/* tell the partition layer to scan and find any subdevices */
partition_publish(buf, 0);
return NO_ERROR;
}

View File

@@ -19,6 +19,7 @@
#include <kernel/event.h>
#include <kernel/mutex.h>
#include <dev/display.h>
#include <platform/interrupts.h>
#if WITH_KERNEL_VM
#include <kernel/vm.h>
@@ -454,6 +455,7 @@ status_t virtio_gpu_init(struct virtio_device *dev, uint32_t host_features) {
/* set our irq handler */
dev->irq_driver_callback = &virtio_gpu_irq_driver_callback;
dev->config_change_callback = &virtio_gpu_config_change_callback;
unmask_interrupt(dev->irq);
/* set DRIVER_OK */
virtio_status_driver_ok(dev);

View File

@@ -20,6 +20,7 @@
#include <kernel/spinlock.h>
#include <lib/pktbuf.h>
#include <lib/minip.h>
#include <platform/interrupts.h>
#define LOCAL_TRACE 0
@@ -150,6 +151,7 @@ status_t virtio_net_init(struct virtio_device *dev, uint32_t host_features) {
/* set our irq handler */
dev->irq_driver_callback = &virtio_net_irq_driver_callback;
unmask_interrupt(dev->irq);
/* set DRIVER_OK */
virtio_status_driver_ok(dev);

View File

@@ -160,9 +160,6 @@ int virtio_mmio_detect(void *ptr, uint count, const uint irqs[], size_t stride)
if (err >= 0) {
// good device
dev->valid = true;
if (dev->irq_driver_callback)
unmask_interrupt(dev->irq);
}
}
#endif // WITH_DEV_VIRTIO_BLOCK
@@ -177,9 +174,6 @@ int virtio_mmio_detect(void *ptr, uint count, const uint irqs[], size_t stride)
if (err >= 0) {
// good device
dev->valid = true;
if (dev->irq_driver_callback)
unmask_interrupt(dev->irq);
}
}
#endif // WITH_DEV_VIRTIO_NET
@@ -195,9 +189,6 @@ int virtio_mmio_detect(void *ptr, uint count, const uint irqs[], size_t stride)
// good device
dev->valid = true;
if (dev->irq_driver_callback)
unmask_interrupt(dev->irq);
virtio_gpu_start(dev);
}
}

View File

@@ -544,7 +544,7 @@ void bio_dump_devices(void) {
entry->name, entry->total_size, entry->block_size, entry->ref);
if (!entry->geometry_count || !entry->geometry) {
printf(" (no erase geometry)\n");
printf(" (no erase geometry)");
} else {
for (size_t i = 0; i < entry->geometry_count; ++i) {
const bio_erase_geometry_info_t *geo = entry->geometry + i;

View File

@@ -5,6 +5,8 @@
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT
*/
#include <lib/partition.h>
#include <lk/debug.h>
#include <stdio.h>
#include <string.h>
@@ -12,7 +14,6 @@
#include <stdlib.h>
#include <arch.h>
#include <lib/bio.h>
#include <lib/partition.h>
struct chs {
uint8_t c;
@@ -93,7 +94,7 @@ int partition_publish(const char *device, off_t offset) {
// publish it
char subdevice[128];
sprintf(subdevice, "%sp%d", device, i);
snprintf(subdevice, sizeof(subdevice), "%sp%d", device, i);
err = bio_publish_subdevice(device, subdevice, part[i].lba_start, part[i].lba_length);
if (err < 0) {
@@ -107,6 +108,10 @@ int partition_publish(const char *device, off_t offset) {
bio_close(dev);
if (err >= 0) {
dprintf(INFO, "partition_publish: %u partition%s found\n", count, (count == 1) ? "" : "s");
}
err:
return (err < 0) ? err : count;
}