mirror of
https://github.com/openhwgroup/cvw
synced 2025-02-11 06:05:49 +00:00
Cleanup busdp.
This commit is contained in:
parent
7c3d6bbdb4
commit
fa8914a830
@ -77,30 +77,25 @@ module busdp #(parameter WORDSPERLINE, parameter LINELEN)
|
|||||||
logic [LOGWPL-1:0] WordCount;
|
logic [LOGWPL-1:0] WordCount;
|
||||||
genvar index;
|
genvar index;
|
||||||
|
|
||||||
for (index = 0; index < WORDSPERLINE; index++) begin:fetchbuffer
|
for (index = 0; index < WORDSPERLINE; index++) begin:fetchbuffer
|
||||||
flopen #(`XLEN) fb(.clk, .en(LSUBusAck & LSUBusRead & (index == WordCount)),
|
flopen #(`XLEN) fb(.clk, .en(LSUBusAck & LSUBusRead & (index == WordCount)),
|
||||||
.d(LSUBusHRDATA), .q(DCacheMemWriteData[(index+1)*`XLEN-1:index*`XLEN]));
|
.d(LSUBusHRDATA), .q(DCacheMemWriteData[(index+1)*`XLEN-1:index*`XLEN]));
|
||||||
end
|
end
|
||||||
|
|
||||||
assign LocalLSUBusAdr = SelUncachedAdr ? LSUPAdrM : DCacheBusAdr ;
|
|
||||||
assign LSUBusAdr = ({{`PA_BITS-LOGWPL{1'b0}}, WordCount} << $clog2(`XLEN/8)) + LocalLSUBusAdr;
|
|
||||||
assign PreLSUBusHWDATA = ReadDataLineSetsM[WordCount]; // only in lsu, not ifu
|
|
||||||
// exclude the subword write for uncached. We don't read the data first so we cannot
|
|
||||||
// select the subword by masking. Subword write also exists inside the uncore to
|
|
||||||
// suport subword masking for i/o. I'm not sure if this is necessary.
|
|
||||||
assign LSUBusHWDATA = SelUncachedAdr ? FinalAMOWriteDataM : PreLSUBusHWDATA; // only in lsu, not ifu
|
|
||||||
|
|
||||||
assign LSUBusSize = SelUncachedAdr ? LSUFunct3M : (`XLEN == 32 ? 3'b010 : 3'b011); // ifu: always the XLEN value.
|
mux2 #(`PA_BITS) localadrmux(DCacheBusAdr, LSUPAdrM, SelUncachedAdr, LocalLSUBusAdr);
|
||||||
|
assign LSUBusAdr = ({{`PA_BITS-LOGWPL{1'b0}}, WordCount} << $clog2(`XLEN/8)) + LocalLSUBusAdr;
|
||||||
|
assign PreLSUBusHWDATA = ReadDataLineSetsM[WordCount]; // only in lsu, not ifu
|
||||||
|
mux2 #(`XLEN) lsubushwdatamux(.d0(PreLSUBusHWDATA), .d1(FinalAMOWriteDataM),
|
||||||
|
.s(SelUncachedAdr), .y(LSUBusHWDATA));
|
||||||
|
mux2 #(3) lsubussizemux(.d0(`XLEN == 32 ? 3'b010 : 3'b011), .d1(LSUFunct3M),
|
||||||
|
.s(SelUncachedAdr), .y(LSUBusSize));
|
||||||
|
mux2 #(`XLEN) UnCachedDataMux(.d0(ReadDataWordM), .d1(DCacheMemWriteData[`XLEN-1:0]),
|
||||||
|
.s(SelUncachedAdr), .y(ReadDataWordMuxM));
|
||||||
|
|
||||||
// select between dcache and direct from the BUS. Always selected if no dcache.
|
busfsm #(WordCountThreshold, LOGWPL, `MEM_DCACHE)
|
||||||
mux2 #(`XLEN) UnCachedDataMux(.d0(ReadDataWordM),
|
busfsm(.clk, .reset, .IgnoreRequest, .LSURWM, .DCacheFetchLine, .DCacheWriteLine,
|
||||||
.d1(DCacheMemWriteData[`XLEN-1:0]),
|
.LSUBusAck, .CPUBusy, .CacheableM, .BusStall, .LSUBusWrite, .LSUBusRead,
|
||||||
.s(SelUncachedAdr),
|
.DCacheBusAck, .BusCommittedM, .SelUncachedAdr, .WordCount);
|
||||||
.y(ReadDataWordMuxM));
|
|
||||||
|
|
||||||
busfsm #(WordCountThreshold, LOGWPL, `MEM_DCACHE)
|
|
||||||
busfsm(.clk, .reset, .IgnoreRequest, .LSURWM, .DCacheFetchLine, .DCacheWriteLine,
|
|
||||||
.LSUBusAck, .CPUBusy, .CacheableM, .BusStall, .LSUBusWrite, .LSUBusRead,
|
|
||||||
.DCacheBusAck, .BusCommittedM, .SelUncachedAdr, .WordCount);
|
|
||||||
|
|
||||||
endmodule
|
endmodule
|
||||||
|
@ -33,23 +33,23 @@
|
|||||||
|
|
||||||
module busfsm #(parameter integer WordCountThreshold,
|
module busfsm #(parameter integer WordCountThreshold,
|
||||||
parameter integer LOGWPL, parameter logic CacheEnabled )
|
parameter integer LOGWPL, parameter logic CacheEnabled )
|
||||||
(input logic clk,
|
(input logic clk,
|
||||||
input logic reset,
|
input logic reset,
|
||||||
|
|
||||||
input logic IgnoreRequest,
|
input logic IgnoreRequest,
|
||||||
input logic [1:0] LSURWM,
|
input logic [1:0] LSURWM,
|
||||||
input logic DCacheFetchLine,
|
input logic DCacheFetchLine,
|
||||||
input logic DCacheWriteLine,
|
input logic DCacheWriteLine,
|
||||||
input logic LSUBusAck,
|
input logic LSUBusAck,
|
||||||
input logic CPUBusy,
|
input logic CPUBusy,
|
||||||
input logic CacheableM,
|
input logic CacheableM,
|
||||||
|
|
||||||
output logic BusStall,
|
output logic BusStall,
|
||||||
output logic LSUBusWrite,
|
output logic LSUBusWrite,
|
||||||
output logic LSUBusRead,
|
output logic LSUBusRead,
|
||||||
output logic DCacheBusAck,
|
output logic DCacheBusAck,
|
||||||
output logic BusCommittedM,
|
output logic BusCommittedM,
|
||||||
output logic SelUncachedAdr,
|
output logic SelUncachedAdr,
|
||||||
output logic [LOGWPL-1:0] WordCount);
|
output logic [LOGWPL-1:0] WordCount);
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,79 +33,79 @@
|
|||||||
`include "wally-config.vh"
|
`include "wally-config.vh"
|
||||||
|
|
||||||
module lsu (
|
module lsu (
|
||||||
input logic clk, reset,
|
input logic clk, reset,
|
||||||
input logic StallM, FlushM, StallW, FlushW,
|
input logic StallM, FlushM, StallW, FlushW,
|
||||||
output logic LSUStallM,
|
output logic LSUStallM,
|
||||||
// connected to cpu (controls)
|
// connected to cpu (controls)
|
||||||
input logic [1:0] MemRWM,
|
input logic [1:0] MemRWM,
|
||||||
input logic [2:0] Funct3M,
|
input logic [2:0] Funct3M,
|
||||||
input logic [6:0] Funct7M,
|
input logic [6:0] Funct7M,
|
||||||
input logic [1:0] AtomicM,
|
input logic [1:0] AtomicM,
|
||||||
input logic TrapM,
|
input logic TrapM,
|
||||||
input logic FlushDCacheM,
|
input logic FlushDCacheM,
|
||||||
output logic CommittedM,
|
output logic CommittedM,
|
||||||
output logic SquashSCW,
|
output logic SquashSCW,
|
||||||
output logic DCacheMiss,
|
output logic DCacheMiss,
|
||||||
output logic DCacheAccess,
|
output logic DCacheAccess,
|
||||||
// address and write data
|
// address and write data
|
||||||
input logic [`XLEN-1:0] IEUAdrE,
|
input logic [`XLEN-1:0] IEUAdrE,
|
||||||
(* mark_debug = "true" *)output logic [`XLEN-1:0] IEUAdrM,
|
(* mark_debug = "true" *)output logic [`XLEN-1:0] IEUAdrM,
|
||||||
input logic [`XLEN-1:0] WriteDataM,
|
input logic [`XLEN-1:0] WriteDataM,
|
||||||
output logic [`XLEN-1:0] ReadDataM,
|
output logic [`XLEN-1:0] ReadDataM,
|
||||||
// cpu privilege
|
// cpu privilege
|
||||||
input logic [1:0] PrivilegeModeW,
|
input logic [1:0] PrivilegeModeW,
|
||||||
input logic DTLBFlushM,
|
input logic DTLBFlushM,
|
||||||
// faults
|
// faults
|
||||||
output logic LoadPageFaultM, StoreAmoPageFaultM,
|
output logic LoadPageFaultM, StoreAmoPageFaultM,
|
||||||
output logic LoadMisalignedFaultM, LoadAccessFaultM,
|
output logic LoadMisalignedFaultM, LoadAccessFaultM,
|
||||||
// cpu hazard unit (trap)
|
// cpu hazard unit (trap)
|
||||||
output logic StoreAmoMisalignedFaultM, StoreAmoAccessFaultM,
|
output logic StoreAmoMisalignedFaultM, StoreAmoAccessFaultM,
|
||||||
// connect to ahb
|
// connect to ahb
|
||||||
(* mark_debug = "true" *) output logic [`PA_BITS-1:0] LSUBusAdr,
|
(* mark_debug = "true" *) output logic [`PA_BITS-1:0] LSUBusAdr,
|
||||||
(* mark_debug = "true" *) output logic LSUBusRead,
|
(* mark_debug = "true" *) output logic LSUBusRead,
|
||||||
(* mark_debug = "true" *) output logic LSUBusWrite,
|
(* mark_debug = "true" *) output logic LSUBusWrite,
|
||||||
(* mark_debug = "true" *) input logic LSUBusAck,
|
(* mark_debug = "true" *) input logic LSUBusAck,
|
||||||
(* mark_debug = "true" *) input logic [`XLEN-1:0] LSUBusHRDATA,
|
(* mark_debug = "true" *) input logic [`XLEN-1:0] LSUBusHRDATA,
|
||||||
(* mark_debug = "true" *) output logic [`XLEN-1:0] LSUBusHWDATA,
|
(* mark_debug = "true" *) output logic [`XLEN-1:0] LSUBusHWDATA,
|
||||||
(* mark_debug = "true" *) output logic [2:0] LSUBusSize,
|
(* mark_debug = "true" *) output logic [2:0] LSUBusSize,
|
||||||
// page table walker
|
// page table walker
|
||||||
input logic [`XLEN-1:0] SATP_REGW, // from csr
|
input logic [`XLEN-1:0] SATP_REGW, // from csr
|
||||||
input logic STATUS_MXR, STATUS_SUM, STATUS_MPRV,
|
input logic STATUS_MXR, STATUS_SUM, STATUS_MPRV,
|
||||||
input logic [1:0] STATUS_MPP,
|
input logic [1:0] STATUS_MPP,
|
||||||
input logic [`XLEN-1:0] PCF,
|
input logic [`XLEN-1:0] PCF,
|
||||||
input logic ITLBMissF,
|
input logic ITLBMissF,
|
||||||
output logic [`XLEN-1:0] PTE,
|
output logic [`XLEN-1:0] PTE,
|
||||||
output logic [1:0] PageType,
|
output logic [1:0] PageType,
|
||||||
output logic ITLBWriteF,
|
output logic ITLBWriteF,
|
||||||
input var logic [7:0] PMPCFG_ARRAY_REGW[`PMP_ENTRIES-1:0],
|
input var logic [7:0] PMPCFG_ARRAY_REGW[`PMP_ENTRIES-1:0],
|
||||||
input var logic [`XLEN-1:0] PMPADDR_ARRAY_REGW[`PMP_ENTRIES-1:0] // *** this one especially has a large note attached to it in pmpchecker.
|
input var logic [`XLEN-1:0] PMPADDR_ARRAY_REGW[`PMP_ENTRIES-1:0] // *** this one especially has a large note attached to it in pmpchecker.
|
||||||
);
|
);
|
||||||
|
|
||||||
logic [`PA_BITS-1:0] LSUPAdrM; // from mmu to dcache
|
logic [`PA_BITS-1:0] LSUPAdrM; // from mmu to dcache
|
||||||
logic DTLBMissM;
|
logic DTLBMissM;
|
||||||
logic DTLBWriteM;
|
logic DTLBWriteM;
|
||||||
logic [1:0] LSURWM;
|
logic [1:0] LSURWM;
|
||||||
logic [1:0] PreLSURWM;
|
logic [1:0] PreLSURWM;
|
||||||
logic [2:0] LSUFunct3M;
|
logic [2:0] LSUFunct3M;
|
||||||
logic [6:0] LSUFunct7M;
|
logic [6:0] LSUFunct7M;
|
||||||
logic [1:0] LSUAtomicM;
|
logic [1:0] LSUAtomicM;
|
||||||
(* mark_debug = "true" *) logic [`PA_BITS-1:0] PreLSUPAdrM, LocalLSUBusAdr;
|
(* mark_debug = "true" *) logic [`PA_BITS-1:0] PreLSUPAdrM;
|
||||||
logic [11:0] PreLSUAdrE, LSUAdrE;
|
logic [11:0] PreLSUAdrE, LSUAdrE;
|
||||||
logic CPUBusy;
|
logic CPUBusy;
|
||||||
logic DCacheStallM;
|
logic DCacheStallM;
|
||||||
logic CacheableM;
|
logic CacheableM;
|
||||||
logic SelHPTW;
|
logic SelHPTW;
|
||||||
logic BusStall;
|
logic BusStall;
|
||||||
logic InterlockStall;
|
logic InterlockStall;
|
||||||
logic IgnoreRequest;
|
logic IgnoreRequest;
|
||||||
logic BusCommittedM, DCacheCommittedM;
|
logic BusCommittedM, DCacheCommittedM;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// HPTW and Interlock FSM (only needed if VM supported)
|
|
||||||
// MMU include PMP and is needed if any privileged supported
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
flopenrc #(`XLEN) AddressMReg(clk, reset, FlushM, ~StallM, IEUAdrE, IEUAdrM);
|
flopenrc #(`XLEN) AddressMReg(clk, reset, FlushM, ~StallM, IEUAdrE, IEUAdrM);
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// HPTW and Interlock FSM (only needed if VM supported)
|
||||||
|
// MMU include PMP and is needed if any privileged supported
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
logic [`XLEN+1:0] IEUAdrExtM;
|
logic [`XLEN+1:0] IEUAdrExtM;
|
||||||
assign IEUAdrExtM = {2'b00, IEUAdrM};
|
assign IEUAdrExtM = {2'b00, IEUAdrM};
|
||||||
@ -118,8 +118,7 @@ module lsu (
|
|||||||
.LSUAdrE, .PreLSUPAdrM, .CPUBusy, .InterlockStall, .SelHPTW,
|
.LSUAdrE, .PreLSUPAdrM, .CPUBusy, .InterlockStall, .SelHPTW,
|
||||||
.IgnoreRequest);
|
.IgnoreRequest);
|
||||||
|
|
||||||
end // if (`MEM_VIRTMEM)
|
end else begin
|
||||||
else begin
|
|
||||||
assign {InterlockStall, SelHPTW, PTE, PageType, DTLBWriteM, ITLBWriteF} = '0;
|
assign {InterlockStall, SelHPTW, PTE, PageType, DTLBWriteM, ITLBWriteF} = '0;
|
||||||
assign IgnoreRequest = TrapM;
|
assign IgnoreRequest = TrapM;
|
||||||
assign CPUBusy = StallW;
|
assign CPUBusy = StallW;
|
||||||
@ -168,10 +167,10 @@ module lsu (
|
|||||||
end
|
end
|
||||||
assign LSUStallM = DCacheStallM | InterlockStall | BusStall;
|
assign LSUStallM = DCacheStallM | InterlockStall | BusStall;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Hart Memory System
|
// Hart Memory System
|
||||||
// Either Data Cache or Data Tightly Integrated Memory or just bus interface
|
// Either Data Cache or Data Tightly Integrated Memory or just bus interface
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
localparam integer WORDSPERLINE = `MEM_DCACHE ? `DCACHE_LINELENINBITS/`XLEN : 1;
|
localparam integer WORDSPERLINE = `MEM_DCACHE ? `DCACHE_LINELENINBITS/`XLEN : 1;
|
||||||
localparam integer LINELEN = `MEM_DCACHE ? `DCACHE_LINELENINBITS : `XLEN;
|
localparam integer LINELEN = `MEM_DCACHE ? `DCACHE_LINELENINBITS : `XLEN;
|
||||||
@ -207,13 +206,14 @@ module lsu (
|
|||||||
cache #(.LINELEN(`DCACHE_LINELENINBITS), .NUMLINES(`DCACHE_WAYSIZEINBYTES*8/LINELEN),
|
cache #(.LINELEN(`DCACHE_LINELENINBITS), .NUMLINES(`DCACHE_WAYSIZEINBYTES*8/LINELEN),
|
||||||
.NUMWAYS(`DCACHE_NUMWAYS), .DCACHE(1))
|
.NUMWAYS(`DCACHE_NUMWAYS), .DCACHE(1))
|
||||||
dcache(.clk, .reset, .CPUBusy,
|
dcache(.clk, .reset, .CPUBusy,
|
||||||
.RW(CacheableM ? LSURWM : 2'b00), .FlushCache(FlushDCacheM), .Atomic(CacheableM ? LSUAtomicM : 2'b00),
|
.RW(CacheableM ? LSURWM : 2'b00), .FlushCache(FlushDCacheM),
|
||||||
.NextAdr(LSUAdrE), .PAdr(LSUPAdrM),
|
.Atomic(CacheableM ? LSUAtomicM : 2'b00), .NextAdr(LSUAdrE), .PAdr(LSUPAdrM),
|
||||||
.FinalWriteData(FinalWriteDataM), .ReadDataWord(ReadDataWordM), .CacheStall(DCacheStallM),
|
.FinalWriteData(FinalWriteDataM), .ReadDataWord(ReadDataWordM),
|
||||||
.CacheMiss(DCacheMiss), .CacheAccess(DCacheAccess),
|
.CacheStall(DCacheStallM), .CacheMiss(DCacheMiss), .CacheAccess(DCacheAccess),
|
||||||
.IgnoreRequest, .CacheCommitted(DCacheCommittedM),
|
.IgnoreRequest, .CacheCommitted(DCacheCommittedM), .CacheBusAdr(DCacheBusAdr),
|
||||||
.CacheBusAdr(DCacheBusAdr), .ReadDataLineSets(ReadDataLineSetsM), .CacheMemWriteData(DCacheMemWriteData),
|
.ReadDataLineSets(ReadDataLineSetsM), .CacheMemWriteData(DCacheMemWriteData),
|
||||||
.CacheFetchLine(DCacheFetchLine), .CacheWriteLine(DCacheWriteLine), .CacheBusAck(DCacheBusAck), .InvalidateCacheM(1'b0));
|
.CacheFetchLine(DCacheFetchLine), .CacheWriteLine(DCacheWriteLine),
|
||||||
|
.CacheBusAck(DCacheBusAck), .InvalidateCacheM(1'b0));
|
||||||
|
|
||||||
end else begin : passthrough
|
end else begin : passthrough
|
||||||
assign {ReadDataWordM, DCacheStallM, DCacheCommittedM, DCacheWriteLine, DCacheFetchLine, DCacheBusAdr} = '0;
|
assign {ReadDataWordM, DCacheStallM, DCacheCommittedM, DCacheWriteLine, DCacheFetchLine, DCacheBusAdr} = '0;
|
||||||
@ -237,19 +237,16 @@ module lsu (
|
|||||||
.HWDATAIN(FinalAMOWriteDataM),
|
.HWDATAIN(FinalAMOWriteDataM),
|
||||||
.HWDATA(FinalWriteDataM));
|
.HWDATA(FinalWriteDataM));
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Atomic operations
|
// Atomic operations
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
if (`A_SUPPORTED) begin:lrsc
|
if (`A_SUPPORTED) begin:lrsc
|
||||||
/*atomic atomic(.clk, .reset, .FlushW, .CPUBusy, .MemRead, .PreLSURWM, .LSUAtomicM, .LSUPAdrM,
|
atomic atomic(.clk, .reset, .FlushW, .CPUBusy, .ReadDataM, .WriteDataM, .LSUPAdrM,
|
||||||
.SquashSCM, .LSURWM, ... ); *** */
|
.LSUFunct7M, .LSUFunct3M, .LSUAtomicM, .PreLSURWM, .IgnoreRequest,
|
||||||
atomic atomic(.clk, .reset, .FlushW, .CPUBusy, .ReadDataM, .WriteDataM, .LSUPAdrM, .LSUFunct7M,
|
.DTLBMissM, .FinalAMOWriteDataM, .SquashSCW, .LSURWM);
|
||||||
.LSUFunct3M, .LSUAtomicM, .PreLSURWM, .IgnoreRequest, .DTLBMissM,
|
|
||||||
.FinalAMOWriteDataM, .SquashSCW, .LSURWM);
|
|
||||||
|
|
||||||
end else begin:lrsc
|
end else begin:lrsc
|
||||||
assign SquashSCW = 0; assign LSURWM = PreLSURWM; assign FinalAMOWriteDataM = WriteDataM;
|
assign SquashSCW = 0; assign LSURWM = PreLSURWM; assign FinalAMOWriteDataM = WriteDataM;
|
||||||
end
|
end
|
||||||
endmodule
|
endmodule
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user