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._
|
|
|
|
import junctions._
|
|
|
|
import junctions.NastiConstants._
|
2016-10-04 00:17:36 +02:00
|
|
|
import regmapper._
|
2016-09-15 03:09:27 +02:00
|
|
|
import uncore.tilelink2._
|
2016-09-02 23:48:16 +02:00
|
|
|
import uncore.util._
|
2016-09-28 06:27:07 +02:00
|
|
|
import 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-09-16 23:26:34 +02:00
|
|
|
class CoreplexLocalInterrupts extends Bundle {
|
|
|
|
val mtip = Bool()
|
|
|
|
val msip = Bool()
|
2016-05-03 02:49:10 +02:00
|
|
|
}
|
|
|
|
|
2016-10-27 02:48:15 +02:00
|
|
|
case class CoreplexLocalInterrupterConfig(address: BigInt = 0x02000000) {
|
2016-09-16 23:26:34 +02:00
|
|
|
def msipOffset(hart: Int) = hart * msipBytes
|
|
|
|
def msipAddress(hart: Int) = address + msipOffset(hart)
|
|
|
|
def timecmpOffset(hart: Int) = 0x4000 + hart * timecmpBytes
|
|
|
|
def timecmpAddress(hart: Int) = address + timecmpOffset(hart)
|
|
|
|
def timeOffset = 0xbff8
|
|
|
|
def timeAddress = address + timeOffset
|
2016-06-28 08:05:48 +02:00
|
|
|
def msipBytes = 4
|
|
|
|
def timecmpBytes = 8
|
2016-09-16 23:26:34 +02:00
|
|
|
def size = 0x10000
|
2016-06-28 08:05:48 +02:00
|
|
|
}
|
|
|
|
|
2016-09-16 23:26:34 +02:00
|
|
|
trait MixCoreplexLocalInterrupterParameters {
|
|
|
|
val params: (CoreplexLocalInterrupterConfig, Parameters)
|
2016-09-15 03:09:27 +02:00
|
|
|
val c = params._1
|
|
|
|
implicit val p = params._2
|
|
|
|
}
|
|
|
|
|
2016-09-16 23:26:34 +02:00
|
|
|
trait CoreplexLocalInterrupterBundle extends Bundle with MixCoreplexLocalInterrupterParameters {
|
|
|
|
val tiles = Vec(p(NTiles), new CoreplexLocalInterrupts).asOutput
|
2016-09-15 03:09:27 +02:00
|
|
|
val rtcTick = Bool(INPUT)
|
|
|
|
}
|
|
|
|
|
2016-09-16 23:26:34 +02:00
|
|
|
trait CoreplexLocalInterrupterModule extends Module with HasRegMap with MixCoreplexLocalInterrupterParameters {
|
|
|
|
val io: CoreplexLocalInterrupterBundle
|
2016-05-03 02:49:10 +02:00
|
|
|
|
2016-06-28 08:05:48 +02:00
|
|
|
val timeWidth = 64
|
2016-09-21 00:00:52 +02:00
|
|
|
val regWidth = 32
|
2016-06-28 08:05:48 +02:00
|
|
|
|
2016-09-21 00:00:52 +02:00
|
|
|
val time = Seq.fill(timeWidth/regWidth)(Reg(init=UInt(0, width = regWidth)))
|
|
|
|
when (io.rtcTick) {
|
2016-09-29 01:10:32 +02:00
|
|
|
val newTime = time.asUInt + UInt(1)
|
2016-09-21 00:00:52 +02:00
|
|
|
for ((reg, i) <- time zip (0 until timeWidth by regWidth))
|
|
|
|
reg := newTime >> i
|
|
|
|
}
|
|
|
|
|
|
|
|
val timecmp = Seq.fill(p(NTiles)) { Seq.fill(timeWidth/regWidth)(Reg(UInt(width = regWidth))) }
|
|
|
|
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-09-16 23:26:34 +02:00
|
|
|
tile.msip := ipi(i)(0)
|
2016-09-21 00:00:52 +02:00
|
|
|
tile.mtip := time.asUInt >= timecmp(i).asUInt
|
2016-06-06 08:06:21 +02:00
|
|
|
}
|
2016-06-28 08:05:48 +02:00
|
|
|
|
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-23 04:49:29 +02:00
|
|
|
|
|
|
|
regmap(
|
|
|
|
0 -> makeRegFields(ipi),
|
|
|
|
c.timecmpOffset(0) -> makeRegFields(timecmp.flatten),
|
|
|
|
c.timeOffset -> makeRegFields(time))
|
2016-09-21 00:00:52 +02:00
|
|
|
|
|
|
|
def makeRegFields(s: Seq[UInt]) = s.map(r => RegField(regWidth, r))
|
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 23:26:34 +02:00
|
|
|
class CoreplexLocalInterrupter(c: CoreplexLocalInterrupterConfig)(implicit val p: Parameters)
|
2016-10-27 02:48:15 +02:00
|
|
|
extends TLRegisterRouter(c.address, size = c.size, beatBytes = p(rocket.XLen)/8, undefZero = false)(
|
2016-09-16 23:26:34 +02:00
|
|
|
new TLRegBundle((c, p), _) with CoreplexLocalInterrupterBundle)(
|
|
|
|
new TLRegModule((c, p), _, _) with CoreplexLocalInterrupterModule)
|