1
0

diplomacy: add RWXC permissions also to ResourceMappings

This commit is contained in:
Wesley W. Terpstra 2017-06-28 14:07:40 -07:00
parent 5436be54ff
commit bca3db0866
4 changed files with 12 additions and 10 deletions

View File

@ -118,14 +118,15 @@ trait CoreplexNetworkModule extends HasCoreplexParameters {
private def collect(path: List[String], value: ResourceValue): List[(String, ResourceAddress)] = { private def collect(path: List[String], value: ResourceValue): List[(String, ResourceAddress)] = {
value match { value match {
case r: ResourceAddress => List((path(1), r)) case r: ResourceAddress => List((path(1), r))
case b: ResourceMapping => List((path(1), ResourceAddress(b.address, b.permissions)))
case ResourceMap(value, _) => value.toList.flatMap { case (key, seq) => seq.flatMap(r => collect(key :: path, r)) } case ResourceMap(value, _) => value.toList.flatMap { case (key, seq) => seq.flatMap(r => collect(key :: path, r)) }
case _ => Nil case _ => Nil
} }
} }
private val ranges = collect(Nil, outer.bindingTree).groupBy(_._2).toList.flatMap { case (key, seq) => private val ranges = collect(Nil, outer.bindingTree).groupBy(_._2).toList.flatMap { case (key, seq) =>
AddressRange.fromSets(key.address).map { r => (r, key.r, key.w, key.x, key.c, seq.map(_._1)) } AddressRange.fromSets(key.address).map { r => (r, key.permissions, seq.map(_._1)) }
}.sortBy(_._1) }.sortBy(_._1)
private val json = ranges.map { case (range, r, w, x, c, names) => private val json = ranges.map { case (range, ResourcePermissions(r, w, x, c), names) =>
println(fmt.format( println(fmt.format(
range.base, range.base,
range.base+range.size, range.base+range.size,

View File

@ -26,12 +26,12 @@ object JSON
} }
private def helper(res: ResourceValue)(implicit path: Map[String, String]): Seq[String] = res match { private def helper(res: ResourceValue)(implicit path: Map[String, String]): Seq[String] = res match {
case ResourceAddress(address, r, w, x, c) => case ResourceAddress(address, ResourcePermissions(r, w, x, c)) =>
AddressRange.fromSets(address).map { case AddressRange(base, size) => AddressRange.fromSets(address).map { case AddressRange(base, size) =>
s"""{"base":${base},"size":${size},"r":${r},"w":${w},"x":${x},"c":${c}}"""} s"""{"base":${base},"size":${size},"r":${r},"w":${w},"x":${x},"c":${c}}"""}
case ResourceMapping(address, offset) => case ResourceMapping(address, offset, ResourcePermissions(r, w, x, c)) =>
AddressRange.fromSets(address).map { case AddressRange(base, size) => AddressRange.fromSets(address).map { case AddressRange(base, size) =>
s"""{"base":${base},"size":${size},"offset":${offset}}"""} s"""{"base":${base},"size":${size},"offset":${offset},"r":${r},"w":${w},"x":${x},"c":${c}}"""}
case ResourceInt(value) => Seq(value.toString) case ResourceInt(value) => Seq(value.toString)
case ResourceString(value) => Seq("\"" + value + "\"") case ResourceString(value) => Seq("\"" + value + "\"")
case ResourceReference(value) => Seq("\"&" + path(value) + "\"") case ResourceReference(value) => Seq("\"&" + path(value) + "\"")

View File

@ -7,8 +7,9 @@ import config._
import scala.collection.immutable.{ListMap,SortedMap} import scala.collection.immutable.{ListMap,SortedMap}
sealed trait ResourceValue sealed trait ResourceValue
final case class ResourceAddress(address: Seq[AddressSet], r: Boolean, w: Boolean, x: Boolean, c: Boolean) extends ResourceValue case class ResourcePermissions(r: Boolean, w: Boolean, x: Boolean, c: Boolean) // Not part of DTS
final case class ResourceMapping(address: Seq[AddressSet], offset: BigInt) extends ResourceValue final case class ResourceAddress(address: Seq[AddressSet], permissions: ResourcePermissions) extends ResourceValue
final case class ResourceMapping(address: Seq[AddressSet], offset: BigInt, permissions: ResourcePermissions) extends ResourceValue
final case class ResourceInt(value: BigInt) extends ResourceValue final case class ResourceInt(value: BigInt) extends ResourceValue
final case class ResourceString(value: String) extends ResourceValue final case class ResourceString(value: String) extends ResourceValue
final case class ResourceReference(value: String) extends ResourceValue final case class ResourceReference(value: String) extends ResourceValue
@ -125,7 +126,7 @@ class SimpleBus(devname: String, devcompat: Seq[String], offset: BigInt = 0) ext
{ {
override def describe(resources: ResourceBindings): Description = { override def describe(resources: ResourceBindings): Description = {
val ranges = resources("ranges").map { val ranges = resources("ranges").map {
case Binding(_, a: ResourceAddress) => ResourceMapping(a.address, offset) case Binding(_, a: ResourceAddress) => ResourceMapping(a.address, offset, a.permissions)
} }
require (!ranges.isEmpty, s"SimpleBus $devname must set ranges") require (!ranges.isEmpty, s"SimpleBus $devname must set ranges")

View File

@ -57,11 +57,11 @@ case class TLManagerParameters(
require (minAlignment >= maxTransfer, s"minAlignment ($minAlignment) must be >= maxTransfer ($maxTransfer)") require (minAlignment >= maxTransfer, s"minAlignment ($minAlignment) must be >= maxTransfer ($maxTransfer)")
def toResource: ResourceAddress = { def toResource: ResourceAddress = {
ResourceAddress(address, ResourceAddress(address, ResourcePermissions(
r = supportsAcquireB || supportsGet, r = supportsAcquireB || supportsGet,
w = supportsAcquireT || supportsPutFull, w = supportsAcquireT || supportsPutFull,
x = executable, x = executable,
c = supportsAcquireB) c = supportsAcquireB))
} }
} }