9front - general discussion about 9front
 help / color / mirror / Atom feed
From: cinap_lenrek@felloff.net
To: 9front@9front.org
Subject: Re: [9front] 9front on Raspberry Pi 400
Date: Fri, 29 Jan 2021 15:58:19 +0100	[thread overview]
Message-ID: <D1D6D28B1120769BA7C3C467BEAA0D0A@felloff.net> (raw)
In-Reply-To: <0100017741afd09d-da43b097-8dba-46b2-98d9-05414e118708-000000@email.amazonses.com>

ok, here we go.

i wrote some code to extract the dma-rangles property from
the device tree and apply it to the pci express code.

this adds new kernel variables *pciwin and *pcidmawin,
that reflect the setting. they get filled in by the
device tree setting when booted from firmware,
but can be overridden in cmdline.txt or when we /dev/reboot.

new kernel images to try:

http://felloff.net/usr/cinap_lenrek/9pi4-pciwin		(image for sdcard)
http://felloff.net/usr/cinap_lenrek/s9pi4-pciwin	(kernel with debug symbols)

sha1sums:

9b8775e9b9b9daebbd72cde308c2b7117d2d065b	9pi4
0a01ed1555e99f847ba9eab8e8693364d4839f2c	s9pi4

what follows is a example bootmessage from my pi4 8GB.
note that in your case, the *pcidmawin print below should be different.
please report back what you get as output there.

Plan 9
intrsoff: GIC intids [0-31]: 01ff0000 are locked in disable state
intrsoff: GIC intids [0-31]: 0000ffff are locked in enable state
cpu0: 1500MHz ARM Cortex-A72 r0p3
8102M memory: 998M kernel data, 7104M user, 31395M swap
*pciwin: 0x600000000 0x604000000
*pcidmawin: 0x0 0xc0000000
pcienable PCI.0.0.0: pcr 0->7
pcienable PCI.1.0.0: pcr 0->2
bus dev type     vid  did  intl memory
0   0/0 06 04 00 14e4 2711   0  ioa:00000000-00001000 4096 mema:600000000-600100000 1048576 ->1
1   0/0 0c 03 30 1106 3483   0  0:600000004 4096 
#l0: genet: 1000Mbps port 0xFFFFFFFFBD580000 irq 189 ea dca632b1adfe
usbxhci: cpu2: 1500MHz ARM Cortex-A72 r0p3
cpu3: 1500MHz ARM Cortex-A72 r0p3
cpu1: 1500MHz ARM Cortex-A72 r0p3
0x1106 0x3483: port 600000000 size 4096 irq 0
#l0: phy1 id 600d84a2 oui 80361

patch:

diff -r 5c327eddc496 sys/src/9/bcm/bootargs.c
--- a/sys/src/9/bcm/bootargs.c	Sat Jan 23 20:36:09 2021 -0800
+++ b/sys/src/9/bcm/bootargs.c	Fri Jan 29 15:45:16 2021 +0100
@@ -12,6 +12,7 @@
 static char *confval[MAXCONF];
 static int nconf;
 static char maxmem[256];
+static char pciwin[38], pcidmawin[38];
 
 static int
 findconf(char *k)
@@ -89,23 +90,23 @@
 static void
 devtreeprop(char *path, char *key, void *val, int len)
 {
+	uvlong addr, size;
+	uchar *p = val;
+	char *s;
+
 	if((strcmp(path, "/memory") == 0 || strcmp(path, "/memory@0") == 0)
 	&& strcmp(key, "reg") == 0){
 		if(findconf("*maxmem") < 0 && len > 0 && (len % (3*4)) == 0){
-			uvlong top;
-			uchar *p = val;
-			char *s;
-
-			top = (uvlong)beget4(p)<<32 | beget4(p+4);
-			top += beget4(p+8);
-			s = seprint(maxmem, &maxmem[sizeof(maxmem)], "%#llux", top);
+			addr = (uvlong)beget4(p)<<32 | beget4(p+4);
+			addr += beget4(p+8);
+			s = seprint(maxmem, &maxmem[sizeof(maxmem)], "%#llux", addr);
 			p += 3*4;
 			len -= 3*4;
 			while(len > 0){
-				top = (uvlong)beget4(p)<<32 | beget4(p+4);
-				s = seprint(s, &maxmem[sizeof(maxmem)], " %#llux", top);
-				top += beget4(p+8);
-				s = seprint(s, &maxmem[sizeof(maxmem)], " %#llux", top);
+				addr = (uvlong)beget4(p)<<32 | beget4(p+4);
+				s = seprint(s, &maxmem[sizeof(maxmem)], " %#llux", addr);
+				addr += beget4(p+8);
+				s = seprint(s, &maxmem[sizeof(maxmem)], " %#llux", addr);
 				p += 3*4;
 				len -= 3*4;
 			}
@@ -113,6 +114,20 @@
 		}
 		return;
 	}
+	if(strncmp(path, "/scb/pcie@", 10) == 0 && len == (3*4 + 4*4)){
+		p += 3*4;
+		addr = (uvlong)beget4(p)<<32 | beget4(p+4);
+		p += 2*4;
+		size = (uvlong)beget4(p)<<32 | beget4(p+4);
+		if(strcmp(key, "ranges") == 0 && findconf("*pciwin") < 0){
+			snprint(pciwin, sizeof(pciwin), "%#llux %#llux", addr, addr+size);
+			addconf("*pciwin", pciwin);
+		} else if(strcmp(key, "dma-ranges") == 0 && findconf("*pcidmawin") < 0){
+			snprint(pcidmawin, sizeof(pcidmawin), "%#llux %#llux", addr, addr+size);
+			addconf("*pcidmawin", pcidmawin);
+		}
+		return;
+	}
 	if(strcmp(path, "/chosen") == 0 && strcmp(key, "bootargs") == 0){
 		if(len > BOOTARGSLEN)
 			len = BOOTARGSLEN;
diff -r 5c327eddc496 sys/src/9/bcm64/dat.h
--- a/sys/src/9/bcm64/dat.h	Sat Jan 23 20:36:09 2021 -0800
+++ b/sys/src/9/bcm64/dat.h	Fri Jan 29 15:44:26 2021 +0100
@@ -249,7 +249,8 @@
 	uintptr	physio;
 	uintptr	virtio;
 	uintptr	armlocal;
-	uintptr	pciwin;
+	uintptr	pciwin;		/* PCI outbound window CPU->PCI */
+	uintptr	pcidmawin;	/* PCI inbound window PCI->DRAM */
 	int	oscfreq;
 };
 extern Soc soc;
diff -r 5c327eddc496 sys/src/9/bcm64/io.h
--- a/sys/src/9/bcm64/io.h	Sat Jan 23 20:36:09 2021 -0800
+++ b/sys/src/9/bcm64/io.h	Fri Jan 29 15:43:55 2021 +0100
@@ -6,5 +6,5 @@
 	IRQether	= IRQgic + 29,
 };
 
-#define PCIWINDOW	0
+#define PCIWINDOW	soc.pcidmawin
 #define PCIWADDR(va)	(PADDR(va)+PCIWINDOW)
diff -r 5c327eddc496 sys/src/9/bcm64/pcibcm.c
--- a/sys/src/9/bcm64/pcibcm.c	Sat Jan 23 20:36:09 2021 -0800
+++ b/sys/src/9/bcm64/pcibcm.c	Fri Jan 29 15:43:55 2021 +0100
@@ -244,6 +244,16 @@
 pcibcmlink(void)
 {
 	int log2dmasize = 30;	// 1GB
+	char *s;
+
+	if((s = getconf("*pciwin")) != nil){
+		print("*pciwin: %s\n", s);
+		soc.pciwin = (uintptr)strtoll(s, nil, 16);
+	}
+	if((s = getconf("*pcidmawin")) != nil){
+		print("*pcidmawin: %s\n", s);
+		soc.pcidmawin = (uintptr)strtoll(s, nil, 16);
+	}
 
 	regs[RGR1_SW_INIT_1] |= 3;
 	delay(200);
@@ -266,8 +276,8 @@
 	// SCB_ACCESS_EN, CFG_READ_UR_MODE, MAX_BURST_SIZE_128, SCB0SIZE
 	regs[MISC_MISC_CTRL] = 1<<12 | 1<<13 | 0<<20 | (log2dmasize-15)<<27;
 
-	regs[MISC_RC_BAR2_CONFIG_LO] = (log2dmasize-15);
-	regs[MISC_RC_BAR2_CONFIG_HI] = 0;
+	regs[MISC_RC_BAR2_CONFIG_LO] = ((u32int)soc.pcidmawin & ~0x1F) | (log2dmasize-15);
+	regs[MISC_RC_BAR2_CONFIG_HI] = soc.pcidmawin >> 32;
 
 	regs[MISC_RC_BAR1_CONFIG_LO] = 0;
 	regs[MISC_RC_BAR3_CONFIG_LO] = 0;

--
cinap

  parent reply	other threads:[~2021-01-30 15:45 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-20 17:23 Mack Wallace
2021-01-23 16:11 ` cinap_lenrek
2021-01-23 21:08   ` Mack Wallace
2021-01-23 21:13   ` Mack Wallace
2021-01-23 23:42     ` cinap_lenrek
2021-01-24 15:01       ` cinap_lenrek
2021-01-26  3:33         ` Mack Wallace
2021-01-26  3:35         ` Mack Wallace
2021-01-26 11:21           ` cinap_lenrek
2021-01-26 12:09           ` cinap_lenrek
2021-01-27  2:32             ` Mack Wallace
2021-01-27 14:30               ` cinap_lenrek
2021-01-27 17:04               ` cinap_lenrek
2021-01-27 17:57               ` cinap_lenrek
2021-01-29 14:58               ` cinap_lenrek [this message]
2021-01-30  2:43                 ` Mack Wallace
2021-01-30  5:54                   ` cinap_lenrek
2021-01-30 19:23                     ` Mack Wallace
2021-01-30 19:41                       ` cinap_lenrek
2021-01-30 19:46                       ` cinap_lenrek
2021-02-01  1:16                         ` Mack Wallace

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D1D6D28B1120769BA7C3C467BEAA0D0A@felloff.net \
    --to=cinap_lenrek@felloff.net \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).