prep_setup.c 28 KB

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