mca_32.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. /*
  2. * Written by Martin Kolinek, February 1996
  3. *
  4. * Changes:
  5. *
  6. * Chris Beauregard July 28th, 1996
  7. * - Fixed up integrated SCSI detection
  8. *
  9. * Chris Beauregard August 3rd, 1996
  10. * - Made mca_info local
  11. * - Made integrated registers accessible through standard function calls
  12. * - Added name field
  13. * - More sanity checking
  14. *
  15. * Chris Beauregard August 9th, 1996
  16. * - Rewrote /proc/mca
  17. *
  18. * Chris Beauregard January 7th, 1997
  19. * - Added basic NMI-processing
  20. * - Added more information to mca_info structure
  21. *
  22. * David Weinehall October 12th, 1998
  23. * - Made a lot of cleaning up in the source
  24. * - Added use of save_flags / restore_flags
  25. * - Added the 'driver_loaded' flag in MCA_adapter
  26. * - Added an alternative implemention of ZP Gu's mca_find_unused_adapter
  27. *
  28. * David Weinehall March 24th, 1999
  29. * - Fixed the output of 'Driver Installed' in /proc/mca/pos
  30. * - Made the Integrated Video & SCSI show up even if they have id 0000
  31. *
  32. * Alexander Viro November 9th, 1999
  33. * - Switched to regular procfs methods
  34. *
  35. * Alfred Arnold & David Weinehall August 23rd, 2000
  36. * - Added support for Planar POS-registers
  37. */
  38. #include <linux/module.h>
  39. #include <linux/types.h>
  40. #include <linux/errno.h>
  41. #include <linux/kernel.h>
  42. #include <linux/mca.h>
  43. #include <linux/kprobes.h>
  44. #include <asm/system.h>
  45. #include <asm/io.h>
  46. #include <linux/proc_fs.h>
  47. #include <linux/mman.h>
  48. #include <linux/mm.h>
  49. #include <linux/pagemap.h>
  50. #include <linux/ioport.h>
  51. #include <asm/uaccess.h>
  52. #include <linux/init.h>
  53. #include <asm/arch_hooks.h>
  54. static unsigned char which_scsi = 0;
  55. int MCA_bus = 0;
  56. EXPORT_SYMBOL(MCA_bus);
  57. /*
  58. * Motherboard register spinlock. Untested on SMP at the moment, but
  59. * are there any MCA SMP boxes?
  60. *
  61. * Yes - Alan
  62. */
  63. static DEFINE_SPINLOCK(mca_lock);
  64. /* Build the status info for the adapter */
  65. static void mca_configure_adapter_status(struct mca_device *mca_dev) {
  66. mca_dev->status = MCA_ADAPTER_NONE;
  67. mca_dev->pos_id = mca_dev->pos[0]
  68. + (mca_dev->pos[1] << 8);
  69. if(!mca_dev->pos_id && mca_dev->slot < MCA_MAX_SLOT_NR) {
  70. /* id = 0x0000 usually indicates hardware failure,
  71. * however, ZP Gu (zpg@castle.net> reports that his 9556
  72. * has 0x0000 as id and everything still works. There
  73. * also seem to be an adapter with id = 0x0000; the
  74. * NCR Parallel Bus Memory Card. Until this is confirmed,
  75. * however, this code will stay.
  76. */
  77. mca_dev->status = MCA_ADAPTER_ERROR;
  78. return;
  79. } else if(mca_dev->pos_id != 0xffff) {
  80. /* 0xffff usually indicates that there's no adapter,
  81. * however, some integrated adapters may have 0xffff as
  82. * their id and still be valid. Examples are on-board
  83. * VGA of the 55sx, the integrated SCSI of the 56 & 57,
  84. * and possibly also the 95 ULTIMEDIA.
  85. */
  86. mca_dev->status = MCA_ADAPTER_NORMAL;
  87. }
  88. if((mca_dev->pos_id == 0xffff ||
  89. mca_dev->pos_id == 0x0000) && mca_dev->slot >= MCA_MAX_SLOT_NR) {
  90. int j;
  91. for(j = 2; j < 8; j++) {
  92. if(mca_dev->pos[j] != 0xff) {
  93. mca_dev->status = MCA_ADAPTER_NORMAL;
  94. break;
  95. }
  96. }
  97. }
  98. if(!(mca_dev->pos[2] & MCA_ENABLED)) {
  99. /* enabled bit is in POS 2 */
  100. mca_dev->status = MCA_ADAPTER_DISABLED;
  101. }
  102. } /* mca_configure_adapter_status */
  103. /*--------------------------------------------------------------------*/
  104. static struct resource mca_standard_resources[] = {
  105. { .start = 0x60, .end = 0x60, .name = "system control port B (MCA)" },
  106. { .start = 0x90, .end = 0x90, .name = "arbitration (MCA)" },
  107. { .start = 0x91, .end = 0x91, .name = "card Select Feedback (MCA)" },
  108. { .start = 0x92, .end = 0x92, .name = "system Control port A (MCA)" },
  109. { .start = 0x94, .end = 0x94, .name = "system board setup (MCA)" },
  110. { .start = 0x96, .end = 0x97, .name = "POS (MCA)" },
  111. { .start = 0x100, .end = 0x107, .name = "POS (MCA)" }
  112. };
  113. #define MCA_STANDARD_RESOURCES ARRAY_SIZE(mca_standard_resources)
  114. /**
  115. * mca_read_and_store_pos - read the POS registers into a memory buffer
  116. * @pos: a char pointer to 8 bytes, contains the POS register value on
  117. * successful return
  118. *
  119. * Returns 1 if a card actually exists (i.e. the pos isn't
  120. * all 0xff) or 0 otherwise
  121. */
  122. static int mca_read_and_store_pos(unsigned char *pos) {
  123. int j;
  124. int found = 0;
  125. for(j=0; j<8; j++) {
  126. if((pos[j] = inb_p(MCA_POS_REG(j))) != 0xff) {
  127. /* 0xff all across means no device. 0x00 means
  128. * something's broken, but a device is
  129. * probably there. However, if you get 0x00
  130. * from a motherboard register it won't matter
  131. * what we find. For the record, on the
  132. * 57SLC, the integrated SCSI adapter has
  133. * 0xffff for the adapter ID, but nonzero for
  134. * other registers. */
  135. found = 1;
  136. }
  137. }
  138. return found;
  139. }
  140. static unsigned char mca_pc_read_pos(struct mca_device *mca_dev, int reg)
  141. {
  142. unsigned char byte;
  143. unsigned long flags;
  144. if(reg < 0 || reg >= 8)
  145. return 0;
  146. spin_lock_irqsave(&mca_lock, flags);
  147. if(mca_dev->pos_register) {
  148. /* Disable adapter setup, enable motherboard setup */
  149. outb_p(0, MCA_ADAPTER_SETUP_REG);
  150. outb_p(mca_dev->pos_register, MCA_MOTHERBOARD_SETUP_REG);
  151. byte = inb_p(MCA_POS_REG(reg));
  152. outb_p(0xff, MCA_MOTHERBOARD_SETUP_REG);
  153. } else {
  154. /* Make sure motherboard setup is off */
  155. outb_p(0xff, MCA_MOTHERBOARD_SETUP_REG);
  156. /* Read the appropriate register */
  157. outb_p(0x8|(mca_dev->slot & 0xf), MCA_ADAPTER_SETUP_REG);
  158. byte = inb_p(MCA_POS_REG(reg));
  159. outb_p(0, MCA_ADAPTER_SETUP_REG);
  160. }
  161. spin_unlock_irqrestore(&mca_lock, flags);
  162. mca_dev->pos[reg] = byte;
  163. return byte;
  164. }
  165. static void mca_pc_write_pos(struct mca_device *mca_dev, int reg,
  166. unsigned char byte)
  167. {
  168. unsigned long flags;
  169. if(reg < 0 || reg >= 8)
  170. return;
  171. spin_lock_irqsave(&mca_lock, flags);
  172. /* Make sure motherboard setup is off */
  173. outb_p(0xff, MCA_MOTHERBOARD_SETUP_REG);
  174. /* Read in the appropriate register */
  175. outb_p(0x8|(mca_dev->slot&0xf), MCA_ADAPTER_SETUP_REG);
  176. outb_p(byte, MCA_POS_REG(reg));
  177. outb_p(0, MCA_ADAPTER_SETUP_REG);
  178. spin_unlock_irqrestore(&mca_lock, flags);
  179. /* Update the global register list, while we have the byte */
  180. mca_dev->pos[reg] = byte;
  181. }
  182. /* for the primary MCA bus, we have identity transforms */
  183. static int mca_dummy_transform_irq(struct mca_device * mca_dev, int irq)
  184. {
  185. return irq;
  186. }
  187. static int mca_dummy_transform_ioport(struct mca_device * mca_dev, int port)
  188. {
  189. return port;
  190. }
  191. static void *mca_dummy_transform_memory(struct mca_device * mca_dev, void *mem)
  192. {
  193. return mem;
  194. }
  195. static int __init mca_init(void)
  196. {
  197. unsigned int i, j;
  198. struct mca_device *mca_dev;
  199. unsigned char pos[8];
  200. short mca_builtin_scsi_ports[] = {0xf7, 0xfd, 0x00};
  201. struct mca_bus *bus;
  202. /* WARNING: Be careful when making changes here. Putting an adapter
  203. * and the motherboard simultaneously into setup mode may result in
  204. * damage to chips (according to The Indispensible PC Hardware Book
  205. * by Hans-Peter Messmer). Also, we disable system interrupts (so
  206. * that we are not disturbed in the middle of this).
  207. */
  208. /* Make sure the MCA bus is present */
  209. if (mca_system_init()) {
  210. printk(KERN_ERR "MCA bus system initialisation failed\n");
  211. return -ENODEV;
  212. }
  213. if (!MCA_bus)
  214. return -ENODEV;
  215. printk(KERN_INFO "Micro Channel bus detected.\n");
  216. /* All MCA systems have at least a primary bus */
  217. bus = mca_attach_bus(MCA_PRIMARY_BUS);
  218. if (!bus)
  219. goto out_nomem;
  220. bus->default_dma_mask = 0xffffffffLL;
  221. bus->f.mca_write_pos = mca_pc_write_pos;
  222. bus->f.mca_read_pos = mca_pc_read_pos;
  223. bus->f.mca_transform_irq = mca_dummy_transform_irq;
  224. bus->f.mca_transform_ioport = mca_dummy_transform_ioport;
  225. bus->f.mca_transform_memory = mca_dummy_transform_memory;
  226. /* get the motherboard device */
  227. mca_dev = kzalloc(sizeof(struct mca_device), GFP_KERNEL);
  228. if(unlikely(!mca_dev))
  229. goto out_nomem;
  230. /*
  231. * We do not expect many MCA interrupts during initialization,
  232. * but let us be safe:
  233. */
  234. spin_lock_irq(&mca_lock);
  235. /* Make sure adapter setup is off */
  236. outb_p(0, MCA_ADAPTER_SETUP_REG);
  237. /* Read motherboard POS registers */
  238. mca_dev->pos_register = 0x7f;
  239. outb_p(mca_dev->pos_register, MCA_MOTHERBOARD_SETUP_REG);
  240. mca_dev->name[0] = 0;
  241. mca_read_and_store_pos(mca_dev->pos);
  242. mca_configure_adapter_status(mca_dev);
  243. /* fake POS and slot for a motherboard */
  244. mca_dev->pos_id = MCA_MOTHERBOARD_POS;
  245. mca_dev->slot = MCA_MOTHERBOARD;
  246. mca_register_device(MCA_PRIMARY_BUS, mca_dev);
  247. mca_dev = kzalloc(sizeof(struct mca_device), GFP_ATOMIC);
  248. if(unlikely(!mca_dev))
  249. goto out_unlock_nomem;
  250. /* Put motherboard into video setup mode, read integrated video
  251. * POS registers, and turn motherboard setup off.
  252. */
  253. mca_dev->pos_register = 0xdf;
  254. outb_p(mca_dev->pos_register, MCA_MOTHERBOARD_SETUP_REG);
  255. mca_dev->name[0] = 0;
  256. mca_read_and_store_pos(mca_dev->pos);
  257. mca_configure_adapter_status(mca_dev);
  258. /* fake POS and slot for the integrated video */
  259. mca_dev->pos_id = MCA_INTEGVIDEO_POS;
  260. mca_dev->slot = MCA_INTEGVIDEO;
  261. mca_register_device(MCA_PRIMARY_BUS, mca_dev);
  262. /* Put motherboard into scsi setup mode, read integrated scsi
  263. * POS registers, and turn motherboard setup off.
  264. *
  265. * It seems there are two possible SCSI registers. Martin says that
  266. * for the 56,57, 0xf7 is the one, but fails on the 76.
  267. * Alfredo (apena@vnet.ibm.com) says
  268. * 0xfd works on his machine. We'll try both of them. I figure it's
  269. * a good bet that only one could be valid at a time. This could
  270. * screw up though if one is used for something else on the other
  271. * machine.
  272. */
  273. for(i = 0; (which_scsi = mca_builtin_scsi_ports[i]) != 0; i++) {
  274. outb_p(which_scsi, MCA_MOTHERBOARD_SETUP_REG);
  275. if(mca_read_and_store_pos(pos))
  276. break;
  277. }
  278. if(which_scsi) {
  279. /* found a scsi card */
  280. mca_dev = kzalloc(sizeof(struct mca_device), GFP_ATOMIC);
  281. if(unlikely(!mca_dev))
  282. goto out_unlock_nomem;
  283. for(j = 0; j < 8; j++)
  284. mca_dev->pos[j] = pos[j];
  285. mca_configure_adapter_status(mca_dev);
  286. /* fake POS and slot for integrated SCSI controller */
  287. mca_dev->pos_id = MCA_INTEGSCSI_POS;
  288. mca_dev->slot = MCA_INTEGSCSI;
  289. mca_dev->pos_register = which_scsi;
  290. mca_register_device(MCA_PRIMARY_BUS, mca_dev);
  291. }
  292. /* Turn off motherboard setup */
  293. outb_p(0xff, MCA_MOTHERBOARD_SETUP_REG);
  294. /* Now loop over MCA slots: put each adapter into setup mode, and
  295. * read its POS registers. Then put adapter setup off.
  296. */
  297. for(i=0; i<MCA_MAX_SLOT_NR; i++) {
  298. outb_p(0x8|(i&0xf), MCA_ADAPTER_SETUP_REG);
  299. if(!mca_read_and_store_pos(pos))
  300. continue;
  301. mca_dev = kzalloc(sizeof(struct mca_device), GFP_ATOMIC);
  302. if(unlikely(!mca_dev))
  303. goto out_unlock_nomem;
  304. for(j=0; j<8; j++)
  305. mca_dev->pos[j]=pos[j];
  306. mca_dev->driver_loaded = 0;
  307. mca_dev->slot = i;
  308. mca_dev->pos_register = 0;
  309. mca_configure_adapter_status(mca_dev);
  310. mca_register_device(MCA_PRIMARY_BUS, mca_dev);
  311. }
  312. outb_p(0, MCA_ADAPTER_SETUP_REG);
  313. /* Enable interrupts and return memory start */
  314. spin_unlock_irq(&mca_lock);
  315. for (i = 0; i < MCA_STANDARD_RESOURCES; i++)
  316. request_resource(&ioport_resource, mca_standard_resources + i);
  317. mca_do_proc_init();
  318. return 0;
  319. out_unlock_nomem:
  320. spin_unlock_irq(&mca_lock);
  321. out_nomem:
  322. printk(KERN_EMERG "Failed memory allocation in MCA setup!\n");
  323. return -ENOMEM;
  324. }
  325. subsys_initcall(mca_init);
  326. /*--------------------------------------------------------------------*/
  327. static __kprobes void
  328. mca_handle_nmi_device(struct mca_device *mca_dev, int check_flag)
  329. {
  330. int slot = mca_dev->slot;
  331. if(slot == MCA_INTEGSCSI) {
  332. printk(KERN_CRIT "NMI: caused by MCA integrated SCSI adapter (%s)\n",
  333. mca_dev->name);
  334. } else if(slot == MCA_INTEGVIDEO) {
  335. printk(KERN_CRIT "NMI: caused by MCA integrated video adapter (%s)\n",
  336. mca_dev->name);
  337. } else if(slot == MCA_MOTHERBOARD) {
  338. printk(KERN_CRIT "NMI: caused by motherboard (%s)\n",
  339. mca_dev->name);
  340. }
  341. /* More info available in POS 6 and 7? */
  342. if(check_flag) {
  343. unsigned char pos6, pos7;
  344. pos6 = mca_device_read_pos(mca_dev, 6);
  345. pos7 = mca_device_read_pos(mca_dev, 7);
  346. printk(KERN_CRIT "NMI: POS 6 = 0x%x, POS 7 = 0x%x\n", pos6, pos7);
  347. }
  348. } /* mca_handle_nmi_slot */
  349. /*--------------------------------------------------------------------*/
  350. static int __kprobes mca_handle_nmi_callback(struct device *dev, void *data)
  351. {
  352. struct mca_device *mca_dev = to_mca_device(dev);
  353. unsigned char pos5;
  354. pos5 = mca_device_read_pos(mca_dev, 5);
  355. if(!(pos5 & 0x80)) {
  356. /* Bit 7 of POS 5 is reset when this adapter has a hardware
  357. * error. Bit 7 it reset if there's error information
  358. * available in POS 6 and 7.
  359. */
  360. mca_handle_nmi_device(mca_dev, !(pos5 & 0x40));
  361. return 1;
  362. }
  363. return 0;
  364. }
  365. void __kprobes mca_handle_nmi(void)
  366. {
  367. /* First try - scan the various adapters and see if a specific
  368. * adapter was responsible for the error.
  369. */
  370. bus_for_each_dev(&mca_bus_type, NULL, NULL, mca_handle_nmi_callback);
  371. mca_nmi_hook();
  372. } /* mca_handle_nmi */