# RV_PLIC register template
#
# Parameter (given by python tool)
#  - src:    Number of Interrupt Sources
#  - target: Number of Targets that handle interrupt requests
#  - prio:   Max value of interrupt priorities
{
  name: "RV_PLIC",
  clock_primary: "clk_fixed",
  bus_device: "tlul",
  regwidth: "32",
  registers: [
    { multireg: {
        name: "IP",
        desc: "Interrupt Pending",
        count: ${src},
        cname: "RV_PLIC",
        swaccess: "ro",
        hwaccess: "hwo",
        fields: [
          { bits: "0", name: "P", desc: "Interrupt Pending of Source" }
        ],
      }
    },
    { multireg: {
        name: "LE",
        desc: "Interrupt Source mode. 0: Level, 1: Edge-triggered",
        count: ${src},
        cname: "RV_PLIC",
        swaccess: "rw",
        hwaccess: "hro",
        fields: [
          { bits: "0", name: "LE", desc: "L0E1" }
        ],
      }
    },
% for i in range(src):
    { name: "PRIO${i}",
      desc: "Interrupt Source ${i} Priority",
      swaccess: "rw",
      hwaccess: "hro",
      fields: [
        { bits: "${(prio).bit_length()-1}:0" }
      ],
    }
% endfor
% for i in range(target):
    { multireg: {
        name: "IE${i}",
        desc: "Interrupt Enable for Target ${i}",
        count: ${src},
        cname: "RV_PLIC",
        swaccess: "rw",
        hwaccess: "hro",
        fields: [
          { bits: "0", name: "E", desc: "Interrupt Enable of Source" }
        ],
      }
    }
% endfor
% for i in range(target):
    { name: "THRESHOLD${i}",
      desc: "Threshold of priority for Target ${i}",
      swaccess: "rw",
      hwaccess: "hro",
      fields: [
        { bits: "${(prio).bit_length()-1}:0" }
      ],
    }
% endfor
% for i in range(target):
    { name: "CC${i}",
      desc: "Claim by read, complete by write for Target ${i}",
      swaccess: "rw",
      hwaccess: "hrw",
      hwext: "true",
      hwqe: "true",
      hwre: "true",
      fields: [
        { bits: "${(src).bit_length()-1}:0" }
      ],
    }
% endfor
  ],
}
