[SLOF] [PATCH v4 20/23] virtio: add and enable 1.0 capability parsing

Nikunj A Dadhania nikunj at linux.vnet.ibm.com
Fri Jan 29 20:24:09 AEDT 2016


Nikunj A Dadhania <nikunj at linux.vnet.ibm.com> writes:

> Thomas Huth <thuth at redhat.com> writes:
>
>> On 28.01.2016 11:24, Nikunj A Dadhania wrote:
>>> Introduce parsing routines for virtio capabilities. This would also
>>> determine whether we need to function in legacy mode or virtio 1.0.
>>> 
>>> Drivers need to negotiate the 1.0 feature capability before starting to
>>> use 1.0.
>>> 
>>> Disable all the drivers until 1.0 is enabled.
>>
>> s/Disable all/Disable it in all/
>>
>>> Signed-off-by: Nikunj A Dadhania <nikunj at linux.vnet.ibm.com>
>>> ---
>>>  board-qemu/slof/virtio.fs   |   1 +
>>>  lib/libvirtio/virtio-9p.c   |   3 ++
>>>  lib/libvirtio/virtio-blk.c  |   3 ++
>>>  lib/libvirtio/virtio-net.c  |   3 ++
>>>  lib/libvirtio/virtio-scsi.c |   3 ++
>>>  lib/libvirtio/virtio.c      | 109 ++++++++++++++++++++++++++++++++++++++++++++
>>>  lib/libvirtio/virtio.code   |   6 +++
>>>  lib/libvirtio/virtio.h      |   1 +
>>>  lib/libvirtio/virtio.in     |   2 +
>>>  9 files changed, 131 insertions(+)
>> ...
>>> +/**
>>> + * Reads the virtio device capabilities, gets called from SLOF routines The
>>> + * function determines legacy or modern device and sets up driver registers
>>> + */
>>> +void virtio_parse_capabilities(struct virtio_device *dev)
>>> +{
>>> +	uint8_t cap_ptr, cap_vndr;
>>> +
>>> +	cap_ptr = SLOF_pci_config_read8(PCI_CONFIG_CAP_REG);
>>> +	while (cap_ptr != 0) {
>>> +		cap_vndr = SLOF_pci_config_read8(cap_ptr + VIRTIO_PCI_CAP_VNDR);
>>> +		if (cap_vndr == PCI_CAP_ID_VNDR)
>>> +			virtio_process_cap(dev, cap_ptr);
>>> +		cap_ptr = SLOF_pci_config_read8(cap_ptr+VIRTIO_PCI_CAP_NEXT);
>>> +	}
>>> +
>>> +	if (dev->common.cap_id && dev->notify.cap_id &&
>>> +	    dev->isr.cap_id && dev->device.cap_id) {
>>> +		dev->is_modern = 1;
>>> +	} else {
>>> +		dev->is_modern = 0;
>>> +		dev->legacy.cap_id = 0;
>>> +		dev->legacy.bar = 0;
>>> +		virtio_cap_set_base_addr(&dev->legacy, 0);
>>> +	}
>>> +}
>>
>> Do you ever use dev->legacy in the code later? struct virtio_device
>> already contains the "addr" field, which is the pointer to the legacy
>> BAR address, right? So you might want to remove dev->addr in the end
>> and use dev->legacy.bar instead, I guess?
>
> I think let me not maintain a separate addr, instead us the
> legacy->addr. Will add a new patch for converting this, as there will be
> changes in all the accessor routines.
>
>> Or remove the dev->legacy
>> structure and set the dev->addr field here instead? Either way, you
>> could finally get rid of the Forth code that reads the legacy BAR in
>> the virtio-setup-vd function.
>>
>> Anyway, you could also do this as a separate clean-up patch later
>> (this patch here basically also looks fine to me as it is right now).
>
> I will add one patch after this to take care of this clean-up

With this patch, I thought of further optimizing this and getting rid of
virtio.fs completely. Here is what I have currently, this can be squashed
to different patches. But for completeness, I have all the diff here.
Alexey, too was suggesting in the first revision not to have the SLOF
structures. I can include this in v5. 

-------------------------------------------------------

virtio: remove virtio.fs and related structures

Now all the required legacy and modern device setup mostly done in the
C code. There is no requiremet for the Forth code. This moves the
allocation of the virtio_device structure to the C code.

Signed-off-by: Nikunj A Dadhania <nikunj at linux.vnet.ibm.com>
---
 board-qemu/slof/OF.fs           |  4 ----
 board-qemu/slof/virtio-block.fs |  3 +--
 board-qemu/slof/virtio-fs.fs    |  3 +--
 board-qemu/slof/virtio-net.fs   |  3 +--
 board-qemu/slof/virtio-scsi.fs  |  3 +--
 board-qemu/slof/virtio.fs       | 39 ---------------------------------------
 lib/libvirtio/virtio.c          | 10 +++++++++-
 lib/libvirtio/virtio.code       |  7 +++----
 lib/libvirtio/virtio.h          |  2 +-
 lib/libvirtio/virtio.in         |  2 +-
 10 files changed, 18 insertions(+), 58 deletions(-)
 delete mode 100644 board-qemu/slof/virtio.fs

diff --git a/board-qemu/slof/OF.fs b/board-qemu/slof/OF.fs
index 561d892..69ee5c1 100644
--- a/board-qemu/slof/OF.fs
+++ b/board-qemu/slof/OF.fs
@@ -134,10 +134,6 @@ check-boot-menu
 \ Grab rtas from qemu
 #include "rtas.fs"
 
-390 cp
-
-#include "virtio.fs"
-
 3f0 cp
 
 #include "tree.fs"
diff --git a/board-qemu/slof/virtio-block.fs b/board-qemu/slof/virtio-block.fs
index ea388fb..bc9013e 100644
--- a/board-qemu/slof/virtio-block.fs
+++ b/board-qemu/slof/virtio-block.fs
@@ -23,8 +23,7 @@ FALSE VALUE initialized?
 
 INSTANCE VARIABLE deblocker
 
-/vd-len BUFFER: virtiodev
-virtiodev virtio-setup-vd
+virtio-setup-vd VALUE virtiodev
 
 \ Quiesce the virtqueue of this device so that no more background
 \ transactions can be pending.
diff --git a/board-qemu/slof/virtio-fs.fs b/board-qemu/slof/virtio-fs.fs
index 8632b46..3898d0b 100644
--- a/board-qemu/slof/virtio-fs.fs
+++ b/board-qemu/slof/virtio-fs.fs
@@ -20,8 +20,7 @@ FALSE VALUE initialized?
 
 2000 CONSTANT VIRTFS-BUF-SIZE \ 8k
 
-/vd-len BUFFER: virtiodev
-virtiodev virtio-setup-vd
+virtio-setup-vd VALUE virtiodev
 
 \
 \ Support methods.
diff --git a/board-qemu/slof/virtio-net.fs b/board-qemu/slof/virtio-net.fs
index 882b733..b16fffe 100644
--- a/board-qemu/slof/virtio-net.fs
+++ b/board-qemu/slof/virtio-net.fs
@@ -16,8 +16,7 @@ s" network" device-type
 
 INSTANCE VARIABLE obp-tftp-package
 
-/vd-len BUFFER: virtiodev
-virtiodev virtio-setup-vd
+virtio-setup-vd VALUE virtiodev
 0 VALUE virtio-net-priv
 0 VALUE open-count
 
diff --git a/board-qemu/slof/virtio-scsi.fs b/board-qemu/slof/virtio-scsi.fs
index ca5fb13..4fedeee 100644
--- a/board-qemu/slof/virtio-scsi.fs
+++ b/board-qemu/slof/virtio-scsi.fs
@@ -22,8 +22,7 @@ FALSE CONSTANT virtio-scsi-debug
 
 FALSE VALUE initialized?
 
-/vd-len BUFFER: virtiodev
-virtiodev virtio-setup-vd
+virtio-setup-vd VALUE virtiodev
 
 STRUCT \ virtio-scsi-config
     /l FIELD vs-cfg>num-queues
diff --git a/board-qemu/slof/virtio.fs b/board-qemu/slof/virtio.fs
deleted file mode 100644
index a21db01..0000000
--- a/board-qemu/slof/virtio.fs
+++ /dev/null
@@ -1,39 +0,0 @@
-\ *****************************************************************************
-\ * Copyright (c) 2011 IBM Corporation
-\ * All rights reserved.
-\ * This program and the accompanying materials
-\ * are made available under the terms of the BSD License
-\ * which accompanies this distribution, and is available at
-\ * http://www.opensource.org/licenses/bsd-license.php
-\ *
-\ * Contributors:
-\ *     IBM Corporation - initial implementation
-\ ****************************************************************************/
-
-\ This struct must match "struct virtio_cap" in virtio.h !
-STRUCT
-   /n FIELD vd>cap>address
-   /c FIELD vd>cap>bar
-   /c FIELD vd>cap>is_io
-   /c FIELD vd>cap>cap_id
-   5  FIELD vd>cap>pad
-CONSTANT /vd-cap-len
-
-\ This struct must match "struct virtio_device" in virtio.h!
-STRUCT
-   /l FIELD vd>is-modern
-   /vd-cap-len FIELD vd>legacy
-   /vd-cap-len FIELD vd>common
-   /vd-cap-len FIELD vd>notify
-   /vd-cap-len FIELD vd>isr
-   /vd-cap-len FIELD vd>device
-   /vd-cap-len FIELD vd>pci
-   /l FIELD vd>notify_off_mul
-CONSTANT /vd-len
-
-
-\ Initialize virtiodev structure for the current node
-\ This routine gets called from pci device files
-: virtio-setup-vd  ( vdstruct -- )
-   virtio-parse-capabilities
-;
diff --git a/lib/libvirtio/virtio.c b/lib/libvirtio/virtio.c
index ebe09f1..a9874b4 100644
--- a/lib/libvirtio/virtio.c
+++ b/lib/libvirtio/virtio.c
@@ -162,9 +162,16 @@ static void virtio_process_cap(struct virtio_device *dev, uint8_t cap_ptr)
  * Reads the virtio device capabilities, gets called from SLOF routines The
  * function determines legacy or modern device and sets up driver registers
  */
-void virtio_parse_capabilities(struct virtio_device *dev)
+struct virtio_device *virtio_setup_vd(void)
 {
 	uint8_t cap_ptr, cap_vndr;
+	struct virtio_device *dev;
+
+	dev = SLOF_alloc_mem(sizeof(struct virtio_device));
+	if(!dev) {
+		printf("Failed to allocate memory");
+		return NULL;
+	}
 
 	cap_ptr = SLOF_pci_config_read8(PCI_CONFIG_CAP_REG);
 	while (cap_ptr != 0) {
@@ -183,6 +190,7 @@ void virtio_parse_capabilities(struct virtio_device *dev)
 		dev->legacy.bar = 0;
 		virtio_cap_set_base_addr(&dev->legacy, 0);
 	}
+	return dev;
 }
 
 /**
diff --git a/lib/libvirtio/virtio.code b/lib/libvirtio/virtio.code
index 701b741..8eec8f0 100644
--- a/lib/libvirtio/virtio.code
+++ b/lib/libvirtio/virtio.code
@@ -18,10 +18,9 @@
 
 /******** core virtio ********/
 
-// : virtio-parse-capabilities  ( dev --  )
-PRIM(virtio_X2d_parse_X2d_capabilities)
-	void *dev = TOS.a; POP;
-	virtio_parse_capabilities(dev);
+// : virtio-setup-vd  ( -- dev )
+PRIM(virtio_X2d_setup_X2d_vd)
+	PUSH; TOS.a = virtio_setup_vd();
 MIRP
 
 // : virtio-vring-size  ( queuesize -- ringsize )
diff --git a/lib/libvirtio/virtio.h b/lib/libvirtio/virtio.h
index f084c0e..d051e3e 100644
--- a/lib/libvirtio/virtio.h
+++ b/lib/libvirtio/virtio.h
@@ -112,7 +112,7 @@ extern void virtio_fill_desc(struct vring_desc *desc, bool is_modern,
                              uint16_t flags, uint16_t next);
 extern int virtio_queue_init_vq(struct virtio_device *dev, struct vqs *vq, unsigned int id);
 
-extern void virtio_parse_capabilities(struct virtio_device *dev);
+extern struct virtio_device *virtio_setup_vd(void);
 extern void virtio_reset_device(struct virtio_device *dev);
 extern void virtio_queue_notify(struct virtio_device *dev, int queue);
 extern void virtio_set_status(struct virtio_device *dev, int status);
diff --git a/lib/libvirtio/virtio.in b/lib/libvirtio/virtio.in
index bd5485e..195840e 100644
--- a/lib/libvirtio/virtio.in
+++ b/lib/libvirtio/virtio.in
@@ -10,7 +10,7 @@
  *     IBM Corporation - initial implementation
  *****************************************************************************/
 
-cod(virtio-parse-capabilities)
+cod(virtio-setup-vd)
 
 cod(virtio-vring-size)
 cod(virtio-get-qsize)
-- 
2.5.0



More information about the SLOF mailing list