1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
|
/**
** Proll (PROM replacement)
** Copyright 1999 Pete Zaitcev
** This code is licensed under GNU General Public License.
**/
#include <stdarg.h>
#include <crs.h>
#include <asi.h>
#include "pgtsrmmu.h"
#include "phys_jk.h"
#include "vconsole.h"
#include "version.h"
#include <general.h> /* __P() */
#include <net.h> /* init_net() */
#include <romlib.h> /* we are a provider for part of this. */
#include <netpriv.h> /* myipaddr */
#include <arpa.h>
#include <system.h> /* our own prototypes */
#include <silo_arg.h> /* Interface to SILO */
#include "pcic.h" /* P3 */
#if 0
void bridge(void);
#endif
#if 0
static int iga_find_darkest(void);
static void iga_set_color(int x, unsigned r, unsigned g, unsigned b);
static void iga_enable_visual(void);
#endif
int load_pre(struct silo_to_proll *ap);
struct vconterm dp0;
struct mem cmem; /* Current memory, virtual */
struct mem cio; /* Current I/O space */
struct phym pmem; /* Current phys. mem. */
struct pcic cpcic; /* Current PCIC. */
/*
* This struct must be pre-initialized,
* or our bss cleaning zaps parameters that were patched in.
*/
struct silo_to_proll silo_arg = { /* <== Will be patched when loading */
{ "LROP" }
};
/*
*/
void prolmain()
{
static char fname[14] = "00000000.PROL";
static char fname_cfg[14] = "00000000.CMDL";
static struct banks bb;
int nmegs;
int i;
unsigned int hiphybas;
void *romvec;
struct silo_to_proll *ap;
#if 0
iga_set_color(255, 0, 0, 0); /* background black */
iga_set_color(0, 255, 255, 255); /* foreground white */
iga_enable_visual();
#endif
vcon_init(&dp0, PHYS_JK_SU_A);
printk("PROLL %s Espresso BOOTP+Serial+SILO\n", PROLL_VERSION_STRING);
get_banks_layout(&bb, BANKS_JK);
if (bb.nbanks <= 0) {
printk("No memory found\n");
return;
}
printk("M:");
nmegs = 0;
for (i = 0; i < bb.nbanks; i++) {
printk(" %d=0x%x[0x%x]", i,
bb.bankv[i].start, bb.bankv[i].length);
nmegs += bb.bankv[i].length/(1024*1024);
}
printk(": %dMB\n", nmegs);
i = bb.nbanks - 1;
hiphybas = bb.bankv[i].start + bb.bankv[i].length - PROLSIZE;
/* printk("high phys base 0x%x\n", hiphybas); */ /* P3 */
/*
* We generate tables and switch two times.
* We start off being in low physical memory (LOADBASE) and
* mapped to high virtual (PROLBASE), running off PROM tables.
* These tables are located somewhere in upper physical so
* when we copy ourselves up we may step on them. The
* solution is to create temporary pages in low physical memory,
* then use them to move ourselves high. After that we may
* create new tables in high physical memory.
*/
mem_init(&cmem, (char *) &_end, (char *)(PROLBASE+PROLSIZE));
makepages(&pmem, LOADBASE);
#if 0
proc_tablewalk(0, PROLBASE+PROLSIZE-PAGE_SIZE);
mem_tablewalk((pmem.pctp[0]&(~0xF))<<4, PROLBASE+PROLSIZE-PAGE_SIZE);
#endif
init_mmu_swift((unsigned int)pmem.pctp - PROLBASE + LOADBASE);
move_phys_high(hiphybas, PROLSIZE);
/*
* We did not use the dynamic memory for anything but
* page tables, which are left down in low memory. Reinitiate cmem.
*/
mem_fini(&cmem);
mem_init(&cmem, (char *) &_end, (char *)(PROLBASE+PROLSIZE));
makepages(&pmem, hiphybas);
init_mmu_swift((unsigned int)pmem.pctp - PROLBASE + hiphybas);
mem_init(&cio, (char *)(PROLBASE+PROLSIZE),
(char *)(PROLBASE+PROLSIZE+IOMAPSIZE));
pcic_init(&cpcic, hiphybas);
/* PROM leaves 0, kernel sets it properly, so it's not needed. */
/* pcic_map_irq(&cpcic, 5, 11); */
/*
*/
init_eeprom();
sched_init();
ap = &silo_arg;
if (ap->magic[0] == 'S' && ap->magic[1] == 'i') {
printk("Found SILO argument.\n");
if (load_pre(ap) != 0) fatal();
} else {
unsigned int saddr;
int len;
printk("Booting from network.\n");
hme_probe();
init_net();
#if 0 /* RARP */
if (rarp() != 0) fatal();
/* printrarp(); */
saddr = servaddr;
#else
if (bootp() != 0) fatal();
/*
* boot_rec.bp_file cannot be used because system PROM uses
* it to locate ourselves. If we load from boot_rec.bp_file,
* we will loop reloading PROLL over and over again.
* Thus we use traditional PROLL scheme "HEXIPADDR.PROL".
*/
saddr = boot_rec.bp_siaddr;
#endif
xtoa(myipaddr, fname_cfg, 8);
len = load_cfg(saddr, fname_cfg, ap->kern_args, SILO_CMDSZ);
if (len < 0) {
printf("No command line\n");
ap = NULL;
} else if (len == 0) {
printf("Empty command line\n");
ap = NULL;
} else {
--len; /* Kill LF or leave space for NUL */
ap->kern_args[len] = 0;
printf("Command line %d bytes\n", len);
}
xtoa(myipaddr, fname, 8);
if (load(saddr, fname) != 0) fatal();
}
pcic_map_irq(&cpcic, PHYS_JK_PIN_RTC, PHYS_JK_IRQ_RTC);
romvec = init_openprom_silo(bb.nbanks, bb.bankv, hiphybas, ap);
printk("Memory used: virt 0x%x:0x%x[%dK] iomap 0x%x:0x%x\n",
PROLBASE, (int)cmem.curp, ((unsigned) cmem.curp - PROLBASE)/1024,
(int)cio.start, (int)cio.curp);
/* No need to delay on a serial console, we can capture it. */
/* set_timeout(5); while (!chk_timeout()) { } */
{
void (*entry)(void *, int) = (void (*)(void*, int)) LOADBASE;
entry(romvec, 0);
}
printk("bye.\n"); /* Not reached, but let it be. */
mem_fini(&cmem);
vcon_fini(&dp0);
/* XXX Redo head.S so that it starts kernel */
}
/*
* There is not a lot to do. Silo loaded stuff for us, so we move it.
*/
int load_pre(struct silo_to_proll *ap)
{
int len;
unsigned int *loadptr = (unsigned int *)LOADBASE;
unsigned int *inbuf;
len = (ap->kern_size + 3) & (~3);
if (len < 0 || len > LOWMEMSZ) {
printk("Illegal kernel size %d(0x%x)\n", len, len);
return -1;
}
inbuf = (unsigned int *) ap->kern_base;
printk("Kernel base 0x%x size %d(0x%x)\n", inbuf, len, len);
while (len >= 4) {
len -= 4;
*loadptr++ = *inbuf++;
}
return 0;
}
#if 0
static int iga_find_darkest()
{
unsigned int mmbase = PHYS_JK_MM_IGA | 0x00800000;
unsigned int r, g, b, mod, mod1;
int i, darkest;
darkest = 0;
mod = 0xff*0xff * 3;
for (i = 0; i < 256; i++) {
stb_bypass(mmbase + 0x3C7, i);
r = ldb_bypass(mmbase + 0x3C9);
g = ldb_bypass(mmbase + 0x3C9);
b = ldb_bypass(mmbase + 0x3C9);
mod1 = r*r + g*g + b*b;
if (mod1 < mod) {
mod = mod1;
darkest = i;
}
}
/* P3 */ printk("darkest %d(0x%x) mod 0%x\n", darkest, darkest, mod);
return darkest;
}
static void iga_set_color(int index,
unsigned int r, unsigned int g, unsigned int b)
{
unsigned int mmbase = PHYS_JK_MM_IGA + 0x00800000;
stb_bypass(mmbase + 0x3C8, index);
stb_bypass(mmbase + 0x3C9, r);
stb_bypass(mmbase + 0x3C9, g);
stb_bypass(mmbase + 0x3C9, b);
}
/*
* This comes handy when we unplug the keyboard then say "boot net".
* The system comes up with a disabled screen.
*
* XXX Nice try, for a punk. It does not work!
*/
static void iga_enable_visual()
{
unsigned int mmbase = PHYS_JK_MM_IGA + 0x00800000;
ldb_bypass(mmbase + 0x3DA); /* required before access to 0x3C0 */
stb_bypass(mmbase + 0x3C0, 0x20);
}
#endif
/*
* dvma_alloc over iommu_alloc.
*/
void *dvma_alloc(int size, unsigned int *pphys)
{
return pcic_alloc(&cpcic, size, pphys);
}
/*
*/
unsigned long virt_to_bus(volatile void *addr)
{
return pcic_virt_to_bus(addr);
}
/*
* Stub for hme.c
*/
unsigned long sbus_dvma_addr(void *addr) {
printk("sbus_dvma_addr!\n");
return (~0);
}
/*
*/
void udelay(unsigned long usecs)
{
int i, n = usecs * 50;
for (i = 0; i < n; i++) { }
}
/*
* P3 temp
*/
#define CONFIG_CMD(bus, device_fn, where) (0x80000000 | (((unsigned int)bus) << 16) | (((unsigned int)device_fn) << 8) | (where & ~3))
/*
* Support for IDE.
* This can be used to program values forcebly but it turns out
* that our theorethically correct values result in garbage on the IRQ line.
* Therefore, deadwood for now, and failure of RTFM.
*/
#if 0
void
bridge()
{
unsigned where;
unsigned devfn = 0x38;
unsigned bus = 0;
unsigned int base0;
where = PCI_VENDOR_ID;
st_bp_swap(PHYS_JK_PCI_CFA, CONFIG_CMD(bus,devfn,where));
base0 = ld_bp_swap(PHYS_JK_PCI_CFD + (where & 4));
printk(" ID %x", base0);
where = PCI_CLASS_REVISION;
st_bp_swap(PHYS_JK_PCI_CFA, CONFIG_CMD(bus,devfn,where));
base0 = ld_bp_swap(PHYS_JK_PCI_CFD + (where & 4));
printk(" CL/R %x", base0);
where = 0x44;
st_bp_swap(PHYS_JK_PCI_CFA, CONFIG_CMD(bus,devfn,where));
/* stb_bypass(PHYS_JK_PCI_CFD + (where & 4), 0); */ /* 0x0D */
printk(" %x", ldb_bypass(PHYS_JK_PCI_CFD + (where & 4)));
/* PROM sets 0x1B == Level/edge transform enable, IRQ12. */
where = 0x58;
st_bp_swap(PHYS_JK_PCI_CFA, CONFIG_CMD(bus,devfn,where));
/* stb_bypass(PHYS_JK_PCI_CFD + (where & 4), 0x4D); */
printk(" %x", ldb_bypass(PHYS_JK_PCI_CFD + (where & 4)));
/* PROM sets 0x4C e.g. SIRQI/SIRQII (nonsense, but works) */
where = 0x75;
/* st_bp_swap(PHYS_JK_PCI_CFA, CONFIG_CMD(bus,devfn,where)); */
stb_bypass(PHYS_JK_PCI_CFD + (where & 4), 0);
printk(" %x", ldb_bypass(PHYS_JK_PCI_CFD + (where & 4)));
/* PROM leaves 0xFF here... bah */
/***
where = 0x42;
st_bp_swap(PHYS_JK_PCI_CFA, CONFIG_CMD(bus,devfn,where));
stb_bypass(PHYS_JK_PCI_CFD + (where & 4), 0x80);
***/
printk(" bridge done\n");
}
#endif
|