1{- 
2   Attr: Mackerel attribute semantics
3   
4  Part of Mackerel: a strawman device definition DSL for Barrelfish
5   
6  Copyright (c) 2007, 2008, ETH Zurich.
7  All rights reserved.
8  
9  This file is distributed under the terms in the attached LICENSE file.
10  If you do not find this file, copies can be found by writing to:
11  ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
12-}  
13
14module Attr where
15
16data Attr =   RO      -- Read Only
17            | WO      -- Write Only
18            | RC      -- Read Only, Read Clears
19            | ROS     -- Read Only Sticky            
20            | RW      -- Read Write
21            | RWC     -- Read Write (1 to) Clear
22            | RWZC    -- Read Write Zero to Clear
23            | RWO     -- Write once 
24            | RWCS    -- R/W clear sticky
25            | RWS     -- Read Write Sticky
26            | RWL     -- Read Write locked
27            | MBZ     -- Must be Zero
28            | MB1     -- Must be one 
29            | RSVD    -- Reserved
30            | NOATTR  -- Default No attribute
31              deriving (Show, Eq)
32
33
34-- User can reasonably read from this register
35attr_user_can_read :: Attr -> Bool
36attr_user_can_read WO = False
37attr_user_can_read MBZ = False
38attr_user_can_read MB1 = False
39attr_user_can_read RSVD = False
40attr_user_can_read _ = True
41
42-- User can reasonably write to this register
43attr_user_can_write :: Attr -> Bool
44attr_user_can_write RO = False
45attr_user_can_write RC = False
46attr_user_can_write ROS = False
47attr_user_can_write MBZ = False
48attr_user_can_write MB1 = False
49attr_user_can_write RSVD = False
50attr_user_can_write _ = True
51
52attr_is_writeable :: Attr -> Bool
53attr_is_writeable RO = False
54attr_is_writeable WO = True
55attr_is_writeable RC = False
56attr_is_writeable ROS = False
57attr_is_writeable RW = True
58attr_is_writeable RWC = True
59attr_is_writeable RWZC = True
60attr_is_writeable RWO = True
61attr_is_writeable RWCS= True
62attr_is_writeable RWS = True
63attr_is_writeable RWL = True
64attr_is_writeable MBZ = False
65attr_is_writeable MB1 = False
66attr_is_writeable RSVD = False
67attr_is_writeable _  = False
68
69attr_is_readable :: Attr -> Bool
70attr_is_readable RO = True
71attr_is_readable WO = False
72attr_is_readable RC = True
73attr_is_readable ROS = True
74attr_is_readable RW = True
75attr_is_readable RWC = True
76attr_is_readable RWZC = True
77attr_is_readable RWO = True
78attr_is_readable RWCS= True
79attr_is_readable RWS = True
80attr_is_readable RWL = True
81attr_is_readable MBZ = False
82attr_is_readable MB1 = False
83attr_is_readable RSVD = False
84attr_is_readable _  = False
85
86attr_is_writeonly :: Attr -> Bool
87attr_is_writeonly RO = False
88attr_is_writeonly WO = True
89attr_is_writeonly RC = False
90attr_is_writeonly ROS = False
91attr_is_writeonly RW = False
92attr_is_writeonly RWC = False
93attr_is_writeonly RWZC = False
94attr_is_writeonly RWO = False
95attr_is_writeonly RWCS= False
96attr_is_writeonly RWS = False
97attr_is_writeonly RWL = False
98attr_is_writeonly MBZ = False
99attr_is_writeonly MB1 = False
100attr_is_writeonly RSVD = False
101attr_is_writeonly _  = False
102
103-- Field must always be written with a value read from the register.
104attr_preserve_on_write :: Attr -> Bool
105attr_preserve_on_write RSVD = True
106attr_preserve_on_write _ = False
107
108-- Field can be preserved by reading from the register
109attr_can_init_from_reg :: Attr -> Bool
110attr_can_init_from_reg RW = True
111attr_can_init_from_reg RSVD = True
112attr_can_init_from_reg RWS = True
113attr_can_init_from_reg RWL = True 
114attr_can_init_from_reg _ = False
115
116-- Field must always be written as zero
117attr_zero_before_write :: Attr -> Bool
118attr_zero_before_write MBZ = True
119attr_zero_before_write _ = False
120
121-- Field must always be written as one
122attr_set_before_write :: Attr -> Bool
123attr_set_before_write MB1 = True
124attr_set_before_write _ = False
125