2014-09-13 00:31:38 +02:00
|
|
|
// See LICENSE for license details.
|
|
|
|
|
2013-07-25 08:22:36 +02:00
|
|
|
package uncore
|
|
|
|
import Chisel._
|
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
case object LNEndpoints extends Field[Int]
|
2015-03-24 10:06:53 +01:00
|
|
|
case object LNHeaderBits extends Field[Int]
|
2013-07-25 08:22:36 +02:00
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
class PhysicalHeader(n: Int) extends Bundle {
|
|
|
|
val src = UInt(width = log2Up(n))
|
|
|
|
val dst = UInt(width = log2Up(n))
|
2013-07-25 08:22:36 +02:00
|
|
|
}
|
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
class PhysicalNetworkIO[T <: Data](n: Int, dType: T) extends Bundle {
|
|
|
|
val header = new PhysicalHeader(n)
|
2015-07-16 03:06:27 +02:00
|
|
|
val payload = dType
|
|
|
|
override def cloneType = new PhysicalNetworkIO(n,dType).asInstanceOf[this.type]
|
2013-07-25 08:22:36 +02:00
|
|
|
}
|
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
class BasicCrossbarIO[T <: Data](n: Int, dType: T) extends Bundle {
|
|
|
|
val in = Vec.fill(n){Decoupled(new PhysicalNetworkIO(n,dType))}.flip
|
|
|
|
val out = Vec.fill(n){Decoupled(new PhysicalNetworkIO(n,dType))}
|
2014-01-21 21:20:55 +01:00
|
|
|
}
|
2013-07-25 08:22:36 +02:00
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
abstract class PhysicalNetwork extends Module
|
|
|
|
|
2014-12-07 11:57:44 +01:00
|
|
|
class BasicCrossbar[T <: Data](n: Int, dType: T, count: Int = 1, needsLock: Option[PhysicalNetworkIO[T] => Bool] = None) extends PhysicalNetwork {
|
2014-08-08 21:21:57 +02:00
|
|
|
val io = new BasicCrossbarIO(n, dType)
|
|
|
|
|
|
|
|
val rdyVecs = List.fill(n){Vec.fill(n)(Bool())}
|
2013-07-25 08:22:36 +02:00
|
|
|
|
|
|
|
io.out.zip(rdyVecs).zipWithIndex.map{ case ((out, rdys), i) => {
|
2014-12-07 11:57:44 +01:00
|
|
|
val rrarb = Module(new LockingRRArbiter(io.in(0).bits, n, count, needsLock))
|
2013-07-25 08:22:36 +02:00
|
|
|
(rrarb.io.in, io.in, rdys).zipped.map{ case (arb, in, rdy) => {
|
2013-08-12 19:36:44 +02:00
|
|
|
arb.valid := in.valid && (in.bits.header.dst === UInt(i))
|
2013-07-25 08:22:36 +02:00
|
|
|
arb.bits := in.bits
|
2013-08-12 19:36:44 +02:00
|
|
|
rdy := arb.ready && (in.bits.header.dst === UInt(i))
|
2013-07-25 08:22:36 +02:00
|
|
|
}}
|
|
|
|
out <> rrarb.io.out
|
|
|
|
}}
|
2014-08-08 21:21:57 +02:00
|
|
|
for(i <- 0 until n) {
|
2013-07-25 08:22:36 +02:00
|
|
|
io.in(i).ready := rdyVecs.map(r => r(i)).reduceLeft(_||_)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
abstract class LogicalNetwork extends Module
|
2014-01-21 21:20:55 +01:00
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
class LogicalHeader extends Bundle {
|
2015-03-24 10:06:53 +01:00
|
|
|
val src = UInt(width = params(LNHeaderBits))
|
|
|
|
val dst = UInt(width = params(LNHeaderBits))
|
2013-07-25 08:22:36 +02:00
|
|
|
}
|
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
class LogicalNetworkIO[T <: Data](dType: T) extends Bundle {
|
2014-03-29 18:53:49 +01:00
|
|
|
val header = new LogicalHeader
|
2015-07-16 03:06:27 +02:00
|
|
|
val payload = dType.cloneType
|
|
|
|
override def cloneType = new LogicalNetworkIO(dType).asInstanceOf[this.type]
|
2014-03-29 18:53:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
object DecoupledLogicalNetworkIOWrapper {
|
2015-04-28 01:59:30 +02:00
|
|
|
def apply[T <: Data](
|
|
|
|
in: DecoupledIO[T],
|
|
|
|
src: UInt = UInt(0),
|
|
|
|
dst: UInt = UInt(0)): DecoupledIO[LogicalNetworkIO[T]] = {
|
2015-07-16 03:06:27 +02:00
|
|
|
val out = Decoupled(new LogicalNetworkIO(in.bits)).asDirectionless
|
2013-08-14 02:52:53 +02:00
|
|
|
out.valid := in.valid
|
|
|
|
out.bits.payload := in.bits
|
|
|
|
out.bits.header.dst := dst
|
|
|
|
out.bits.header.src := src
|
|
|
|
in.ready := out.ready
|
|
|
|
out
|
2013-07-25 08:22:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:53:49 +01:00
|
|
|
object DecoupledLogicalNetworkIOUnwrapper {
|
2015-04-28 01:59:30 +02:00
|
|
|
def apply[T <: Data](in: DecoupledIO[LogicalNetworkIO[T]]): DecoupledIO[T] = {
|
2015-07-16 03:06:27 +02:00
|
|
|
val out = Decoupled(in.bits.payload).asDirectionless
|
2013-08-14 02:52:53 +02:00
|
|
|
out.valid := in.valid
|
|
|
|
out.bits := in.bits.payload
|
|
|
|
in.ready := out.ready
|
|
|
|
out
|
2013-07-25 08:22:36 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-28 01:59:30 +02:00
|
|
|
|
|
|
|
object DefaultFromPhysicalShim {
|
|
|
|
def apply[T <: Data](in: DecoupledIO[PhysicalNetworkIO[T]]): DecoupledIO[LogicalNetworkIO[T]] = {
|
|
|
|
val out = Decoupled(new LogicalNetworkIO(in.bits.payload)).asDirectionless
|
|
|
|
out.bits.header := in.bits.header
|
|
|
|
out.bits.payload := in.bits.payload
|
|
|
|
out.valid := in.valid
|
|
|
|
in.ready := out.ready
|
|
|
|
out
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object DefaultToPhysicalShim {
|
|
|
|
def apply[T <: Data](n: Int, in: DecoupledIO[LogicalNetworkIO[T]]): DecoupledIO[PhysicalNetworkIO[T]] = {
|
|
|
|
val out = Decoupled(new PhysicalNetworkIO(n, in.bits.payload)).asDirectionless
|
|
|
|
out.bits.header := in.bits.header
|
|
|
|
out.bits.payload := in.bits.payload
|
|
|
|
out.valid := in.valid
|
|
|
|
in.ready := out.ready
|
|
|
|
out
|
|
|
|
}
|
|
|
|
}
|