Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle definition #3

Merged
merged 6 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/out/
/.idea/
/.bsp/
117 changes: 117 additions & 0 deletions tilelink/src/bundle/MessageTypes.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// SPDX-License-Identifier: Apache-2.0

package org.chipsalliance.tilelink
package bundle
OceanS2000 marked this conversation as resolved.
Show resolved Hide resolved

import chisel3._
import chisel3.internal.firrtl.Width

/** opcode field of TileLink messages
*
* cf. TileLink Spec 1.9.3 Table 12
*/
object OpCode {
protected[tilelink] val width: Width = 3.W

val PutFullData: UInt = 0.U(width)
val PutPartialData: UInt = 1.U(width)
val ArithmeticData: UInt = 2.U(width)
val LogicalData: UInt = 3.U(width)
val Get: UInt = 4.U(width)
val Intent: UInt = 5.U(width)
val AcquireBlock: UInt = 6.U(width)
val AcquirePerm: UInt = 7.U(width)
val ProbePerm: UInt = 7.U(width)
val AccessAck: UInt = 0.U(width)
val AccessAckData: UInt = 1.U(width)
val HintAck: UInt = 2.U(width)
val ProbeAck: UInt = 4.U(width)
val ProbeAckData: UInt = 5.U(width)
val Release: UInt = 6.U(width)
val ReleaseData: UInt = 7.U(width)
val Grant: UInt = 4.U(width)
val GrantData: UInt = 5.U(width)
val ProbeBlock: UInt = 6.U(width)
val ReleaseAck: UInt = 6.U(width)
// GrantAck has no Opcode
}

/** param field of TileLink messages
*
* Allowed values are dependent on opcode of the message.
*/
object Param {
protected[tilelink] val width: Width = 3.W

/** Reserved param fields (e.g. a_param in Get message) should be tied to zero
*/
def tieZero: UInt = 0.U(width)

/** param field for ArithmeticData
* TileLink Spec 1.9.3 Table 23
*/
object Arithmetic {
val MIN: UInt = 0.U(width)
val MAX: UInt = 1.U(width)
val MINU: UInt = 2.U(width)
val MAXU: UInt = 3.U(width)
val ADD: UInt = 4.U(width)
}

/** param field for LogicalData
* TileLink Spec 1.9.3 Table 25
*/
object Logical {
val XOR: UInt = 0.U(width)
val OR: UInt = 1.U(width)
val AND: UInt = 2.U(width)
val SWAP: UInt = 3.U(width)
}

/** param field for Intent
* TileLink Spec 1.9.3 Table 27
*/
object Intent {
val PrefetchRead: UInt = 0.U(width)
val PrefetchWrite: UInt = 1.U(width)
val CBOInval: UInt = 5.U(width)
val CBOClean: UInt = 6.U(width)
val CBOFlush: UInt = 7.U(width)
}

/** permissions transitions encodings for Cap
* TileLink Spec 1.9.3 Table 31
*/
object Cap {
val toT: UInt = 0.U(width)
val toB: UInt = 1.U(width)
val toN: UInt = 2.U(width)
}

/** permissions transitions encodings for Grow
* TileLink Spec 1.9.3 Table 31
*/
object Grow {
val NtoB: UInt = 0.U(width)
val NtoT: UInt = 1.U(width)
val BtoT: UInt = 2.U(width)
}

/** permissions transitions encodings for Prune
* TileLink Spec 1.9.3 Table 31
*/
object Prune {
val TtoB: UInt = 0.U(width)
val TtoN: UInt = 1.U(width)
val BtoN: UInt = 2.U(width)
}

/** permissions transitions encodings for Report
* TileLink Spec 1.9.3 Table 31
*/
object Report {
val TtoT: UInt = 3.U(width)
val BtoB: UInt = 4.U(width)
val NtoN: UInt = 5.U(width)
}
}
12 changes: 12 additions & 0 deletions tilelink/src/bundle/NoTLCException.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: Apache-2.0

package org.chipsalliance.tilelink
package bundle
OceanS2000 marked this conversation as resolved.
Show resolved Hide resolved

import chisel3.ChiselException
private class NoTLCException(
channel: String,
linkParameter: TLLinkParameter)
extends ChiselException(
s"call $channel in TLLink is not present in a TL-UL or TL-UH bus:\n $linkParameter"
)
60 changes: 60 additions & 0 deletions tilelink/src/bundle/TLChannel.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: Apache-2.0

package org.chipsalliance.tilelink
package bundle
OceanS2000 marked this conversation as resolved.
Show resolved Hide resolved

import chisel3._

trait TLChannel extends Bundle {
val parameter: TLChannelParameter
}

class TLChannelA(val parameter: TileLinkChannelAParameter) extends TLChannel {
private val maskWidth = parameter.dataWidth / 8
// NOTE: this field is called a_code in TileLink spec version 1.9.3 p. 16, which is probably a typo
val opcode: UInt = UInt(OpCode.width)
val param: UInt = UInt(Param.width)
val size: UInt = UInt(parameter.sizeWidth.W)
val source: UInt = UInt(parameter.sourceWidth.W)
val address: UInt = UInt(parameter.addressWidth.W)
val mask: UInt = UInt(maskWidth.W)
val data: UInt = UInt(parameter.dataWidth.W)
val corrupt: Bool = Bool()
}

class TLChannelB(val parameter: TileLinkChannelBParameter) extends TLChannel {
private val maskWidth = parameter.dataWidth / 8
val opcode: UInt = UInt(OpCode.width)
val param: UInt = UInt(Param.width)
val size: UInt = UInt(parameter.sizeWidth.W)
val source: UInt = UInt(parameter.sourceWidth.W)
val address: UInt = UInt(parameter.addressWidth.W)
val mask: UInt = UInt(maskWidth.W)
val data: UInt = UInt(parameter.dataWidth.W)
val corrupt: Bool = Bool()
}

class TLChannelC(val parameter: TileLinkChannelCParameter) extends TLChannel {
val opcode: UInt = UInt(OpCode.width)
val param: UInt = UInt(Param.width)
val size: UInt = UInt(parameter.sizeWidth.W)
val source: UInt = UInt(parameter.sourceWidth.W)
val address: UInt = UInt(parameter.addressWidth.W)
val data: UInt = UInt(parameter.dataWidth.W)
val corrupt: Bool = Bool()
}

class TLChannelD(val parameter: TileLinkChannelDParameter) extends TLChannel {
val opcode: UInt = UInt(OpCode.width)
val param: UInt = UInt(Param.width)
val size: UInt = UInt(parameter.sizeWidth.W)
val source: UInt = UInt(parameter.sourceWidth.W)
val sink: UInt = UInt(parameter.sinkWidth.W)
val denied: Bool = Bool()
val data: UInt = UInt(parameter.dataWidth.W)
val corrupt: Bool = Bool()
}

class TLChannelE(val parameter: TileLinkChannelEParameter) extends TLChannel {
val sink: UInt = UInt(parameter.sinkWidth.W)
}
117 changes: 117 additions & 0 deletions tilelink/src/bundle/TLChannelParameter.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// SPDX-License-Identifier: Apache-2.0

package org.chipsalliance.tilelink
package bundle
OceanS2000 marked this conversation as resolved.
Show resolved Hide resolved

import chisel3.util.isPow2

import upickle.default.{macroRW, ReadWriter => RW}

sealed trait TLChannelParameter

object TLChannelParameter {
implicit val rw: RW[TLChannelParameter] = RW.merge(
TileLinkChannelAParameter.rw,
TileLinkChannelBParameter.rw,
TileLinkChannelCParameter.rw,
TileLinkChannelDParameter.rw,
TileLinkChannelEParameter.rw
)

def bundle(p: TLChannelParameter): TLChannel = {
p match {
case a: TileLinkChannelAParameter => new TLChannelA(a)
case b: TileLinkChannelBParameter => new TLChannelB(b)
case c: TileLinkChannelCParameter => new TLChannelC(c)
case d: TileLinkChannelDParameter => new TLChannelD(d)
case e: TileLinkChannelEParameter => new TLChannelE(e)
}
}
}

case class TileLinkChannelAParameter(
addressWidth: Int,
sourceWidth: Int,
dataWidth: Int,
sizeWidth: Int)
extends TLChannelParameter {
require(addressWidth > 0)
require(sourceWidth > 0)
require(dataWidth > 0)
require(sizeWidth > 0)
require(dataWidth % 8 == 0, "Width of data field must be multiples of 8")
require(
isPow2(dataWidth / 8),
"Width of data field in bytes must be power of 2"
)
}
object TileLinkChannelAParameter {
implicit val rw: RW[TileLinkChannelAParameter] = macroRW
}

case class TileLinkChannelBParameter(
addressWidth: Int,
sourceWidth: Int,
dataWidth: Int,
sizeWidth: Int)
extends TLChannelParameter {
require(addressWidth > 0)
require(sourceWidth > 0)
require(dataWidth > 0)
require(sizeWidth > 0)
require(dataWidth % 8 == 0, "Width of data field must be multiples of 8")
require(
isPow2(dataWidth / 8),
"Width of data field in bytes must be power of 2"
)
}
object TileLinkChannelBParameter {
implicit val rw: RW[TileLinkChannelBParameter] = macroRW
}

case class TileLinkChannelCParameter(
addressWidth: Int,
sourceWidth: Int,
dataWidth: Int,
sizeWidth: Int)
extends TLChannelParameter {
require(addressWidth > 0)
require(sourceWidth > 0)
require(dataWidth > 0)
require(sizeWidth > 0)
require(dataWidth % 8 == 0, "Width of data field must be multiples of 8")
require(
isPow2(dataWidth / 8),
"Width of data field in bytes must be power of 2"
)
}
object TileLinkChannelCParameter {
implicit val rw: RW[TileLinkChannelCParameter] = macroRW
}

case class TileLinkChannelDParameter(
sourceWidth: Int,
sinkWidth: Int,
dataWidth: Int,
sizeWidth: Int)
extends TLChannelParameter {
require(sourceWidth > 0)
require(sinkWidth > 0)
require(dataWidth > 0)
require(sizeWidth > 0)
require(dataWidth % 8 == 0, "Width of data field must be multiples of 8")
require(
isPow2(dataWidth / 8),
"Width of data field in bytes must be power of 2"
)
}
object TileLinkChannelDParameter {
implicit val rw: RW[TileLinkChannelDParameter] = macroRW
}

case class TileLinkChannelEParameter(sinkWidth: Int) extends TLChannelParameter {
require(sinkWidth > 0)
}
object TileLinkChannelEParameter {
implicit val rw: RW[TileLinkChannelEParameter] = macroRW
}
Loading