Skip to content

Commit

Permalink
Support breaking out ChipTop I/O out of the expected bundle type
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryz123 committed Oct 31, 2023
1 parent a5597fd commit 3fa3d74
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 77 deletions.
2 changes: 1 addition & 1 deletion fpga/src/main/scala/arty/IOBinders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class WithDebugResetPassthrough extends ComposeIOBinder({
val io_sjtag_reset: Bool = IO(Input(Bool())).suggestName("sjtag_reset")
sjtag.reset := io_sjtag_reset

(Seq(DebugResetPort(io_ndreset), JTAGResetPort(io_sjtag_reset)), Nil)
(Seq(DebugResetPort(() => io_ndreset), JTAGResetPort(() => io_sjtag_reset)), Nil)
}
})
4 changes: 2 additions & 2 deletions fpga/src/main/scala/vcu118/bringup/IOBinders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import testchipip.{HasPeripheryTSIHostWidget, TSIHostWidgetIO}

import chipyard.iobinders.{OverrideIOBinder, Port, TLMemPort}

case class TSIHostWidgetPort(val io: TSIHostWidgetIO)
case class TSIHostWidgetPort(val getIO: () => TSIHostWidgetIO)
extends Port[TSIHostWidgetIO]

class WithTSITLIOPassthrough extends OverrideIOBinder({
Expand All @@ -25,6 +25,6 @@ class WithTSITLIOPassthrough extends OverrideIOBinder({
require(system.tsiSerial.size == 1)
val io_tsi_serial_pins_temp = IO(DataMirror.internal.chiselTypeClone[TSIHostWidgetIO](system.tsiSerial.head)).suggestName("tsi_serial")
io_tsi_serial_pins_temp <> system.tsiSerial.head
(Seq(TLMemPort(io_tsi_tl_mem_pins_temp), TSIHostWidgetPort(io_tsi_serial_pins_temp)), Nil)
(Seq(TLMemPort(() => io_tsi_tl_mem_pins_temp), TSIHostWidgetPort(() => io_tsi_serial_pins_temp)), Nil)
}
})
4 changes: 2 additions & 2 deletions generators/chipyard/src/main/scala/ChipTop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import freechips.rocketchip.prci.{ClockGroupIdentityNode, ClockSinkParameters, C
import freechips.rocketchip.subsystem.{BaseSubsystem, SubsystemDriveAsyncClockGroupsKey}
import org.chipsalliance.cde.config.{Parameters, Field}
import freechips.rocketchip.diplomacy.{LazyModule, LazyModuleImp, LazyRawModuleImp, LazyModuleImpLike, BindingScope}
import freechips.rocketchip.util.{ResetCatchAndSync}
import freechips.rocketchip.util.{DontTouch}
import chipyard.iobinders._

import barstools.iocell.chisel._
Expand All @@ -31,5 +31,5 @@ class ChipTop(implicit p: Parameters) extends LazyModule with BindingScope
// of ChipTop (ex: ClockGroup) do not receive clock or reset.
// However. anonymous children of ChipTop should not need an implicit Clock or Reset
// anyways, they probably need to be explicitly clocked.
lazy val module: LazyModuleImpLike = new LazyRawModuleImp(this) { }
lazy val module: LazyModuleImpLike = new LazyRawModuleImp(this) with DontTouch { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ class WithPLLSelectorDividerClockGenerator extends OverrideLazyIOBinder({
o.reset := reset_wire
}

(Seq(ClockPort(clock_io, 100), ResetPort(reset_io)), clockIOCell ++ resetIOCell)
(Seq(ClockPort(() => clock_io, 100), ResetPort(() => reset_io)), clockIOCell ++ resetIOCell)
}
}
})

// This passes all clocks through to the TestHarness
class WithPassthroughClockGenerator extends OverrideLazyIOBinder({
(system: HasChipyardPRCI) => {
Expand Down Expand Up @@ -113,9 +113,9 @@ class WithPassthroughClockGenerator extends OverrideLazyIOBinder({
val clock_io = IO(Input(Clock())).suggestName(s"clock_${m.name.get}")
b.clock := clock_io
b.reset := reset_io
ClockPort(clock_io, freq)
ClockPort(() => clock_io, freq)
}.toSeq
((clock_ios :+ ResetPort(reset_io)), Nil)
((clock_ios :+ ResetPort(() => reset_io)), Nil)
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import freechips.rocketchip.diplomacy.{AsynchronousCrossing}

// DOC include start: FFTRocketConfig
class FFTRocketConfig extends Config(
new chipyard.iobinders.WithDontTouchIOBinders(false) ++ // TODO: hack around dontTouch not working in SFC
new chipyard.harness.WithDontTouchChipTopPorts(false) ++ // TODO: hack around dontTouch not working in SFC
new fftgenerator.WithFFTGenerator(numPoints=8, width=16, decPt=8) ++ // add 8-point mmio fft at the default addr (0x2400) with 16bit fixed-point numbers.
new freechips.rocketchip.subsystem.WithNBigCores(1) ++
new chipyard.config.AbstractConfig)
Expand Down Expand Up @@ -59,7 +59,7 @@ class LargeNVDLARocketConfig extends Config(
new chipyard.config.AbstractConfig)

class ManyMMIOAcceleratorRocketConfig extends Config(
new chipyard.iobinders.WithDontTouchIOBinders(false) ++ // TODO: hack around dontTouch not working in SFC
new chipyard.harness.WithDontTouchChipTopPorts(false) ++ // TODO: hack around dontTouch not working in SFC
new fftgenerator.WithFFTGenerator(numPoints=8, width=16, decPt=8) ++ // add 8-point mmio fft at the default addr (0x2400) with 16bit fixed-point numbers.
new chipyard.example.WithStreamingPassthrough ++ // use top with tilelink-controlled streaming passthrough
new chipyard.example.WithStreamingFIR ++ // use top with tilelink-controlled streaming FIR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class RocketConfig extends Config(
new chipyard.config.AbstractConfig)

class TinyRocketConfig extends Config(
new chipyard.iobinders.WithDontTouchIOBinders(false) ++ // TODO FIX: Don't dontTouch the ports
new chipyard.harness.WithDontTouchChipTopPorts(false) ++ // TODO FIX: Don't dontTouch the ports
new freechips.rocketchip.subsystem.WithIncoherentBusTopology ++ // use incoherent bus topology
new freechips.rocketchip.subsystem.WithNBanks(0) ++ // remove L2$
new freechips.rocketchip.subsystem.WithNoMemPort ++ // remove backing memory
Expand Down Expand Up @@ -97,6 +97,7 @@ class MulticlockRocketConfig extends Config(
new chipyard.config.AbstractConfig)

class CustomIOChipTopRocketConfig extends Config(
new chipyard.example.WithBrokenOutUARTIO ++
new chipyard.example.WithCustomChipTop ++
new chipyard.example.WithCustomIOCells ++
new freechips.rocketchip.subsystem.WithNBigCores(1) ++ // single rocket-core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class TutorialSha3BlackBoxConfig extends Config(

// Tutorial Phase 5: Map a multicore heterogeneous SoC with multiple cores and memory-mapped accelerators
class TutorialNoCConfig extends Config(
new chipyard.iobinders.WithDontTouchIOBinders(false) ++
new chipyard.harness.WithDontTouchChipTopPorts(false) ++
// Try changing the dimensions of the Mesh topology
new constellation.soc.WithGlobalNoC(constellation.soc.GlobalNoCParams(
NoCParams(
Expand Down
20 changes: 20 additions & 0 deletions generators/chipyard/src/main/scala/example/CustomChipTop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import chipyard.iobinders._

import org.chipsalliance.cde.config._
import freechips.rocketchip.diplomacy.{InModuleBody}
import freechips.rocketchip.subsystem.{PBUS, HasTileLinkLocations}
import barstools.iocell.chisel._
import chipyard._
import chipyard.harness.{BuildTop}
import sifive.blocks.devices.uart._

// A "custom" IOCell with additional I/O
// The IO don't do anything here in this example
Expand Down Expand Up @@ -63,3 +65,21 @@ class WithCustomIOCells extends Config((site, here, up) => {
class WithCustomChipTop extends Config((site, here, up) => {
case BuildTop => (p: Parameters) => new CustomChipTop()(p)
})

class WithBrokenOutUARTIO extends OverrideIOBinder({
(system: HasPeripheryUARTModuleImp) => {
val uart_txd = IO(Output(Bool()))
val uart_rxd = IO(Input(Bool()))
system.uart(0).rxd := uart_rxd
uart_txd := system.uart(0).txd
val where = PBUS // TODO fix
val bus = system.outer.asInstanceOf[HasTileLinkLocations].locateTLBusWrapper(where)
val freqMHz = bus.dtsFrequency.get / 1000000
(Seq(UARTPort(() => {
val uart_wire = Wire(new UARTPortIO(system.uart(0).c))
uart_wire.txd := uart_txd
uart_rxd := uart_wire.rxd
uart_wire
}, 0, freqMHz.toInt)), Nil)
}
})
12 changes: 6 additions & 6 deletions generators/chipyard/src/main/scala/example/FlatChipTop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class FlatChipTop(implicit p: Parameters) extends LazyModule with HasChipyardPor
o.reset := reset_wire
}

ports = ports :+ ClockPort(clock_pad, 100.0)
ports = ports :+ ResetPort(reset_pad)
ports = ports :+ ClockPort(() => clock_pad, 100.0)
ports = ports :+ ResetPort(() => reset_pad)

// For a real chip you should replace this ClockSourceAtFreqFromPlusArg
// with a blackbox of whatever PLL is being integrated
Expand All @@ -104,13 +104,13 @@ class FlatChipTop(implicit p: Parameters) extends LazyModule with HasChipyardPor
// Custom Boot
//=========================
val (custom_boot_pad, customBootIOCell) = IOCell.generateIOFromSignal(system.custom_boot_pin.get.getWrappedValue, "custom_boot", p(IOCellKey))
ports = ports :+ CustomBootPort(custom_boot_pad)
ports = ports :+ CustomBootPort(() => custom_boot_pad)

//=========================
// Serialized TileLink
//=========================
val (serial_tl_pad, serialTLIOCells) = IOCell.generateIOFromSignal(system.serial_tl.get.getWrappedValue, "serial_tl", p(IOCellKey))
ports = ports :+ SerialTLPort(serial_tl_pad, p(SerialTLKey).get, system.serdesser.get, 0)
ports = ports :+ SerialTLPort(() => serial_tl_pad, p(SerialTLKey).get, system.serdesser.get, 0)

//=========================
// JTAG/Debug
Expand Down Expand Up @@ -149,7 +149,7 @@ class FlatChipTop(implicit p: Parameters) extends LazyModule with HasChipyardPor
IOCell.generateIOFromSignal(jtag_wire, "jtag", p(IOCellKey), abstractResetAsAsync = true)
}.get

ports = ports :+ JTAGPort(jtag_pad)
ports = ports :+ JTAGPort(() => jtag_pad)

//==========================
// UART
Expand All @@ -159,7 +159,7 @@ class FlatChipTop(implicit p: Parameters) extends LazyModule with HasChipyardPor
val where = PBUS // TODO fix
val bus = system.asInstanceOf[HasTileLinkLocations].locateTLBusWrapper(where)
val freqMHz = bus.dtsFrequency.get / 1000000
ports = ports :+ UARTPort(uart_pad, 0, freqMHz.toInt)
ports = ports :+ UARTPort(() => uart_pad, 0, freqMHz.toInt)

//==========================
// External interrupts (tie off)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import chisel3._
import scala.collection.mutable.{ArrayBuffer, LinkedHashMap}
import freechips.rocketchip.diplomacy.{LazyModule}
import org.chipsalliance.cde.config.{Field, Parameters, Config}
import freechips.rocketchip.util.{ResetCatchAndSync}
import freechips.rocketchip.util.{ResetCatchAndSync, DontTouch}
import freechips.rocketchip.prci.{ClockBundle, ClockBundleParameters, ClockSinkParameters, ClockParameters}
import chipyard.stage.phases.TargetDirKey

Expand All @@ -24,6 +24,7 @@ case object BuildTop extends Field[Parameters => LazyModule]((p: Parameters) =>
case object HarnessClockInstantiatorKey extends Field[() => HarnessClockInstantiator]()
case object HarnessBinderClockFrequencyKey extends Field[Double](100.0) // MHz
case object MultiChipIdx extends Field[Int](0)
case object DontTouchChipTopPorts extends Field[Boolean](true)

class WithMultiChip(id: Int, p: Parameters) extends Config((site, here, up) => {
case MultiChipParameters(`id`) => p
Expand All @@ -39,6 +40,10 @@ class WithHarnessBinderClockFreqMHz(freqMHz: Double) extends Config((site, here,
case HarnessBinderClockFrequencyKey => freqMHz
})

class WithDontTouchChipTopPorts(b: Boolean = true) extends Config((site, here, up) => {
case DontTouchChipTopPorts => b
})

// A TestHarness mixing this in will
// - use the HarnessClockInstantiator clock provide
trait HasHarnessInstantiators {
Expand Down Expand Up @@ -83,12 +88,18 @@ trait HasHarnessInstantiators {

withClockAndReset (harnessBinderClock, harnessBinderReset) {
lazyDuts.zipWithIndex.foreach {
case (d: HasChipyardPorts, i: Int) => ApplyHarnessBinders(this, d.ports)(chipParameters(i))
case (d: HasChipyardPorts, i: Int) => {
ApplyHarnessBinders(this, d.ports)(chipParameters(i))
}
case _ =>
}
ApplyMultiHarnessBinders(this, lazyDuts)
}

duts.map(_ match {
case d: DontTouch => d.dontTouchPorts()
})

val harnessBinderClk = harnessClockInstantiator.requestClockMHz("harnessbinder_clock", getHarnessBinderClockFreqMHz)
println(s"Harness binder clock is $harnessBinderClockFreq")
harnessBinderClock := harnessBinderClk
Expand Down
Loading

0 comments on commit 3fa3d74

Please sign in to comment.