prep_setup.c 28 KB

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