prep_setup.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  1. /*
  2. * Copyright (C) 1995 Linus Torvalds
  3. * Adapted from 'alpha' version by Gary Thomas
  4. * Modified by Cort Dougan (cort@cs.nmt.edu)
  5. *
  6. * Support for PReP (Motorola MTX/MVME)
  7. * by Troy Benjegerdes (hozer@drgw.net)
  8. */
  9. /*
  10. * bootup setup stuff..
  11. */
  12. #include <linux/delay.h>
  13. #include <linux/module.h>
  14. #include <linux/errno.h>
  15. #include <linux/sched.h>
  16. #include <linux/kernel.h>
  17. #include <linux/mm.h>
  18. #include <linux/stddef.h>
  19. #include <linux/unistd.h>
  20. #include <linux/ptrace.h>
  21. #include <linux/slab.h>
  22. #include <linux/user.h>
  23. #include <linux/a.out.h>
  24. #include <linux/screen_info.h>
  25. #include <linux/major.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/reboot.h>
  28. #include <linux/init.h>
  29. #include <linux/initrd.h>
  30. #include <linux/ioport.h>
  31. #include <linux/console.h>
  32. #include <linux/timex.h>
  33. #include <linux/pci.h>
  34. #include <linux/ide.h>
  35. #include <linux/seq_file.h>
  36. #include <linux/root_dev.h>
  37. #include <asm/sections.h>
  38. #include <asm/mmu.h>
  39. #include <asm/processor.h>
  40. #include <asm/residual.h>
  41. #include <asm/io.h>
  42. #include <asm/pgtable.h>
  43. #include <asm/cache.h>
  44. #include <asm/dma.h>
  45. #include <asm/machdep.h>
  46. #include <asm/mc146818rtc.h>
  47. #include <asm/mk48t59.h>
  48. #include <asm/prep_nvram.h>
  49. #include <asm/raven.h>
  50. #include <asm/vga.h>
  51. #include <asm/time.h>
  52. #include <asm/mpc10x.h>
  53. #include <asm/i8259.h>
  54. #include <asm/open_pic.h>
  55. #include <asm/pci-bridge.h>
  56. #include <asm/todc.h>
  57. /* prep registers for L2 */
  58. #define CACHECRBA 0x80000823 /* Cache configuration register address */
  59. #define L2CACHE_MASK 0x03 /* Mask for 2 L2 Cache bits */
  60. #define L2CACHE_512KB 0x00 /* 512KB */
  61. #define L2CACHE_256KB 0x01 /* 256KB */
  62. #define L2CACHE_1MB 0x02 /* 1MB */
  63. #define L2CACHE_NONE 0x03 /* NONE */
  64. #define L2CACHE_PARITY 0x08 /* Mask for L2 Cache Parity Protected bit */
  65. TODC_ALLOC();
  66. unsigned char ucBoardRev;
  67. unsigned char ucBoardRevMaj, ucBoardRevMin;
  68. extern unsigned char prep_nvram_read_val(int addr);
  69. extern void prep_nvram_write_val(int addr,
  70. unsigned char val);
  71. extern unsigned char rs_nvram_read_val(int addr);
  72. extern void rs_nvram_write_val(int addr,
  73. unsigned char val);
  74. extern void ibm_prep_init(void);
  75. extern void prep_find_bridges(void);
  76. int _prep_type;
  77. extern void prep_residual_setup_pci(char *irq_edge_mask_lo, char *irq_edge_mask_hi);
  78. extern void prep_sandalfoot_setup_pci(char *irq_edge_mask_lo, char *irq_edge_mask_hi);
  79. extern void prep_thinkpad_setup_pci(char *irq_edge_mask_lo, char *irq_edge_mask_hi);
  80. extern void prep_carolina_setup_pci(char *irq_edge_mask_lo, char *irq_edge_mask_hi);
  81. extern void prep_tiger1_setup_pci(char *irq_edge_mask_lo, char *irq_edge_mask_hi);
  82. #define cached_21 (((char *)(ppc_cached_irq_mask))[3])
  83. #define cached_A1 (((char *)(ppc_cached_irq_mask))[2])
  84. #ifdef CONFIG_SOUND_CS4232
  85. long ppc_cs4232_dma, ppc_cs4232_dma2;
  86. #endif
  87. extern PTE *Hash, *Hash_end;
  88. extern unsigned long Hash_size, Hash_mask;
  89. extern int probingmem;
  90. extern unsigned long loops_per_jiffy;
  91. #ifdef CONFIG_SOUND_CS4232
  92. EXPORT_SYMBOL(ppc_cs4232_dma);
  93. EXPORT_SYMBOL(ppc_cs4232_dma2);
  94. #endif
  95. /* useful ISA ports */
  96. #define PREP_SYSCTL 0x81c
  97. /* present in the IBM reference design; possibly identical in Mot boxes: */
  98. #define PREP_IBM_SIMM_ID 0x803 /* SIMM size: 32 or 8 MiB */
  99. #define PREP_IBM_SIMM_PRESENCE 0x804
  100. #define PREP_IBM_EQUIPMENT 0x80c
  101. #define PREP_IBM_L2INFO 0x80d
  102. #define PREP_IBM_PM1 0x82a /* power management register 1 */
  103. #define PREP_IBM_PLANAR 0x852 /* planar ID - identifies the motherboard */
  104. #define PREP_IBM_DISP 0x8c0 /* 4-digit LED display */
  105. /* Equipment Present Register masks: */
  106. #define PREP_IBM_EQUIPMENT_RESERVED 0x80
  107. #define PREP_IBM_EQUIPMENT_SCSIFUSE 0x40
  108. #define PREP_IBM_EQUIPMENT_L2_COPYBACK 0x08
  109. #define PREP_IBM_EQUIPMENT_L2_256 0x04
  110. #define PREP_IBM_EQUIPMENT_CPU 0x02
  111. #define PREP_IBM_EQUIPMENT_L2 0x01
  112. /* planar ID values: */
  113. /* Sandalfoot/Sandalbow (6015/7020) */
  114. #define PREP_IBM_SANDALFOOT 0xfc
  115. /* Woodfield, Thinkpad 850/860 (6042/7249) */
  116. #define PREP_IBM_THINKPAD 0xff /* planar ID unimplemented */
  117. /* PowerSeries 830/850 (6050/6070) */
  118. #define PREP_IBM_CAROLINA_IDE_0 0xf0
  119. #define PREP_IBM_CAROLINA_IDE_1 0xf1
  120. #define PREP_IBM_CAROLINA_IDE_2 0xf2
  121. #define PREP_IBM_CAROLINA_IDE_3 0xf3
  122. /* 7248-43P */
  123. #define PREP_IBM_CAROLINA_SCSI_0 0xf4
  124. #define PREP_IBM_CAROLINA_SCSI_1 0xf5
  125. #define PREP_IBM_CAROLINA_SCSI_2 0xf6
  126. #define PREP_IBM_CAROLINA_SCSI_3 0xf7 /* missing from Carolina Tech Spec */
  127. /* Tiger1 (7043-140) */
  128. #define PREP_IBM_TIGER1_133 0xd1
  129. #define PREP_IBM_TIGER1_166 0xd2
  130. #define PREP_IBM_TIGER1_180 0xd3
  131. #define PREP_IBM_TIGER1_xxx 0xd4 /* unknown, but probably exists */
  132. #define PREP_IBM_TIGER1_333 0xd5 /* missing from Tiger Tech Spec */
  133. /* setup_ibm_pci:
  134. * set Motherboard_map_name, Motherboard_map, Motherboard_routes.
  135. * return 8259 edge/level masks.
  136. */
  137. void (*setup_ibm_pci)(char *irq_lo, char *irq_hi);
  138. extern char *Motherboard_map_name; /* for use in *_cpuinfo */
  139. /*
  140. * As found in the PReP reference implementation.
  141. * Used by Thinkpad, Sandalfoot (6015/7020), and all Motorola PReP.
  142. */
  143. static void __init
  144. prep_gen_enable_l2(void)
  145. {
  146. outb(inb(PREP_SYSCTL) | 0x3, PREP_SYSCTL);
  147. }
  148. /* Used by Carolina and Tiger1 */
  149. static void __init
  150. prep_carolina_enable_l2(void)
  151. {
  152. outb(inb(PREP_SYSCTL) | 0xc0, PREP_SYSCTL);
  153. }
  154. /* cpuinfo code common to all IBM PReP */
  155. static void
  156. prep_ibm_cpuinfo(struct seq_file *m)
  157. {
  158. unsigned int equip_reg = inb(PREP_IBM_EQUIPMENT);
  159. seq_printf(m, "machine\t\t: PReP %s\n", Motherboard_map_name);
  160. seq_printf(m, "upgrade cpu\t: ");
  161. if (equip_reg & PREP_IBM_EQUIPMENT_CPU) {
  162. seq_printf(m, "not ");
  163. }
  164. seq_printf(m, "present\n");
  165. /* print info about the SCSI fuse */
  166. seq_printf(m, "scsi fuse\t: ");
  167. if (equip_reg & PREP_IBM_EQUIPMENT_SCSIFUSE)
  168. seq_printf(m, "ok");
  169. else
  170. seq_printf(m, "bad");
  171. seq_printf(m, "\n");
  172. /* print info about SIMMs */
  173. if (have_residual_data) {
  174. int i;
  175. seq_printf(m, "simms\t\t: ");
  176. for (i = 0; (res->ActualNumMemories) && (i < MAX_MEMS); i++) {
  177. if (res->Memories[i].SIMMSize != 0)
  178. seq_printf(m, "%d:%ldMiB ", i,
  179. (res->Memories[i].SIMMSize > 1024) ?
  180. res->Memories[i].SIMMSize>>20 :
  181. res->Memories[i].SIMMSize);
  182. }
  183. seq_printf(m, "\n");
  184. }
  185. }
  186. static int
  187. prep_gen_cpuinfo(struct seq_file *m)
  188. {
  189. prep_ibm_cpuinfo(m);
  190. return 0;
  191. }
  192. static int
  193. prep_sandalfoot_cpuinfo(struct seq_file *m)
  194. {
  195. unsigned int equip_reg = inb(PREP_IBM_EQUIPMENT);
  196. prep_ibm_cpuinfo(m);
  197. /* report amount and type of L2 cache present */
  198. seq_printf(m, "L2 cache\t: ");
  199. if (equip_reg & PREP_IBM_EQUIPMENT_L2) {
  200. seq_printf(m, "not present");
  201. } else {
  202. if (equip_reg & PREP_IBM_EQUIPMENT_L2_256)
  203. seq_printf(m, "256KiB");
  204. else
  205. seq_printf(m, "unknown size");
  206. if (equip_reg & PREP_IBM_EQUIPMENT_L2_COPYBACK)
  207. seq_printf(m, ", copy-back");
  208. else
  209. seq_printf(m, ", write-through");
  210. }
  211. seq_printf(m, "\n");
  212. return 0;
  213. }
  214. static int
  215. prep_thinkpad_cpuinfo(struct seq_file *m)
  216. {
  217. unsigned int equip_reg = inb(PREP_IBM_EQUIPMENT);
  218. char *cpubus_speed, *pci_speed;
  219. prep_ibm_cpuinfo(m);
  220. /* report amount and type of L2 cache present */
  221. seq_printf(m, "l2 cache\t: ");
  222. if ((equip_reg & 0x1) == 0) {
  223. switch ((equip_reg & 0xc) >> 2) {
  224. case 0x0:
  225. seq_printf(m, "128KiB look-aside 2-way write-through\n");
  226. break;
  227. case 0x1:
  228. seq_printf(m, "512KiB look-aside direct-mapped write-back\n");
  229. break;
  230. case 0x2:
  231. seq_printf(m, "256KiB look-aside 2-way write-through\n");
  232. break;
  233. case 0x3:
  234. seq_printf(m, "256KiB look-aside direct-mapped write-back\n");
  235. break;
  236. }
  237. } else {
  238. seq_printf(m, "not present\n");
  239. }
  240. /* report bus speeds because we can */
  241. if ((equip_reg & 0x80) == 0) {
  242. switch ((equip_reg & 0x30) >> 4) {
  243. case 0x1:
  244. cpubus_speed = "50";
  245. pci_speed = "25";
  246. break;
  247. case 0x3:
  248. cpubus_speed = "66";
  249. pci_speed = "33";
  250. break;
  251. default:
  252. cpubus_speed = "unknown";
  253. pci_speed = "unknown";
  254. break;
  255. }
  256. } else {
  257. switch ((equip_reg & 0x30) >> 4) {
  258. case 0x1:
  259. cpubus_speed = "25";
  260. pci_speed = "25";
  261. break;
  262. case 0x2:
  263. cpubus_speed = "60";
  264. pci_speed = "30";
  265. break;
  266. case 0x3:
  267. cpubus_speed = "33";
  268. pci_speed = "33";
  269. break;
  270. default:
  271. cpubus_speed = "unknown";
  272. pci_speed = "unknown";
  273. break;
  274. }
  275. }
  276. seq_printf(m, "60x bus\t\t: %sMHz\n", cpubus_speed);
  277. seq_printf(m, "pci bus\t\t: %sMHz\n", pci_speed);
  278. return 0;
  279. }
  280. static int
  281. prep_carolina_cpuinfo(struct seq_file *m)
  282. {
  283. unsigned int equip_reg = inb(PREP_IBM_EQUIPMENT);
  284. prep_ibm_cpuinfo(m);
  285. /* report amount and type of L2 cache present */
  286. seq_printf(m, "l2 cache\t: ");
  287. if ((equip_reg & 0x1) == 0) {
  288. unsigned int l2_reg = inb(PREP_IBM_L2INFO);
  289. /* L2 size */
  290. if ((l2_reg & 0x60) == 0)
  291. seq_printf(m, "256KiB");
  292. else if ((l2_reg & 0x60) == 0x20)
  293. seq_printf(m, "512KiB");
  294. else
  295. seq_printf(m, "unknown size");
  296. /* L2 type */
  297. if ((l2_reg & 0x3) == 0)
  298. seq_printf(m, ", async");
  299. else if ((l2_reg & 0x3) == 1)
  300. seq_printf(m, ", sync");
  301. else
  302. seq_printf(m, ", unknown type");
  303. seq_printf(m, "\n");
  304. } else {
  305. seq_printf(m, "not present\n");
  306. }
  307. return 0;
  308. }
  309. static int
  310. prep_tiger1_cpuinfo(struct seq_file *m)
  311. {
  312. unsigned int l2_reg = inb(PREP_IBM_L2INFO);
  313. prep_ibm_cpuinfo(m);
  314. /* report amount and type of L2 cache present */
  315. seq_printf(m, "l2 cache\t: ");
  316. if ((l2_reg & 0xf) == 0xf) {
  317. seq_printf(m, "not present\n");
  318. } else {
  319. if (l2_reg & 0x8)
  320. seq_printf(m, "async, ");
  321. else
  322. seq_printf(m, "sync burst, ");
  323. if (l2_reg & 0x4)
  324. seq_printf(m, "parity, ");
  325. else
  326. seq_printf(m, "no parity, ");
  327. switch (l2_reg & 0x3) {
  328. case 0x0:
  329. seq_printf(m, "256KiB\n");
  330. break;
  331. case 0x1:
  332. seq_printf(m, "512KiB\n");
  333. break;
  334. case 0x2:
  335. seq_printf(m, "1MiB\n");
  336. break;
  337. default:
  338. seq_printf(m, "unknown size\n");
  339. break;
  340. }
  341. }
  342. return 0;
  343. }
  344. /* Used by all Motorola PReP */
  345. static int
  346. prep_mot_cpuinfo(struct seq_file *m)
  347. {
  348. unsigned int cachew = *((unsigned char *)CACHECRBA);
  349. seq_printf(m, "machine\t\t: PReP %s\n", Motherboard_map_name);
  350. /* report amount and type of L2 cache present */
  351. seq_printf(m, "l2 cache\t: ");
  352. switch (cachew & L2CACHE_MASK) {
  353. case L2CACHE_512KB:
  354. seq_printf(m, "512KiB");
  355. break;
  356. case L2CACHE_256KB:
  357. seq_printf(m, "256KiB");
  358. break;
  359. case L2CACHE_1MB:
  360. seq_printf(m, "1MiB");
  361. break;
  362. case L2CACHE_NONE:
  363. seq_printf(m, "none\n");
  364. goto no_l2;
  365. break;
  366. default:
  367. seq_printf(m, "%x\n", cachew);
  368. }
  369. seq_printf(m, ", parity %s",
  370. (cachew & L2CACHE_PARITY)? "enabled" : "disabled");
  371. seq_printf(m, " SRAM:");
  372. switch ( ((cachew & 0xf0) >> 4) & ~(0x3) ) {
  373. case 1: seq_printf(m, "synchronous, parity, flow-through\n");
  374. break;
  375. case 2: seq_printf(m, "asynchronous, no parity\n");
  376. break;
  377. case 3: seq_printf(m, "asynchronous, parity\n");
  378. break;
  379. default:seq_printf(m, "synchronous, pipelined, no parity\n");
  380. break;
  381. }
  382. no_l2:
  383. /* print info about SIMMs */
  384. if (have_residual_data) {
  385. int i;
  386. seq_printf(m, "simms\t\t: ");
  387. for (i = 0; (res->ActualNumMemories) && (i < MAX_MEMS); i++) {
  388. if (res->Memories[i].SIMMSize != 0)
  389. seq_printf(m, "%d:%ldM ", i,
  390. (res->Memories[i].SIMMSize > 1024) ?
  391. res->Memories[i].SIMMSize>>20 :
  392. res->Memories[i].SIMMSize);
  393. }
  394. seq_printf(m, "\n");
  395. }
  396. return 0;
  397. }
  398. static void
  399. prep_restart(char *cmd)
  400. {
  401. #define PREP_SP92 0x92 /* Special Port 92 */
  402. local_irq_disable(); /* no interrupts */
  403. /* set exception prefix high - to the prom */
  404. _nmask_and_or_msr(0, MSR_IP);
  405. /* make sure bit 0 (reset) is a 0 */
  406. outb( inb(PREP_SP92) & ~1L , PREP_SP92);
  407. /* signal a reset to system control port A - soft reset */
  408. outb( inb(PREP_SP92) | 1 , PREP_SP92);
  409. while ( 1 ) ;
  410. /* not reached */
  411. #undef PREP_SP92
  412. }
  413. static void
  414. prep_halt(void)
  415. {
  416. local_irq_disable(); /* no interrupts */
  417. /* set exception prefix high - to the prom */
  418. _nmask_and_or_msr(0, MSR_IP);
  419. while ( 1 ) ;
  420. /* not reached */
  421. }
  422. /* Carrera is the power manager in the Thinkpads. Unfortunately not much is
  423. * known about it, so we can't power down.
  424. */
  425. static void
  426. prep_carrera_poweroff(void)
  427. {
  428. prep_halt();
  429. }
  430. /*
  431. * On most IBM PReP's, power management is handled by a Signetics 87c750
  432. * behind the Utah component on the ISA bus. To access the 750 you must write
  433. * a series of nibbles to port 0x82a (decoded by the Utah). This is described
  434. * somewhat in the IBM Carolina Technical Specification.
  435. * -Hollis
  436. */
  437. static void
  438. utah_sig87c750_setbit(unsigned int bytenum, unsigned int bitnum, int value)
  439. {
  440. /*
  441. * byte1: 0 0 0 1 0 d a5 a4
  442. * byte2: 0 0 0 1 a3 a2 a1 a0
  443. *
  444. * d = the bit's value, enabled or disabled
  445. * (a5 a4 a3) = the byte number, minus 20
  446. * (a2 a1 a0) = the bit number
  447. *
  448. * example: set the 5th bit of byte 21 (21.5)
  449. * a5 a4 a3 = 001 (byte 1)
  450. * a2 a1 a0 = 101 (bit 5)
  451. *
  452. * byte1 = 0001 0100 (0x14)
  453. * byte2 = 0001 1101 (0x1d)
  454. */
  455. unsigned char byte1=0x10, byte2=0x10;
  456. /* the 750's '20.0' is accessed as '0.0' through Utah (which adds 20) */
  457. bytenum -= 20;
  458. byte1 |= (!!value) << 2; /* set d */
  459. byte1 |= (bytenum >> 1) & 0x3; /* set a5, a4 */
  460. byte2 |= (bytenum & 0x1) << 3; /* set a3 */
  461. byte2 |= bitnum & 0x7; /* set a2, a1, a0 */
  462. outb(byte1, PREP_IBM_PM1); /* first nibble */
  463. mb();
  464. udelay(100); /* important: let controller recover */
  465. outb(byte2, PREP_IBM_PM1); /* second nibble */
  466. mb();
  467. udelay(100); /* important: let controller recover */
  468. }
  469. static void
  470. prep_sig750_poweroff(void)
  471. {
  472. /* tweak the power manager found in most IBM PRePs (except Thinkpads) */
  473. local_irq_disable();
  474. /* set exception prefix high - to the prom */
  475. _nmask_and_or_msr(0, MSR_IP);
  476. utah_sig87c750_setbit(21, 5, 1); /* set bit 21.5, "PMEXEC_OFF" */
  477. while (1) ;
  478. /* not reached */
  479. }
  480. static int
  481. prep_show_percpuinfo(struct seq_file *m, int i)
  482. {
  483. /* PREP's without residual data will give incorrect values here */
  484. seq_printf(m, "clock\t\t: ");
  485. if (have_residual_data)
  486. seq_printf(m, "%ldMHz\n",
  487. (res->VitalProductData.ProcessorHz > 1024) ?
  488. res->VitalProductData.ProcessorHz / 1000000 :
  489. res->VitalProductData.ProcessorHz);
  490. else
  491. seq_printf(m, "???\n");
  492. return 0;
  493. }
  494. #ifdef CONFIG_SOUND_CS4232
  495. static long __init masktoint(unsigned int i)
  496. {
  497. int t = -1;
  498. while (i >> ++t)
  499. ;
  500. return (t-1);
  501. }
  502. /*
  503. * ppc_cs4232_dma and ppc_cs4232_dma2 are used in include/asm/dma.h
  504. * to distinguish sound dma-channels from others. This is because
  505. * blocksize on 16 bit dma-channels 5,6,7 is 128k, but
  506. * the cs4232.c uses 64k like on 8 bit dma-channels 0,1,2,3
  507. */
  508. static void __init prep_init_sound(void)
  509. {
  510. PPC_DEVICE *audiodevice = NULL;
  511. /*
  512. * Get the needed resource informations from residual data.
  513. *
  514. */
  515. if (have_residual_data)
  516. audiodevice = residual_find_device(~0, NULL,
  517. MultimediaController, AudioController, -1, 0);
  518. if (audiodevice != NULL) {
  519. PnP_TAG_PACKET *pkt;
  520. pkt = PnP_find_packet((unsigned char *)&res->DevicePnPHeap[audiodevice->AllocatedOffset],
  521. S5_Packet, 0);
  522. if (pkt != NULL)
  523. ppc_cs4232_dma = masktoint(pkt->S5_Pack.DMAMask);
  524. pkt = PnP_find_packet((unsigned char*)&res->DevicePnPHeap[audiodevice->AllocatedOffset],
  525. S5_Packet, 1);
  526. if (pkt != NULL)
  527. ppc_cs4232_dma2 = masktoint(pkt->S5_Pack.DMAMask);
  528. }
  529. /*
  530. * These are the PReP specs' defaults for the cs4231. We use these
  531. * as fallback incase we don't have residual data.
  532. * At least the IBM Thinkpad 850 with IDE DMA Channels at 6 and 7
  533. * will use the other values.
  534. */
  535. if (audiodevice == NULL) {
  536. switch (_prep_type) {
  537. case _PREP_IBM:
  538. ppc_cs4232_dma = 1;
  539. ppc_cs4232_dma2 = -1;
  540. break;
  541. default:
  542. ppc_cs4232_dma = 6;
  543. ppc_cs4232_dma2 = 7;
  544. }
  545. }
  546. /*
  547. * Find a way to push these informations to the cs4232 driver
  548. * Give it out with printk, when not in cmd_line?
  549. * Append it to cmd_line and saved_command_line?
  550. * Format is cs4232=io,irq,dma,dma2
  551. */
  552. }
  553. #endif /* CONFIG_SOUND_CS4232 */
  554. /*
  555. * Fill out screen_info according to the residual data. This allows us to use
  556. * at least vesafb.
  557. */
  558. static void __init
  559. prep_init_vesa(void)
  560. {
  561. #if (defined(CONFIG_FB_VGA16) || defined(CONFIG_FB_VGA16_MODULE) || \
  562. defined(CONFIG_FB_VESA))
  563. PPC_DEVICE *vgadev = NULL;
  564. if (have_residual_data)
  565. vgadev = residual_find_device(~0, NULL, DisplayController,
  566. SVGAController, -1, 0);
  567. if (vgadev != NULL) {
  568. PnP_TAG_PACKET *pkt;
  569. pkt = PnP_find_large_vendor_packet(
  570. (unsigned char *)&res->DevicePnPHeap[vgadev->AllocatedOffset],
  571. 0x04, 0); /* 0x04 = Display Tag */
  572. if (pkt != NULL) {
  573. unsigned char *ptr = (unsigned char *)pkt;
  574. if (ptr[4]) {
  575. /* graphics mode */
  576. screen_info.orig_video_isVGA = VIDEO_TYPE_VLFB;
  577. screen_info.lfb_depth = ptr[4] * 8;
  578. screen_info.lfb_width = swab16(*(short *)(ptr+6));
  579. screen_info.lfb_height = swab16(*(short *)(ptr+8));
  580. screen_info.lfb_linelength = swab16(*(short *)(ptr+10));
  581. screen_info.lfb_base = swab32(*(long *)(ptr+12));
  582. screen_info.lfb_size = swab32(*(long *)(ptr+20)) / 65536;
  583. }
  584. }
  585. }
  586. #endif
  587. }
  588. /*
  589. * Set DBAT 2 to access 0x80000000 so early progress messages will work
  590. */
  591. static __inline__ void
  592. prep_set_bat(void)
  593. {
  594. /* wait for all outstanding memory access to complete */
  595. mb();
  596. /* setup DBATs */
  597. mtspr(SPRN_DBAT2U, 0x80001ffe);
  598. mtspr(SPRN_DBAT2L, 0x8000002a);
  599. /* wait for updates */
  600. mb();
  601. }
  602. /*
  603. * IBM 3-digit status LED
  604. */
  605. static unsigned int ibm_statusled_base;
  606. static void
  607. ibm_statusled_progress(char *s, unsigned short hex);
  608. static int
  609. ibm_statusled_panic(struct notifier_block *dummy1, unsigned long dummy2,
  610. void * dummy3)
  611. {
  612. ibm_statusled_progress(NULL, 0x505); /* SOS */
  613. return NOTIFY_DONE;
  614. }
  615. static struct notifier_block ibm_statusled_block = {
  616. ibm_statusled_panic,
  617. NULL,
  618. INT_MAX /* try to do it first */
  619. };
  620. static void
  621. ibm_statusled_progress(char *s, unsigned short hex)
  622. {
  623. static int notifier_installed;
  624. /*
  625. * Progress uses 4 digits and we have only 3. So, we map 0xffff to
  626. * 0xfff for display switch off. Out of range values are mapped to
  627. * 0xeff, as I'm told 0xf00 and above are reserved for hardware codes.
  628. * Install the panic notifier when the display is first switched off.
  629. */
  630. if (hex == 0xffff) {
  631. hex = 0xfff;
  632. if (!notifier_installed) {
  633. ++notifier_installed;
  634. atomic_notifier_chain_register(&panic_notifier_list,
  635. &ibm_statusled_block);
  636. }
  637. }
  638. else
  639. if (hex > 0xfff)
  640. hex = 0xeff;
  641. mb();
  642. outw(hex, ibm_statusled_base);
  643. }
  644. static void __init
  645. ibm_statusled_init(void)
  646. {
  647. /*
  648. * The IBM 3-digit LED display is specified in the residual data
  649. * as an operator panel device, type "System Status LED". Find
  650. * that device and determine its address. We validate all the
  651. * other parameters on the off-chance another, similar device
  652. * exists.
  653. */
  654. if (have_residual_data) {
  655. PPC_DEVICE *led;
  656. PnP_TAG_PACKET *pkt;
  657. led = residual_find_device(~0, NULL, SystemPeripheral,
  658. OperatorPanel, SystemStatusLED, 0);
  659. if (!led)
  660. return;
  661. pkt = PnP_find_packet((unsigned char *)
  662. &res->DevicePnPHeap[led->AllocatedOffset], S8_Packet, 0);
  663. if (!pkt)
  664. return;
  665. if (pkt->S8_Pack.IOInfo != ISAAddr16bit)
  666. return;
  667. if (*(unsigned short *)pkt->S8_Pack.RangeMin !=
  668. *(unsigned short *)pkt->S8_Pack.RangeMax)
  669. return;
  670. if (pkt->S8_Pack.IOAlign != 2)
  671. return;
  672. if (pkt->S8_Pack.IONum != 2)
  673. return;
  674. ibm_statusled_base = ld_le16((unsigned short *)
  675. (pkt->S8_Pack.RangeMin));
  676. ppc_md.progress = ibm_statusled_progress;
  677. }
  678. }
  679. static void __init
  680. prep_setup_arch(void)
  681. {
  682. unsigned char reg;
  683. int is_ide=0;
  684. /* init to some ~sane value until calibrate_delay() runs */
  685. loops_per_jiffy = 50000000;
  686. /* Lookup PCI host bridges */
  687. prep_find_bridges();
  688. /* Set up floppy in PS/2 mode */
  689. outb(0x09, SIO_CONFIG_RA);
  690. reg = inb(SIO_CONFIG_RD);
  691. reg = (reg & 0x3F) | 0x40;
  692. outb(reg, SIO_CONFIG_RD);
  693. outb(reg, SIO_CONFIG_RD); /* Have to write twice to change! */
  694. switch ( _prep_type )
  695. {
  696. case _PREP_IBM:
  697. reg = inb(PREP_IBM_PLANAR);
  698. printk(KERN_INFO "IBM planar ID: %02x", reg);
  699. switch (reg) {
  700. case PREP_IBM_SANDALFOOT:
  701. prep_gen_enable_l2();
  702. setup_ibm_pci = prep_sandalfoot_setup_pci;
  703. ppc_md.power_off = prep_sig750_poweroff;
  704. ppc_md.show_cpuinfo = prep_sandalfoot_cpuinfo;
  705. break;
  706. case PREP_IBM_THINKPAD:
  707. prep_gen_enable_l2();
  708. setup_ibm_pci = prep_thinkpad_setup_pci;
  709. ppc_md.power_off = prep_carrera_poweroff;
  710. ppc_md.show_cpuinfo = prep_thinkpad_cpuinfo;
  711. break;
  712. default:
  713. if (have_residual_data) {
  714. prep_gen_enable_l2();
  715. setup_ibm_pci = prep_residual_setup_pci;
  716. ppc_md.power_off = prep_halt;
  717. ppc_md.show_cpuinfo = prep_gen_cpuinfo;
  718. break;
  719. }
  720. else
  721. printk(" - unknown! Assuming Carolina");
  722. /* fall through */
  723. case PREP_IBM_CAROLINA_IDE_0:
  724. case PREP_IBM_CAROLINA_IDE_1:
  725. case PREP_IBM_CAROLINA_IDE_2:
  726. case PREP_IBM_CAROLINA_IDE_3:
  727. is_ide = 1;
  728. case PREP_IBM_CAROLINA_SCSI_0:
  729. case PREP_IBM_CAROLINA_SCSI_1:
  730. case PREP_IBM_CAROLINA_SCSI_2:
  731. case PREP_IBM_CAROLINA_SCSI_3:
  732. prep_carolina_enable_l2();
  733. setup_ibm_pci = prep_carolina_setup_pci;
  734. ppc_md.power_off = prep_sig750_poweroff;
  735. ppc_md.show_cpuinfo = prep_carolina_cpuinfo;
  736. break;
  737. case PREP_IBM_TIGER1_133:
  738. case PREP_IBM_TIGER1_166:
  739. case PREP_IBM_TIGER1_180:
  740. case PREP_IBM_TIGER1_xxx:
  741. case PREP_IBM_TIGER1_333:
  742. prep_carolina_enable_l2();
  743. setup_ibm_pci = prep_tiger1_setup_pci;
  744. ppc_md.power_off = prep_sig750_poweroff;
  745. ppc_md.show_cpuinfo = prep_tiger1_cpuinfo;
  746. break;
  747. }
  748. printk("\n");
  749. /* default root device */
  750. if (is_ide)
  751. ROOT_DEV = MKDEV(IDE0_MAJOR, 3);
  752. else
  753. ROOT_DEV = MKDEV(SCSI_DISK0_MAJOR, 3);
  754. break;
  755. case _PREP_Motorola:
  756. prep_gen_enable_l2();
  757. ppc_md.power_off = prep_halt;
  758. ppc_md.show_cpuinfo = prep_mot_cpuinfo;
  759. #ifdef CONFIG_BLK_DEV_INITRD
  760. if (initrd_start)
  761. ROOT_DEV = Root_RAM0;
  762. else
  763. #endif
  764. #ifdef CONFIG_ROOT_NFS
  765. ROOT_DEV = Root_NFS;
  766. #else
  767. ROOT_DEV = Root_SDA2;
  768. #endif
  769. break;
  770. }
  771. /* Read in NVRAM data */
  772. init_prep_nvram();
  773. /* if no bootargs, look in NVRAM */
  774. if ( cmd_line[0] == '\0' ) {
  775. char *bootargs;
  776. bootargs = prep_nvram_get_var("bootargs");
  777. if (bootargs != NULL) {
  778. strcpy(cmd_line, bootargs);
  779. /* again.. */
  780. strcpy(saved_command_line, cmd_line);
  781. }
  782. }
  783. #ifdef CONFIG_SOUND_CS4232
  784. prep_init_sound();
  785. #endif /* CONFIG_SOUND_CS4232 */
  786. prep_init_vesa();
  787. switch (_prep_type) {
  788. case _PREP_Motorola:
  789. raven_init();
  790. break;
  791. case _PREP_IBM:
  792. ibm_prep_init();
  793. break;
  794. }
  795. #ifdef CONFIG_VGA_CONSOLE
  796. /* vgacon.c needs to know where we mapped IO memory in io_block_mapping() */
  797. vgacon_remap_base = 0xf0000000;
  798. conswitchp = &vga_con;
  799. #endif
  800. }
  801. /*
  802. * First, see if we can get this information from the residual data.
  803. * This is important on some IBM PReP systems. If we cannot, we let the
  804. * TODC code handle doing this.
  805. */
  806. static void __init
  807. prep_calibrate_decr(void)
  808. {
  809. if (have_residual_data) {
  810. unsigned long freq, divisor = 4;
  811. if ( res->VitalProductData.ProcessorBusHz ) {
  812. freq = res->VitalProductData.ProcessorBusHz;
  813. printk("time_init: decrementer frequency = %lu.%.6lu MHz\n",
  814. (freq/divisor)/1000000,
  815. (freq/divisor)%1000000);
  816. tb_to_us = mulhwu_scale_factor(freq/divisor, 1000000);
  817. tb_ticks_per_jiffy = freq / HZ / divisor;
  818. }
  819. }
  820. else
  821. todc_calibrate_decr();
  822. }
  823. static void __init
  824. prep_init_IRQ(void)
  825. {
  826. unsigned int pci_viddid, pci_did;
  827. if (OpenPIC_Addr != NULL) {
  828. openpic_init(NUM_8259_INTERRUPTS);
  829. /* We have a cascade on OpenPIC IRQ 0, Linux IRQ 16 */
  830. openpic_hookup_cascade(NUM_8259_INTERRUPTS, "82c59 cascade",
  831. i8259_irq);
  832. }
  833. if (have_residual_data) {
  834. i8259_init(residual_isapic_addr(), 0);
  835. return;
  836. }
  837. /* If we have a Raven PCI bridge or a Hawk PCI bridge / Memory
  838. * controller, we poll (as they have a different int-ack address). */
  839. early_read_config_dword(NULL, 0, 0, PCI_VENDOR_ID, &pci_viddid);
  840. pci_did = (pci_viddid & 0xffff0000) >> 16;
  841. if (((pci_viddid & 0xffff) == PCI_VENDOR_ID_MOTOROLA)
  842. && ((pci_did == PCI_DEVICE_ID_MOTOROLA_RAVEN)
  843. || (pci_did == PCI_DEVICE_ID_MOTOROLA_HAWK)))
  844. i8259_init(0, 0);
  845. else
  846. /* PCI interrupt ack address given in section 6.1.8 of the
  847. * PReP specification. */
  848. i8259_init(MPC10X_MAPA_PCI_INTACK_ADDR, 0);
  849. }
  850. #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
  851. /*
  852. * IDE stuff.
  853. */
  854. static int
  855. prep_ide_default_irq(unsigned long base)
  856. {
  857. switch (base) {
  858. case 0x1f0: return 13;
  859. case 0x170: return 13;
  860. case 0x1e8: return 11;
  861. case 0x168: return 10;
  862. case 0xfff0: return 14; /* MCP(N)750 ide0 */
  863. case 0xffe0: return 15; /* MCP(N)750 ide1 */
  864. default: return 0;
  865. }
  866. }
  867. static unsigned long
  868. prep_ide_default_io_base(int index)
  869. {
  870. switch (index) {
  871. case 0: return 0x1f0;
  872. case 1: return 0x170;
  873. case 2: return 0x1e8;
  874. case 3: return 0x168;
  875. default:
  876. return 0;
  877. }
  878. }
  879. #endif
  880. #ifdef CONFIG_SMP
  881. /* PReP (MTX) support */
  882. static int __init
  883. smp_prep_probe(void)
  884. {
  885. extern int mot_multi;
  886. if (mot_multi) {
  887. openpic_request_IPIs();
  888. smp_hw_index[1] = 1;
  889. return 2;
  890. }
  891. return 1;
  892. }
  893. static void __init
  894. smp_prep_kick_cpu(int nr)
  895. {
  896. *(unsigned long *)KERNELBASE = nr;
  897. asm volatile("dcbf 0,%0"::"r"(KERNELBASE):"memory");
  898. printk("CPU1 released, waiting\n");
  899. }
  900. static void __init
  901. smp_prep_setup_cpu(int cpu_nr)
  902. {
  903. if (OpenPIC_Addr)
  904. do_openpic_setup_cpu();
  905. }
  906. static struct smp_ops_t prep_smp_ops = {
  907. smp_openpic_message_pass,
  908. smp_prep_probe,
  909. smp_prep_kick_cpu,
  910. smp_prep_setup_cpu,
  911. .give_timebase = smp_generic_give_timebase,
  912. .take_timebase = smp_generic_take_timebase,
  913. };
  914. #endif /* CONFIG_SMP */
  915. /*
  916. * Setup the bat mappings we're going to load that cover
  917. * the io areas. RAM was mapped by mapin_ram().
  918. * -- Cort
  919. */
  920. static void __init
  921. prep_map_io(void)
  922. {
  923. io_block_mapping(0x80000000, PREP_ISA_IO_BASE, 0x10000000, _PAGE_IO);
  924. io_block_mapping(0xf0000000, PREP_ISA_MEM_BASE, 0x08000000, _PAGE_IO);
  925. }
  926. static int __init
  927. prep_request_io(void)
  928. {
  929. #ifdef CONFIG_NVRAM
  930. request_region(PREP_NVRAM_AS0, 0x8, "nvram");
  931. #endif
  932. request_region(0x00,0x20,"dma1");
  933. request_region(0x40,0x20,"timer");
  934. request_region(0x80,0x10,"dma page reg");
  935. request_region(0xc0,0x20,"dma2");
  936. return 0;
  937. }
  938. device_initcall(prep_request_io);
  939. void __init
  940. prep_init(unsigned long r3, unsigned long r4, unsigned long r5,
  941. unsigned long r6, unsigned long r7)
  942. {
  943. #ifdef CONFIG_PREP_RESIDUAL
  944. /* make a copy of residual data */
  945. if ( r3 ) {
  946. memcpy((void *)res,(void *)(r3+KERNELBASE),
  947. sizeof(RESIDUAL));
  948. }
  949. #endif
  950. isa_io_base = PREP_ISA_IO_BASE;
  951. isa_mem_base = PREP_ISA_MEM_BASE;
  952. pci_dram_offset = PREP_PCI_DRAM_OFFSET;
  953. ISA_DMA_THRESHOLD = 0x00ffffff;
  954. DMA_MODE_READ = 0x44;
  955. DMA_MODE_WRITE = 0x48;
  956. ppc_do_canonicalize_irqs = 1;
  957. /* figure out what kind of prep workstation we are */
  958. if (have_residual_data) {
  959. if ( !strncmp(res->VitalProductData.PrintableModel,"IBM",3) )
  960. _prep_type = _PREP_IBM;
  961. else
  962. _prep_type = _PREP_Motorola;
  963. }
  964. else {
  965. /* assume motorola if no residual (netboot?) */
  966. _prep_type = _PREP_Motorola;
  967. }
  968. #ifdef CONFIG_PREP_RESIDUAL
  969. /* Switch off all residual data processing if the user requests it */
  970. if (strstr(cmd_line, "noresidual") != NULL)
  971. res = NULL;
  972. #endif
  973. /* Initialise progress early to get maximum benefit */
  974. prep_set_bat();
  975. ibm_statusled_init();
  976. ppc_md.setup_arch = prep_setup_arch;
  977. ppc_md.show_percpuinfo = prep_show_percpuinfo;
  978. ppc_md.show_cpuinfo = NULL; /* set in prep_setup_arch() */
  979. ppc_md.init_IRQ = prep_init_IRQ;
  980. /* this gets changed later on if we have an OpenPIC -- Cort */
  981. ppc_md.get_irq = i8259_irq;
  982. ppc_md.phys_mem_access_prot = pci_phys_mem_access_prot;
  983. ppc_md.restart = prep_restart;
  984. ppc_md.power_off = NULL; /* set in prep_setup_arch() */
  985. ppc_md.halt = prep_halt;
  986. ppc_md.nvram_read_val = prep_nvram_read_val;
  987. ppc_md.nvram_write_val = prep_nvram_write_val;
  988. ppc_md.time_init = todc_time_init;
  989. if (_prep_type == _PREP_IBM) {
  990. ppc_md.rtc_read_val = todc_mc146818_read_val;
  991. ppc_md.rtc_write_val = todc_mc146818_write_val;
  992. TODC_INIT(TODC_TYPE_MC146818, RTC_PORT(0), NULL, RTC_PORT(1),
  993. 8);
  994. } else {
  995. TODC_INIT(TODC_TYPE_MK48T59, PREP_NVRAM_AS0, PREP_NVRAM_AS1,
  996. PREP_NVRAM_DATA, 8);
  997. }
  998. ppc_md.calibrate_decr = prep_calibrate_decr;
  999. ppc_md.set_rtc_time = todc_set_rtc_time;
  1000. ppc_md.get_rtc_time = todc_get_rtc_time;
  1001. ppc_md.setup_io_mappings = prep_map_io;
  1002. #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
  1003. ppc_ide_md.default_irq = prep_ide_default_irq;
  1004. ppc_ide_md.default_io_base = prep_ide_default_io_base;
  1005. #endif
  1006. #ifdef CONFIG_SMP
  1007. smp_ops = &prep_smp_ops;
  1008. #endif /* CONFIG_SMP */
  1009. }