Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / board-qemu / slof / virtio-fs.fs
1 \ *****************************************************************************
2 \ * Copyright (c) 2011 IBM Corporation
3 \ * All rights reserved.
4 \ * This program and the accompanying materials
5 \ * are made available under the terms of the BSD License
6 \ * which accompanies this distribution, and is available at
7 \ * http://www.opensource.org/licenses/bsd-license.php
8 \ *
9 \ * Contributors:
10 \ *     IBM Corporation - initial implementation
11 \ ****************************************************************************/
12
13 ." Populating " pwd cr
14
15 s" network" device-type
16
17 0 VALUE virtfs-rx-buffer
18 0 VALUE virtfs-tx-buffer
19 FALSE VALUE initialized?
20
21 2000 CONSTANT VIRTFS-BUF-SIZE \ 8k
22
23 /vd-len BUFFER: virtiodev
24 virtiodev virtio-setup-vd
25
26 \
27 \ Support methods.
28
29 : shutdown  ( -- )
30    initialized? 0= IF EXIT THEN
31    virtiodev virtio-fs-shutdown
32    virtfs-rx-buffer VIRTFS-BUF-SIZE free-mem
33    virtfs-tx-buffer VIRTFS-BUF-SIZE free-mem
34    FALSE to initialized?
35 ;
36
37 : init  ( -- success )
38    VIRTFS-BUF-SIZE alloc-mem to virtfs-rx-buffer
39    VIRTFS-BUF-SIZE alloc-mem to virtfs-tx-buffer
40    
41    virtiodev                    ( dev )
42    virtfs-tx-buffer             ( dev tx )
43    virtfs-rx-buffer             ( reg tx rx )
44    VIRTFS-BUF-SIZE              ( reg tx rx size )   
45    virtio-fs-init               ( success )
46    
47    dup IF
48       TRUE to initialized?
49       ['] shutdown add-quiesce-xt
50    THEN
51 ;
52
53 \
54 \ Standard network interface.
55
56 : open  ( -- okay? )
57    open 0= IF false EXIT THEN
58    initialized? 0= IF
59       init 0= IF false EXIT THEN
60    THEN   
61    true
62 ;
63
64 : load ( addr -- len )
65    virtiodev swap               ( dev addr )   
66    my-args                      ( dev addr str strlen )
67    1 +          \ hack to make the following allocate 1 more byte
68    \-to-/       \ convert path elements
69    1 - 2dup + 0 swap c! drop
70    virtio-fs-load               ( length )
71 ;
72
73 : close  ( -- )
74    initialized? IF
75       shutdown
76    THEN
77    close
78 ;
79
80 : ping ( -- )
81    cr s" ping not supported for this device" type cr cr
82 ;
83
84
85 : (set-alias)
86     " virtfs" find-alias 0= IF
87         " virtfs" get-node node>path set-alias
88     ELSE
89         drop
90     THEN
91 ;
92
93 \
94 \ Init the module.
95
96 (set-alias)