diff modules/bluespec/Pygar/lab4/MemArb.bsv @ 8:74716e9a81cc pygar svn.9

[svn r9] Pygar now has the proper directory structure to play nicely with awb. Also, the apm file for audio-core willcompile successfully.
author rlm
date Fri, 23 Apr 2010 02:32:05 -0400
parents
children 3958de09a7c1
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/modules/bluespec/Pygar/lab4/MemArb.bsv	Fri Apr 23 02:32:05 2010 -0400
     1.3 @@ -0,0 +1,139 @@
     1.4 +// The MIT License
     1.5 +
     1.6 +// Copyright (c) 2009 Massachusetts Institute of Technology
     1.7 +
     1.8 +// Permission is hereby granted, free of charge, to any person obtaining a copy
     1.9 +// of this software and associated documentation files (the "Software"), to deal
    1.10 +// in the Software without restriction, including without limitation the rights
    1.11 +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    1.12 +// copies of the Software, and to permit persons to whom the Software is
    1.13 +// furnished to do so, subject to the following conditions:
    1.14 +
    1.15 +// The above copyright notice and this permission notice shall be included in
    1.16 +// all copies or substantial portions of the Software.
    1.17 +
    1.18 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    1.19 +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    1.20 +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    1.21 +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    1.22 +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    1.23 +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    1.24 +// THE SOFTWARE.
    1.25 +
    1.26 +import Connectable::*;
    1.27 +import GetPut::*;
    1.28 +import ClientServer::*;
    1.29 +import FIFOF::*;
    1.30 +import FIFO::*;
    1.31 +
    1.32 +// Local includes
    1.33 +`include "asim/provides/processor_library.bsh"
    1.34 +
    1.35 +interface MemArb;
    1.36 +
    1.37 +  interface Server#(MainMemReq,MainMemResp) cache0_server;
    1.38 +  interface Server#(MainMemReq,MainMemResp) cache1_server;
    1.39 +  interface Client#(MainMemReq,MainMemResp) mmem_client;
    1.40 +
    1.41 +endinterface
    1.42 +
    1.43 +typedef enum { REQ0, REQ1 } ReqPtr deriving(Eq,Bits);
    1.44 +
    1.45 +module mkMemArb( MemArb );
    1.46 +
    1.47 +  //-----------------------------------------------------------
    1.48 +  // State
    1.49 +
    1.50 +  FIFOF#(MainMemReq) req0Q  <- mkBFIFOF1();
    1.51 +  FIFO#(MainMemResp) resp0Q <- mkBFIFO1();
    1.52 +
    1.53 +  FIFOF#(MainMemReq) req1Q  <- mkBFIFOF1();
    1.54 +  FIFO#(MainMemResp) resp1Q <- mkBFIFO1();
    1.55 +
    1.56 +  FIFO#(MainMemReq)  mreqQ  <- mkBFIFO1();
    1.57 +  FIFO#(MainMemResp) mrespQ <- mkBFIFO1();
    1.58 +
    1.59 +  Reg#(ReqPtr) nextReq <- mkReg(REQ0);
    1.60 +
    1.61 +  //-----------------------------------------------------------
    1.62 +  // Some wires
    1.63 +
    1.64 +  let req0avail = req0Q.notEmpty();
    1.65 +  let req1avail = req1Q.notEmpty();
    1.66 +  
    1.67 +  //-----------------------------------------------------------
    1.68 +  // Rules
    1.69 +
    1.70 +  rule chooseReq0 ( req0avail && (!req1avail || (nextReq == REQ0)) );
    1.71 +    traceTiny("mkMemArb", "memArb req0",req0Q.first());
    1.72 +
    1.73 +    // Rewrite tag field if this is a load ...
    1.74 +    MainMemReq mreq
    1.75 +     = case ( req0Q.first() ) matches
    1.76 +	 tagged LoadReq  .ld : return LoadReq { tag:0, addr:ld.addr };
    1.77 +	 tagged StoreReq .st : return req0Q.first();
    1.78 +       endcase;
    1.79 +
    1.80 +    // Send out the request
    1.81 +    mreqQ.enq(mreq);
    1.82 +    nextReq <= REQ1;
    1.83 +    req0Q.deq();
    1.84 +
    1.85 +  endrule
    1.86 +
    1.87 +  rule chooseReq1 ( req1avail && (!req0avail || (nextReq == REQ1)) );
    1.88 +    traceTiny("mkMemArb", "memArb req1",req1Q.first);
    1.89 +
    1.90 +    // Rewrite tag field if this is a load ...
    1.91 +    MainMemReq mreq 
    1.92 +     = case ( req1Q.first() ) matches
    1.93 +         tagged LoadReq  .ld : return LoadReq { tag:1, addr:ld.addr };
    1.94 +	 tagged StoreReq .st : return req1Q.first();
    1.95 +       endcase;
    1.96 +
    1.97 +    // Send out the request
    1.98 +    mreqQ.enq(mreq);
    1.99 +    nextReq <= REQ0;
   1.100 +    req1Q.deq();
   1.101 +
   1.102 +  endrule
   1.103 +
   1.104 +  rule returnResp;
   1.105 +    traceTiny("mkMemArb", "resp",mrespQ.first());
   1.106 +
   1.107 +    // Use tag to figure out where to send response
   1.108 +    mrespQ.deq();
   1.109 +    let tag 
   1.110 +     = case ( mrespQ.first() ) matches
   1.111 +	 tagged LoadResp  .ld : return ld.tag;
   1.112 +	 tagged StoreResp .st : return st.tag;
   1.113 +       endcase;
   1.114 +     
   1.115 +    if ( tag == 0 ) 
   1.116 +      resp0Q.enq(mrespQ.first());                                    
   1.117 +    else
   1.118 +      resp1Q.enq(mrespQ.first());
   1.119 +
   1.120 +  endrule
   1.121 +
   1.122 +  //-----------------------------------------------------------
   1.123 +  // Methods
   1.124 +  
   1.125 +  interface Server cache0_server;
   1.126 +    interface Put request  = fifofToPut(req0Q);
   1.127 +    interface Get response = fifoToGet(resp0Q);
   1.128 +  endinterface
   1.129 +
   1.130 +  interface Server cache1_server;
   1.131 +    interface Put request  = fifofToPut(req1Q);
   1.132 +    interface Get response = fifoToGet(resp1Q);
   1.133 +  endinterface
   1.134 +
   1.135 +  interface Client mmem_client;
   1.136 +    interface Get request  = fifoToGet(mreqQ);
   1.137 +    interface Put response = fifoToPut(mrespQ);
   1.138 +  endinterface
   1.139 +
   1.140 +endmodule
   1.141 +
   1.142 +