These changes are the raw update to qemu-2.6.
[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 virtio-setup-vd VALUE virtiodev
24
25 \
26 \ Support methods.
27
28 : shutdown  ( -- )
29    initialized? 0= IF EXIT THEN
30    virtiodev virtio-fs-shutdown
31    virtfs-rx-buffer VIRTFS-BUF-SIZE free-mem
32    virtfs-tx-buffer VIRTFS-BUF-SIZE free-mem
33    FALSE to initialized?
34 ;
35
36 : init  ( -- success )
37    VIRTFS-BUF-SIZE alloc-mem to virtfs-rx-buffer
38    VIRTFS-BUF-SIZE alloc-mem to virtfs-tx-buffer
39    
40    virtiodev                    ( dev )
41    virtfs-tx-buffer             ( dev tx )
42    virtfs-rx-buffer             ( reg tx rx )
43    VIRTFS-BUF-SIZE              ( reg tx rx size )   
44    virtio-fs-init               ( success )
45    
46    dup IF
47       TRUE to initialized?
48       ['] shutdown add-quiesce-xt
49    THEN
50 ;
51
52 \
53 \ Standard network interface.
54
55 : open  ( -- okay? )
56    open 0= IF false EXIT THEN
57    initialized? 0= IF
58       init 0= IF false EXIT THEN
59    THEN   
60    true
61 ;
62
63 : load ( addr -- len )
64    virtiodev swap               ( dev addr )   
65    my-args                      ( dev addr str strlen )
66    1 +          \ hack to make the following allocate 1 more byte
67    \-to-/       \ convert path elements
68    1 - 2dup + 0 swap c! drop
69    virtio-fs-load               ( length )
70 ;
71
72 : close  ( -- )
73    initialized? IF
74       shutdown
75    THEN
76    close
77 ;
78
79 : ping ( -- )
80    cr s" ping not supported for this device" type cr cr
81 ;
82
83
84 : (set-alias)
85     " virtfs" find-alias 0= IF
86         " virtfs" get-node node>path set-alias
87     ELSE
88         drop
89     THEN
90 ;
91
92 \
93 \ Init the module.
94
95 (set-alias)