`timescale 1ns / 1ps
|
`timescale 1ns / 1ps
|
// ============================================================================
|
// ============================================================================
|
// __
|
// __
|
// \\__/ o\ (C) 2015-2022 Robert Finch, Waterloo
|
// \\__/ o\ (C) 2015-2022 Robert Finch, Waterloo
|
// \ __ / All rights reserved.
|
// \ __ / All rights reserved.
|
// \/_// robfinch@finitron.ca
|
// \/_// robfinch@finitron.ca
|
// ||
|
// ||
|
//
|
//
|
// BSD 3-Clause License
|
// BSD 3-Clause License
|
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
// modification, are permitted provided that the following conditions are met:
|
// modification, are permitted provided that the following conditions are met:
|
//
|
//
|
// 1. Redistributions of source code must retain the above copyright notice, this
|
// 1. Redistributions of source code must retain the above copyright notice, this
|
// list of conditions and the following disclaimer.
|
// list of conditions and the following disclaimer.
|
//
|
//
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
// this list of conditions and the following disclaimer in the documentation
|
// this list of conditions and the following disclaimer in the documentation
|
// and/or other materials provided with the distribution.
|
// and/or other materials provided with the distribution.
|
//
|
//
|
// 3. Neither the name of the copyright holder nor the names of its
|
// 3. Neither the name of the copyright holder nor the names of its
|
// contributors may be used to endorse or promote products derived from
|
// contributors may be used to endorse or promote products derived from
|
// this software without specific prior written permission.
|
// this software without specific prior written permission.
|
//
|
//
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
//
|
//
|
// ============================================================================
|
// ============================================================================
|
//
|
//
|
import mpmc10_pkg::*;
|
import mpmc10_pkg::*;
|
|
|
module mpmc10_addr_resv_man(rst, clk, state,
|
module mpmc10_addr_resv_man(rst, clk, state,
|
adr0, adr1, adr2, adr3, adr4, adr5, adr6, adr7,
|
adr0, adr1, adr2, adr3, adr4, adr5, adr6, adr7,
|
sr0, sr1, sr2, sr3, sr4, sr5, sr6, sr7,
|
sr0, sr1, sr2, sr3, sr4, sr5, sr6, sr7,
|
wch, we, wadr, cr, ch1_taghit,
|
wch, we, wadr, cr, ch1_taghit,
|
resv_ch, resv_adr, rack);
|
resv_ch, resv_adr, rack);
|
parameter NAR = 2;
|
parameter NAR = 2;
|
input rst;
|
input rst;
|
input clk;
|
input clk;
|
input [3:0] state;
|
input mpmc10_state_t state;
|
input [31:0] adr0;
|
input [31:0] adr0;
|
input [31:0] adr1;
|
input [31:0] adr1;
|
input [31:0] adr2;
|
input [31:0] adr2;
|
input [31:0] adr3;
|
input [31:0] adr3;
|
input [31:0] adr4;
|
input [31:0] adr4;
|
input [31:0] adr5;
|
input [31:0] adr5;
|
input [31:0] adr6;
|
input [31:0] adr6;
|
input [31:0] adr7;
|
input [31:0] adr7;
|
input sr0;
|
input sr0;
|
input sr1;
|
input sr1;
|
input sr2;
|
input sr2;
|
input sr3;
|
input sr3;
|
input sr4;
|
input sr4;
|
input sr5;
|
input sr5;
|
input sr6;
|
input sr6;
|
input sr7;
|
input sr7;
|
input [3:0] wch;
|
input [3:0] wch;
|
input cr;
|
input cr;
|
input we;
|
input we;
|
input [31:0] wadr;
|
input [31:0] wadr;
|
input ch1_taghit;
|
input ch1_taghit;
|
output reg [3:0] resv_ch [0:NAR-1];
|
output reg [3:0] resv_ch [0:NAR-1];
|
output reg [31:0] resv_adr [0:NAR-1];
|
output reg [31:0] resv_adr [0:NAR-1];
|
output reg [7:0] rack; // reservation acknowledged
|
output reg [7:0] rack; // reservation acknowledged
|
|
|
reg [19:0] resv_to_cnt;
|
reg [19:0] resv_to_cnt;
|
wire [2:0] enc;
|
wire [3:0] enc;
|
wire [7:0] srr = {sr7,sr6,sr5,sr4,sr3,sr2,sr1,sr0};
|
wire [7:0] srr = {sr7,sr6,sr5,sr4,sr3,sr2,sr1,sr0};
|
wire [31:0] adr [0:7];
|
wire [31:0] adr [0:7];
|
|
|
assign adr[0] = adr0;
|
assign adr[0] = adr0;
|
assign adr[1] = adr1;
|
assign adr[1] = adr1;
|
assign adr[2] = adr2;
|
assign adr[2] = adr2;
|
assign adr[3] = adr3;
|
assign adr[3] = adr3;
|
assign adr[4] = adr4;
|
assign adr[4] = adr4;
|
assign adr[5] = adr5;
|
assign adr[5] = adr5;
|
assign adr[6] = adr6;
|
assign adr[6] = adr6;
|
assign adr[7] = adr7;
|
assign adr[7] = adr7;
|
|
|
roundRobin urr1
|
roundRobin urr1
|
(
|
(
|
.rst(rst),
|
.rst(rst),
|
.clk(clk),
|
.clk(clk),
|
.ce(1'b1),
|
.ce(1'b1),
|
.req(srr),
|
.req(srr),
|
.lock(8'h00),
|
.lock(8'h00),
|
.sel(),
|
.sel(),
|
.sel_enc(enc)
|
.sel_enc(enc)
|
);
|
);
|
|
|
// For address reservation below
|
// For address reservation below
|
reg [7:0] match;
|
reg [7:0] match;
|
always @(posedge clk)
|
always @(posedge clk)
|
if (rst)
|
if (rst)
|
match <= 8'h00;
|
match <= 8'h00;
|
else begin
|
else begin
|
if (match >= NAR)
|
if (match >= NAR)
|
match <= 8'h00;
|
match <= 8'h00;
|
else
|
else
|
match <= match + 8'd1;
|
match <= match + 8'd1;
|
end
|
end
|
|
|
always_comb
|
always_comb
|
rack = ~srr | srr[enc];
|
rack = ~srr | srr[enc];
|
|
|
// Managing address reservations
|
// Managing address reservations
|
integer n7;
|
integer n7;
|
always_ff @(posedge clk)
|
always_ff @(posedge clk)
|
if (rst) begin
|
if (rst) begin
|
resv_to_cnt <= 20'd0;
|
resv_to_cnt <= 20'd0;
|
for (n7 = 0; n7 < NAR; n7 = n7 + 1)
|
for (n7 = 0; n7 < NAR; n7 = n7 + 1)
|
resv_ch[n7] <= 4'hF;
|
resv_ch[n7] <= 4'hF;
|
end
|
end
|
else begin
|
else begin
|
resv_to_cnt <= resv_to_cnt + 20'd1;
|
resv_to_cnt <= resv_to_cnt + 20'd1;
|
|
|
for (n7 = 0; n7 < 8; n7 = n7 + 1)
|
for (n7 = 0; n7 < 8; n7 = n7 + 1)
|
if (enc==n7 && |srr)
|
if (enc==n7 && |srr)
|
reserve_adr({1'b0,n7[2:0]},adr[n7]);
|
reserve_adr({1'b0,n7[2:0]},adr[n7]);
|
|
|
if (state==mpmc10_pkg::IDLE) begin
|
if (state==IDLE) begin
|
if (we) begin
|
if (we) begin
|
if (cr) begin
|
if (cr) begin
|
for (n7 = 0; n7 < NAR; n7 = n7 + 1)
|
for (n7 = 0; n7 < NAR; n7 = n7 + 1)
|
if ((resv_ch[n7]==wch) && (resv_adr[n7][31:4]==wadr[31:4]))
|
if ((resv_ch[n7]==wch) && (resv_adr[n7][31:4]==wadr[31:4]))
|
resv_ch[n7] <= 4'hF;
|
resv_ch[n7] <= 4'hF;
|
end
|
end
|
end
|
end
|
end
|
end
|
end
|
end
|
|
|
integer empty_resv;
|
integer empty_resv;
|
function resv_held;
|
function resv_held;
|
input [3:0] ch;
|
input [3:0] ch;
|
input [31:0] adr;
|
input [31:0] adr;
|
integer n8;
|
integer n8;
|
begin
|
begin
|
resv_held = mpmc10_pkg::FALSE;
|
resv_held = 1'b0;
|
for (n8 = 0; n8 < NAR; n8 = n8 + 1)
|
for (n8 = 0; n8 < NAR; n8 = n8 + 1)
|
if (resv_ch[n8]==ch && resv_adr[n8][31:5]==adr[31:5])
|
if (resv_ch[n8]==ch && resv_adr[n8][31:5]==adr[31:5])
|
resv_held = mpmc10_pkg::TRUE;
|
resv_held = 1'b1;
|
end
|
end
|
endfunction
|
endfunction
|
|
|
// Find an empty reservation bucket
|
// Find an empty reservation bucket
|
integer n9;
|
integer n9;
|
always_comb
|
always_comb
|
begin
|
begin
|
empty_resv <= -1;
|
empty_resv <= -1;
|
for (n9 = 0; n9 < NAR; n9 = n9 + 1)
|
for (n9 = 0; n9 < NAR; n9 = n9 + 1)
|
if (resv_ch[n9]==4'hF)
|
if (resv_ch[n9]==4'hF)
|
empty_resv <= n9;
|
empty_resv <= n9;
|
end
|
end
|
|
|
// Two reservation buckets are allowed for. There are two (or more) CPU's in the
|
// Two reservation buckets are allowed for. There are two (or more) CPU's in the
|
// system and as long as they are not trying to control the same resource (the
|
// system and as long as they are not trying to control the same resource (the
|
// same semaphore) then they should be able to set a reservation. Ideally there
|
// same semaphore) then they should be able to set a reservation. Ideally there
|
// could be more reservation buckets available, but it starts to be a lot of
|
// could be more reservation buckets available, but it starts to be a lot of
|
// hardware.
|
// hardware.
|
task reserve_adr;
|
task reserve_adr;
|
input [3:0] ch;
|
input [3:0] ch;
|
input [31:0] adr;
|
input [31:0] adr;
|
begin
|
begin
|
// Ignore an attempt to reserve an address that's already reserved. The LWAR
|
// Ignore an attempt to reserve an address that's already reserved. The LWAR
|
// instruction is usually called in a loop and we don't want it to use up
|
// instruction is usually called in a loop and we don't want it to use up
|
// all address reservations.
|
// all address reservations.
|
if (!resv_held(ch,adr)) begin
|
if (!resv_held(ch,adr)) begin
|
if (empty_resv >= 0) begin
|
if (empty_resv >= 0) begin
|
resv_ch[empty_resv] <= ch;
|
resv_ch[empty_resv] <= ch;
|
resv_adr[empty_resv] <= adr;
|
resv_adr[empty_resv] <= adr;
|
end
|
end
|
// Here there were no free reservation buckets, so toss one of the
|
// Here there were no free reservation buckets, so toss one of the
|
// old reservations out.
|
// old reservations out.
|
else begin
|
else begin
|
resv_ch[match] <= ch;
|
resv_ch[match] <= ch;
|
resv_adr[match] <= adr;
|
resv_adr[match] <= adr;
|
end
|
end
|
end
|
end
|
end
|
end
|
endtask
|
endtask
|
|
|
endmodule
|
endmodule
|
|
|