changelog shortlog tags branches changeset files revisions annotate raw help

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

changeset 7206: 53f5476f9ffd
parent: ba62683c0e2d
child: 19de954d8073
author: cinap_lenrek@felloff.net
date: Sun, 05 May 2019 13:57:48 +0200
permissions: -rw-r--r--
description: bcm64: get rid of usb workaround delay
1 #include "u.h"
2 #include "tos.h"
3 #include "../port/lib.h"
4 #include "mem.h"
5 #include "dat.h"
6 #include "fns.h"
7 #include "../port/error.h"
8 #include "io.h"
9 #include "init.h"
10 #include "sysreg.h"
11 
12 #include <pool.h>
13 #include <libsec.h>
14 
15 Conf conf;
16 ulong memsize = GiB;
17 
18 /*
19  * starting place for first process
20  */
21 void
22 init0(void)
23 {
24  char buf[2*KNAMELEN], **sp;
25 
26  up->nerrlab = 0;
27  spllo();
28 
29  /*
30  * These are o.k. because rootinit is null.
31  * Then early kproc's will have a root and dot.
32  */
33  up->slash = namec("#/", Atodir, 0, 0);
34  pathclose(up->slash->path);
35  up->slash->path = newpath("/");
36  up->dot = cclone(up->slash);
37  chandevinit();
38 
39  if(!waserror()){
40  snprint(buf, sizeof(buf), "%s %s", "ARM64", conffile);
41  ksetenv("terminal", buf, 0);
42  ksetenv("cputype", "arm64", 0);
43  if(cpuserver)
44  ksetenv("service", "cpu", 0);
45  else
46  ksetenv("service", "terminal", 0);
47  snprint(buf, sizeof(buf), "-a %s", getethermac());
48  ksetenv("etherargs", buf, 0);
49 
50  /* convert plan9.ini variables to #e and #ec */
51  setconfenv();
52  poperror();
53  }
54  kproc("alarm", alarmkproc, 0);
55 
56  sp = (char**)(USTKTOP-sizeof(Tos) - 8 - sizeof(sp[0])*4);
57  sp[3] = sp[2] = sp[1] = nil;
58  strcpy(sp[1] = (char*)&sp[4], "boot");
59  sp[0] = (void*)&sp[1];
60 
61  touser((uintptr)sp);
62 
63  assert(0); /* shouldn't have returned */
64 }
65 
66 /*
67  * create the first process
68  */
69 void
70 userinit(void)
71 {
72  Proc *p;
73  Segment *s;
74  KMap *k;
75  Page *pg;
76 
77  /* no processes yet */
78  up = nil;
79 
80  p = newproc();
81  p->pgrp = newpgrp();
82  p->egrp = smalloc(sizeof(Egrp));
83  p->egrp->ref = 1;
84  p->fgrp = dupfgrp(nil);
85  p->rgrp = newrgrp();
86  p->procmode = 0640;
87 
88  kstrdup(&eve, "");
89  kstrdup(&p->text, "*init*");
90  kstrdup(&p->user, eve);
91 
92  /*
93  * Kernel Stack
94  */
95  p->sched.pc = (uintptr)init0;
96  p->sched.sp = (uintptr)p->kstack+KSTACK-sizeof(up->s.args)-sizeof(uintptr);
97  p->sched.sp = STACKALIGN(p->sched.sp);
98  *(void**)p->sched.sp = kproc; // fake
99 
100  /*
101  * User Stack
102  *
103  * Technically, newpage can't be called here because it
104  * should only be called when in a user context as it may
105  * try to sleep if there are no pages available, but that
106  * shouldn't be the case here.
107  */
108  s = newseg(SG_STACK, USTKTOP-USTKSIZE, USTKSIZE/BY2PG);
109  s->flushme++;
110  p->seg[SSEG] = s;
111  pg = newpage(1, 0, USTKTOP-BY2PG);
112  segpage(s, pg);
113  k = kmap(pg);
114  memset((void*)VA(k), 0, BY2PG);
115  kunmap(k);
116 
117  /*
118  * Text
119  */
120  s = newseg(SG_TEXT, UTZERO, 1);
121  p->seg[TSEG] = s;
122  pg = newpage(1, 0, UTZERO);
123  pg->txtflush = ~0;
124  segpage(s, pg);
125  k = kmap(s->map[0]->pages[0]);
126  memmove((void*)VA(k), initcode, sizeof initcode);
127  kunmap(k);
128 
129  ready(p);
130 }
131 
132 void
133 confinit(void)
134 {
135  int i, userpcnt;
136  ulong kpages;
137  uintptr pa;
138  char *p;
139 
140  if(p = getconf("service")){
141  if(strcmp(p, "cpu") == 0)
142  cpuserver = 1;
143  else if(strcmp(p,"terminal") == 0)
144  cpuserver = 0;
145  }
146 
147  if(p = getconf("*kernelpercent"))
148  userpcnt = 100 - strtol(p, 0, 0);
149  else
150  userpcnt = 0;
151 
152  if((p = getconf("*maxmem")) != nil){
153  memsize = strtoul(p, 0, 0) - PHYSDRAM;
154  if (memsize < 16*MB) /* sanity */
155  memsize = 16*MB;
156  }
157 
158  getramsize(&conf.mem[0]);
159  if(conf.mem[0].limit == 0){
160  conf.mem[0].base = PHYSDRAM;
161  conf.mem[0].limit = PHYSDRAM + memsize;
162  }else if(p != nil)
163  conf.mem[0].limit = conf.mem[0].base + memsize;
164 
165  conf.npage = 0;
166  pa = PADDR(PGROUND((uintptr)end));
167 
168  /*
169  * we assume that the kernel is at the beginning of one of the
170  * contiguous chunks of memory and fits therein.
171  */
172  for(i=0; i<nelem(conf.mem); i++){
173  /* take kernel out of allocatable space */
174  if(pa > conf.mem[i].base && pa < conf.mem[i].limit)
175  conf.mem[i].base = pa;
176 
177  conf.mem[i].npage = (conf.mem[i].limit - conf.mem[i].base)/BY2PG;
178  conf.npage += conf.mem[i].npage;
179  }
180 
181  if(userpcnt < 10)
182  userpcnt = 60 + cpuserver*10;
183  kpages = conf.npage - (conf.npage*userpcnt)/100;
184 
185  /*
186  * can't go past the end of virtual memory
187  * (uintptr)-KZERO is 2^32 - KZERO
188  */
189  if(kpages > ((uintptr)-KZERO)/BY2PG)
190  kpages = ((uintptr)-KZERO)/BY2PG;
191 
192  conf.upages = conf.npage - kpages;
193  conf.ialloc = (kpages/2)*BY2PG;
194 
195  conf.nmach = getncpus();
196 
197  /* set up other configuration parameters */
198  conf.nproc = 100 + ((conf.npage*BY2PG)/MB)*5;
199  if(cpuserver)
200  conf.nproc *= 3;
201  if(conf.nproc > 2000)
202  conf.nproc = 2000;
203  conf.nswap = conf.npage*3;
204  conf.nswppo = 4096;
205  conf.nimage = 200;
206 
207  conf.copymode = conf.nmach > 1;
208 
209  /*
210  * Guess how much is taken by the large permanent
211  * datastructures. Mntcache and Mntrpc are not accounted for.
212  */
213  kpages = conf.npage - conf.upages;
214  kpages *= BY2PG;
215  kpages -= conf.upages*sizeof(Page)
216  + conf.nproc*sizeof(Proc)
217  + conf.nimage*sizeof(Image)
218  + conf.nswap
219  + conf.nswppo*sizeof(Page*);
220  mainmem->maxsize = kpages;
221  if(!cpuserver)
222  /*
223  * give terminals lots of image memory, too; the dynamic
224  * allocation will balance the load properly, hopefully.
225  * be careful with 32-bit overflow.
226  */
227  imagmem->maxsize = kpages;
228 }
229 
230 void
231 machinit(void)
232 {
233  m->ticks = 1;
234  m->perf.period = 1;
235  active.machs[m->machno] = 1;
236 }
237 
238 void
239 mpinit(void)
240 {
241  extern void _start(void);
242  int i;
243 
244  for(i = 0; i < MAXMACH; i++)
245  ((uintptr*)SPINTABLE)[i] = 0;
246 
247  for(i = 1; i < conf.nmach; i++)
248  MACHP(i)->machno = i;
249 
250  cachedwbinv();
251 
252  for(i = 1; i < conf.nmach; i++)
253  ((uintptr*)SPINTABLE)[i] = PADDR(_start);
254 
255  cachedwbinvse((void*)SPINTABLE, MAXMACH*8);
256  sev();
257  delay(100);
258  sev();
259  synccycles();
260 }
261 
262 void
263 idlehands(void)
264 {
265 }
266 
267 void
268 main(void)
269 {
270  machinit();
271  if(m->machno){
272  trapinit();
273  fpuinit();
274  clockinit();
275  cpuidprint();
276  synccycles();
277  timersinit();
278  flushtlb();
279  mmu1init();
280  m->ticks = MACHP(0)->ticks;
281  schedinit();
282  return;
283  }
284  bootargsinit();
285  confinit();
286  xinit();
287  printinit();
288  fmtinstall('H', encodefmt);
289  quotefmtinstall();
290  uartconsinit();
291  screeninit();
292  print("\nPlan 9\n");
293  xsummary();
294 
295  /* set clock rate to arm_freq from config.txt */
296  setclkrate(ClkArm, 0);
297 
298  trapinit();
299  fpuinit();
300  clockinit();
301  cpuidprint();
302  timersinit();
303  pageinit();
304  procinit0();
305  initseg();
306  links();
307  chandevreset();
308  userinit();
309  mpinit();
310  mmu0clear((uintptr*)L1);
311  flushtlb();
312  mmu1init();
313  schedinit();
314 }
315 
316 void
317 exit(int)
318 {
319  cpushutdown();
320  for(;;);
321 }
322 
323 void
324 reboot(void*, void*, ulong)
325 {
326  error(Egreg);
327 }
328 
329 /*
330  * stub for ../omap/devether.c
331  */
332 int
333 isaconfig(char *, int, ISAConf *)
334 {
335  return 0;
336 }