forked from rarias/nixos-riscv
Add claim support in plictool
This commit is contained in:
@@ -8,9 +8,10 @@
|
||||
* v0.0.1 (2024-09-03): Initial version.
|
||||
* v0.0.2 (2024-09-04): Print contexts in another line and masked information.
|
||||
* v0.0.3 (2024-09-04): Make output format more clear and add manual.
|
||||
* v0.0.4 (2024-09-30): Implement support for claiming an interrupt.
|
||||
*/
|
||||
|
||||
#define VERSION "v0.0.3"
|
||||
#define VERSION "v0.0.4"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -21,10 +22,12 @@
|
||||
#include <sys/mman.h>
|
||||
#include <errno.h>
|
||||
|
||||
enum op { DUMP, CLAIM } operation = DUMP;
|
||||
const char *plic_address_str = "0x40800000";
|
||||
long ncontexts = 15872L;
|
||||
long maxsources = 1024L;
|
||||
long nsources = 1024L;
|
||||
long claim_ctx = 0;
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
@@ -34,7 +37,7 @@ usage(void)
|
||||
" plictool - dump PLIC information\n"
|
||||
"\n"
|
||||
"SYNOPSIS\n"
|
||||
" plictool [-a addr] [-s nsources] [-c ncontexts]\n"
|
||||
" plictool [-a addr] [-s nsources] [-c ncontexts] [-C ctx]\n"
|
||||
"\n"
|
||||
"DESCRIPTION\n"
|
||||
" Dumps information about the RISC-V PLIC interrupt controller.\n"
|
||||
@@ -49,6 +52,8 @@ usage(void)
|
||||
" -c ncontexts Limit the number of contexts to print.\n"
|
||||
" The default is 15872.\n"
|
||||
"\n"
|
||||
" -C ctx Claim the interrupt on the given context.\n"
|
||||
"\n"
|
||||
"OUTPUT FORMAT\n"
|
||||
" Information is printed for each source that has some bit set\n"
|
||||
" in the pending or priority registers, or it has some context\n"
|
||||
@@ -75,7 +80,31 @@ usage(void)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void dump_sources(void *base)
|
||||
static uint32_t
|
||||
read_reg(void *base, size_t offset)
|
||||
{
|
||||
volatile uint32_t *p = base + offset;
|
||||
return *p;
|
||||
}
|
||||
|
||||
static void
|
||||
write_reg(void *base, size_t offset, uint32_t value)
|
||||
{
|
||||
volatile uint32_t *p = base + offset;
|
||||
*p = value;
|
||||
}
|
||||
|
||||
static void
|
||||
claim_interrupt(void *base, long ctx)
|
||||
{
|
||||
size_t offset = 0x200004L + ctx * 0x1000;
|
||||
uint32_t value = read_reg(base, offset);
|
||||
printf("ctx=%ld claim=%u\n", ctx, value);
|
||||
write_reg(base, offset, value);
|
||||
}
|
||||
|
||||
static void
|
||||
dump_sources(void *base)
|
||||
{
|
||||
for (long s = 0; s < nsources; s++) {
|
||||
int printed_source = 0;
|
||||
@@ -133,7 +162,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
int opt;
|
||||
|
||||
while ((opt = getopt(argc, argv, "a:hs:c:")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "a:hs:c:C:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'a':
|
||||
plic_address_str = optarg;
|
||||
@@ -144,6 +173,10 @@ int main(int argc, char *argv[])
|
||||
case 'c':
|
||||
ncontexts = atol(optarg);
|
||||
break;
|
||||
case 'C':
|
||||
operation = CLAIM;
|
||||
claim_ctx = atol(optarg);
|
||||
break;
|
||||
case 'h':
|
||||
default: /* '?' */
|
||||
usage();
|
||||
@@ -177,7 +210,10 @@ int main(int argc, char *argv[])
|
||||
exit(1);
|
||||
}
|
||||
|
||||
dump_sources(map_base);
|
||||
if (operation == CLAIM)
|
||||
claim_interrupt(map_base, claim_ctx);
|
||||
else if (operation == DUMP)
|
||||
dump_sources(map_base);
|
||||
|
||||
munmap(map_base, map_size);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user