[dev][virtio] add no kernel VM workaround
Also add stride to the mmio detect routine. Not all virtio apertures are tightly packed as they are on arm.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
#include <dev/virtio/block.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <lk/debug.h>
|
||||
#include <assert.h>
|
||||
#include <lk/trace.h>
|
||||
@@ -16,9 +17,12 @@
|
||||
#include <kernel/thread.h>
|
||||
#include <kernel/event.h>
|
||||
#include <kernel/mutex.h>
|
||||
#include <kernel/vm.h>
|
||||
#include <lib/bio.h>
|
||||
|
||||
#if WITH_KERNEL_VM
|
||||
#include <kernel/vm.h>
|
||||
#endif
|
||||
|
||||
#define LOCAL_TRACE 0
|
||||
|
||||
struct virtio_blk_config {
|
||||
@@ -98,7 +102,7 @@ status_t virtio_block_init(struct virtio_device *dev, uint32_t host_features) {
|
||||
#if WITH_KERNEL_VM
|
||||
bdev->blk_req_phys = vaddr_to_paddr(bdev->blk_req);
|
||||
#else
|
||||
bdev->blk_freq_phys = (uint64_t)(uintptr_t)bdev->blk_req;
|
||||
bdev->blk_req_phys = (uint64_t)(uintptr_t)bdev->blk_req;
|
||||
#endif
|
||||
LTRACEF("blk_req structure at %p (0x%lx phys)\n", bdev->blk_req, bdev->blk_req_phys);
|
||||
|
||||
@@ -189,8 +193,6 @@ ssize_t virtio_block_read_write(struct virtio_device *dev, void *buf, off_t offs
|
||||
|
||||
uint16_t i;
|
||||
struct vring_desc *desc;
|
||||
paddr_t pa;
|
||||
vaddr_t va = (vaddr_t)buf;
|
||||
|
||||
LTRACEF("dev %p, buf %p, offset 0x%llx, len %zu\n", dev, buf, offset, len);
|
||||
|
||||
@@ -219,7 +221,8 @@ ssize_t virtio_block_read_write(struct virtio_device *dev, void *buf, off_t offs
|
||||
desc = virtio_desc_index_to_desc(dev, 0, desc->next);
|
||||
#if WITH_KERNEL_VM
|
||||
/* translate the first buffer */
|
||||
pa = vaddr_to_paddr((void *)va);
|
||||
vaddr_t va = (vaddr_t)buf;
|
||||
paddr_t pa = vaddr_to_paddr((void *)va);
|
||||
desc->addr = (uint64_t)pa;
|
||||
/* desc->len is filled in below */
|
||||
#else
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
#include <dev/virtio/gpu.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <lk/debug.h>
|
||||
#include <assert.h>
|
||||
#include <lk/trace.h>
|
||||
@@ -17,9 +18,12 @@
|
||||
#include <kernel/thread.h>
|
||||
#include <kernel/event.h>
|
||||
#include <kernel/mutex.h>
|
||||
#include <kernel/vm.h>
|
||||
#include <dev/display.h>
|
||||
|
||||
#if WITH_KERNEL_VM
|
||||
#include <kernel/vm.h>
|
||||
#endif
|
||||
|
||||
#include "virtio_gpu.h"
|
||||
|
||||
#define LOCAL_TRACE 0
|
||||
@@ -208,7 +212,11 @@ static status_t attach_backing(struct virtio_gpu_dev *gdev, uint32_t resource_id
|
||||
req.req.nr_entries = 1;
|
||||
|
||||
paddr_t pa;
|
||||
#if WITH_KERNEL_VM
|
||||
pa = vaddr_to_paddr(ptr);
|
||||
#else
|
||||
pa = (paddr_t)ptr;
|
||||
#endif
|
||||
req.mem.addr = pa;
|
||||
req.mem.length = buf_len;
|
||||
|
||||
@@ -356,7 +364,11 @@ status_t virtio_gpu_start(struct virtio_device *dev) {
|
||||
|
||||
/* attach a backing store to the resource */
|
||||
size_t len = gdev->pmode.r.width * gdev->pmode.r.height * 4;
|
||||
#if WITH_KERNEL_VM
|
||||
gdev->fb = pmm_alloc_kpages(ROUNDUP(len, PAGE_SIZE) / PAGE_SIZE, NULL);
|
||||
#else
|
||||
gdev->fb = memalign(PAGE_SIZE, ROUNDUP(len, PAGE_SIZE));
|
||||
#endif
|
||||
if (!gdev->fb) {
|
||||
TRACEF("failed to allocate framebuffer, wanted 0x%zx bytes\n", len);
|
||||
return ERR_NO_MEMORY;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
/* detect a virtio mmio hardware block
|
||||
* returns number of devices found */
|
||||
int virtio_mmio_detect(void *ptr, uint count, const uint irqs[]);
|
||||
int virtio_mmio_detect(void *ptr, uint count, const uint irqs[], size_t stride);
|
||||
|
||||
#define MAX_VIRTIO_RINGS 4
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
#include <dev/virtio/net.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <lk/debug.h>
|
||||
#include <assert.h>
|
||||
#include <lk/trace.h>
|
||||
@@ -17,7 +18,6 @@
|
||||
#include <kernel/thread.h>
|
||||
#include <kernel/event.h>
|
||||
#include <kernel/spinlock.h>
|
||||
#include <kernel/vm.h>
|
||||
#include <lib/pktbuf.h>
|
||||
#include <lib/minip.h>
|
||||
|
||||
|
||||
@@ -19,8 +19,10 @@
|
||||
#include <lk/pow2.h>
|
||||
#include <lk/init.h>
|
||||
#include <kernel/thread.h>
|
||||
#include <kernel/vm.h>
|
||||
#include <platform/interrupts.h>
|
||||
#if WITH_KERNEL_VM
|
||||
#include <kernel/vm.h>
|
||||
#endif
|
||||
|
||||
#include "virtio_priv.h"
|
||||
|
||||
@@ -109,7 +111,7 @@ static enum handler_return virtio_mmio_irq(void *arg) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int virtio_mmio_detect(void *ptr, uint count, const uint irqs[]) {
|
||||
int virtio_mmio_detect(void *ptr, uint count, const uint irqs[], size_t stride) {
|
||||
LTRACEF("ptr %p, count %u\n", ptr, count);
|
||||
|
||||
DEBUG_ASSERT(ptr);
|
||||
@@ -123,7 +125,7 @@ int virtio_mmio_detect(void *ptr, uint count, const uint irqs[]) {
|
||||
|
||||
int found = 0;
|
||||
for (uint i = 0; i < count; i++) {
|
||||
volatile struct virtio_mmio_config *mmio = (struct virtio_mmio_config *)((uint8_t *)ptr + i * 0x200);
|
||||
volatile struct virtio_mmio_config *mmio = (struct virtio_mmio_config *)((uint8_t *)ptr + i * stride);
|
||||
struct virtio_device *dev = &devices[i];
|
||||
|
||||
dev->index = i;
|
||||
@@ -132,8 +134,8 @@ int virtio_mmio_detect(void *ptr, uint count, const uint irqs[]) {
|
||||
mask_interrupt(irqs[i]);
|
||||
register_int_handler(irqs[i], &virtio_mmio_irq, (void *)dev);
|
||||
|
||||
LTRACEF("looking at magic 0x%x version 0x%x did 0x%x vid 0x%x\n",
|
||||
mmio->magic, mmio->version, mmio->device_id, mmio->vendor_id);
|
||||
LTRACEF("looking at %p: magic 0x%x version 0x%x did 0x%x vid 0x%x\n",
|
||||
mmio, mmio->magic, mmio->version, mmio->device_id, mmio->vendor_id);
|
||||
|
||||
if (mmio->magic != VIRTIO_MMIO_MAGIC) {
|
||||
continue;
|
||||
@@ -283,7 +285,7 @@ void virtio_submit_chain(struct virtio_device *dev, uint ring_index, uint16_t de
|
||||
struct vring_avail *avail = dev->ring[ring_index].avail;
|
||||
|
||||
avail->ring[avail->idx & dev->ring[ring_index].num_mask] = desc_index;
|
||||
DSB;
|
||||
mb();
|
||||
avail->idx++;
|
||||
|
||||
#if LOCAL_TRACE
|
||||
@@ -295,7 +297,7 @@ void virtio_kick(struct virtio_device *dev, uint ring_index) {
|
||||
LTRACEF("dev %p, ring %u\n", dev, ring_index);
|
||||
|
||||
dev->mmio_config->queue_notify = ring_index;
|
||||
DSB;
|
||||
mb();
|
||||
}
|
||||
|
||||
status_t virtio_alloc_ring(struct virtio_device *dev, uint index, uint16_t len) {
|
||||
|
||||
Reference in New Issue
Block a user