aboutsummaryrefslogtreecommitdiffstats
path: root/roms/SLOF/lib/libvirtio/virtio.code
diff options
context:
space:
mode:
Diffstat (limited to 'roms/SLOF/lib/libvirtio/virtio.code')
-rw-r--r--roms/SLOF/lib/libvirtio/virtio.code203
1 files changed, 203 insertions, 0 deletions
diff --git a/roms/SLOF/lib/libvirtio/virtio.code b/roms/SLOF/lib/libvirtio/virtio.code
new file mode 100644
index 000000000..db3ed600f
--- /dev/null
+++ b/roms/SLOF/lib/libvirtio/virtio.code
@@ -0,0 +1,203 @@
+/******************************************************************************
+ * Copyright (c) 2004, 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
+ *****************************************************************************/
+
+#include <virtio.h>
+#include <virtio-blk.h>
+#include <virtio-9p.h>
+#include <virtio-scsi.h>
+#include <virtio-net.h>
+#include <virtio-serial.h>
+
+/******** core virtio ********/
+
+// : virtio-setup-vd ( -- dev )
+PRIM(virtio_X2d_setup_X2d_vd)
+ PUSH; TOS.a = virtio_setup_vd();
+MIRP
+
+// : virtio-vring-size ( queuesize -- ringsize )
+PRIM(virtio_X2d_vring_X2d_size)
+ TOS.u = virtio_vring_size(TOS.u);
+MIRP
+
+// : virtio-get-qsize ( dev queue -- queuesize )
+PRIM(virtio_X2d_get_X2d_qsize)
+ int queue = TOS.u; POP;
+ TOS.u = virtio_get_qsize(TOS.a, queue);
+MIRP
+
+// : virtio-get-config ( dev offset size -- val )
+PRIM(virtio_X2d_get_X2d_config)
+ int size = TOS.u; POP;
+ int offset = TOS.u; POP;
+ TOS.u = virtio_get_config(TOS.a, offset, size);
+MIRP
+
+/******** virtio-blk ********/
+
+// : virtio-blk-init ( dev -- blk-size)
+PRIM(virtio_X2d_blk_X2d_init)
+ void *dev = TOS.a;
+ TOS.u = virtioblk_init(dev);
+MIRP
+
+// : virtio-blk-shutdown ( dev -- )
+PRIM(virtio_X2d_blk_X2d_shutdown)
+ void *dev = TOS.a; POP;
+ virtioblk_shutdown(dev);
+MIRP
+
+// : virtio-blk-read ( buf blkno cnt dev -- #read )
+PRIM(virtio_X2d_blk_X2d_read)
+ void *dev = TOS.a; POP;
+ long cnt = TOS.n; POP;
+ long blkno = TOS.n; POP;
+ void *buf = TOS.a;
+ TOS.n = virtioblk_transfer(dev, buf, blkno, cnt, VIRTIO_BLK_T_IN);
+MIRP
+
+// : virtio-blk-write ( buf blkno cnt dev -- #written )
+PRIM(virtio_X2d_blk_X2d_write)
+ void *dev = TOS.a; POP;
+ long cnt = TOS.n; POP;
+ long blkno = TOS.n; POP;
+ void *buf = TOS.a;
+ TOS.n = virtioblk_transfer(dev, buf, blkno, cnt, VIRTIO_BLK_T_OUT);
+MIRP
+
+/******** virtio-fs ********/
+
+// : virtio-fs-init ( dev tx rx size -- success )
+PRIM(virtio_X2d_fs_X2d_init)
+ int size = TOS.n; POP;
+ void *rx = TOS.a; POP;
+ void *tx = TOS.a; POP;
+ void *dev = TOS.a;
+
+ TOS.n = virtio_9p_init(dev, tx, rx, size) == 0 ? -1 : 0;
+MIRP
+
+// : virtio-fs-shutdown ( dev -- )
+PRIM(virtio_X2d_fs_X2d_shutdown)
+ void *dev = TOS.a; POP;
+
+ virtio_9p_shutdown(dev);
+MIRP
+
+// : virtio-fs-load ( dev buf str -- #read )
+PRIM(virtio_X2d_fs_X2d_load)
+ char *str = TOS.a; POP;
+ void *buf = TOS.a; POP;
+ void *dev = TOS.a;
+
+ TOS.n = virtio_9p_load(dev, str, buf);
+MIRP
+
+/******** virtio-scsi ********/
+
+// : virtio-scsi-init ( dev -- success )
+PRIM(virtio_X2d_scsi_X2d_init)
+ void *dev = TOS.a;
+ TOS.u = virtioscsi_init(dev);
+MIRP
+
+// : virtio-scsi-shutdown ( dev -- )
+PRIM(virtio_X2d_scsi_X2d_shutdown)
+ void *dev = TOS.a; POP;
+ virtioscsi_shutdown(dev);
+MIRP
+
+// : virtio-scsi-send ( buf_addr buf_len is_read req_ptr rsp_ptr dev -- success)
+PRIM(virtio_X2d_scsi_X2d_send)
+ void *dev = TOS.a; POP;
+ void *resp = TOS.a; POP;
+ void *req = TOS.a; POP;
+ int is_read = !!TOS.n; POP;
+ uint64_t blen = TOS.n; POP;
+ void *buf = TOS.a;
+ TOS.n = virtioscsi_send(dev, req, resp, is_read, buf, blen);
+MIRP
+
+/******** virtio-net ********/
+
+// : virtio-net-open ( dev -- false | [ vnet true ] )
+PRIM(virtio_X2d_net_X2d_open)
+{
+ void *dev = TOS.a;
+
+ void *vnet = virtionet_open(dev);
+
+ if (vnet) {
+ TOS.u = (unsigned long)vnet; PUSH;
+ TOS.n = -1;
+ } else
+ TOS.n = 0;
+}
+MIRP
+
+// : virtio-net-close ( vnet -- )
+PRIM(virtio_X2d_net_X2d_close)
+{
+ void *vnet = TOS.a; POP;
+ virtionet_close(vnet);
+}
+MIRP
+
+// : virtio-net-read ( addr len vnet -- actual )
+PRIM(virtio_X2d_net_X2d_read)
+{
+ void *vnet = TOS.a; POP;
+ int len = TOS.u; POP;
+ TOS.n = virtionet_read(vnet, TOS.a, len);
+}
+MIRP
+
+// : virtio-net-write ( addr len vnet -- actual )
+PRIM(virtio_X2d_net_X2d_write)
+{
+ void *vnet = TOS.a; POP;
+ int len = TOS.u; POP;
+ TOS.n = virtionet_write(vnet, TOS.a, len);
+}
+MIRP
+
+/*********** virtio-serial ***********/
+// : virtio-serial-init ( dev -- false | true)
+PRIM(virtio_X2d_serial_X2d_init)
+ void *dev = TOS.a;
+ TOS.u = virtio_serial_init(dev);
+MIRP
+
+// : virtio-serial-shutdown ( dev -- )
+PRIM(virtio_X2d_serial_X2d_shutdown)
+ void *dev = TOS.a; POP;
+ virtio_serial_shutdown(dev);
+MIRP
+
+// : virtio-serial-putchar ( dev char -- )
+PRIM(virtio_X2d_serial_X2d_putchar)
+ unsigned long c = TOS.n; POP;
+ void *dev = TOS.a; POP;
+ virtio_serial_putchar(dev, c);
+MIRP
+
+// : virtio-serial-getchar ( dev -- char)
+PRIM(virtio_X2d_serial_X2d_getchar)
+ void *dev = TOS.a;
+ TOS.n = virtio_serial_getchar(dev);
+MIRP
+
+// : virtio-serial-haschar ( dev -- true | false)
+PRIM(virtio_X2d_serial_X2d_haschar)
+ void *dev = TOS.a;
+ TOS.n = virtio_serial_haschar(dev);
+MIRP