Add claim support in plictool
This commit is contained in:
parent
cae948e923
commit
44a6ef47b8
31
JOURNAL.md
31
JOURNAL.md
@ -4311,3 +4311,34 @@ helpful.
|
||||
For that I need to first switch to the 8250/16550 driver. Let's try switch to
|
||||
the ttyS0 without enabling flow control yet. We probably need to change the
|
||||
stage1 and stage2 scripts to follow the proper console device.
|
||||
|
||||
It works, but very slowly:
|
||||
|
||||
[ 0.000000] Kernel command line: root=/dev/ram0 loglevel=7 rw earlycon=sbi console=ttyS0,115200n8 debug2 ...
|
||||
...
|
||||
[ 42.069358] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
|
||||
[ 42.473860] of_serial 40001000.serial: error -ENXIO: IRQ index 0 not found
|
||||
[ 42.559263] printk: legacy console [ttyS0] disabled
|
||||
[ 42.614225] 40001000.serial: ttyS0 at MMIO 0x40001000 (irq = 0, base_baud = 3125000) is a 16550
|
||||
[ 42.645519] printk: legacy console [ttyS0] enabled
|
||||
[ 42.645519] printk: legacy console [ttyS0] enabled
|
||||
[ 42.656865] printk: legacy bootconsole [sbi0] disabled
|
||||
[ 42.656865] printk: legacy bootconsole [sbi0] disabled
|
||||
[ 42.896358] 40003000.serial: ttyS1 at MMIO 0x40003000 (irq = 1, base_baud = 3125000) is a 16550
|
||||
[ 42.999450] SuperH (H)SCI(F) driver initialized
|
||||
...
|
||||
~ # stty -a
|
||||
speed 115200 baud;stty: standard input
|
||||
line = 0;
|
||||
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
|
||||
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
|
||||
werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
|
||||
-parenb -parodd -cmspar cs8 hupcl -cstopb cread clocal -crtscts
|
||||
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
|
||||
-iuclc -ixany -imaxbel -iutf8
|
||||
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
|
||||
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
|
||||
echoctl echoke -flusho -extproc
|
||||
|
||||
Let's add the ability to claim a context in the plictool, as I suspect the claim
|
||||
may be broken.
|
||||
|
@ -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,6 +210,9 @@ int main(int argc, char *argv[])
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (operation == CLAIM)
|
||||
claim_interrupt(map_base, claim_ctx);
|
||||
else if (operation == DUMP)
|
||||
dump_sources(map_base);
|
||||
|
||||
munmap(map_base, map_size);
|
||||
|
Loading…
Reference in New Issue
Block a user