2016-05-03 00:19:43 +02:00
|
|
|
// See LICENSE for license details.
|
|
|
|
|
2016-06-28 20:21:38 +02:00
|
|
|
package uncore.devices
|
2016-05-03 00:19:43 +02:00
|
|
|
|
|
|
|
import Chisel._
|
2016-09-02 23:48:16 +02:00
|
|
|
import rocket.Util._
|
2016-05-03 00:19:43 +02:00
|
|
|
import junctions._
|
|
|
|
import junctions.NastiConstants._
|
2016-09-15 03:09:27 +02:00
|
|
|
import uncore.tilelink2._
|
2016-09-02 23:48:16 +02:00
|
|
|
import uncore.util._
|
2016-09-16 07:06:39 +02:00
|
|
|
import scala.math.{min,max}
|
2016-05-03 00:19:43 +02:00
|
|
|
import cde.{Parameters, Field}
|
|
|
|
|
|
|
|
/** Number of tiles */
|
|
|
|
case object NTiles extends Field[Int]
|
|
|
|
|
2016-05-03 02:49:10 +02:00
|
|
|
class PRCITileIO(implicit p: Parameters) extends Bundle {
|
2016-05-03 00:19:43 +02:00
|
|
|
val reset = Bool(OUTPUT)
|
2016-09-14 01:25:31 +02:00
|
|
|
val interrupts = new Bundle {
|
|
|
|
val mtip = Bool()
|
|
|
|
val msip = Bool()
|
2016-08-23 19:54:19 +02:00
|
|
|
}
|
2016-05-03 00:19:43 +02:00
|
|
|
|
2016-05-03 02:49:10 +02:00
|
|
|
override def cloneType: this.type = new PRCITileIO().asInstanceOf[this.type]
|
|
|
|
}
|
|
|
|
|
2016-06-28 08:05:48 +02:00
|
|
|
object PRCI {
|
|
|
|
def msip(hart: Int) = hart * msipBytes
|
|
|
|
def timecmp(hart: Int) = 0x4000 + hart * timecmpBytes
|
|
|
|
def time = 0xbff8
|
|
|
|
def msipBytes = 4
|
|
|
|
def timecmpBytes = 8
|
|
|
|
def size = 0xc000
|
|
|
|
}
|
|
|
|
|
2016-09-16 07:06:39 +02:00
|
|
|
case class PRCIConfig(beatBytes: Int, address: BigInt = 0x44000000)
|
2016-09-15 03:09:27 +02:00
|
|
|
|
|
|
|
trait MixPRCIParameters {
|
|
|
|
val params: (PRCIConfig, Parameters)
|
|
|
|
val c = params._1
|
|
|
|
implicit val p = params._2
|
|
|
|
}
|
|
|
|
|
|
|
|
trait PRCIBundle extends Bundle with MixPRCIParameters {
|
|
|
|
val tiles = Vec(p(NTiles), new PRCITileIO)
|
|
|
|
val rtcTick = Bool(INPUT)
|
|
|
|
}
|
|
|
|
|
|
|
|
trait PRCIModule extends Module with HasRegMap with MixPRCIParameters {
|
|
|
|
val io: PRCIBundle
|
2016-05-03 02:49:10 +02:00
|
|
|
|
2016-06-28 08:05:48 +02:00
|
|
|
val timeWidth = 64
|
2016-09-16 07:06:39 +02:00
|
|
|
val time = Reg(init=UInt(0, width = timeWidth))
|
2016-06-28 08:05:48 +02:00
|
|
|
when (io.rtcTick) { time := time + UInt(1) }
|
|
|
|
|
2016-09-15 03:09:27 +02:00
|
|
|
val timecmp = Seq.fill(p(NTiles)) { Reg(UInt(width = timeWidth)) }
|
|
|
|
val ipi = Seq.fill(p(NTiles)) { RegInit(UInt(0, width = 1)) }
|
2016-05-03 02:49:10 +02:00
|
|
|
|
2016-06-06 08:06:21 +02:00
|
|
|
for ((tile, i) <- io.tiles zipWithIndex) {
|
2016-06-28 08:05:48 +02:00
|
|
|
tile.interrupts.msip := ipi(i)(0)
|
|
|
|
tile.interrupts.mtip := time >= timecmp(i)
|
2016-09-14 01:25:31 +02:00
|
|
|
tile.reset := reset
|
2016-06-06 08:06:21 +02:00
|
|
|
}
|
2016-06-28 08:05:48 +02:00
|
|
|
|
2016-09-16 23:19:42 +02:00
|
|
|
def pad = RegField(8) // each use is a new field
|
|
|
|
val ipi_fields = ipi.map(r => Seq(RegField(1, r), RegField(7), pad, pad, pad)).flatten
|
|
|
|
val timecmp_fields = timecmp.map(RegField.bytes(_)).flatten
|
|
|
|
val time_fields = Seq.fill(PRCI.time%c.beatBytes)(pad) ++ RegField.bytes(time)
|
|
|
|
|
2016-09-15 03:09:27 +02:00
|
|
|
/* 0000 msip hart 0
|
|
|
|
* 0004 msip hart 1
|
|
|
|
* 4000 mtimecmp hart 0 lo
|
|
|
|
* 4004 mtimecmp hart 0 hi
|
|
|
|
* 4008 mtimecmp hart 1 lo
|
|
|
|
* 400c mtimecmp hart 1 hi
|
|
|
|
* bff8 mtime lo
|
|
|
|
* bffc mtime hi
|
|
|
|
*/
|
2016-09-16 23:19:42 +02:00
|
|
|
val ipi_base = 0
|
|
|
|
val timecmp_base = PRCI.timecmp(0) / c.beatBytes
|
|
|
|
val time_base = PRCI.time / c.beatBytes
|
|
|
|
|
|
|
|
regmap((
|
|
|
|
RegField.split(ipi_fields, ipi_base, c.beatBytes) ++
|
|
|
|
RegField.split(timecmp_fields, timecmp_base, c.beatBytes) ++
|
|
|
|
RegField.split(time_fields, time_base, c.beatBytes)):_*)
|
2016-05-03 00:19:43 +02:00
|
|
|
}
|
2016-09-15 03:09:27 +02:00
|
|
|
|
|
|
|
/** Power, Reset, Clock, Interrupt */
|
|
|
|
// Magic TL2 Incantation to create a TL2 Slave
|
2016-09-16 07:06:39 +02:00
|
|
|
class PRCI(c: PRCIConfig)(implicit val p: Parameters)
|
|
|
|
extends TLRegisterRouter(c.address, 0, 0x10000, None, c.beatBytes, false)(
|
2016-09-15 03:09:27 +02:00
|
|
|
new TLRegBundle((c, p), _) with PRCIBundle)(
|
|
|
|
new TLRegModule((c, p), _, _) with PRCIModule)
|