db984b194395fc51320d14198b79057ab5478ffa
[shakti-core.git] / src / lib / MemoryMap.bsv
1 /*
2 Copyright (c) 2013, IIT Madras
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14 * Neither the name of IIT Madras nor the names of its contributors
15 may be used to endorse or promote products derived from this software
16 without specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 ---------------------------------------------------------------------
30 */
31 package MemoryMap;
32 /*=== Project imports ==== */
33 import defined_types::*;
34 import fast_memory_map::*;
35 import slow_memory_map::*;
36 `include "slow_instance_defines.bsv"
37 `include "fast_instance_defines.bsv"
38 `include "instance_defines.bsv"
39 `include "core_parameters.bsv"
40 /*========================= */
41
42
43 function Tuple2 #(Bool, Bit#(TLog#(Num_Fast_Slaves)))
44 fn_addr_to_slave_num (Bit#(`PADDR) addr);
45
46 let ft = fn_addr_to_fastslave_num(addr);
47 Bool isfast = tpl_1(ft);
48 Bit#(TLog#(Num_Fast_Slaves)) x = tpl_2(ft);
49
50 let st = fn_slow_address_mapping(addr);
51 Bool isslow = tpl_1(st);
52 Bit#(TLog#(Num_Slow_Slaves)) y = tpl_2(st);
53 if (isfast)
54 return tuple2(isfast, x);
55 else if (isslow)
56 return tuple2(True,fromInteger(valueOf(SlowPeripheral_slave_num)));
57 else
58 return tuple2(False,?);
59
60 endfunction
61
62 function Bool is_IO_Addr(Bit#(`PADDR) addr); // TODO Shuold be PADDR
63 if(addr>=`DebugBase && addr<=`DebugEnd)
64 return (True);
65 `ifdef SDR0_0_Base
66 else if(addr>=`SDR0_0_Base && addr<=`SDR0_0_End)
67 `ifdef FlexBus
68 return (True);
69 `else
70 return (False);
71 `endif
72 `endif
73 `ifdef BOOTROM
74 else if(addr>=`BootRomBase && addr<=`BootRomEnd)
75 return (False);
76 `endif
77 `ifdef TCMemory
78 else if(addr>=`TCMBase && addr<=`TCMEnd)
79 return (False);
80 `endif
81 else
82 return True;
83 endfunction
84
85 endpackage