1/*
2 * Copyright (c) 2012, ETH Zurich. All rights reserved.
3 *
4 * This file is distributed under the terms in the attached LICENSE file.
5 * If you do not find this file, copies can be found by writing to:
6 * ETH Zurich D-INFK, Universitaetsstrasse 6, CH-8092 Zurich. Attn: Systems Group.
7 */
8
9/*
10 * virtio.dev
11 *
12 * The following structurs are taken from the Virtio Specification 1.0
13 *
14 */
15 
16device virtio_blk lsbfirst ( addr base ) "Virtio Block Device Specification" {
17   
18    datatype features lsbfirst (32)  "Feature bits for block devices"  {
19        barrier             1 "Device supports request barriers (Legacy)";
20        size_max            1 "Maximum size of any single segment in size_max";
21        seg_max             1 "Maximum number of segments in a request in seg_max";
22        _                   1 "Reserved";
23        geometry            1 "Disk-style geometry specified in geometry";
24        read_only           1 "Device is read-only";
25        blk_size            1 "Block size of disk is in blk_size";
26        scsi                1 "Device supports scsi packet commands";
27        _                   1 "Reserved";
28        flush               1 "Cache flush command support (Legacy)";
29        topology            1 "Device exports information on optimal IO alignment";
30        _                  12 "Reserved";
31        notify_on_empty     1 "(Legacy) The device MUST issue an interrupt if the device runs out of available descriptors"; 
32        _                   2 "Reserved";
33        any_layout          1 "(Legacy) his feature indicates that the device accepts arbitrary descriptor layouts";
34        ring_indirect_desc  1 "river can use descriptors with the VIRTQ_DESC_F_INDIRECT";
35        ring_event_idx      1 "enables the used_event and the avail_event fields";
36        _                   2 "Reserved";
37        version_1           1 "Distinction Legacy / Version 1 Device";
38    };
39    
40    /*
41     * Note: 
42     */
43    datatype req lsbfirst(32)  "Request header" {
44        rtype   32 "The type of the request";
45        ioprio  32 "The IO prioroty (Legacy)";
46        sector  64 "The sector where to write/read";
47        /* data */
48    };
49    
50    /*
51     * The cmd field is only present for scsi packet command requests, and 
52     * indicates the command to perform. This field MUST reside in a single, 
53     * separate device-readable buffer; command length can be derived from the 
54     * length of this buffer.
55     */
56    datatype scsi_req lsbfirst(32) "SCSI trailer"{	
57        errors      32  "Errors that may have occurred";
58        data_len    32  "Deprecated: Should be ignored.";
59        sense_len   32  "The number of bytes in the sense buffer";
60        residual    32  "The residual size: total - transferred";
61    };
62    
63    constants req_type "Possible request types for the block device" {
64        in           = 0x00000000 "Request type is an IN operation";
65        out          = 0x00000001 "Request type is an OUT operation";
66        scsi_cmd     = 0x00000002 "Request type is an OUT operation";
67        scsi_cmd_out = 0x00000003 "Request type is an OUT operation";
68        flush        = 0x00000004 "Request type is a cache flush";
69        flush_out    = 0x00000005 "Request type is a cache flush";
70        barrier      = 0x80000000 "IO Barrier (Legacy)";
71    };
72    
73    constants req_status "The status of the request" {
74        ok      = 0x0 "Everythin ok";
75        ioerror = 0x1 "IO error occured";
76        unsupp  = 0x2 "The request is not supported";
77    };
78    
79    
80    
81   /*
82    * ------------------------------------------------------------------------
83    * Reading / Writing the configuration space
84    * ------------------------------------------------------------------------ 
85    */
86    
87    
88    
89   register capacity addr(base, 0x00) "The capacity in 512byte sectors" {
90       sectors  64  "Number of 512byte sectors";
91   };
92   
93   register seg_size addr(base, 0x08) "The maximum segment size" {
94       max 32 "Maximum segment size";
95   };
96   
97   register seg_num addr(base, 0x0C) "The maximum number of segments" {
98       max 32 "Maximum number of segments";
99   };
100   
101   register geometry addr(base, 0x10) "Geometry Information" {
102       cylinders 16 "Number of cylinders";
103       heads      8 "Number of heads"; 
104       sectors    8 "Number of sectors";
105   };
106   
107   
108   register block_size addr(base, 0x14) "Block Size" {
109       size 32 "The size of a block";
110   };
111   
112   register topo_blocks addr(base, 0x18) "Toplogy: Logical Blocks" {
113      logic_per_phys 8 "Number of logical blocks per physical block";
114      offset_aligned 8 "Offset of first aligned logical block";
115   };
116   
117   register topo_io_size addr(base, 0x1A) "Topology: minimum IO Size" {
118       min 16 "Minimum number of IO size in blocks";
119       opt 16 "Maximum number of IO size in  blocks";
120   };
121   
122   
123   register writeback addr(base, 0x1E) "Legacy Writeback Register" {
124       wb   8 "Write back";
125   };
126 };
127