OpenCores
URL https://opencores.org/ocsvn/mpmc8/mpmc8/trunk

Subversion Repositories mpmc8

[/] [mpmc8/] [trunk/] [rtl/] [mpmc8_addr_resv_man.sv] - Blame information for rev 8

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 robfinch
`timescale 1ns / 1ps
2
// ============================================================================
3
//        __
4
//   \\__/ o\    (C) 2015-2022  Robert Finch, Waterloo
5
//    \  __ /    All rights reserved.
6
//     \/_//     robfinch@finitron.ca
7
//       ||
8
//
9
// BSD 3-Clause License
10
// Redistribution and use in source and binary forms, with or without
11
// modification, are permitted provided that the following conditions are met:
12
//
13
// 1. Redistributions of source code must retain the above copyright notice, this
14
//    list of conditions and the following disclaimer.
15
//
16
// 2. Redistributions in binary form must reproduce the above copyright notice,
17
//    this list of conditions and the following disclaimer in the documentation
18
//    and/or other materials provided with the distribution.
19
//
20
// 3. Neither the name of the copyright holder nor the names of its
21
//    contributors may be used to endorse or promote products derived from
22
//    this software without specific prior written permission.
23
//
24
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
//
35
// ============================================================================
36
//
37
import mpmc8_pkg::*;
38
 
39
module mpmc8_addr_resv_man(rst, clk, state,
40
        cs1, ack1, we1, adr1, sr1, cr1, ch1_taghit,
41
        cs7, ack7, we7, adr7, sr7, cr7, ch7_taghit,
42
        resv_ch, resv_adr);
43
input rst;
44
input clk;
45
input [3:0] state;
46
input cs1;
47
input ack1;
48
input we1;
49
input [31:0] adr1;
50
input sr1;
51
input cr1;
52
input ch1_taghit;
53
input cs7;
54
input ack7;
55
input we7;
56
input [31:0] adr7;
57
input sr7;
58
input cr7;
59
input ch7_taghit;
60
output reg [3:0] resv_ch [0:NAR-1];
61
output reg [31:0] resv_adr [0:NAR-1];
62
 
63
reg [19:0] resv_to_cnt;
64
reg toggle, toggle_sr;
65
 
66
// For address reservation below
67
reg [7:0] match;
68
always @(posedge clk)
69
if (rst)
70
        match <= 8'h00;
71
else begin
72
        if (match >= NAR)
73
                match <= 8'h00;
74
        else
75
                match <= match + 8'd1;
76
end
77
 
78
// Managing address reservations
79
integer n7;
80
always_ff @(posedge clk)
81
if (rst) begin
82
        resv_to_cnt <= 20'd0;
83
        toggle <= FALSE;
84
        toggle_sr <= FALSE;
85
        for (n7 = 0; n7 < NAR; n7 = n7 + 1)
86
                resv_ch[n7] <= 4'hF;
87
end
88
else begin
89
        resv_to_cnt <= resv_to_cnt + 20'd1;
90
 
91
        if (sr1 & sr7) begin
92
                if (toggle_sr) begin
93
                        reserve_adr(4'h1,adr1);
94
                        toggle_sr <= 1'b0;
95
                end
96
                else begin
97
                        reserve_adr(4'h7,adr7);
98
                        toggle_sr <= 1'b1;
99
                end
100
        end
101
        else begin
102
                if (sr1)
103
                        reserve_adr(4'h1,adr1);
104
                if (sr7)
105
                        reserve_adr(4'h7,adr7);
106
        end
107
 
108
        if (state==IDLE) begin
109
                if (cs1 & we1 & ~ack1) begin
110
                    toggle <= 1'b1;
111
                    if (cr1) begin
112
                        for (n7 = 0; n7 < NAR; n7 = n7 + 1)
113
                        if ((resv_ch[n7]==4'd1) && (resv_adr[n7][31:4]==adr1[31:4]))
114
                            resv_ch[n7] <= 4'hF;
115
                    end
116
                end
117
                else if (cs7 & we7 & ~ack7) begin
118
                    toggle <= 1'b1;
119
                    if (cr7) begin
120
                        for (n7 = 0; n7 < NAR; n7 = n7 + 1)
121
                        if ((resv_ch[n7]==4'd7) && (resv_adr[n7][31:4]==adr7[31:4]))
122
                            resv_ch[n7] <= 4'hF;
123
                    end
124
                end
125
                else if (!we1 & cs1 & ~ch1_taghit & (cs7 ? toggle : 1'b1))
126
                        toggle <= 1'b0;
127
                else if (!we7 & cs7 & ~ch7_taghit)
128
                        toggle <= 1'b1;
129
        end
130
end
131
 
132
integer empty_resv;
133
function resv_held;
134
input [3:0] ch;
135
input [31:0] adr;
136
integer n8;
137
begin
138
        resv_held = FALSE;
139
        for (n8 = 0; n8 < NAR; n8 = n8 + 1)
140
                if (resv_ch[n8]==ch && resv_adr[n8]==adr)
141
                        resv_held = TRUE;
142
end
143
endfunction
144
 
145
// Find an empty reservation bucket
146
integer n9;
147
always_comb
148
begin
149
        empty_resv <= -1;
150
        for (n9 = 0; n9 < NAR; n9 = n9 + 1)
151
                if (resv_ch[n9]==4'hF)
152
                        empty_resv <= n9;
153
end
154
 
155
// Two reservation buckets are allowed for. There are two (or more) CPU's in the
156
// system and as long as they are not trying to control the same resource (the
157
// same semaphore) then they should be able to set a reservation. Ideally there
158
// could be more reservation buckets available, but it starts to be a lot of
159
// hardware.
160
task reserve_adr;
161
input [3:0] ch;
162
input [31:0] adr;
163
begin
164
        // Ignore an attempt to reserve an address that's already reserved. The LWAR
165
        // instruction is usually called in a loop and we don't want it to use up
166
        // all address reservations.
167
        if (!resv_held(ch,adr)) begin
168
                if (empty_resv >= 0) begin
169
                        resv_ch[empty_resv] <= ch;
170
                        resv_adr[empty_resv] <= adr;
171
                end
172
                // Here there were no free reservation buckets, so toss one of the
173
                // old reservations out.
174
                else begin
175
                        resv_ch[match] <= ch;
176
                        resv_adr[match] <= adr;
177
                end
178
        end
179
end
180
endtask
181
 
182
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.