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._
|
2015-10-22 03:16:44 +02:00
|
|
|
import cde.{Parameters, Field}
|
2013-07-25 08:22:36 +02:00
|
|
|
|
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-08-06 01:47:49 +02:00
|
|
|
val payload = dType.cloneType
|
2015-07-16 03:06:27 +02:00
|
|
|
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 {
|
2016-01-14 22:47:47 +01:00
|
|
|
val in = Vec(n, Decoupled(new PhysicalNetworkIO(n,dType))).flip
|
|
|
|
val out = Vec(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)
|
|
|
|
|
2016-04-01 22:27:50 +02:00
|
|
|
io.in.foreach { _.ready := Bool(false) }
|
2013-07-25 08:22:36 +02:00
|
|
|
|
2016-04-01 22:27:50 +02:00
|
|
|
io.out.zipWithIndex.map{ case (out, i) => {
|
2014-12-07 11:57:44 +01:00
|
|
|
val rrarb = Module(new LockingRRArbiter(io.in(0).bits, n, count, needsLock))
|
2016-04-01 22:27:50 +02:00
|
|
|
(rrarb.io.in, io.in).zipped.map{ case (arb, in) => {
|
|
|
|
val destined = in.bits.header.dst === UInt(i)
|
|
|
|
arb.valid := in.valid && destined
|
2013-07-25 08:22:36 +02:00
|
|
|
arb.bits := in.bits
|
2016-04-01 22:27:50 +02:00
|
|
|
when (arb.ready && destined) { in.ready := Bool(true) }
|
2013-07-25 08:22:36 +02:00
|
|
|
}}
|
|
|
|
out <> rrarb.io.out
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2014-08-08 21:21:57 +02:00
|
|
|
abstract class LogicalNetwork extends Module
|
2014-01-21 21:20:55 +01:00
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class LogicalHeader(implicit p: Parameters) extends junctions.ParameterizedBundle()(p) {
|
|
|
|
val src = UInt(width = p(LNHeaderBits))
|
|
|
|
val dst = UInt(width = p(LNHeaderBits))
|
2013-07-25 08:22:36 +02:00
|
|
|
}
|
|
|
|
|
2015-10-06 06:41:46 +02:00
|
|
|
class LogicalNetworkIO[T <: Data](dType: T)(implicit p: Parameters) 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
|
2015-10-06 06:41:46 +02:00
|
|
|
override def cloneType = new LogicalNetworkIO(dType)(p).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](
|
2015-10-06 06:41:46 +02:00
|
|
|
in: DecoupledIO[T],
|
|
|
|
src: UInt = UInt(0),
|
|
|
|
dst: UInt = UInt(0))
|
|
|
|
(implicit p: Parameters): DecoupledIO[LogicalNetworkIO[T]] = {
|
2015-07-23 23:58:46 +02:00
|
|
|
val out = Wire(Decoupled(new LogicalNetworkIO(in.bits)))
|
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-10-06 06:41:46 +02:00
|
|
|
def apply[T <: Data](in: DecoupledIO[LogicalNetworkIO[T]])
|
|
|
|
(implicit p: Parameters): DecoupledIO[T] = {
|
2015-07-16 05:24:03 +02:00
|
|
|
val out = Wire(Decoupled(in.bits.payload))
|
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 {
|
2015-10-06 06:41:46 +02:00
|
|
|
def apply[T <: Data](in: DecoupledIO[PhysicalNetworkIO[T]])
|
|
|
|
(implicit p: Parameters): DecoupledIO[LogicalNetworkIO[T]] = {
|
2015-07-23 23:58:46 +02:00
|
|
|
val out = Wire(Decoupled(new LogicalNetworkIO(in.bits.payload)))
|
2015-04-28 01:59:30 +02:00
|
|
|
out.bits.header := in.bits.header
|
|
|
|
out.bits.payload := in.bits.payload
|
|
|
|
out.valid := in.valid
|
|
|
|
in.ready := out.ready
|
|
|
|
out
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object DefaultToPhysicalShim {
|
2015-10-06 06:41:46 +02:00
|
|
|
def apply[T <: Data](n: Int, in: DecoupledIO[LogicalNetworkIO[T]])
|
|
|
|
(implicit p: Parameters): DecoupledIO[PhysicalNetworkIO[T]] = {
|
2015-07-23 23:58:46 +02:00
|
|
|
val out = Wire(Decoupled(new PhysicalNetworkIO(n, in.bits.payload)))
|
2015-04-28 01:59:30 +02:00
|
|
|
out.bits.header := in.bits.header
|
|
|
|
out.bits.payload := in.bits.payload
|
|
|
|
out.valid := in.valid
|
|
|
|
in.ready := out.ready
|
|
|
|
out
|
|
|
|
}
|
|
|
|
}
|