git: plan9front

Download patch

ref: acd2079ebf458c20ad5b3e5504c00a92d5fe46f1
parent: ce815eb209fa12fd3e0b67adc745170483ecc5d1
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Feb 23 15:57:11 EST 2025

io: Add -f option to pass a I/O file (such as /dev/pci/*raw)

--- a/sys/man/1/io
+++ b/sys/man/1/io
@@ -4,7 +4,14 @@
 .SH SYNOPSIS
 .B io
 [
-.B -WLMErw
+.B -f
+.I file
+] [
+.B -WLME
+] [
+.B -r
+|
+.B -w
 ]
 .I address
 [
@@ -41,6 +48,19 @@
 .TP
 .B  -E
 Access embedded controller space.
+.TP
+.B  -f
+Instead of using
+.B /dev/io*
+as the I/O file depending on the options above,
+use the argument
+.I file
+instead. This can be used,
+for example,
+to access some PCI card
+config space by specifying
+.B /dev/pci/*raw
+as the I/O file.
 .SH SOURCE
 .B /sys/src/cmd/io.c
 .SH SEE ALSO
--- a/sys/src/cmd/io.c
+++ b/sys/src/cmd/io.c
@@ -2,8 +2,16 @@
 #include <libc.h>
 
 char *datac[] = {0,"#P/iob","#P/iow",0,"#P/iol",0,0,0,"#P/msr"};
+char *file;
 
 void
+usage(void)
+{
+	fprint(2, "%s: [-f file] [ -WLME ] [-r | -w] address [ value ]\n", argv0);
+	exits("usage");
+}
+
+void
 main(int argc, char** argv) {
 	int fd, size, op;
 	ulong port;
@@ -14,6 +22,7 @@
 	size = 1;
 	op = -1;
 	ARGBEGIN {
+		case 'f': file = EARGF(usage()); break;
 		case 'W': size = 2; break;
 		case 'L': size = 4; break;
 		case 'M': size = 8; break;
@@ -20,15 +29,15 @@
 		case 'E': datac[1] = datac[2] = datac[4] = datac[8] = "#P/ec"; break;
 		case 'r': op = OREAD; break;
 		case 'w': op = OWRITE; break;
-		default: sysfatal("bad flag %c", ARGC());
+		default: usage();
 	} ARGEND;
-	if(op == -1) sysfatal("no operation selected");
-	if(argc < 1) sysfatal("no port selected");
-	if(op == OWRITE && argc < 2) sysfatal("no data selected");
+	if(op == -1) usage();
+	if(argc < 1) usage();
+	if(op == OWRITE && argc < 2) usage();
 	port = strtoul(argv[0], 0, 0);
 	if(op == OWRITE) data = strtoull(argv[1], 0, 0);
 	
-	fd = open(datac[size], op);
+	fd = open(file==nil?datac[size]:file, op);
 	if(fd == -1) sysfatal("open: %r");
 	
 	if(op == OWRITE) {
--