static int virtio_blk_probe(int skip) { int r; /* sub device id for virtio-blk is 0x0002 */ blk_dev = virtio_setup_device(0x0002, name, blkf, sizeof(blkf) / sizeof(blkf[0]), VIRTIO_BLK_NUM_THREADS, skip); if (!blk_dev) return ENXIO; /* virtio-blk has one queue only */ if ((r = virtio_alloc_queues(blk_dev, 1)) != OK) { virtio_free_device(blk_dev); return r; } /* Allocate memory for headers and status */ if ((r = virtio_blk_alloc_requests() != OK)) { virtio_free_queues(blk_dev); virtio_free_device(blk_dev); return r; } virtio_blk_config(); /* Let the host now that we are ready */ virtio_device_ready(blk_dev); virtio_irq_enable(blk_dev); return OK; }
static int virtio_net_probe(unsigned int skip) { /* virtio-net has at least 2 queues */ int queues = 2; net_dev= virtio_setup_device(0x00001, name, netf, sizeof(netf) / sizeof(netf[0]), 1 /* threads */, skip); if (net_dev == NULL) return ENXIO; /* If the host supports the control queue, allocate it as well */ if (virtio_host_supports(net_dev, VIRTIO_NET_F_CTRL_VQ)) queues += 1; if (virtio_alloc_queues(net_dev, queues) != OK) { virtio_free_device(net_dev); return ENOMEM; } return OK; }
int init_virtio_net() { virtio_dev_t dev = to_virtio_dev_t(&pci_vn); if (virtio_setup_device(dev, VIRTIO_NET_SUBID, 1)) { virtio_net_read_config(&pci_vn); /* virtio-net has at least 2 queues */ int queues = 2; if (pci_vn._ctrl_vq) { queues++; } int ret = virtio_alloc_queues(dev, queues); pci_d("virtio_alloc_queues ret:%d\n", ret); if (virtio_net_alloc_bufs() != OK) panic("%s: Buffer allocation failed", name); pci_d("virtio_net_alloc_bufs:%d\n", ret); virtio_net_init_queues(); pci_d("virtio_net_init_queues:%d\n", ret); /* Add packets to the receive queue. */ virtio_net_refill_rx_queue(); pci_d("virtio_net_refill_rx_queue:%d\n", ret); virtio_device_ready(to_virtio_dev_t(&pci_vn)); pci_d("virtio_device_ready:%d\n", ret); // virtio_irq_enable(to_virtio_dev_t(&pci_vn)); bool virtio_had_irq(struct virtio_device *dev); pci_d("had_irq:%d\n", virtio_had_irq(to_virtio_dev_t(&pci_vn))); set_timeout(1000, vn_timeout); sti(); } return OK; }