changelog shortlog tags branches changeset file revisions annotate raw help

Mercurial > hg > plan9front / sys/src/9/bcm/main.c

revision 6832: f80792d28e0e
parent 6198: f498f01d02f3
child 6851: 817828d0da99
     1.1--- a/sys/src/9/bcm/main.c
     1.2+++ b/sys/src/9/bcm/main.c
     1.3@@ -4,6 +4,7 @@
     1.4 #include "mem.h"
     1.5 #include "dat.h"
     1.6 #include "fns.h"
     1.7+#include "io.h"
     1.8 
     1.9 #include "init.h"
    1.10 #include <pool.h>
    1.11@@ -191,14 +192,27 @@ ataginit(Atag *a)
    1.12 void
    1.13 machinit(void)
    1.14 {
    1.15+	Mach *m0;
    1.16+
    1.17+	m->ticks = 1;
    1.18+	m->perf.period = 1;
    1.19+	m0 = MACHP(0);
    1.20+	if (m->machno != 0) {
    1.21+		/* synchronise with cpu 0 */
    1.22+		m->ticks = m0->ticks;
    1.23+	}
    1.24+}
    1.25+
    1.26+void
    1.27+mach0init(void)
    1.28+{
    1.29+	m->mmul1 = (PTE*)L1;
    1.30 	m->machno = 0;
    1.31 	machaddr[m->machno] = m;
    1.32 
    1.33 	m->ticks = 1;
    1.34 	m->perf.period = 1;
    1.35 
    1.36-	conf.nmach = 1;
    1.37-
    1.38 	active.machs[0] = 1;
    1.39 	active.exiting = 0;
    1.40 
    1.41@@ -206,6 +220,32 @@ machinit(void)
    1.42 }
    1.43 
    1.44 static void
    1.45+launchinit(void)
    1.46+{
    1.47+	int mach;
    1.48+	Mach *mm;
    1.49+	PTE *l1;
    1.50+
    1.51+	for(mach = 1; mach < conf.nmach; mach++){
    1.52+		machaddr[mach] = mm = mallocalign(MACHSIZE, MACHSIZE, 0, 0);
    1.53+		l1 = mallocalign(L1SIZE, L1SIZE, 0, 0);
    1.54+		if(mm == nil || l1 == nil)
    1.55+			panic("launchinit");
    1.56+		memset(mm, 0, MACHSIZE);
    1.57+		mm->machno = mach;
    1.58+
    1.59+		memmove(l1, m->mmul1, L1SIZE);  /* clone cpu0's l1 table */
    1.60+		cachedwbse(l1, L1SIZE);
    1.61+		mm->mmul1 = l1;
    1.62+		cachedwbse(mm, MACHSIZE);
    1.63+
    1.64+	}
    1.65+	cachedwbse(machaddr, sizeof machaddr);
    1.66+	if((mach = startcpus(conf.nmach)) < conf.nmach)
    1.67+			print("only %d cpu%s started\n", mach, mach == 1? "" : "s");
    1.68+}
    1.69+
    1.70+static void
    1.71 optionsinit(char* s)
    1.72 {
    1.73 	strecpy(oargb, oargb+sizeof(oargb), s);
    1.74@@ -216,29 +256,14 @@ optionsinit(char* s)
    1.75 }
    1.76 
    1.77 void
    1.78-gpiomeminit(void)
    1.79-{
    1.80-	Physseg seg;
    1.81-	memset(&seg, 0, sizeof seg);
    1.82-	seg.attr = SG_PHYSICAL;
    1.83-	seg.name = "gpio";
    1.84-	seg.pa = (VIRTIO+0x200000);
    1.85-	seg.size = BY2PG;
    1.86-	addphysseg(&seg);
    1.87-}
    1.88-
    1.89-
    1.90-void
    1.91 main(void)
    1.92 {
    1.93 	extern char edata[], end[];
    1.94-	uint rev;
    1.95+	uint fw, board;
    1.96 
    1.97-	okay(1);
    1.98 	m = (Mach*)MACHADDR;
    1.99 	memset(edata, 0, end - edata);	/* clear bss */
   1.100-	machinit();
   1.101-	mmuinit1();
   1.102+	mach0init();
   1.103 
   1.104 	optionsinit("/boot/boot boot");
   1.105 	quotefmtinstall();
   1.106@@ -250,20 +275,24 @@ main(void)
   1.107 	screeninit();
   1.108 
   1.109 	print("\nPlan 9 from Bell Labs\n");
   1.110-	rev = getfirmware();
   1.111-	print("firmware: rev %d\n", rev);
   1.112-	if(rev < Minfirmrev){
   1.113-		print("Sorry, firmware (start.elf) must be at least rev %d (%s)\n",
   1.114-			Minfirmrev, Minfirmdate);
   1.115+	board = getboardrev();
   1.116+	fw = getfirmware();
   1.117+	print("board rev: %#ux firmware rev: %d\n", board, fw);
   1.118+	if(fw < Minfirmrev){
   1.119+		print("Sorry, firmware (start*.elf) must be at least rev %d"
   1.120+		      " or newer than %s\n", Minfirmrev, Minfirmdate);
   1.121 		for(;;)
   1.122 			;
   1.123 	}
   1.124+	/* set clock rate to arm_freq from config.txt (default pi1:700Mhz pi2:900MHz) */
   1.125+	setclkrate(ClkArm, 0);
   1.126 	trapinit();
   1.127 	clockinit();
   1.128 	printinit();
   1.129 	timersinit();
   1.130 	cpuidprint();
   1.131 	archreset();
   1.132+	vgpinit();
   1.133 
   1.134 	procinit0();
   1.135 	initseg();
   1.136@@ -271,7 +300,8 @@ main(void)
   1.137 	chandevreset();			/* most devices are discovered here */
   1.138 	pageinit();
   1.139 	userinit();
   1.140-	gpiomeminit();
   1.141+	launchinit();
   1.142+	mmuinit1();
   1.143 	schedinit();
   1.144 	assert(0);			/* shouldn't have returned */
   1.145 }
   1.146@@ -484,8 +514,7 @@ confinit(void)
   1.147 	conf.upages = conf.npage - kpages;
   1.148 	conf.ialloc = (kpages/2)*BY2PG;
   1.149 
   1.150-	/* only one processor */
   1.151-	conf.nmach = 1;
   1.152+	conf.nmach = getncpus();
   1.153 
   1.154 	/* set up other configuration parameters */
   1.155 	conf.nproc = 100 + ((conf.npage*BY2PG)/MB)*5;
   1.156@@ -497,7 +526,7 @@ confinit(void)
   1.157 	conf.nswppo = 4096;
   1.158 	conf.nimage = 200;
   1.159 
   1.160-	conf.copymode = 0;		/* copy on write */
   1.161+	conf.copymode = conf.nmach > 1;
   1.162 
   1.163 	/*
   1.164 	 * Guess how much is taken by the large permanent
   1.165@@ -529,6 +558,14 @@ exit(int)
   1.166 {
   1.167 	cpushutdown();
   1.168 	splfhi();
   1.169+	if(m->machno != 0){
   1.170+		void (*f)(ulong, ulong, ulong) = (void*)REBOOTADDR;
   1.171+		intrsoff();
   1.172+		intrcpushutdown();
   1.173+		cacheuwbinv();
   1.174+		(*f)(0, 0, 0);
   1.175+		for(;;);
   1.176+	}
   1.177 	archreboot();
   1.178 }
   1.179 
   1.180@@ -536,11 +573,9 @@ exit(int)
   1.181  * stub for ../omap/devether.c
   1.182  */
   1.183 int
   1.184-isaconfig(char *class, int ctlrno, ISAConf *isa)
   1.185+isaconfig(char *, int, ISAConf *)
   1.186 {
   1.187-	USED(ctlrno);
   1.188-	USED(isa);
   1.189-	return strcmp(class, "ether") == 0;
   1.190+	return 0;
   1.191 }
   1.192 
   1.193 /*
   1.194@@ -553,37 +588,39 @@ reboot(void *entry, void *code, ulong si
   1.195 	void (*f)(ulong, ulong, ulong);
   1.196 
   1.197 	writeconf();
   1.198+	if (m->machno != 0) {
   1.199+		procwired(up, 0);
   1.200+		sched();
   1.201+	}
   1.202+
   1.203+	/* setup reboot trampoline function */
   1.204+	f = (void*)REBOOTADDR;
   1.205+	memmove(f, rebootcode, sizeof(rebootcode));
   1.206+	cachedwbse(f, sizeof(rebootcode));
   1.207+
   1.208 	cpushutdown();
   1.209+	delay(500);
   1.210+
   1.211+	splfhi();
   1.212 
   1.213 	/* turn off buffered serial console */
   1.214 	serialoq = nil;
   1.215-	kprintoq = nil;
   1.216-	screenputs = nil;
   1.217 
   1.218 	/* shutdown devices */
   1.219 	chandevshutdown();
   1.220 
   1.221 	/* stop the clock (and watchdog if any) */
   1.222 	clockshutdown();
   1.223-
   1.224-	splfhi();
   1.225 	intrsoff();
   1.226+	intrcpushutdown();
   1.227 
   1.228-	/* setup reboot trampoline function */
   1.229-	f = (void*)REBOOTADDR;
   1.230-	memmove(f, rebootcode, sizeof(rebootcode));
   1.231 	cacheuwbinv();
   1.232+	l2cacheuwbinv();
   1.233 
   1.234 	/* off we go - never to return */
   1.235 	(*f)(PADDR(entry), PADDR(code), size);
   1.236 }
   1.237 
   1.238-int
   1.239-cmpswap(long *addr, long old, long new)
   1.240-{
   1.241-	return cas32(addr, old, new);
   1.242-}
   1.243-
   1.244 void
   1.245 setupwatchpts(Proc *, Watchpt *, int n)
   1.246 {