| 1 |
3 |
jamey.hick |
|
| 2 |
83 |
jamey.hick |
// The MIT License
|
| 3 |
|
|
|
| 4 |
|
|
// Copyright (c) 2006-2007 Massachusetts Institute of Technology
|
| 5 |
|
|
|
| 6 |
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 7 |
|
|
// of this software and associated documentation files (the "Software"), to deal
|
| 8 |
|
|
// in the Software without restriction, including without limitation the rights
|
| 9 |
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 10 |
|
|
// copies of the Software, and to permit persons to whom the Software is
|
| 11 |
|
|
// furnished to do so, subject to the following conditions:
|
| 12 |
|
|
|
| 13 |
|
|
// The above copyright notice and this permission notice shall be included in
|
| 14 |
|
|
// all copies or substantial portions of the Software.
|
| 15 |
|
|
|
| 16 |
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 17 |
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 18 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 19 |
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 20 |
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 21 |
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 22 |
|
|
// THE SOFTWARE.
|
| 23 |
|
|
|
| 24 |
|
|
|
| 25 |
3 |
jamey.hick |
package mkBRAMMemController;
|
| 26 |
|
|
|
| 27 |
|
|
import MemControllerTypes::*;
|
| 28 |
|
|
import IMemClient::*;
|
| 29 |
|
|
import IMemClientBackend::*;
|
| 30 |
|
|
import IMemController::*;
|
| 31 |
|
|
import IMemScheduler::*;
|
| 32 |
|
|
import mkMemClient::*;
|
| 33 |
|
|
import BRAM::*;
|
| 34 |
|
|
import FIFOF::*;
|
| 35 |
|
|
import FIFO::*;
|
| 36 |
|
|
import Vector::*;
|
| 37 |
|
|
|
| 38 |
|
|
|
| 39 |
|
|
`define FIFO_SIZE 4
|
| 40 |
|
|
|
| 41 |
|
|
module mkBRAMMemController#(IMemScheduler#(client_number, address_type) scheduler) (IMemController#(client_number, address_type, data_type))
|
| 42 |
|
|
provisos
|
| 43 |
|
|
(Bits#(address_type, addr_p),
|
| 44 |
|
|
Bits#(data_type, data_p),
|
| 45 |
|
|
Bits#(MemReq#(address_type, data_type), mem_req_p),
|
| 46 |
|
|
Literal#(address_type)
|
| 47 |
|
|
);
|
| 48 |
|
|
|
| 49 |
|
|
BRAM#(address_type, data_type) bram <- mkBRAM_Full();
|
| 50 |
|
|
|
| 51 |
|
|
Vector#(client_number, IMemClientBackend#(address_type, data_type)) client_backends = newVector();
|
| 52 |
|
|
|
| 53 |
|
|
Vector#(client_number, IMemClient#(address_type, data_type)) mem_clients = newVector();
|
| 54 |
|
|
|
| 55 |
|
|
FIFO#(Bit#((TAdd#(1,TLog#(client_number))))) client_tags_fifo <- mkSizedFIFO(`FIFO_SIZE);
|
| 56 |
|
|
|
| 57 |
|
|
for (Integer i = 0; i < valueof(client_number); i = i+1)
|
| 58 |
|
|
begin
|
| 59 |
|
|
client_backends[i] <- mkMemClient(i);
|
| 60 |
|
|
mem_clients[i] = client_backends[i].client_interface;
|
| 61 |
|
|
end
|
| 62 |
|
|
|
| 63 |
|
|
rule send_request;
|
| 64 |
|
|
|
| 65 |
|
|
Vector#(client_number, MemReqType#(address_type)) req_vec = newVector();
|
| 66 |
|
|
//make a vector of the appropriate data
|
| 67 |
|
|
for(int index = 0; index < fromInteger(valueof(client_number)); index = index + 1)
|
| 68 |
|
|
begin
|
| 69 |
|
|
if(client_backends[index].request_fifo.notEmpty())
|
| 70 |
|
|
begin
|
| 71 |
|
|
req_vec[index] = case(client_backends[index].request_fifo.first()) matches
|
| 72 |
|
|
tagged StoreReq .sreq: return MemReqType{ prio: client_backends[index].get_priority(),
|
| 73 |
|
|
req: tagged StoreReq sreq.addr};
|
| 74 |
|
|
tagged LoadReq .lreq : return MemReqType{ prio: client_backends[index].get_priority(),
|
| 75 |
|
|
req: tagged LoadReq lreq.addr};
|
| 76 |
|
|
endcase;
|
| 77 |
|
|
end
|
| 78 |
|
|
else
|
| 79 |
|
|
begin
|
| 80 |
|
|
req_vec[index] = MemReqType{ prio:client_backends[index].get_priority(), req: tagged Nop};
|
| 81 |
|
|
end
|
| 82 |
|
|
end
|
| 83 |
|
|
|
| 84 |
|
|
|
| 85 |
|
|
Maybe#(Bit#(TAdd#(1, TLog#(client_number)))) scheduling_result <- scheduler.choose_client(req_vec);
|
| 86 |
|
|
|
| 87 |
|
|
|
| 88 |
|
|
|
| 89 |
|
|
// Throw request to BRAM
|
| 90 |
|
|
if(scheduling_result matches tagged Valid .v)
|
| 91 |
|
|
begin
|
| 92 |
|
|
case (client_backends[v].request_fifo.first()) matches
|
| 93 |
|
|
tagged StoreReq .sreq:
|
| 94 |
|
|
begin
|
| 95 |
|
|
$display("BRAMMemController: Write request, addr: %x data: %x, from client %d", sreq.addr, sreq.data, v);
|
| 96 |
|
|
bram.write(sreq.addr, sreq.data);
|
| 97 |
|
|
end
|
| 98 |
|
|
tagged LoadReq .lreq:
|
| 99 |
|
|
begin
|
| 100 |
|
|
bram.read_req(lreq.addr);
|
| 101 |
|
|
client_tags_fifo.enq(v);
|
| 102 |
|
|
$display("BRAMMemController: Read request, addr: %x , from client %d", lreq.addr, v);
|
| 103 |
|
|
end
|
| 104 |
|
|
endcase
|
| 105 |
|
|
client_backends[v].request_fifo.deq();
|
| 106 |
|
|
end
|
| 107 |
|
|
|
| 108 |
|
|
endrule
|
| 109 |
|
|
|
| 110 |
|
|
// read response and shove it into the appropriate buffer.
|
| 111 |
|
|
rule read_bram_response;
|
| 112 |
|
|
Bit#((TAdd#(1, TLog#(client_number)))) target_client = client_tags_fifo.first();
|
| 113 |
|
|
data_type read_result <- bram.read_resp();
|
| 114 |
|
|
client_backends[target_client].enqueue_response(read_result);
|
| 115 |
|
|
client_tags_fifo.deq();
|
| 116 |
|
|
$display("BRAMMemController: Read response, data: %x , to client %d", read_result, target_client);
|
| 117 |
|
|
endrule
|
| 118 |
|
|
|
| 119 |
|
|
|
| 120 |
|
|
|
| 121 |
|
|
interface client_interfaces = mem_clients;
|
| 122 |
|
|
|
| 123 |
|
|
endmodule
|
| 124 |
|
|
endpackage
|